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/reals/CMakeLists.txt b/interfaces/tests/reals/CMakeLists.txt new file mode 100644 index 0000000..996a10f --- /dev/null +++ b/interfaces/tests/reals/CMakeLists.txt @@ -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. + +cmake_minimum_required(VERSION 2.8.11) + +set(azure_c_pal_reals_h_files + real_threadapi.h + real_threadapi_renames.h +) + +if(WIN32) +set(azure_c_pal_reals_c_files ${azure_c_pal_reals_c_files} + ../../../win32/src/reals_win32/real_interlocked_hl_win32.c + ../../../win32/src/reals_win32/real_srw_lock_win32.c + ../../../win32/src/reals_win32/real_string_utils_win32.c + ../../../win32/src/reals_win32/real_timer_win32.c +) + +set(azure_c_pal_reals_h_files ${azure_c_pal_reals_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 +) +set(REALS_SRC_DIR ../../../win32/src/reals_win32) +else() +set(REALS_SRC_DIR ../../../linux/src/reals_linux) +endif() + + + +include_directories(${REALS_SRC_DIR}) +add_library(azure_c_pal_reals ${azure_c_pal_reals_c_files} ${azure_c_pal_reals_h_files}) +target_include_directories(azure_c_pal_reals PUBLIC $) +target_link_libraries(azure_c_pal_reals azure_c_logging) 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/src/reals_linux/CMakeLists.txt b/linux/src/reals_linux/CMakeLists.txt new file mode 100644 index 0000000..5de3737 --- /dev/null +++ b/linux/src/reals_linux/CMakeLists.txt @@ -0,0 +1,65 @@ +#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(azure_c_util_reals_c_files + real_constbuffer.c + real_constbuffer_array.c + real_constbuffer_array_batcher_nv.c + real_crt_abstractions.c + real_doublylinkedlist.c + real_memory_data.c + real_singlylinkedlist.c + real_threadapi.c + real_uuid.c +) + +set(azure_c_util_reals_h_files + real_constbuffer.h + real_constbuffer_renames.h + real_constbuffer_array.h + real_constbuffer_array_renames.h + real_constbuffer_array_batcher_nv.h + real_constbuffer_array_batcher_nv_renames.h + real_crt_abstractions.h + real_crt_abstractions_renames.h + real_doublylinkedlist.h + real_doublylinkedlist_renames.h + real_memory_data.h + real_memory_data_renames.h + real_singlylinkedlist.h + real_uuid.h + real_uuid_renames.h + real_threadapi.h + real_threadapi_renames.h +) + +if(WIN32) +set(azure_c_util_reals_c_files ${azure_c_util_reals_c_files} + real_interlocked_hl.c + real_srw_lock.c + real_string_utils.c + real_timer.c + real_sm.c +) + +set(azure_c_util_reals_h_files ${azure_c_util_reals_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 + real_sm.h + real_sm_renames.h +) +endif() + + +include_directories(${CMAKE_CURRENT_LIST_DIR}/../../src) +add_library(azure_c_util_reals ${azure_c_util_reals_c_files} ${azure_c_util_reals_h_files}) +target_include_directories(azure_c_util_reals PUBLIC $) +target_link_libraries(azure_c_util_reals azure_c_logging) diff --git a/linux/src/reals_linux/real_constbuffer_array_batcher_nv_linux.c b/linux/src/reals_linux/real_constbuffer_array_batcher_nv_linux.c new file mode 100644 index 0000000..7ba9f2b --- /dev/null +++ b/linux/src/reals_linux/real_constbuffer_array_batcher_nv_linux.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_constbuffer_array_batcher_nv_renames.h" +#include "real_constbuffer_array_renames.h" +#include "real_constbuffer_renames.h" +#include "real_memory_data_renames.h" + +#include "constbuffer_array_batcher_nv.c" diff --git a/linux/src/reals_linux/real_constbuffer_array_linux.c b/linux/src/reals_linux/real_constbuffer_array_linux.c new file mode 100644 index 0000000..aaf45e3 --- /dev/null +++ b/linux/src/reals_linux/real_constbuffer_array_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_constbuffer_array_renames.h" +#include "real_constbuffer_renames.h" + +#include "../src/constbuffer_array.c" diff --git a/linux/src/reals_linux/real_constbuffer_linux.c b/linux/src/reals_linux/real_constbuffer_linux.c new file mode 100644 index 0000000..372bbb7 --- /dev/null +++ b/linux/src/reals_linux/real_constbuffer_linux.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. + +#include "real_constbuffer_renames.h" + +#define GBALLOC_H + +#include "../src/constbuffer.c" diff --git a/linux/src/reals_linux/real_crt_abstractions_linux.c b/linux/src/reals_linux/real_crt_abstractions_linux.c new file mode 100644 index 0000000..cbf19f2 --- /dev/null +++ b/linux/src/reals_linux/real_crt_abstractions_linux.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. + +#include "real_crt_abstractions_renames.h" + +#define GBALLOC_H + +#include "crt_abstractions.c" diff --git a/linux/src/reals_linux/real_doublylinkedlist_linux.c b/linux/src/reals_linux/real_doublylinkedlist_linux.c new file mode 100644 index 0000000..354297a --- /dev/null +++ b/linux/src/reals_linux/real_doublylinkedlist_linux.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. + +#include "real_doublylinkedlist_renames.h" + +#define GBALLOC_H + +#include "doublylinkedlist.c" diff --git a/linux/src/reals_linux/real_interlocked_hl_linux.c b/linux/src/reals_linux/real_interlocked_hl_linux.c new file mode 100644 index 0000000..6fea9c6 --- /dev/null +++ b/linux/src/reals_linux/real_interlocked_hl_linux.c @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft. All rights reserved. + +#define GBALLOC_H + +#include "real_interlocked_hl_renames.h" + +#include "../../adapters/interlocked_hl_win32.c" diff --git a/linux/src/reals_linux/real_memory_data_linux.c b/linux/src/reals_linux/real_memory_data_linux.c new file mode 100644 index 0000000..601f073 --- /dev/null +++ b/linux/src/reals_linux/real_memory_data_linux.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_memory_data_renames.h" + +#include "../../src/memory_data.c" diff --git a/linux/src/reals_linux/real_singlylinkedlist_linux.c b/linux/src/reals_linux/real_singlylinkedlist_linux.c new file mode 100644 index 0000000..3195379 --- /dev/null +++ b/linux/src/reals_linux/real_singlylinkedlist_linux.c @@ -0,0 +1,18 @@ +// 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 + +#define singlylinkedlist_create real_singlylinkedlist_create +#define singlylinkedlist_destroy real_singlylinkedlist_destroy +#define singlylinkedlist_add real_singlylinkedlist_add +#define singlylinkedlist_add_head real_singlylinkedlist_add_head +#define singlylinkedlist_remove real_singlylinkedlist_remove +#define singlylinkedlist_get_head_item real_singlylinkedlist_get_head_item +#define singlylinkedlist_get_next_item real_singlylinkedlist_get_next_item +#define singlylinkedlist_find real_singlylinkedlist_find +#define singlylinkedlist_item_get_value real_singlylinkedlist_item_get_value +#define singlylinkedlist_remove_if real_singlylinkedlist_remove_if +#define singlylinkedlist_foreach real_singlylinkedlist_foreach + +#include "singlylinkedlist.c" diff --git a/linux/src/reals_linux/real_sm_linux.c b/linux/src/reals_linux/real_sm_linux.c new file mode 100644 index 0000000..3e8eca3 --- /dev/null +++ b/linux/src/reals_linux/real_sm_linux.c @@ -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 GBALLOC_H + +#include "real_interlocked_hl_renames.h" + +#include "real_sm_renames.h" + +#include "../../src/sm.c" diff --git a/linux/src/reals_linux/real_srw_lock_linux.c b/linux/src/reals_linux/real_srw_lock_linux.c new file mode 100644 index 0000000..a45bbfb --- /dev/null +++ b/linux/src/reals_linux/real_srw_lock_linux.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 "../../adapters/srw_lock.c" diff --git a/linux/src/reals_linux/real_string_utils_linux.c b/linux/src/reals_linux/real_string_utils_linux.c new file mode 100644 index 0000000..a0b5632 --- /dev/null +++ b/linux/src/reals_linux/real_string_utils_linux.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 "../../adapters/string_utils.c" diff --git a/linux/src/reals_linux/real_threadapi_linux.c b/linux/src/reals_linux/real_threadapi_linux.c new file mode 100644 index 0000000..added1b --- /dev/null +++ b/linux/src/reals_linux/real_threadapi_linux.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. + +#define GBALLOC_H + +#include "real_threadapi_renames.h" + +#if _MSC_VER +#include "../../adapters/threadapi_win32.c" +#else +#include "../../adapters/threadapi_pthreads.c" +#endif diff --git a/linux/src/reals_linux/real_timer_linux.c b/linux/src/reals_linux/real_timer_linux.c new file mode 100644 index 0000000..72bec88 --- /dev/null +++ b/linux/src/reals_linux/real_timer_linux.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 "../../adapters/timer.c" diff --git a/linux/src/reals_linux/real_uuid_linux.c b/linux/src/reals_linux/real_uuid_linux.c new file mode 100644 index 0000000..05a1352 --- /dev/null +++ b/linux/src/reals_linux/real_uuid_linux.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_uuid_renames.h" + +#include "uuid.c" diff --git a/win32/src/reals_win32/CMakeLists.txt b/win32/src/reals_win32/CMakeLists.txt new file mode 100644 index 0000000..5de3737 --- /dev/null +++ b/win32/src/reals_win32/CMakeLists.txt @@ -0,0 +1,65 @@ +#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(azure_c_util_reals_c_files + real_constbuffer.c + real_constbuffer_array.c + real_constbuffer_array_batcher_nv.c + real_crt_abstractions.c + real_doublylinkedlist.c + real_memory_data.c + real_singlylinkedlist.c + real_threadapi.c + real_uuid.c +) + +set(azure_c_util_reals_h_files + real_constbuffer.h + real_constbuffer_renames.h + real_constbuffer_array.h + real_constbuffer_array_renames.h + real_constbuffer_array_batcher_nv.h + real_constbuffer_array_batcher_nv_renames.h + real_crt_abstractions.h + real_crt_abstractions_renames.h + real_doublylinkedlist.h + real_doublylinkedlist_renames.h + real_memory_data.h + real_memory_data_renames.h + real_singlylinkedlist.h + real_uuid.h + real_uuid_renames.h + real_threadapi.h + real_threadapi_renames.h +) + +if(WIN32) +set(azure_c_util_reals_c_files ${azure_c_util_reals_c_files} + real_interlocked_hl.c + real_srw_lock.c + real_string_utils.c + real_timer.c + real_sm.c +) + +set(azure_c_util_reals_h_files ${azure_c_util_reals_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 + real_sm.h + real_sm_renames.h +) +endif() + + +include_directories(${CMAKE_CURRENT_LIST_DIR}/../../src) +add_library(azure_c_util_reals ${azure_c_util_reals_c_files} ${azure_c_util_reals_h_files}) +target_include_directories(azure_c_util_reals PUBLIC $) +target_link_libraries(azure_c_util_reals azure_c_logging) diff --git a/win32/src/reals_win32/real_interlocked_hl_win32.c b/win32/src/reals_win32/real_interlocked_hl_win32.c new file mode 100644 index 0000000..6fea9c6 --- /dev/null +++ b/win32/src/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 "../../adapters/interlocked_hl_win32.c" diff --git a/win32/src/reals_win32/real_memory_data_win32.c b/win32/src/reals_win32/real_memory_data_win32.c new file mode 100644 index 0000000..601f073 --- /dev/null +++ b/win32/src/reals_win32/real_memory_data_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_memory_data_renames.h" + +#include "../../src/memory_data.c" diff --git a/win32/src/reals_win32/real_singlylinkedlist_win32.c b/win32/src/reals_win32/real_singlylinkedlist_win32.c new file mode 100644 index 0000000..3195379 --- /dev/null +++ b/win32/src/reals_win32/real_singlylinkedlist_win32.c @@ -0,0 +1,18 @@ +// 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 + +#define singlylinkedlist_create real_singlylinkedlist_create +#define singlylinkedlist_destroy real_singlylinkedlist_destroy +#define singlylinkedlist_add real_singlylinkedlist_add +#define singlylinkedlist_add_head real_singlylinkedlist_add_head +#define singlylinkedlist_remove real_singlylinkedlist_remove +#define singlylinkedlist_get_head_item real_singlylinkedlist_get_head_item +#define singlylinkedlist_get_next_item real_singlylinkedlist_get_next_item +#define singlylinkedlist_find real_singlylinkedlist_find +#define singlylinkedlist_item_get_value real_singlylinkedlist_item_get_value +#define singlylinkedlist_remove_if real_singlylinkedlist_remove_if +#define singlylinkedlist_foreach real_singlylinkedlist_foreach + +#include "singlylinkedlist.c" diff --git a/win32/src/reals_win32/real_sm_win32.c b/win32/src/reals_win32/real_sm_win32.c new file mode 100644 index 0000000..3e8eca3 --- /dev/null +++ b/win32/src/reals_win32/real_sm_win32.c @@ -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 GBALLOC_H + +#include "real_interlocked_hl_renames.h" + +#include "real_sm_renames.h" + +#include "../../src/sm.c" diff --git a/win32/src/reals_win32/real_srw_lock_win32.c b/win32/src/reals_win32/real_srw_lock_win32.c new file mode 100644 index 0000000..a45bbfb --- /dev/null +++ b/win32/src/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 "../../adapters/srw_lock.c" diff --git a/win32/src/reals_win32/real_string_utils_win32.c b/win32/src/reals_win32/real_string_utils_win32.c new file mode 100644 index 0000000..a0b5632 --- /dev/null +++ b/win32/src/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 "../../adapters/string_utils.c" diff --git a/win32/src/reals_win32/real_threadapi_win32.c b/win32/src/reals_win32/real_threadapi_win32.c new file mode 100644 index 0000000..added1b --- /dev/null +++ b/win32/src/reals_win32/real_threadapi_win32.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. + +#define GBALLOC_H + +#include "real_threadapi_renames.h" + +#if _MSC_VER +#include "../../adapters/threadapi_win32.c" +#else +#include "../../adapters/threadapi_pthreads.c" +#endif diff --git a/win32/src/reals_win32/real_timer_win32.c b/win32/src/reals_win32/real_timer_win32.c new file mode 100644 index 0000000..72bec88 --- /dev/null +++ b/win32/src/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 "../../adapters/timer.c" diff --git a/win32/src/reals_win32/real_uuid_win32.c b/win32/src/reals_win32/real_uuid_win32.c new file mode 100644 index 0000000..05a1352 --- /dev/null +++ b/win32/src/reals_win32/real_uuid_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_uuid_renames.h" + +#include "uuid.c" diff --git a/win32/tests/CMakeLists.txt b/win32/tests/CMakeLists.txt index 38489ad..0fe50e6 100644 --- a/win32/tests/CMakeLists.txt +++ b/win32/tests/CMakeLists.txt @@ -12,6 +12,7 @@ if(${run_unittests}) add_subdirectory(uniqueid_win32_ut) add_subdirectory(timer_win32_ut) add_subdirectory(srw_lock_win32_ut) + add_subdirectory(reals_ut) endif() if(${run_int_tests}) diff --git a/win32/tests/reals_ut/CMakeLists.txt b/win32/tests/reals_ut/CMakeLists.txt new file mode 100644 index 0000000..b82d3a2 --- /dev/null +++ b/win32/tests/reals_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 azure_c_pal_reals_ut) + +set(${theseTestsName}_test_files + ${theseTestsName}.c +) + +build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS azure_c_pal azure_c_pal_reals) diff --git a/win32/tests/reals_ut/azure_c_pal_reals_ut.c b/win32/tests/reals_ut/azure_c_pal_reals_ut.c new file mode 100644 index 0000000..3c41185 --- /dev/null +++ b/win32/tests/reals_ut/azure_c_pal_reals_ut.c @@ -0,0 +1,46 @@ +// 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 "real_threadapi.h" +#include "threadapi.h" + +#if defined _MSC_VER +#include "../../../interfaces/tests/reals/real_srw_lock.h" +#include "../../../interfaces/tests/reals/real_string_utils.h" +#include "../../../interfaces/tests/reals/real_timer.h" +#include "../../../interfaces/tests/reals/real_interlocked_hl.h" + +#include "srw_lock.h" +#include "string_utils.h" +#include "timer.h" +#include "interlocked_hl.h" +#endif + +BEGIN_TEST_SUITE(azure_c_pal_reals_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(); + +#if defined _MSC_VER + REGISTER_SRW_LOCK_GLOBAL_MOCK_HOOK(); + REGISTER_STRING_UTILS_GLOBAL_MOCK_HOOK(); + REGISTER_TIMER_GLOBAL_MOCK_HOOK(); + REGISTER_INTERLOCKED_HL_GLOBAL_MOCK_HOOK(); +#endif + + // assert + // no explicit assert, if it builds it works +} + +END_TEST_SUITE(azure_c_pal_reals_ut) diff --git a/win32/tests/reals_ut/main.c b/win32/tests/reals_ut/main.c new file mode 100644 index 0000000..5fb9e49 --- /dev/null +++ b/win32/tests/reals_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(azure_c_util_reals_ut, failedTestCount); + return failedTestCount; +}