diff --git a/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake b/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake index 0d1984b5d17..ad599eed3a3 100644 --- a/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake +++ b/modules/rostests/apitests/crt/msvcrt_crt_apitest.cmake @@ -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 diff --git a/modules/rostests/apitests/crt/rand_s.c b/modules/rostests/apitests/crt/rand_s.c new file mode 100644 index 00000000000..5825f0031df --- /dev/null +++ b/modules/rostests/apitests/crt/rand_s.c @@ -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 + */ + +#include +#include + +#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); +} diff --git a/modules/rostests/apitests/crt/static_crt_apitest.cmake b/modules/rostests/apitests/crt/static_crt_apitest.cmake index eb84fd5b145..78f4487ec2f 100644 --- a/modules/rostests/apitests/crt/static_crt_apitest.cmake +++ b/modules/rostests/apitests/crt/static_crt_apitest.cmake @@ -13,6 +13,7 @@ list(APPEND SOURCE_STATIC fpcontrol.c mbstowcs.c mbtowc.c + rand_s.c sprintf.c strcpy.c strlen.c diff --git a/modules/rostests/apitests/crt/testlist.c b/modules/rostests/apitests/crt/testlist.c index e1592928611..331c368f114 100644 --- a/modules/rostests/apitests/crt/testlist.c +++ b/modules/rostests/apitests/crt/testlist.c @@ -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