1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for NtQueryTimerResolution and NtSetTimerResolution. 5 * PROGRAMMER: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> 6 */ 7 8 #include "precomp.h" 9 10 START_TEST(TimerResolution) 11 { 12 NTSTATUS Status; 13 ULONG CurrentResolution; 14 ULONG MinimumResolution; 15 ULONG MaximumResolution; 16 ULONG CurrentResolution2; 17 18 /* Get the current timer resolution */ 19 Status = NtSetTimerResolution(0, /* Ignored */ 20 FALSE, /* Don't change resolution */ 21 &CurrentResolution); 22 23 /* 24 * If the timer resolution hasn't been changed for this process, 25 * it returns STATUS_TIMER_RESOLUTION_NOT_SET 26 */ 27 ok_hex(Status, STATUS_TIMER_RESOLUTION_NOT_SET); 28 29 /* 30 * Get the timer resolution limits and current timer resolution 31 * using a different method 32 */ 33 Status = NtQueryTimerResolution(&MinimumResolution, 34 &MaximumResolution, 35 &CurrentResolution2); 36 37 /* This function should always return STATUS_SUCCESS */ 38 ok_hex(Status, STATUS_SUCCESS); 39 40 /* The MinimumResolution should be higher than the MaximumResolution */ 41 ok(MinimumResolution >= MaximumResolution, "MaximumResolution higher than MinimumResolution!\n"); 42 43 /* These two values should be the same */ 44 ok_hex(CurrentResolution, CurrentResolution2); 45 46 /* 47 * Even if you give it invalid values, 48 * NtSetTimerResolution will return STATUS_SUCCESS, 49 * but it will not change the resolution. 50 */ 51 Status = NtSetTimerResolution(MinimumResolution + 1, 52 TRUE, 53 &CurrentResolution); 54 ok_hex(Status, STATUS_SUCCESS); 55 printf("Current resolution: %lu ; minimum resolution: %lu\n", CurrentResolution, MinimumResolution); 56 ok(CurrentResolution <= MinimumResolution, "Current resolution: %lu became too high! (minimum resolution: %lu)\n", CurrentResolution, MinimumResolution); 57 58 Status = NtSetTimerResolution(MaximumResolution - 1, 59 TRUE, 60 &CurrentResolution); 61 ok_hex(Status, STATUS_SUCCESS); 62 printf("Current resolution: %lu ; maximum resolution: %lu\n", CurrentResolution, MaximumResolution); 63 #if 0 // Why? This doesn't hold true on Windows Server 2003. 64 ok(abs((LONG)MaximumResolution - (LONG)CurrentResolution) < 200, "Current resolution: %lu became too low! (maximum resolution: %lu)\n", CurrentResolution, MaximumResolution); 65 #endif 66 67 /* Get the current timer resolution */ 68 Status = NtSetTimerResolution(0, /* Ignored */ 69 FALSE, /* Don't change resolution */ 70 &CurrentResolution); 71 72 /* Since we have changed the resolution earlier, it returns STATUS_SUCCESS. */ 73 ok_hex(Status, STATUS_SUCCESS); 74 75 /* Get the current timer resolution again */ 76 Status = NtSetTimerResolution(0, /* Ignored */ 77 FALSE, /* Don't change resolution */ 78 &CurrentResolution); 79 80 /* The resolution is not changed now, so it should return STATUS_TIMER_RESOLUTION_NOT_SET */ 81 ok_hex(Status, STATUS_TIMER_RESOLUTION_NOT_SET); 82 } 83