ReactOS  0.4.14-dev-614-gbfd8a84
timer.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "mmsystem.h"
#include "mmreg.h"
#include "winmm_test.h"
Include dependency graph for timer.c:

Go to the source code of this file.

Macros

#define NOBITMAP
 
#define NUM_SAMPLES   100
 
#define STR(x)   case x: return #x
 

Functions

static void test_timeGetDevCaps (void)
 
static void CALLBACK testTimeProc (UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
 
static void test_timer (UINT period, UINT resolution)
 
static const charget_priority (int priority)
 
static void CALLBACK priorityTimeProc (UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
 
static void test_priority (void)
 
 START_TEST (timer)
 

Variables

static TIMECAPS tc
 
static DWORD count = 0
 
static DWORD times [NUM_SAMPLES]
 
static int priority = 0
 
static BOOL fired = FALSE
 

Macro Definition Documentation

◆ NOBITMAP

#define NOBITMAP

Definition at line 31 of file timer.c.

◆ NUM_SAMPLES

#define NUM_SAMPLES   100

Definition at line 66 of file timer.c.

◆ STR

#define STR (   x)    case x: return #x

Function Documentation

◆ get_priority()

static const char* get_priority ( int  priority)
static

Definition at line 146 of file timer.c.

147 {
148  static char tmp[32];
149 #define STR(x) case x: return #x
150  switch(priority) {
158  }
159  sprintf(tmp, "UNKNOWN(%d)", priority);
160  return tmp;
161 }
#define THREAD_PRIORITY_LOWEST
Definition: winbase.h:276
#define THREAD_PRIORITY_NORMAL
Definition: winbase.h:277
#define THREAD_PRIORITY_BELOW_NORMAL
Definition: winbase.h:273
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define THREAD_PRIORITY_ABOVE_NORMAL
Definition: winbase.h:272
#define THREAD_PRIORITY_HIGHEST
Definition: winbase.h:274
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:278
#define THREAD_PRIORITY_IDLE
Definition: winbase.h:275
#define STR(x)
static int priority
Definition: timer.c:163

Referenced by test_priority().

◆ priorityTimeProc()

static void CALLBACK priorityTimeProc ( UINT  uID,
UINT  uMsg,
DWORD_PTR  dwUser,
DWORD_PTR  dw1,
DWORD_PTR  dw2 
)
static

Definition at line 166 of file timer.c.

168 {
170  ok(priority!=THREAD_PRIORITY_ERROR_RETURN, "GetThreadPriority() failed, GetLastError() = %u\n", GetLastError());
171  fired = TRUE;
172 }
#define TRUE
Definition: types.h:120
#define THREAD_PRIORITY_ERROR_RETURN
Definition: winbase.h:279
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
static BOOL fired
Definition: timer.c:164
#define ok(value,...)
Definition: atltest.h:57
static int priority
Definition: timer.c:163
int WINAPI GetThreadPriority(IN HANDLE hThread)
Definition: thread.c:738

Referenced by test_priority().

◆ START_TEST()

START_TEST ( timer  )

Definition at line 196 of file timer.c.

197 {
199 
200  if (tc.wPeriodMin <= 1) {
201  test_timer(1, 0);
202  test_timer(1, 1);
203  }
204 
205  if (tc.wPeriodMin <= 10) {
206  test_timer(10, 0);
207  test_timer(10, 1);
208  test_timer(10, 10);
209  }
210 
211  if (tc.wPeriodMin <= 20) {
212  test_timer(20, 0);
213  test_timer(20, 1);
214  test_timer(20, 10);
215  test_timer(20, 20);
216  }
217 
218  test_priority();
219 }
static void test_timer(UINT period, UINT resolution)
Definition: timer.c:78
static void test_timeGetDevCaps(void)
Definition: timer.c:38
static void test_priority(void)
Definition: timer.c:174
const GLfloat * tc
Definition: glext.h:8925

◆ test_priority()

static void test_priority ( void  )
static

Definition at line 174 of file timer.c.

175 {
176  UINT id;
177 
178  id = timeSetEvent(100, 100, priorityTimeProc, 0, TIME_ONESHOT);
179  ok(id != 0, "timeSetEvent(100, 100, %p, 0, TIME_ONESHOT) returned %d, "
180  "should have returned id > 0\n", priorityTimeProc, id);
181  if (id == 0)
182  return;
183 
184  Sleep(200);
185 
186  ok(fired == TRUE, "Callback not called\n");
187  if (fired)
188  {
190  "thread priority is %s, should be THREAD_PRIORITY_TIME_CRITICAL\n",
192  }
193  timeKillEvent(id);
194 }
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
MMRESULT WINAPI timeSetEvent(UINT wDelay, UINT wResol, LPTIMECALLBACK lpFunc, DWORD_PTR dwUser, UINT wFlags)
Definition: time.c:359
MMRESULT WINAPI timeKillEvent(UINT wID)
Definition: time.c:369
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:278
static const char * get_priority(int priority)
Definition: timer.c:146
static BOOL fired
Definition: timer.c:164
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
GLenum GLuint id
Definition: glext.h:5579
static int priority
Definition: timer.c:163
static void CALLBACK priorityTimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
Definition: timer.c:166
#define TIME_ONESHOT
Definition: mmsystem.h:421

Referenced by START_TEST().

◆ test_timeGetDevCaps()

static void test_timeGetDevCaps ( void  )
static

Definition at line 38 of file timer.c.

39 {
40  MMRESULT rc;
41 
42  rc = timeGetDevCaps(&tc, 0);
43  ok(rc == TIMERR_NOCANDO || rc == MMSYSERR_INVALPARAM,
44  "timeGetDevCaps() returned %s, should have returned TIMERR_NOCANDO "
45  "or MMSYSERR_INVALPARAM\n", mmsys_error(rc));
46 
47  rc = timeGetDevCaps(0, sizeof(tc));
48  ok(rc == TIMERR_NOCANDO || rc == TIMERR_STRUCT,
49  "timeGetDevCaps() returned %s, should have returned TIMERR_NOCANDO "
50  "or TIMERR_STRUCT\n", mmsys_error(rc));
51 
52  rc = timeGetDevCaps(0, 0);
53  ok(rc == TIMERR_NOCANDO || rc == MMSYSERR_INVALPARAM,
54  "timeGetDevCaps() returned %s, should have returned TIMERR_NOCANDO "
55  "or MMSYSERR_INVALPARAM\n", mmsys_error(rc));
56 
57  rc = timeGetDevCaps(&tc, sizeof(tc));
58  ok(rc == TIMERR_NOERROR, "timeGetDevCaps() returned %s, "
59  "should have returned TIMERR_NOERROR\n", mmsys_error(rc));
60 
61  if (rc == TIMERR_NOERROR)
62  trace("wPeriodMin = %u, wPeriodMax = %u\n",
63  tc.wPeriodMin, tc.wPeriodMax);
64 }
MMRESULT WINAPI timeGetDevCaps(LPTIMECAPS lpCaps, UINT wSize)
Definition: time.c:400
#define TIMERR_NOERROR
Definition: mmsystem.h:418
UINT MMRESULT
Definition: mmsystem.h:962
#define TIMERR_NOCANDO
Definition: mmsystem.h:419
const GLfloat * tc
Definition: glext.h:8925
#define trace
Definition: atltest.h:70
const char * mmsys_error(MMRESULT error)
Definition: wave.c:220
#define MMSYSERR_INVALPARAM
Definition: mmsystem.h:107
#define ok(value,...)
Definition: atltest.h:57
#define TIMERR_STRUCT
Definition: mmsystem.h:420

Referenced by START_TEST().

◆ test_timer()

static void test_timer ( UINT  period,
UINT  resolution 
)
static

Definition at line 78 of file timer.c.

79 {
80  MMRESULT rc;
81  UINT i, id, delta;
82  DWORD dwMin = 0xffffffff, dwMax = 0;
83  double sum = 0.0;
84  double deviation = 0.0;
85 
86  count = 0;
87 
88  for (i = 0; i < NUM_SAMPLES; i++)
89  times[i] = 0;
90 
91  rc = timeBeginPeriod(period);
92  ok(rc == TIMERR_NOERROR, "timeBeginPeriod(%u) returned %s, "
93  "should have returned TIMERR_NOERROR\n", period, mmsys_error(rc));
94  if (rc != TIMERR_NOERROR)
95  return;
96 
97  id = timeSetEvent(period, resolution, testTimeProc, 0, TIME_PERIODIC);
98  ok(id != 0, "timeSetEvent(%u, %u, %p, 0, TIME_PERIODIC) returned %d, "
99  "should have returned id > 0\n", period, resolution, testTimeProc, id);
100  if (id == 0)
101  return;
102 
103  Sleep((NUM_SAMPLES * period) + (2 * period));
104 
105  rc = timeEndPeriod(period);
106  ok(rc == TIMERR_NOERROR, "timeEndPeriod(%u) returned %s, "
107  "should have returned TIMERR_NOERROR\n", period, mmsys_error(rc));
108  if (rc != TIMERR_NOERROR)
109  return;
110 
111  rc = timeKillEvent(id);
112  ok(rc == TIMERR_NOERROR, "timeKillEvent(%u) returned %s, "
113  "should have returned TIMERR_NOERROR\n", id, mmsys_error(rc));
114 
115  trace("period = %u, resolution = %u\n", period, resolution);
116 
117  for (i = 0; i < count; i++)
118  {
119  if (i == 0)
120  {
121  if (winetest_debug > 1)
122  trace("time[%d] = %u\n", i, times[i]);
123  }
124  else
125  {
126  delta = times[i] - times[i - 1];
127 
128  if (winetest_debug > 1)
129  trace("time[%d] = %u delta = %d\n", i, times[i], delta);
130 
131  sum += delta;
132  deviation += ((delta - period) * (delta - period));
133 
134  if (delta < dwMin)
135  dwMin = delta;
136 
137  if (delta > dwMax)
138  dwMax = delta;
139  }
140  }
141 
142  trace("min = %u, max = %u, average = %f, standard deviation = %f\n",
143  dwMin, dwMax, sum / (count - 1), sqrt(deviation / (count - 2)));
144 }
_STLP_DECLSPEC complex< float > _STLP_CALL sqrt(const complex< float > &)
Definition: complex.cpp:188
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define TIMERR_NOERROR
Definition: mmsystem.h:418
static DWORD count
Definition: timer.c:68
GLuint GLuint GLsizei count
Definition: gl.h:1545
MMRESULT WINAPI timeEndPeriod(UINT wPeriod)
Definition: time.c:438
UINT MMRESULT
Definition: mmsystem.h:962
int winetest_debug
MMRESULT WINAPI timeSetEvent(UINT wDelay, UINT wResol, LPTIMECALLBACK lpFunc, DWORD_PTR dwUser, UINT wFlags)
Definition: time.c:359
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NUM_SAMPLES
Definition: timer.c:66
MMRESULT WINAPI timeKillEvent(UINT wID)
Definition: time.c:369
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
#define trace
Definition: atltest.h:70
unsigned long DWORD
Definition: ntddk_ex.h:95
MMRESULT WINAPI timeBeginPeriod(UINT wPeriod)
Definition: time.c:422
const char * mmsys_error(MMRESULT error)
Definition: wave.c:220
static void CALLBACK testTimeProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
Definition: timer.c:71
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
static DWORD times[NUM_SAMPLES]
Definition: timer.c:69
GLenum GLuint id
Definition: glext.h:5579
#define TIME_PERIODIC
Definition: mmsystem.h:422

Referenced by START_TEST().

◆ testTimeProc()

static void CALLBACK testTimeProc ( UINT  uID,
UINT  uMsg,
DWORD_PTR  dwUser,
DWORD_PTR  dw1,
DWORD_PTR  dw2 
)
static

Definition at line 71 of file timer.c.

73 {
74  if (count < NUM_SAMPLES)
75  times[count++] = timeGetTime();
76 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define NUM_SAMPLES
Definition: timer.c:66
DWORD WINAPI timeGetTime(void)
Definition: time.c:454
static DWORD times[NUM_SAMPLES]
Definition: timer.c:69

Referenced by test_timer().

Variable Documentation

◆ count

DWORD count = 0
static

Definition at line 68 of file timer.c.

Referenced by test_timer().

◆ fired

BOOL fired = FALSE
static

Definition at line 164 of file timer.c.

Referenced by priorityTimeProc(), and test_priority().

◆ priority

int priority = 0
static

Definition at line 163 of file timer.c.

Referenced by bind_callback_GetPriority(), BindProtocol_StartEx(), component_SetCurrentPriority(), d3d8_indexbuffer_GetPriority(), d3d8_indexbuffer_SetPriority(), d3d8_texture_2d_SetPriority(), d3d8_texture_3d_SetPriority(), d3d8_texture_cube_SetPriority(), d3d8_vertexbuffer_GetPriority(), d3d8_vertexbuffer_SetPriority(), d3d9_device_GetGPUThreadPriority(), d3d9_device_SetGPUThreadPriority(), d3d9_indexbuffer_GetPriority(), d3d9_indexbuffer_SetPriority(), d3d9_surface_SetPriority(), d3d9_texture_2d_SetPriority(), d3d9_texture_3d_SetPriority(), d3d9_texture_cube_SetPriority(), d3d9_vertexbuffer_GetPriority(), d3d9_vertexbuffer_SetPriority(), d3dx9_animation_controller_SetTrackPriority(), ddraw_surface7_GetPriority(), ddraw_surface7_SetPriority(), DECLARE_INTERFACE_(), do_test_about_protocol(), do_write_file(), do_write_file_prealloc(), DoSetPriority(), downloadcb_GetPriority(), get_priority(), IDirectPlay4AImpl_SendEx(), IDirectPlay4Impl_SendEx(), InstallEngine_SetAction(), InternetSetOptionW(), iso9660_file_length(), map_user_buffer(), midi_IDirectMusicPort_GetChannelPriority(), midi_IDirectMusicPort_SetChannelPriority(), prepare_raid5_write(), prepare_raid6_write(), priorityTimeProc(), read_data(), SynthPortImpl_IDirectMusicPort_GetChannelPriority(), SynthPortImpl_IDirectMusicPort_SetChannelPriority(), TCPSleep(), test_CreateBinding(), test_priority(), test_query_process_priority(), test_res_protocol(), timelinegrp_GetPriority(), wined3d_resource_set_priority(), write_data(), write_data_complete(), xsltAddTemplate(), xsltGetTemplate(), and xsltParseStylesheetTemplate().

◆ tc

TIMECAPS tc
static

Definition at line 36 of file timer.c.

◆ times

DWORD times[NUM_SAMPLES]
static

Definition at line 69 of file timer.c.

Referenced by test_timer(), and testTimeProc().