ReactOS 0.4.16-dev-106-g10b08aa
rand_s.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Tests for rand_s
5 * COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#include <apitest.h>
9#include <stdio.h>
10
11#ifdef TEST_STATIC_CRT
12errno_t __cdecl rand_s(_Out_ unsigned int* _RandomValue);
13#endif
14
15typedef int __cdecl rand_s_t(unsigned int*);
17
19{
20 unsigned long long start, end;
21 unsigned int val;
22 int i;
23
24 start = __rdtsc();
25 for (i = 0; i < 10000; i++)
26 {
27 p_rand_s(&val);
28 }
29 end = __rdtsc();
30 printf("rand_s took %llu cycles\n", end - start);
31}
32
34{
35 unsigned int val;
36 int ret;
37
38#ifndef TEST_STATIC_CRT
39 /* Dynamically load rand_s from mvcrt */
40 HMODULE msvcrt = GetModuleHandleA("msvcrt");
41 p_rand_s = (rand_s_t*)GetProcAddress(msvcrt, "rand_s");
42 if (!p_rand_s)
43 {
44 win_skip("rand_s is not available\n");
45 return;
46 }
47#else
49#endif
50
51 /* Test performance */
53
54 /* Test with NULL pointer */
55 ret = p_rand_s(NULL);
56 ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
57
58 /* Test with valid pointer */
59 ret = p_rand_s(&val);
60 ok(ret == 0, "Expected 0, got %d\n", ret);
61}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
int errno_t
Definition: crtdefs.h:374
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define printf
Definition: freeldr.h:97
GLuint start
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLuint GLfloat * val
Definition: glext.h:7180
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
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
int __cdecl rand_s_t(unsigned int *)
Definition: rand_s.c:15
rand_s_t * p_rand_s
Definition: rand_s.c:16
void test_rand_s_performance(void)
Definition: rand_s.c:18
#define _Out_
Definition: ms_sal.h:345
#define win_skip
Definition: test.h:163
int CDECL rand_s(unsigned int *pval)
Definition: rand_s.c:18
int ret