diff --git a/.gitignore b/.gitignore index ef649e1..24cf74c 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,5 @@ Module.symvers Mkfile.old dkms.conf -cmake*/ \ No newline at end of file +cmake*/ +.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ab3a98..fee9ddf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,11 +20,15 @@ set(original_run_e2e_tests ${run_e2e_tests}) set(original_run_unittests ${run_unittests}) set(original_run_int_tests ${run_int_tests}) set(original_run_traceability ${run_traceability}) +set(original_run_perf_tests ${run_perf_tests}) + set(run_e2e_tests OFF) set(run_unittests OFF) set(run_int_tests OFF) set(run_traceability OFF) +set(run_perf_tests OFF) + if ((NOT TARGET azure_c_build_tools) AND (EXISTS ${CMAKE_CURRENT_LIST_DIR}/deps/azure-c-build-tools/CMakeLists.txt)) add_subdirectory(deps/azure-c-build-tools) @@ -63,6 +67,7 @@ set(run_e2e_tests ${original_run_e2e_tests}) set(run_unittests ${original_run_unittests}) set(run_int_tests ${original_run_int_tests}) set(run_traceability ${original_run_traceability}) +set(run_perf_tests ${original_run_perf_tests}) add_subdirectory(interfaces) add_subdirectory(common) @@ -93,5 +98,12 @@ if((WIN32) AND (${run_traceability})) add_dependencies(azure_c_pal_traceability traceabilitytool) endif() +add_library(azure_c_pal_reals INTERFACE) +if(MSVC) + target_link_libraries(azure_c_pal_reals INTERFACE reals_win32) +else() + target_link_libraries(azure_c_pal_reals INTERFACE reals_linux) +endif() + include(CMakePackageConfigHelpers) diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index 2967e7b..bf8f582 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -25,6 +25,5 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/inc) include_directories(${MACRO_UTILS_INC_FOLDER}) add_library(pal_interfaces INTERFACE) -#target_sources(pal_interfaces INTERFACE ${pal_interfaces_md_files} ${pal_interfaces_h_files}) target_include_directories(pal_interfaces INTERFACE ${CMAKE_CURRENT_LIST_DIR}/inc) add_subdirectory(tests) diff --git a/interfaces/tests/CMakeLists.txt b/interfaces/tests/CMakeLists.txt index cfb4394..17a530c 100644 --- a/interfaces/tests/CMakeLists.txt +++ b/interfaces/tests/CMakeLists.txt @@ -1,5 +1,7 @@ #Copyright (C) Microsoft Corporation. All rights reserved. +add_subdirectory(reals) + if(${run_ut_tests}) add_subdirectory(lock_ut) endif() diff --git a/interfaces/tests/reals/CMakeLists.txt b/interfaces/tests/reals/CMakeLists.txt new file mode 100644 index 0000000..5c68fd0 --- /dev/null +++ b/interfaces/tests/reals/CMakeLists.txt @@ -0,0 +1,27 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cmake_minimum_required(VERSION 2.8.11) + +set(reals_pal_interface_h_files + real_threadapi.h + real_threadapi_renames.h +) + +if(WIN32) +set(reals_pal_interface_h_files ${reals_pal_interface_h_files} + real_interlocked_hl.h + real_interlocked_hl_renames.h + real_srw_lock.h + real_srw_lock_renames.h + real_string_utils.h + real_string_utils_renames.h + real_timer.h + real_timer_renames.h +) +else() +endif() + +add_library(reals_pal_interface INTERFACE) +target_include_directories(reals_pal_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR}) +target_link_libraries(reals_pal_interface INTERFACE azure_c_logging pal_common) diff --git a/interfaces/tests/reals/real_interlocked_hl.h b/interfaces/tests/reals/real_interlocked_hl.h new file mode 100644 index 0000000..36ce567 --- /dev/null +++ b/interfaces/tests/reals/real_interlocked_hl.h @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef REAL_INTERLOCKED_HL_H +#define REAL_INTERLOCKED_HL_H + +#include "azure_macro_utils/macro_utils.h" + +#include "windows.h" + +#define R2(X) REGISTER_GLOBAL_MOCK_HOOK(X, real_##X); + +#define REGISTER_INTERLOCKED_HL_GLOBAL_MOCK_HOOK() \ + MU_FOR_EACH_1(R2, \ + InterlockedHL_Add64WithCeiling, \ + InterlockedHL_WaitForValue, \ + InterlockedHL_WaitForNotValue, \ + InterlockedHL_SetAndWake, \ + InterlockedHL_CompareExchange64If \ + ) + +#include "interlocked_hl.h" + +#ifdef __cplusplus +extern "C" { +#endif + + INTERLOCKED_HL_RESULT real_InterlockedHL_Add64WithCeiling(LONGLONG volatile * Addend, LONGLONG Ceiling, LONGLONG Value, LONGLONG* originalAddend); + INTERLOCKED_HL_RESULT real_InterlockedHL_WaitForValue(LONG volatile* address, LONG value, DWORD milliseconds); + INTERLOCKED_HL_RESULT real_InterlockedHL_WaitForValue64(LONG64 volatile* address, LONG64 value, DWORD milliseconds); + INTERLOCKED_HL_RESULT real_InterlockedHL_WaitForNotValue(LONG volatile* address, LONG value, DWORD milliseconds); + INTERLOCKED_HL_RESULT real_InterlockedHL_SetAndWake(LONG volatile* address, LONG value); + INTERLOCKED_HL_RESULT real_InterlockedHL_CompareExchange64If(LONG64 volatile* target, LONG64 exchange, INTERLOCKED_COMPARE_EXCHANGE_64_IF compare, LONG64* original_target); + +#ifdef __cplusplus +} +#endif + +#endif //REAL_INTERLOCKED_HL_H diff --git a/interfaces/tests/reals/real_interlocked_hl_renames.h b/interfaces/tests/reals/real_interlocked_hl_renames.h new file mode 100644 index 0000000..3083b6a --- /dev/null +++ b/interfaces/tests/reals/real_interlocked_hl_renames.h @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define InterlockedHL_Add64WithCeiling real_InterlockedHL_Add64WithCeiling +#define InterlockedHL_WaitForValue real_InterlockedHL_WaitForValue +#define InterlockedHL_WaitForValue64 real_InterlockedHL_WaitForValue64 +#define InterlockedHL_WaitForNotValue real_InterlockedHL_WaitForNotValue +#define InterlockedHL_SetAndWake real_InterlockedHL_SetAndWake +#define InterlockedHL_CompareExchange64If real_InterlockedHL_CompareExchange64If + +#define INTERLOCKED_HL_RESULT real_INTERLOCKED_HL_RESULT diff --git a/interfaces/tests/reals/real_srw_lock.h b/interfaces/tests/reals/real_srw_lock.h new file mode 100644 index 0000000..b1cf08b --- /dev/null +++ b/interfaces/tests/reals/real_srw_lock.h @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef REAL_SRW_LOCK_H +#define REAL_SRW_LOCK_H + +#ifdef __cplusplus +#include +#else +#include +#endif + +#include "azure_macro_utils/macro_utils.h" + +#include "srw_lock.h" + +#define R2(X) REGISTER_GLOBAL_MOCK_HOOK(X, real_##X); + +#define REGISTER_SRW_LOCK_GLOBAL_MOCK_HOOK() \ + MU_FOR_EACH_1(R2, \ + srw_lock_create, \ + srw_lock_destroy, \ + srw_lock_acquire_exclusive, \ + srw_lock_release_exclusive, \ + srw_lock_acquire_shared, \ + srw_lock_release_shared \ +) + +#ifdef __cplusplus +extern "C" { +#endif + + +SRW_LOCK_HANDLE real_srw_lock_create(bool do_statistics, const char* lock_name); + +void real_srw_lock_destroy(SRW_LOCK_HANDLE handle); + +void real_srw_lock_acquire_exclusive(SRW_LOCK_HANDLE handle); + +void real_srw_lock_release_exclusive(SRW_LOCK_HANDLE handle); + +void real_srw_lock_acquire_shared(SRW_LOCK_HANDLE handle); + +void real_srw_lock_release_shared(SRW_LOCK_HANDLE handle); + +#ifdef __cplusplus +} +#endif + +#endif // REAL_SRW_LOCK_H diff --git a/interfaces/tests/reals/real_srw_lock_renames.h b/interfaces/tests/reals/real_srw_lock_renames.h new file mode 100644 index 0000000..bed455f --- /dev/null +++ b/interfaces/tests/reals/real_srw_lock_renames.h @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define srw_lock_create real_srw_lock_create +#define srw_lock_destroy real_srw_lock_destroy +#define srw_lock_acquire_exclusive real_srw_lock_acquire_exclusive +#define srw_lock_release_exclusive real_srw_lock_release_exclusive +#define srw_lock_acquire_shared real_srw_lock_acquire_shared +#define srw_lock_release_shared real_srw_lock_release_shared diff --git a/interfaces/tests/reals/real_string_utils.h b/interfaces/tests/reals/real_string_utils.h new file mode 100644 index 0000000..a5da99d --- /dev/null +++ b/interfaces/tests/reals/real_string_utils.h @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef REAL_STRING_UTILS_H +#define REAL_STRING_UTILS_H + +#ifdef __cplusplus +#include +#else +#include +#endif + +#include "azure_macro_utils/macro_utils.h" + +#include "srw_lock.h" + +#define R2(X) REGISTER_GLOBAL_MOCK_HOOK(X, real_##X); + +#define REGISTER_STRING_UTILS_GLOBAL_MOCK_HOOK() \ + MU_FOR_EACH_1(R2, \ + sprintf_char_function, \ + sprintf_wchar_function, \ + vsprintf_char, \ + vsprintf_wchar, \ + FILETIME_toAsciiArray, \ + mbs_to_wcs, \ + wcs_to_mbs \ +) + +#ifdef __cplusplus +extern "C" { +#endif + +#include "windows.h" + +char* real_sprintf_char_function(const char* format, ...); + +wchar_t* real_sprintf_wchar_function(const wchar_t* format, ...); + +char* real_vsprintf_char(const char* format, va_list va); + +wchar_t* real_vsprintf_wchar(const wchar_t* format, va_list va); + +char* real_FILETIME_toAsciiArray(const FILETIME* fileTime); + +wchar_t* real_mbs_to_wcs(const char* source); + +char* real_wcs_to_mbs(const wchar_t* source); + +#ifdef __cplusplus +} +#endif + +#endif // REAL_STRING_UTILS_H diff --git a/interfaces/tests/reals/real_string_utils_renames.h b/interfaces/tests/reals/real_string_utils_renames.h new file mode 100644 index 0000000..8e60b28 --- /dev/null +++ b/interfaces/tests/reals/real_string_utils_renames.h @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define sprintf_char_function real_sprintf_char_function +#define sprintf_wchar_function real_sprintf_wchar_function +#define vsprintf_char real_vsprintf_char +#define vsprintf_wchar real_vsprintf_wchar +#define FILETIME_toAsciiArray real_FILETIME_toAsciiArray +#define mbs_to_wcs real_mbs_to_wcs +#define wcs_to_mbs real_wcs_to_mbs diff --git a/interfaces/tests/reals/real_threadapi.h b/interfaces/tests/reals/real_threadapi.h new file mode 100644 index 0000000..fbfd19c --- /dev/null +++ b/interfaces/tests/reals/real_threadapi.h @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef REAL_THREADAPI_H +#define REAL_THREADAPI_H + +#include "azure_macro_utils/macro_utils.h" + +#include "threadapi.h" + +#define R2(X) REGISTER_GLOBAL_MOCK_HOOK(X, real_##X); + +#define REGISTER_THREADAPI_GLOBAL_MOCK_HOOK() \ + MU_FOR_EACH_1(R2, \ + ThreadAPI_Create, \ + ThreadAPI_Join, \ + ThreadAPI_Exit, \ + ThreadAPI_Sleep \ +) + +#ifdef __cplusplus +extern "C" { +#endif + +THREADAPI_RESULT real_ThreadAPI_Create(THREAD_HANDLE* threadHandle, THREAD_START_FUNC func, void* arg); + +THREADAPI_RESULT real_ThreadAPI_Join(THREAD_HANDLE threadHandle, int* res); + +void real_ThreadAPI_Exit(int res); + +void real_ThreadAPI_Sleep(unsigned int milliseconds); + +#ifdef __cplusplus +} +#endif + +#endif // REAL_THREADAPI_H diff --git a/interfaces/tests/reals/real_threadapi_renames.h b/interfaces/tests/reals/real_threadapi_renames.h new file mode 100644 index 0000000..9beeed1 --- /dev/null +++ b/interfaces/tests/reals/real_threadapi_renames.h @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define ThreadAPI_Create real_ThreadAPI_Create +#define ThreadAPI_Join real_ThreadAPI_Join +#define ThreadAPI_Exit real_ThreadAPI_Exit +#define ThreadAPI_Sleep real_ThreadAPI_Sleep + +#define THREADAPI_RESULT real_THREADAPI_RESULT diff --git a/interfaces/tests/reals/real_timer.h b/interfaces/tests/reals/real_timer.h new file mode 100644 index 0000000..948e21c --- /dev/null +++ b/interfaces/tests/reals/real_timer.h @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef REAL_TIMER_H +#define REAL_TIMER_H + +#include "azure_macro_utils/macro_utils.h" + +#include "timer.h" + +#define R2(X) REGISTER_GLOBAL_MOCK_HOOK(X, real_##X); + +#define REGISTER_TIMER_GLOBAL_MOCK_HOOK() \ + MU_FOR_EACH_1(R2, \ + timer_create, \ + timer_start, \ + timer_get_elapsed, \ + timer_global_get_elapsed_ms, \ + timer_destroy \ +) + +#ifdef __cplusplus +extern "C" { +#endif + + +TIMER_HANDLE real_timer_create(void); + +void real_timer_start(TIMER_HANDLE handle); + +double real_timer_get_elapsed(TIMER_HANDLE handle); + +double real_timer_get_elapsed_ms(TIMER_HANDLE handle); + +double real_timer_global_get_elapsed_ms(void); + +double real_timer_global_get_elapsed_us(void); + +void real_timer_destroy(TIMER_HANDLE handle); + +#ifdef __cplusplus +} +#endif + +#endif // REAL_TIMER_H diff --git a/interfaces/tests/reals/real_timer_renames.h b/interfaces/tests/reals/real_timer_renames.h new file mode 100644 index 0000000..f56a839 --- /dev/null +++ b/interfaces/tests/reals/real_timer_renames.h @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define timer_create real_timer_create +#define timer_start real_timer_start +#define timer_get_elapsed real_timer_get_elapsed +#define timer_get_elapsed_ms real_timer_get_elapsed_ms +#define timer_destroy real_timer_destroy +#define timer_global_get_elapsed_ms real_timer_global_get_elapsed_ms +#define timer_global_get_elapsed_us real_timer_global_get_elapsed_us diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 28ae860..ef51095 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -18,7 +18,7 @@ SOURCE_GROUP(devdoc FILES ${pal_linux_md_files}) include_directories(${CMAKE_CURRENT_LIST_DIR}/inc) add_library(pal_linux ${pal_linux_h_files} ${pal_linux_c_files} ${pal_linux_md_files}) -target_link_libraries(pal_linux pal_interfaces) +target_link_libraries(pal_linux pal_interfaces pthread m rt uuid) target_include_directories(pal_linux PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc) add_subdirectory(tests) diff --git a/linux/tests/CMakeLists.txt b/linux/tests/CMakeLists.txt index 843a064..a8477ce 100644 --- a/linux/tests/CMakeLists.txt +++ b/linux/tests/CMakeLists.txt @@ -1,9 +1,11 @@ #Copyright (C) Microsoft Corporation. All rights reserved. +add_subdirectory(reals_linux) # unit tests if(${run_unittests}) add_subdirectory(interlocked_linux_ut) add_subdirectory(uniqueid_ut) + add_subdirectory(reals_linux_ut) endif() if(${run_int_tests}) diff --git a/linux/tests/reals_linux/CMakeLists.txt b/linux/tests/reals_linux/CMakeLists.txt new file mode 100644 index 0000000..d884f0e --- /dev/null +++ b/linux/tests/reals_linux/CMakeLists.txt @@ -0,0 +1,12 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cmake_minimum_required(VERSION 2.8.11) + +set(reals_linux_c_files + real_threadapi_linux.c +) + +include_directories(${CMAKE_CURRENT_LIST_DIR}/../../src) +add_library(reals_linux ${reals_linux_c_files}) +target_link_libraries(reals_linux reals_pal_interface) diff --git a/linux/tests/reals_linux/real_threadapi_linux.c b/linux/tests/reals_linux/real_threadapi_linux.c new file mode 100644 index 0000000..28b4dd0 --- /dev/null +++ b/linux/tests/reals_linux/real_threadapi_linux.c @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define GBALLOC_H + +#include "real_threadapi_renames.h" + +#include "threadapi_pthreads.c" + diff --git a/linux/tests/reals_linux_ut/CMakeLists.txt b/linux/tests/reals_linux_ut/CMakeLists.txt new file mode 100644 index 0000000..72431a4 --- /dev/null +++ b/linux/tests/reals_linux_ut/CMakeLists.txt @@ -0,0 +1,10 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set(theseTestsName reals_linux_ut) + +set(${theseTestsName}_test_files + ${theseTestsName}.c +) + +build_c_tests(${theseTestsName} ON "tests/azure_c_pal/linux" ADDITIONAL_LIBS pal_linux reals_linux) diff --git a/linux/tests/reals_linux_ut/main.c b/linux/tests/reals_linux_ut/main.c new file mode 100644 index 0000000..70fff65 --- /dev/null +++ b/linux/tests/reals_linux_ut/main.c @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include +#include "testrunnerswitcher.h" + +int main(void) +{ + size_t failedTestCount = 0; + RUN_TEST_SUITE(reals_linux_ut, failedTestCount); + return failedTestCount; +} diff --git a/linux/tests/reals_linux_ut/reals_linux_ut.c b/linux/tests/reals_linux_ut/reals_linux_ut.c new file mode 100644 index 0000000..963e6bb --- /dev/null +++ b/linux/tests/reals_linux_ut/reals_linux_ut.c @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include "testrunnerswitcher.h" + +#define REGISTER_GLOBAL_MOCK_HOOK(original, real) \ + (original == real) ? (void)0 : (void)1; + +#include "threadapi.h" + +#include "real_threadapi.h" + +BEGIN_TEST_SUITE(reals_linux_ut) + +// this test makes sure that the mappings work +// (there is a real_ function corresponding to the original) +TEST_FUNCTION(check_all_c_pal_reals) +{ + // arrange + + // act + REGISTER_THREADAPI_GLOBAL_MOCK_HOOK(); + + // assert + // no explicit assert, if it builds it works +} + +END_TEST_SUITE(reals_linux_ut) diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt index dffaf41..c9bad0f 100644 --- a/win32/CMakeLists.txt +++ b/win32/CMakeLists.txt @@ -26,7 +26,7 @@ SOURCE_GROUP(devdoc FILES ${pal_win32_md_files}) include_directories(${CMAKE_CURRENT_LIST_DIR}/inc) add_library(pal_win32 ${pal_win32_h_files} ${pal_win32_c_files} ${pal_win32_md_files}) -target_link_libraries(pal_win32 pal_interfaces pal_common ws2_32 synchronization) +target_link_libraries(pal_win32 pal_interfaces pal_common ws2_32 synchronization rpcrt4 azure_c_logging) target_include_directories(pal_win32 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc) add_subdirectory(tests) diff --git a/win32/src/string_utils.c b/win32/src/string_utils.c index ca5d6a7..4487c72 100644 --- a/win32/src/string_utils.c +++ b/win32/src/string_utils.c @@ -8,9 +8,9 @@ #include "windows.h" #include "azure_macro_utils/macro_utils.h" -#include "gballoc.h" #include "azure_c_logging/xlogging.h" +#include "gballoc.h" #include "string_utils.h" IMPLEMENT_MOCKABLE_FUNCTION(, char*, vsprintf_char, const char*, format, va_list, va) diff --git a/win32/tests/CMakeLists.txt b/win32/tests/CMakeLists.txt index 38489ad..2e88a6b 100644 --- a/win32/tests/CMakeLists.txt +++ b/win32/tests/CMakeLists.txt @@ -1,5 +1,6 @@ #Copyright (C) Microsoft Corporation. All rights reserved. +add_subdirectory(reals_win32) # unit tests if(${run_unittests}) add_subdirectory(execution_engine_win32_ut) @@ -12,6 +13,7 @@ if(${run_unittests}) add_subdirectory(uniqueid_win32_ut) add_subdirectory(timer_win32_ut) add_subdirectory(srw_lock_win32_ut) + add_subdirectory(reals_win32_ut) endif() if(${run_int_tests}) diff --git a/win32/tests/reals_win32/CMakeLists.txt b/win32/tests/reals_win32/CMakeLists.txt new file mode 100644 index 0000000..76aa96a --- /dev/null +++ b/win32/tests/reals_win32/CMakeLists.txt @@ -0,0 +1,17 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cmake_minimum_required(VERSION 2.8.11) + + +set(reals_win32_c_files + real_threadapi.c + real_interlocked_hl_win32.c + real_srw_lock_win32.c + real_string_utils_win32.c + real_timer_win32.c +) + +include_directories(${CMAKE_CURRENT_LIST_DIR}/../../src) +add_library(reals_win32 ${reals_win32_c_files}) +target_link_libraries(reals_win32 reals_pal_interface) diff --git a/win32/tests/reals_win32/real_interlocked_hl_win32.c b/win32/tests/reals_win32/real_interlocked_hl_win32.c new file mode 100644 index 0000000..278646d --- /dev/null +++ b/win32/tests/reals_win32/real_interlocked_hl_win32.c @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft. All rights reserved. + +#define GBALLOC_H + +#include "real_interlocked_hl_renames.h" + +#include "interlocked_hl_win32.c" diff --git a/win32/tests/reals_win32/real_srw_lock_win32.c b/win32/tests/reals_win32/real_srw_lock_win32.c new file mode 100644 index 0000000..81d3355 --- /dev/null +++ b/win32/tests/reals_win32/real_srw_lock_win32.c @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define GBALLOC_H + +#include "real_string_utils_renames.h" +#include "real_timer_renames.h" + +#include "real_srw_lock_renames.h" + +#include "srw_lock_win32.c" diff --git a/win32/tests/reals_win32/real_string_utils_win32.c b/win32/tests/reals_win32/real_string_utils_win32.c new file mode 100644 index 0000000..b905f6c --- /dev/null +++ b/win32/tests/reals_win32/real_string_utils_win32.c @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define GBALLOC_H + +#include "real_string_utils_renames.h" + +#include "string_utils.c" diff --git a/win32/tests/reals_win32/real_threadapi.c b/win32/tests/reals_win32/real_threadapi.c new file mode 100644 index 0000000..9129d16 --- /dev/null +++ b/win32/tests/reals_win32/real_threadapi.c @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define GBALLOC_H + +#include "real_threadapi_renames.h" + +#include "threadapi_win32.c" + diff --git a/win32/tests/reals_win32/real_timer_win32.c b/win32/tests/reals_win32/real_timer_win32.c new file mode 100644 index 0000000..5ec1052 --- /dev/null +++ b/win32/tests/reals_win32/real_timer_win32.c @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#define GBALLOC_H + +#include "real_timer_renames.h" + +#include "timer.c" diff --git a/win32/tests/reals_win32_ut/CMakeLists.txt b/win32/tests/reals_win32_ut/CMakeLists.txt new file mode 100644 index 0000000..d376865 --- /dev/null +++ b/win32/tests/reals_win32_ut/CMakeLists.txt @@ -0,0 +1,10 @@ +#Copyright (c) Microsoft. All rights reserved. +#Licensed under the MIT license. See LICENSE file in the project root for full license information. + +set(theseTestsName reals_win32_ut) + +set(${theseTestsName}_test_files + ${theseTestsName}.c +) + +build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_win32 reals_win32) diff --git a/win32/tests/reals_win32_ut/main.c b/win32/tests/reals_win32_ut/main.c new file mode 100644 index 0000000..d71364f --- /dev/null +++ b/win32/tests/reals_win32_ut/main.c @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include +#include "testrunnerswitcher.h" + +int main(void) +{ + size_t failedTestCount = 0; + RUN_TEST_SUITE(reals_win32_ut, failedTestCount); + return failedTestCount; +} diff --git a/win32/tests/reals_win32_ut/reals_win32_ut.c b/win32/tests/reals_win32_ut/reals_win32_ut.c new file mode 100644 index 0000000..8a47890 --- /dev/null +++ b/win32/tests/reals_win32_ut/reals_win32_ut.c @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#include "testrunnerswitcher.h" + +#define REGISTER_GLOBAL_MOCK_HOOK(original, real) \ + (original == real) ? (void)0 : (void)1; + +#include "threadapi.h" +#include "srw_lock.h" +#include "string_utils.h" +#include "timer.h" +#include "interlocked_hl.h" + +#include "real_threadapi.h" +#include "real_srw_lock.h" +#include "real_string_utils.h" +#include "real_timer.h" +#include "real_interlocked_hl.h" + +BEGIN_TEST_SUITE(reals_win32_ut) + +// this test makes sure that the mappings work +// (there is a real_ function corresponding to the original) +TEST_FUNCTION(check_all_c_pal_reals) +{ + // arrange + + // act + REGISTER_THREADAPI_GLOBAL_MOCK_HOOK(); + REGISTER_SRW_LOCK_GLOBAL_MOCK_HOOK(); + REGISTER_STRING_UTILS_GLOBAL_MOCK_HOOK(); + REGISTER_TIMER_GLOBAL_MOCK_HOOK(); + REGISTER_INTERLOCKED_HL_GLOBAL_MOCK_HOOK(); + + // assert + // no explicit assert, if it builds it works +} + +END_TEST_SUITE(reals_win32_ut)