зеркало из https://github.com/Azure/c-logging.git
what does the gate say (#152)
This commit is contained in:
Родитель
50db473946
Коммит
477a9de2d2
|
@ -25,6 +25,8 @@ configuration:
|
|||
then:
|
||||
- requestReview:
|
||||
reviewer: anporumb
|
||||
- requestReview:
|
||||
reviewer: avranju
|
||||
- requestReview:
|
||||
reviewer: mattdurak
|
||||
- requestReview:
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit cf1d07b665db6965268b982544d61a9a7c07c5ee
|
||||
Subproject commit 66e850f7ddc73ac0c27c9acc8de9ca694d588765
|
|
@ -1 +1 @@
|
|||
Subproject commit 1f2d9813ba72505eea52a673b6e2fcf0aae85caf
|
||||
Subproject commit c0a389e2d46073dbe4b21fedee64c27bf3f48147
|
|
@ -39,7 +39,7 @@ static void lazyRegisterEventProvider(void)
|
|||
if (SUCCEEDED(t))
|
||||
{
|
||||
(void)InterlockedExchange(&isETWLoggerRegistered, 2);
|
||||
LogInfo("block_storage_2 ETW provider was registered succesfully (self test). Executable file full path name = %s", _pgmptr); /*_pgmptr comes from https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea */
|
||||
LogInfo("block_storage_2 ETW provider was registered succesfully (self test). Executable file full path name = %s", MU_P_OR_NULL(_pgmptr)); /*_pgmptr comes from https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-GetModuleFileNameA */
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
[Event Tracing For Windows](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/event-tracing-for-windows--etw-)
|
||||
|
||||
[GetModuleFileNameA](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-GetModuleFileNameA)
|
||||
|
||||
## Exposed API
|
||||
|
||||
```
|
||||
|
@ -26,7 +28,7 @@ Note: No other APIs (`deinit`, `log`) should be called while `init` executes.
|
|||
|
||||
**SRS_LOG_SINK_ETW_01_006: [** `log_sink_etw.init` shall register the ETW TraceLogging provider by calling `TraceLoggingRegister` (`TraceLoggingRegister_EventRegister_EventSetInformation`). **]**
|
||||
|
||||
**SRS_LOG_SINK_ETW_01_008: [** `log_sink_etw.init` shall emit a `LOG_LEVEL_INFO` event as a self test, printing the fact that the provider was registered and from which executable (as obtained by calling `_get_pgmptr`). **]**
|
||||
**SRS_LOG_SINK_ETW_01_008: [** `log_sink_etw.init` shall emit a `LOG_LEVEL_INFO` event as a self test, printing the fact that the provider was registered and from which executable (as obtained by calling `GetModuleFileNameA`). **]**
|
||||
|
||||
**SRS_LOG_SINK_ETW_01_084: [** `log_sink_etw.init` shall use as provider GUID `DAD29F36-0A48-4DEF-9D50-8EF9036B92B4`. **]**
|
||||
|
||||
|
@ -62,9 +64,7 @@ typedef void (*LOG_SINK_LOG_FUNC)(LOG_LEVEL log_level, LOG_CONTEXT_HANDLE log_co
|
|||
|
||||
**SRS_LOG_SINK_ETW_01_001: [** If `message_format` is `NULL`, `log_sink_etw.log` shall return. **]**
|
||||
|
||||
Note: `_get_pgmptr` is documented [here](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-pgmptr?view=msvc-170).
|
||||
|
||||
**SRS_LOG_SINK_ETW_01_083: [** If `_get_pgmptr` fails, the executable shall be printed as `UNKNOWN`. **]**
|
||||
**SRS_LOG_SINK_ETW_01_083: [** If `GetModuleFileNameA` fails, the executable shall be printed as `UNKNOWN`. **]**
|
||||
|
||||
Note this can (and should) be improved to be configurable in a subsequent task.
|
||||
|
||||
|
|
|
@ -584,12 +584,12 @@ static int log_sink_etw_init(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
char* temp_executable_full_path_name;
|
||||
char temp_executable_full_path_name[MAX_PATH];
|
||||
const char* executable_full_path_name;
|
||||
|
||||
if (_get_pgmptr(&temp_executable_full_path_name) != 0)
|
||||
if (!GetModuleFileNameA(NULL, temp_executable_full_path_name, sizeof(temp_executable_full_path_name)))
|
||||
{
|
||||
/* Codes_SRS_LOG_SINK_ETW_01_083: [ If _get_pgmptr fails, the executable shall be printed as UNKNOWN. ]*/
|
||||
/* Codes_SRS_LOG_SINK_ETW_01_083: [ If GetModuleFileNameA fails, the executable shall be printed as UNKNOWN. ]*/
|
||||
executable_full_path_name = "UNKNOWN";
|
||||
}
|
||||
else
|
||||
|
@ -597,7 +597,7 @@ static int log_sink_etw_init(void)
|
|||
executable_full_path_name = temp_executable_full_path_name;
|
||||
}
|
||||
|
||||
/* Codes_SRS_LOG_SINK_ETW_01_008: [ log_sink_etw.init shall emit a LOG_LEVEL_INFO event as a self test, printing the fact that the provider was registered and from which executable (as obtained by calling _get_pgmptr). ]*/
|
||||
/* Codes_SRS_LOG_SINK_ETW_01_008: [ log_sink_etw.init shall emit a LOG_LEVEL_INFO event as a self test, printing the fact that the provider was registered and from which executable (as obtained by calling GetModuleFileNameA). ]*/
|
||||
internal_emit_self_described_event(event_name_info, sizeof(event_name_info), TRACE_LEVEL_INFORMATION, NULL, 0, __FILE__, __FUNCTION__, __LINE__, "ETW provider was registered succesfully (self test). Executable file full path name = %s", executable_full_path_name);
|
||||
|
||||
log_sink_etw_state = LOG_SINK_ETW_STATE_INITIALIZED;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
MOCK_CALL_TYPE_log_context_get_property_value_pair_count, \
|
||||
MOCK_CALL_TYPE_log_context_get_property_value_pairs, \
|
||||
MOCK_CALL_TYPE_TraceLoggingRegister_EventRegister_EventSetInformation, \
|
||||
MOCK_CALL_TYPE__get_pgmptr, \
|
||||
MOCK_CALL_TYPE_GetModuleFileNameA, \
|
||||
MOCK_CALL_TYPE__tlgCreate1Sz_char, \
|
||||
MOCK_CALL_TYPE_EventDataDescCreate, \
|
||||
MOCK_CALL_TYPE__tlgWriteTransfer_EventWriteTransfer, \
|
||||
|
@ -97,12 +97,10 @@ typedef struct TraceLoggingRegister_EventRegister_EventSetInformation_CALL_TAG
|
|||
uint8_t enable_provider_level;
|
||||
} TraceLoggingRegister_EventRegister_EventSetInformation_CALL;
|
||||
|
||||
typedef struct _get_pgmptr_CALL_TAG
|
||||
typedef struct GetModuleFileNameA_CALL_TAG
|
||||
{
|
||||
bool override_result;
|
||||
char* injected_pValue;
|
||||
errno_t call_result;
|
||||
} _get_pgmptr_CALL;
|
||||
bool override_result; /*when override_result is TRUE then GetModuleFileNameA returns FALSE. Otherwise it doesn't fail and returns the current executable filename name*/
|
||||
} GetModuleFileNameA_CALL;
|
||||
|
||||
typedef struct _tlgWriteTransfer_EventWriteTransfer_CALL_TAG
|
||||
{
|
||||
|
@ -141,7 +139,7 @@ typedef struct MOCK_CALL_TAG
|
|||
log_context_get_property_value_pair_count_CALL log_context_get_property_value_pair_count_call;
|
||||
log_context_get_property_value_pairs_CALL log_context_get_property_value_pairs_call;
|
||||
TraceLoggingRegister_EventRegister_EventSetInformation_CALL TraceLoggingRegister_EventRegister_EventSetInformation_call;
|
||||
_get_pgmptr_CALL _get_pgmptr_call;
|
||||
GetModuleFileNameA_CALL GetModuleFileNameA_call;
|
||||
_tlgWriteTransfer_EventWriteTransfer_CALL _tlgWriteTransfer_EventWriteTransfer_call;
|
||||
log_context_property_if_get_type_CALL log_context_property_if_get_type_call;
|
||||
vsnprintf_CALL vsnprintf_call;
|
||||
|
@ -320,27 +318,30 @@ TLG_STATUS mock_TraceLoggingRegister_EventRegister_EventSetInformation(const str
|
|||
return result;
|
||||
}
|
||||
|
||||
errno_t mock__get_pgmptr(char** pValue)
|
||||
static char GetModuleFileNameA_value[MAX_PATH];
|
||||
|
||||
BOOL mock_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
{
|
||||
(void)nSize;
|
||||
(void)hModule;
|
||||
TLG_STATUS result;
|
||||
|
||||
if ((actual_call_count == expected_call_count) ||
|
||||
(expected_calls[actual_call_count].mock_call_type != MOCK_CALL_TYPE__get_pgmptr))
|
||||
(expected_calls[actual_call_count].mock_call_type != MOCK_CALL_TYPE_GetModuleFileNameA))
|
||||
{
|
||||
actual_and_expected_match = false;
|
||||
result = E_FAIL;
|
||||
result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expected_calls[actual_call_count]._get_pgmptr_call.override_result)
|
||||
if (expected_calls[actual_call_count].GetModuleFileNameA_call.override_result)
|
||||
{
|
||||
*pValue = expected_calls[actual_call_count]._get_pgmptr_call.injected_pValue;
|
||||
result = expected_calls[actual_call_count]._get_pgmptr_call.call_result;
|
||||
result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// call "real" function
|
||||
result = _get_pgmptr(pValue);
|
||||
(void)strcpy(lpFilename, GetModuleFileNameA_value);
|
||||
result = TRUE;
|
||||
}
|
||||
|
||||
actual_call_count++;
|
||||
|
@ -589,10 +590,10 @@ static void setup_TraceLoggingRegister_EventRegister_EventSetInformation_call(ui
|
|||
expected_call_count++;
|
||||
}
|
||||
|
||||
static void setup__get_pgmptr_call(void)
|
||||
static void setup_GetModuleFileNameA_call(void)
|
||||
{
|
||||
expected_calls[expected_call_count].mock_call_type = MOCK_CALL_TYPE__get_pgmptr;
|
||||
expected_calls[expected_call_count]._get_pgmptr_call.override_result = false;
|
||||
expected_calls[expected_call_count].mock_call_type = MOCK_CALL_TYPE_GetModuleFileNameA;
|
||||
expected_calls[expected_call_count].GetModuleFileNameA_call.override_result = false;
|
||||
expected_call_count++;
|
||||
}
|
||||
|
||||
|
@ -621,18 +622,18 @@ static void setup__tlgWriteTransfer_EventWriteTransfer(void* event_metadata, uin
|
|||
|
||||
/* log_sink_etw.init */
|
||||
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_083: [ If _get_pgmptr fails, the executable shall be printed as UNKNOWN. ]*/
|
||||
static void when__get_pgmptr_fails_log_sink_etw_log_prints_executable_as_UNKNOWN(void)
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_083: [ If GetModuleFileNameA fails, the executable shall be printed as UNKNOWN. ]*/
|
||||
static void when_GetModuleFileNameA_fails_log_sink_etw_log_prints_executable_as_UNKNOWN(void)
|
||||
{
|
||||
// arrange
|
||||
setup_mocks();
|
||||
setup_TraceLoggingRegister_EventRegister_EventSetInformation_call(TRACE_LEVEL_INFORMATION);
|
||||
|
||||
// self test event
|
||||
setup__get_pgmptr_call();
|
||||
setup_GetModuleFileNameA_call();
|
||||
|
||||
setup__tlgCreate1Sz_char(); // message
|
||||
setup__tlgCreate1Sz_char(); // file
|
||||
setup__tlgCreate1Sz_char(); // file
|
||||
setup__tlgCreate1Sz_char(); // func
|
||||
setup_EventDataDescCreate(); // line
|
||||
uint8_t extra_metadata_bytes[256];
|
||||
|
@ -687,8 +688,7 @@ static void when__get_pgmptr_fails_log_sink_etw_log_prints_executable_as_UNKNOWN
|
|||
|
||||
setup__tlgWriteTransfer_EventWriteTransfer(expected_event_metadata, 6, expected_event_data_descriptors, /* ignore file and func data */true);
|
||||
|
||||
expected_calls[1]._get_pgmptr_call.override_result = true;
|
||||
expected_calls[1]._get_pgmptr_call.call_result = 1;
|
||||
expected_calls[1].GetModuleFileNameA_call.override_result = true;
|
||||
|
||||
// act
|
||||
POOR_MANS_ASSERT(log_sink_etw.init() == 0);
|
||||
|
@ -701,10 +701,13 @@ static void when__get_pgmptr_fails_log_sink_etw_log_prints_executable_as_UNKNOWN
|
|||
/* very "poor man's" way of testing, as no test harness and mocking framework are available */
|
||||
int main(void)
|
||||
{
|
||||
/*suite init*/
|
||||
POOR_MANS_ASSERT(GetModuleFileNameA(NULL, GetModuleFileNameA_value, sizeof(GetModuleFileNameA_value)));
|
||||
|
||||
// make abort not popup
|
||||
_set_abort_behavior(_CALL_REPORTFAULT, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
|
||||
when__get_pgmptr_fails_log_sink_etw_log_prints_executable_as_UNKNOWN();
|
||||
when_GetModuleFileNameA_fails_log_sink_etw_log_prints_executable_as_UNKNOWN();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define log_context_get_property_value_pair_count mock_log_context_get_property_value_pair_count
|
||||
#define log_context_get_property_value_pairs mock_log_context_get_property_value_pairs
|
||||
#define TraceLoggingRegister_EventRegister_EventSetInformation mock_TraceLoggingRegister_EventRegister_EventSetInformation
|
||||
#define _get_pgmptr mock__get_pgmptr
|
||||
#define GetModuleFileNameA mock_GetModuleFileNameA
|
||||
#define _tlgCreate1Sz_char mock__tlgCreate1Sz_char
|
||||
#define EventDataDescCreate mock_EventDataDescCreate
|
||||
#define _tlgWriteTransfer_EventWriteTransfer mock__tlgWriteTransfer_EventWriteTransfer
|
||||
|
@ -31,7 +31,7 @@ LONG mock_InterlockedExchange(LONG volatile* Target, LONG Value);
|
|||
uint32_t mock_log_context_get_property_value_pair_count(LOG_CONTEXT_HANDLE log_context);
|
||||
const LOG_CONTEXT_PROPERTY_VALUE_PAIR* mock_log_context_get_property_value_pairs(LOG_CONTEXT_HANDLE log_context);
|
||||
TLG_STATUS mock_TraceLoggingRegister_EventRegister_EventSetInformation(const struct _tlgProvider_t* hProvider);
|
||||
errno_t mock__get_pgmptr(char** pValue);
|
||||
BOOL mock_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
|
||||
void mock__tlgCreate1Sz_char(PEVENT_DATA_DESCRIPTOR pDesc, char const* psz);
|
||||
void mock_EventDataDescCreate(PEVENT_DATA_DESCRIPTOR EventDataDescriptor, const VOID* DataPtr, ULONG DataSize);
|
||||
TLG_STATUS mock__tlgWriteTransfer_EventWriteTransfer(TraceLoggingHProvider hProvider, void const* pEventMetadata, LPCGUID pActivityId, LPCGUID pRelatedActivityId, UINT32 cData, EVENT_DATA_DESCRIPTOR* pData);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#define log_context_get_property_value_pair_count mock_log_context_get_property_value_pair_count
|
||||
#define log_context_get_property_value_pairs mock_log_context_get_property_value_pairs
|
||||
#define TraceLoggingRegister_EventRegister_EventSetInformation mock_TraceLoggingRegister_EventRegister_EventSetInformation
|
||||
#define _get_pgmptr mock__get_pgmptr
|
||||
#define GetModuleFileNameA mock_GetModuleFileNameA
|
||||
#define _tlgCreate1Sz_char mock__tlgCreate1Sz_char
|
||||
#define _tlgCreate1Sz_wchar_t mock__tlgCreate1Sz_wchar_t
|
||||
#define EventDataDescCreate mock_EventDataDescCreate
|
||||
|
@ -30,7 +30,7 @@ int mock_printf(const char* format, ...);
|
|||
uint32_t mock_log_context_get_property_value_pair_count(LOG_CONTEXT_HANDLE log_context);
|
||||
const LOG_CONTEXT_PROPERTY_VALUE_PAIR* mock_log_context_get_property_value_pairs(LOG_CONTEXT_HANDLE log_context);
|
||||
TLG_STATUS mock_TraceLoggingRegister_EventRegister_EventSetInformation(const struct _tlgProvider_t* hProvider);
|
||||
errno_t mock__get_pgmptr(char** pValue);
|
||||
BOOL mock_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
|
||||
void mock__tlgCreate1Sz_char(PEVENT_DATA_DESCRIPTOR pDesc, char const* psz);
|
||||
void mock__tlgCreate1Sz_wchar_t(PEVENT_DATA_DESCRIPTOR pDesc, wchar_t const* psz);
|
||||
void mock_EventDataDescCreate(PEVENT_DATA_DESCRIPTOR EventDataDescriptor, const VOID* DataPtr, ULONG DataSize);
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
MOCK_CALL_TYPE_log_context_get_property_value_pair_count, \
|
||||
MOCK_CALL_TYPE_log_context_get_property_value_pairs, \
|
||||
MOCK_CALL_TYPE_TraceLoggingRegister_EventRegister_EventSetInformation, \
|
||||
MOCK_CALL_TYPE__get_pgmptr, \
|
||||
MOCK_CALL_TYPE_GetModuleFileNameA, \
|
||||
MOCK_CALL_TYPE__tlgCreate1Sz_char, \
|
||||
MOCK_CALL_TYPE__tlgCreate1Sz_wchar_t, \
|
||||
MOCK_CALL_TYPE_EventDataDescCreate, \
|
||||
|
@ -102,12 +102,10 @@ typedef struct TraceLoggingRegister_EventRegister_EventSetInformation_CALL_TAG
|
|||
const char* expected_provider_id_as_string;
|
||||
} TraceLoggingRegister_EventRegister_EventSetInformation_CALL;
|
||||
|
||||
typedef struct _get_pgmptr_CALL_TAG
|
||||
typedef struct GetModuleFileNameA_CALL_TAG
|
||||
{
|
||||
bool override_result;
|
||||
char* injected_pValue;
|
||||
errno_t call_result;
|
||||
} _get_pgmptr_CALL;
|
||||
bool override_result; /*when override_result is TRUE then GetModuleFileNameA returns FALSE. Otherwise it doesn't fail and returns the current executable filename name*/
|
||||
} GetModuleFileNameA_CALL;
|
||||
|
||||
typedef struct _tlgWriteTransfer_EventWriteTransfer_CALL_TAG
|
||||
{
|
||||
|
@ -146,7 +144,7 @@ typedef struct MOCK_CALL_TAG
|
|||
log_context_get_property_value_pair_count_CALL log_context_get_property_value_pair_count_call;
|
||||
log_context_get_property_value_pairs_CALL log_context_get_property_value_pairs_call;
|
||||
TraceLoggingRegister_EventRegister_EventSetInformation_CALL TraceLoggingRegister_EventRegister_EventSetInformation_call;
|
||||
_get_pgmptr_CALL _get_pgmptr_call;
|
||||
GetModuleFileNameA_CALL GetModuleFileNameA_call;
|
||||
_tlgWriteTransfer_EventWriteTransfer_CALL _tlgWriteTransfer_EventWriteTransfer_call;
|
||||
log_context_property_if_get_type_CALL log_context_property_if_get_type_call;
|
||||
vsnprintf_CALL vsnprintf_call;
|
||||
|
@ -340,27 +338,30 @@ TLG_STATUS mock_TraceLoggingRegister_EventRegister_EventSetInformation(const str
|
|||
return result;
|
||||
}
|
||||
|
||||
errno_t mock__get_pgmptr(char** pValue)
|
||||
static char GetModuleFileNameA_value[MAX_PATH];
|
||||
|
||||
BOOL mock_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
{
|
||||
(void)nSize;
|
||||
(void)hModule;
|
||||
TLG_STATUS result;
|
||||
|
||||
if ((actual_call_count == expected_call_count) ||
|
||||
(expected_calls[actual_call_count].mock_call_type != MOCK_CALL_TYPE__get_pgmptr))
|
||||
(expected_calls[actual_call_count].mock_call_type != MOCK_CALL_TYPE_GetModuleFileNameA))
|
||||
{
|
||||
actual_and_expected_match = false;
|
||||
result = E_FAIL;
|
||||
result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expected_calls[actual_call_count]._get_pgmptr_call.override_result)
|
||||
if (expected_calls[actual_call_count].GetModuleFileNameA_call.override_result)
|
||||
{
|
||||
*pValue = expected_calls[actual_call_count]._get_pgmptr_call.injected_pValue;
|
||||
result = expected_calls[actual_call_count]._get_pgmptr_call.call_result;
|
||||
result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// call "real" function
|
||||
result = _get_pgmptr(pValue);
|
||||
(void)strcpy(lpFilename, GetModuleFileNameA_value);
|
||||
result = TRUE;
|
||||
}
|
||||
|
||||
actual_call_count++;
|
||||
|
@ -652,10 +653,10 @@ static void setup_TraceLoggingRegister_EventRegister_EventSetInformation_call(co
|
|||
expected_call_count++;
|
||||
}
|
||||
|
||||
static void setup__get_pgmptr_call(void)
|
||||
static void setup_GetModuleFileNameA_call(void)
|
||||
{
|
||||
expected_calls[expected_call_count].mock_call_type = MOCK_CALL_TYPE__get_pgmptr;
|
||||
expected_calls[expected_call_count]._get_pgmptr_call.override_result = false;
|
||||
expected_calls[expected_call_count].mock_call_type = MOCK_CALL_TYPE_GetModuleFileNameA;
|
||||
expected_calls[expected_call_count].GetModuleFileNameA_call.override_result = false;
|
||||
expected_call_count++;
|
||||
}
|
||||
|
||||
|
@ -749,7 +750,7 @@ static void when_TraceLoggingRegister_fails_log_sink_etw_init_fails(void)
|
|||
}
|
||||
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_006: [ log_sink_etw.init shall register the ETW TraceLogging provider by calling TraceLoggingRegister (TraceLoggingRegister_EventRegister_EventSetInformation). ]*/
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_008: [ log_sink_etw.init shall emit a LOG_LEVEL_INFO event as a self test, printing the fact that the provider was registered and from which executable (as obtained by calling _get_pgmptr). ]*/
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_008: [ log_sink_etw.init shall emit a LOG_LEVEL_INFO event as a self test, printing the fact that the provider was registered and from which executable (as obtained by calling GetModuleFileNameA). ]*/
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_084: [ log_sink_etw.init shall use as provider GUID DAD29F36-0A48-4DEF-9D50-8EF9036B92B4. ]*/
|
||||
/* Tests_SRS_LOG_SINK_ETW_01_091: [ log_sink_etw.init shall succeed and return 0. ] */
|
||||
static void log_sink_etw_init_works(void)
|
||||
|
@ -760,7 +761,7 @@ static void log_sink_etw_init_works(void)
|
|||
setup_TraceLoggingRegister_EventRegister_EventSetInformation_call("DAD29F36-0A48-4DEF-9D50-8EF9036B92B4", TRACE_LEVEL_INFORMATION);
|
||||
|
||||
// self test event
|
||||
setup__get_pgmptr_call();
|
||||
setup_GetModuleFileNameA_call();
|
||||
|
||||
setup_vsnprintf_call(); // formatting message
|
||||
setup__tlgCreate1Sz_char(); // message
|
||||
|
@ -804,9 +805,7 @@ static void log_sink_etw_init_works(void)
|
|||
|
||||
int captured_line = __LINE__;
|
||||
|
||||
expected_calls[1]._get_pgmptr_call.override_result = true;
|
||||
expected_calls[1]._get_pgmptr_call.call_result = 0;
|
||||
expected_calls[1]._get_pgmptr_call.injected_pValue = "some_test_executable.exe";
|
||||
expected_calls[1].GetModuleFileNameA_call.override_result = true;
|
||||
|
||||
static const char expected_event_message[] = "ETW provider was registered succesfully (self test). Executable file full path name = some_test_executable.exe";
|
||||
|
||||
|
@ -3068,6 +3067,9 @@ static void log_sink_etw_deinit_after_deinit_returns(void)
|
|||
/* very "poor man's" way of testing, as no test harness and mocking framework are available */
|
||||
int main(void)
|
||||
{
|
||||
/*suite setup*/
|
||||
POOR_MANS_ASSERT(GetModuleFileNameA(NULL, GetModuleFileNameA_value, sizeof(GetModuleFileNameA_value)));
|
||||
|
||||
// make abort not popup
|
||||
_set_abort_behavior(_CALL_REPORTFAULT, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define log_context_get_property_value_pair_count mock_log_context_get_property_value_pair_count
|
||||
#define log_context_get_property_value_pairs mock_log_context_get_property_value_pairs
|
||||
#define TraceLoggingRegister_EventRegister_EventSetInformation mock_TraceLoggingRegister_EventRegister_EventSetInformation
|
||||
#define _get_pgmptr mock__get_pgmptr
|
||||
#define GetModuleFileNameA mock_GetModuleFileNameA
|
||||
#define _tlgCreate1Sz_char mock__tlgCreate1Sz_char
|
||||
#define EventDataDescCreate mock_EventDataDescCreate
|
||||
#define _tlgWriteTransfer_EventWriteTransfer mock__tlgWriteTransfer_EventWriteTransfer
|
||||
|
@ -28,7 +28,7 @@ int mock_printf(const char* format, ...);
|
|||
uint32_t mock_log_context_get_property_value_pair_count(LOG_CONTEXT_HANDLE log_context);
|
||||
const LOG_CONTEXT_PROPERTY_VALUE_PAIR* mock_log_context_get_property_value_pairs(LOG_CONTEXT_HANDLE log_context);
|
||||
TLG_STATUS mock_TraceLoggingRegister_EventRegister_EventSetInformation(const struct _tlgProvider_t* hProvider);
|
||||
errno_t mock__get_pgmptr(char** pValue);
|
||||
BOOL mock_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
|
||||
void mock__tlgCreate1Sz_char(PEVENT_DATA_DESCRIPTOR pDesc, char const* psz);
|
||||
void mock_EventDataDescCreate(PEVENT_DATA_DESCRIPTOR EventDataDescriptor, const VOID* DataPtr, ULONG DataSize);
|
||||
TLG_STATUS mock__tlgWriteTransfer_EventWriteTransfer(TraceLoggingHProvider hProvider, void const* pEventMetadata, LPCGUID pActivityId, LPCGUID pRelatedActivityId, UINT32 cData, EVENT_DATA_DESCRIPTOR* pData);
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
MOCK_CALL_TYPE_log_context_get_property_value_pair_count, \
|
||||
MOCK_CALL_TYPE_log_context_get_property_value_pairs, \
|
||||
MOCK_CALL_TYPE_TraceLoggingRegister_EventRegister_EventSetInformation, \
|
||||
MOCK_CALL_TYPE__get_pgmptr, \
|
||||
MOCK_CALL_TYPE_GetModuleFileNameA, \
|
||||
MOCK_CALL_TYPE__tlgCreate1Sz_char, \
|
||||
MOCK_CALL_TYPE_EventDataDescCreate, \
|
||||
MOCK_CALL_TYPE__tlgWriteTransfer_EventWriteTransfer, \
|
||||
|
@ -96,11 +96,10 @@ typedef struct TraceLoggingRegister_EventRegister_EventSetInformation_CALL_TAG
|
|||
TLG_STATUS call_result;
|
||||
} TraceLoggingRegister_EventRegister_EventSetInformation_CALL;
|
||||
|
||||
typedef struct _get_pgmptr_CALL_TAG
|
||||
typedef struct GetModuleFileNameA_CALL_TAG
|
||||
{
|
||||
bool override_result;
|
||||
errno_t call_result;
|
||||
} _get_pgmptr_CALL;
|
||||
bool override_result; /*when override_result is TRUE then GetModuleFileNameA returns FALSE. Otherwise it doesn't fail and returns the current executable filename name*/
|
||||
} GetModuleFileNameA_CALL;
|
||||
|
||||
typedef struct _tlgWriteTransfer_EventWriteTransfer_CALL_TAG
|
||||
{
|
||||
|
@ -139,7 +138,7 @@ typedef struct MOCK_CALL_TAG
|
|||
log_context_get_property_value_pair_count_CALL log_context_get_property_value_pair_count_call;
|
||||
log_context_get_property_value_pairs_CALL log_context_get_property_value_pairs_call;
|
||||
TraceLoggingRegister_EventRegister_EventSetInformation_CALL TraceLoggingRegister_EventRegister_EventSetInformation_call;
|
||||
_get_pgmptr_CALL _get_pgmptr_call;
|
||||
GetModuleFileNameA_CALL GetModuleFileNameA_call;
|
||||
_tlgWriteTransfer_EventWriteTransfer_CALL _tlgWriteTransfer_EventWriteTransfer_call;
|
||||
log_context_property_if_get_type_CALL log_context_property_if_get_type_call;
|
||||
vsnprintf_CALL vsnprintf_call;
|
||||
|
@ -315,25 +314,31 @@ TLG_STATUS mock_TraceLoggingRegister_EventRegister_EventSetInformation(const str
|
|||
return result;
|
||||
}
|
||||
|
||||
errno_t mock__get_pgmptr(char** pValue)
|
||||
static char GetModuleFileNameA_value[MAX_PATH];
|
||||
|
||||
BOOL mock_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
||||
{
|
||||
(void)nSize;
|
||||
(void)lpFilename;
|
||||
(void)hModule;
|
||||
TLG_STATUS result;
|
||||
|
||||
if ((actual_call_count == expected_call_count) ||
|
||||
(expected_calls[actual_call_count].mock_call_type != MOCK_CALL_TYPE__get_pgmptr))
|
||||
(expected_calls[actual_call_count].mock_call_type != MOCK_CALL_TYPE_GetModuleFileNameA))
|
||||
{
|
||||
actual_and_expected_match = false;
|
||||
result = E_FAIL;
|
||||
result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expected_calls[actual_call_count]._get_pgmptr_call.override_result)
|
||||
if (expected_calls[actual_call_count].GetModuleFileNameA_call.override_result)
|
||||
{
|
||||
result = expected_calls[actual_call_count]._get_pgmptr_call.call_result;
|
||||
result = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = _get_pgmptr(pValue);
|
||||
(void)strcpy(lpFilename, GetModuleFileNameA_value);
|
||||
result = TRUE;
|
||||
}
|
||||
|
||||
actual_call_count++;
|
||||
|
@ -372,7 +377,7 @@ void mock_EventDataDescCreate(PEVENT_DATA_DESCRIPTOR EventDataDescriptor, const
|
|||
}
|
||||
}
|
||||
|
||||
errno_t mock__tlgWriteTransfer_EventWriteTransfer(TraceLoggingHProvider hProvider, void const* pEventMetadata, LPCGUID pActivityId, LPCGUID pRelatedActivityId, UINT32 cData, EVENT_DATA_DESCRIPTOR* pData)
|
||||
BOOL mock__tlgWriteTransfer_EventWriteTransfer(TraceLoggingHProvider hProvider, void const* pEventMetadata, LPCGUID pActivityId, LPCGUID pRelatedActivityId, UINT32 cData, EVENT_DATA_DESCRIPTOR* pData)
|
||||
{
|
||||
TLG_STATUS result;
|
||||
|
||||
|
@ -600,10 +605,10 @@ static void setup_TraceLoggingRegister_EventRegister_EventSetInformation_call(vo
|
|||
expected_call_count++;
|
||||
}
|
||||
|
||||
static void setup__get_pgmptr_call(void)
|
||||
static void setup_GetModuleFileNameA_call(void)
|
||||
{
|
||||
expected_calls[expected_call_count].mock_call_type = MOCK_CALL_TYPE__get_pgmptr;
|
||||
expected_calls[expected_call_count]._get_pgmptr_call.override_result = false;
|
||||
expected_calls[expected_call_count].mock_call_type = MOCK_CALL_TYPE_GetModuleFileNameA;
|
||||
expected_calls[expected_call_count].GetModuleFileNameA_call.override_result = false;
|
||||
expected_call_count++;
|
||||
}
|
||||
|
||||
|
@ -657,6 +662,9 @@ static void when_module_is_not_initialized_deinit_returns(void)
|
|||
/* very "poor man's" way of testing, as no test harness and mocking framework are available */
|
||||
int main(void)
|
||||
{
|
||||
/*suite init*/
|
||||
POOR_MANS_ASSERT(GetModuleFileNameA(NULL, GetModuleFileNameA_value, sizeof(GetModuleFileNameA_value)));
|
||||
|
||||
// make abort not popup
|
||||
_set_abort_behavior(_CALL_REPORTFAULT, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче