2013-08-19 21:44:26 +00:00
/*
* PROJECT : ReactOS API tests
* LICENSE : GPL - See COPYING in the top level directory
* PURPOSE : Test for NtQueryTimerResolution and NtSetTimerResolution .
* PROGRAMMER : Aleksandar Andrejevic < theflash AT sdf DOT lonestar DOT org >
*/
2017-12-02 20:05:46 +00:00
# include "precomp.h"
2013-08-19 21:44:26 +00:00
START_TEST ( TimerResolution )
{
NTSTATUS Status ;
ULONG CurrentResolution ;
ULONG MinimumResolution ;
ULONG MaximumResolution ;
ULONG CurrentResolution2 ;
/* Get the current timer resolution */
Status = NtSetTimerResolution ( 0 , /* Ignored */
FALSE , /* Don't change resolution */
& CurrentResolution ) ;
/*
2013-08-20 18:55:42 +00:00
* If the timer resolution hasn ' t been changed for this process ,
* it returns STATUS_TIMER_RESOLUTION_NOT_SET
2013-08-19 21:44:26 +00:00
*/
ok_hex ( Status , STATUS_TIMER_RESOLUTION_NOT_SET ) ;
/*
* Get the timer resolution limits and current timer resolution
* using a different method
*/
Status = NtQueryTimerResolution ( & MinimumResolution ,
& MaximumResolution ,
& CurrentResolution2 ) ;
/* This function should always return STATUS_SUCCESS */
ok_hex ( Status , STATUS_SUCCESS ) ;
2013-08-20 18:55:42 +00:00
/* The MinimumResolution should be higher than the MaximumResolution */
2013-08-21 11:14:22 +00:00
ok ( MinimumResolution > = MaximumResolution , " MaximumResolution higher than MinimumResolution! \n " ) ;
2013-08-20 18:55:42 +00:00
2013-08-19 21:44:26 +00:00
/* These two values should be the same */
ok_hex ( CurrentResolution , CurrentResolution2 ) ;
/*
* Even if you give it invalid values ,
* NtSetTimerResolution will return STATUS_SUCCESS ,
* but it will not change the resolution .
*/
2013-08-20 18:55:42 +00:00
Status = NtSetTimerResolution ( MinimumResolution + 1 ,
2013-08-19 21:44:26 +00:00
TRUE ,
& CurrentResolution ) ;
ok_hex ( Status , STATUS_SUCCESS ) ;
2014-03-26 12:07:25 +00:00
printf ( " Current resolution: %lu ; minimum resolution: %lu \n " , CurrentResolution , MinimumResolution ) ;
ok ( CurrentResolution < = MinimumResolution , " Current resolution: %lu became too high! (minimum resolution: %lu) \n " , CurrentResolution , MinimumResolution ) ;
2013-08-19 21:44:26 +00:00
2013-08-20 18:55:42 +00:00
Status = NtSetTimerResolution ( MaximumResolution - 1 ,
2013-08-19 21:44:26 +00:00
TRUE ,
& CurrentResolution ) ;
ok_hex ( Status , STATUS_SUCCESS ) ;
2014-03-26 12:07:25 +00:00
printf ( " Current resolution: %lu ; maximum resolution: %lu \n " , CurrentResolution , MaximumResolution ) ;
2019-12-09 16:16:02 +00:00
ok ( abs ( ( LONG ) MaximumResolution - ( LONG ) CurrentResolution ) < 200 , " Current resolution: %lu became too low! (maximum resolution: %lu) \n " , CurrentResolution , MaximumResolution ) ;
2013-08-20 18:55:42 +00:00
/* Get the current timer resolution */
Status = NtSetTimerResolution ( 0 , /* Ignored */
FALSE , /* Don't change resolution */
& CurrentResolution ) ;
/* Since we have changed the resolution earlier, it returns STATUS_SUCCESS. */
ok_hex ( Status , STATUS_SUCCESS ) ;
2013-09-28 09:55:29 +00:00
/* Get the current timer resolution again */
Status = NtSetTimerResolution ( 0 , /* Ignored */
FALSE , /* Don't change resolution */
& CurrentResolution ) ;
/* The resolution is not changed now, so it should return STATUS_TIMER_RESOLUTION_NOT_SET */
ok_hex ( Status , STATUS_TIMER_RESOLUTION_NOT_SET ) ;
2013-08-19 21:44:26 +00:00
}