[CRT_APITEST] Add test for rand_s

This commit is contained in:
Timo Kreuzer 2024-04-19 20:27:51 +03:00
parent f319538d98
commit 3c55252828
4 changed files with 65 additions and 1 deletions

View file

@ -1137,7 +1137,7 @@ list(APPEND SOURCE_MSVCRT
# qsort_s
# raise.c
# rand.c
# rand_s.c
rand_s.c
# realloc.c
# remove.c
# rename.c

View file

@ -0,0 +1,61 @@
/*
* PROJECT: ReactOS API Tests
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Tests for rand_s
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <apitest.h>
#include <stdio.h>
#ifdef TEST_STATIC_CRT
errno_t __cdecl rand_s(_Out_ unsigned int* _RandomValue);
#endif
typedef int __cdecl rand_s_t(unsigned int*);
rand_s_t *p_rand_s;
void test_rand_s_performance(void)
{
unsigned long long start, end;
unsigned int val;
int i;
start = __rdtsc();
for (i = 0; i < 10000; i++)
{
p_rand_s(&val);
}
end = __rdtsc();
printf("rand_s took %llu cycles\n", end - start);
}
START_TEST(rand_s)
{
unsigned int val;
int ret;
#ifndef TEST_STATIC_CRT
/* Dynamically load rand_s from mvcrt */
HMODULE msvcrt = GetModuleHandleA("msvcrt");
p_rand_s = (rand_s_t*)GetProcAddress(msvcrt, "rand_s");
if (!p_rand_s)
{
win_skip("rand_s is not available\n");
return;
}
#else
p_rand_s = rand_s;
#endif
/* Test performance */
test_rand_s_performance();
/* Test with NULL pointer */
ret = p_rand_s(NULL);
ok(ret == EINVAL, "Expected EINVAL, got %d\n", ret);
/* Test with valid pointer */
ret = p_rand_s(&val);
ok(ret == 0, "Expected 0, got %d\n", ret);
}

View file

@ -13,6 +13,7 @@ list(APPEND SOURCE_STATIC
fpcontrol.c
mbstowcs.c
mbtowc.c
rand_s.c
sprintf.c
strcpy.c
strlen.c

View file

@ -32,6 +32,7 @@ extern void func__vsnprintf(void);
extern void func__vsnwprintf(void);
extern void func_mbstowcs(void);
extern void func_mbtowc(void);
extern void func_rand_s(void);
extern void func_sprintf(void);
extern void func_strcpy(void);
extern void func_strlen(void);
@ -79,6 +80,7 @@ const struct test winetest_testlist[] =
{ "ceil", func_ceil },
{ "fabs", func_fabs },
{ "floor", func_floor },
{ "rand_s", func_rand_s },
#ifdef _M_AMD64 // x86 / arm need fixing
{ "fpcontrol", func_fpcontrol },
#endif