Merge pull request #2 from Azure/reals

Reals
This commit is contained in:
Parth Aggarwal 2020-06-12 17:13:23 -04:00 коммит произвёл GitHub
Родитель f530c15498 c6a0af26be
Коммит fb39b8c7e8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
34 изменённых файлов: 517 добавлений и 5 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -51,4 +51,5 @@ Module.symvers
Mkfile.old
dkms.conf
cmake*/
cmake*/
.vscode/

Просмотреть файл

@ -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)

Просмотреть файл

@ -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)

Просмотреть файл

@ -1,5 +1,7 @@
#Copyright (C) Microsoft Corporation. All rights reserved.
add_subdirectory(reals)
if(${run_ut_tests})
add_subdirectory(lock_ut)
endif()

Просмотреть файл

@ -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)

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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 <cstdbool>
#else
#include <stdbool.h>
#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

Просмотреть файл

@ -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

Просмотреть файл

@ -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 <cstdbool>
#else
#include <stdbool.h>
#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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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)

Просмотреть файл

@ -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})

Просмотреть файл

@ -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)

Просмотреть файл

@ -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"

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 <stddef.h>
#include "testrunnerswitcher.h"
int main(void)
{
size_t failedTestCount = 0;
RUN_TEST_SUITE(reals_linux_ut, failedTestCount);
return failedTestCount;
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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)

Просмотреть файл

@ -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)

Просмотреть файл

@ -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})

Просмотреть файл

@ -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)

Просмотреть файл

@ -0,0 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
#define GBALLOC_H
#include "real_interlocked_hl_renames.h"
#include "interlocked_hl_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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 <stddef.h>
#include "testrunnerswitcher.h"
int main(void)
{
size_t failedTestCount = 0;
RUN_TEST_SUITE(reals_win32_ut, failedTestCount);
return failedTestCount;
}

Просмотреть файл

@ -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)