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 ok(CurrentResolution >= MaximumResolution, "Current resolution: %lu became too low! (maximum resolution: %lu)\n", CurrentResolution, MaximumResolution); 64 65 /* Get the current timer resolution */ 66 Status = NtSetTimerResolution(0, /* Ignored */ 67 FALSE, /* Don't change resolution */ 68 &CurrentResolution); 69 70 /* Since we have changed the resolution earlier, it returns STATUS_SUCCESS. */ 71 ok_hex(Status, STATUS_SUCCESS); 72 73 /* Get the current timer resolution again */ 74 Status = NtSetTimerResolution(0, /* Ignored */ 75 FALSE, /* Don't change resolution */ 76 &CurrentResolution); 77 78 /* The resolution is not changed now, so it should return STATUS_TIMER_RESOLUTION_NOT_SET */ 79 ok_hex(Status, STATUS_TIMER_RESOLUTION_NOT_SET); 80 } 81