Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a general debuglib for both teeio_debug and spdm_debug #61

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/ide_test_ini.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ EntryName=EntryValue
|Entry|Value|Default|Mandatory|Comment|
|------|------|------|------|------|
| pci_log|0/1 |0 | O | enable pci log if 1|
| libspdm_log|0/1 |0 | O | enable libspdm log if 1|
| debug_level | verbose/info/warn/error | warn | O | debug level|

[Ports]
Expand Down
11 changes: 2 additions & 9 deletions teeio-validator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ endif()
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
ADD_COMPILE_OPTIONS(-DLIBSPDM_DEBUG_ENABLE=0)
endif()

if(ENABLE_CODEQL STREQUAL "ON")
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/library/spdm_common_lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/library/spdm_requester_lib)
Expand All @@ -199,8 +195,7 @@ if(ENABLE_CODEQL STREQUAL "ON")
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/library/spdm_transport_mctp_lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/library/spdm_transport_pcidoe_lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/memlib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/debuglib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/debuglib_null)
ADD_SUBDIRECTORY(${TEEIO_VALIDATOR_DIR}/library/debuglib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/rnglib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/platform_lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/platform_lib_null)
Expand Down Expand Up @@ -236,8 +231,7 @@ ADD_COMPILE_OPTIONS(-DLIBSPDM_CONFIG="${PROJECT_SOURCE_DIR}/include/spdm_lib_con
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/library/spdm_secured_message_lib out/spdm_secured_message_lib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/library/spdm_transport_pcidoe_lib out/spdm_transport_pcidoe_lib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/memlib out/spdm_memlib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/debuglib out/spdm_debuglib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/debuglib_null out/spdm_debuglib_null.lib)
ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/library/debuglib out/debuglib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/rnglib out/spdm_rnglib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/platform_lib out/spdm_platform_lib.lib)
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/platform_lib_null out/spdm_platform_lib_null.lib)
Expand All @@ -246,7 +240,6 @@ ADD_COMPILE_OPTIONS(-DLIBSPDM_CONFIG="${PROJECT_SOURCE_DIR}/include/spdm_lib_con
ADD_SUBDIRECTORY(${LIBSPDM_DIR}/os_stub/spdm_device_secret_lib_null out/spdm_device_secret_lib_null.lib)

ADD_SUBDIRECTORY(${LIBSPDM_DIR}/unit_test/test_size/intrinsiclib out/intrinsiclib.lib)
#ADD_SUBDIRECTORY(${LIBSPDM_DIR}/unit_test/test_size/malloclib_null out/malloclib_null.lib)

ADD_SUBDIRECTORY(${SPDM_EMU_DIR}/library/pci_doe_requester_lib out/pci_doe_requester_lib.lib)
ADD_SUBDIRECTORY(${SPDM_EMU_DIR}/library/pci_ide_km_requester_lib out/pci_ide_km_requester_lib.lib)
Expand Down
1 change: 1 addition & 0 deletions teeio-validator/include/ide_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ typedef struct
{
bool pci_log;
uint32_t debug_level;
bool libspdm_log;
bool wo_tdisp;
} IDE_TEST_MAIN_CONFIG;

Expand Down
23 changes: 23 additions & 0 deletions teeio-validator/library/debuglib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 2.8.12)

ADD_COMPILE_OPTIONS(-Wno-unused-result -Werror=format-overflow -Werror)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
ADD_COMPILE_OPTIONS(-Wno-error=unused-variable -Wno-error=unused-but-set-variable)
endif()

SET(BUILD_SHARED_LIBS OFF)
SET(CMAKE_EXE_LINKER_FLAGS "-static")

INCLUDE_DIRECTORIES(
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/include/hal
${PROJECT_SOURCE_DIR}/include
)

SET(src_debuglib
spdm_debug.c
teeio_debug.c
)

ADD_LIBRARY(debuglib STATIC ${src_debuglib})
62 changes: 62 additions & 0 deletions teeio-validator/library/debuglib/spdm_debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

#include <base.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#include "library/debuglib.h"
#include "teeio_debug.h"

extern bool g_libspdm_log;
extern FILE* m_logfile;
extern TEEIO_DEBUG_LEVEL g_debug_level;

#define LIBSPDM_MAX_LOG_MESSAGE_LENGTH 1024

#ifndef LIBSPDM_DEBUG_LEVEL_CONFIG
#define LIBSPDM_DEBUG_LEVEL_CONFIG (LIBSPDM_DEBUG_INFO | LIBSPDM_DEBUG_ERROR)
#endif

void debug_lib_assert(const char* which_assert, const char *file_name, int line_number, const char *description);

void libspdm_debug_assert(const char *file_name, size_t line_number,
const char *description)
{
debug_lib_assert("LIBSPDM_ASSERT", file_name, line_number, description);
}

void libspdm_debug_print(size_t error_level, const char *format, ...)
{
if(!g_libspdm_log) {
return;
}

if ((error_level & LIBSPDM_DEBUG_LEVEL_CONFIG) == 0) {
return;
}

char buffer[LIBSPDM_MAX_LOG_MESSAGE_LENGTH];
va_list marker;

if ((error_level & LIBSPDM_DEBUG_LEVEL_CONFIG) == 0) {
return;
}

va_start(marker, format);

vsnprintf(buffer, sizeof(buffer), format, marker);

va_end(marker);

printf("%s", buffer);

if(m_logfile) {
fprintf(m_logfile, "%s", buffer);
fflush(m_logfile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ void teeio_print(const char *format, ...)
#define IDE_ASSERT_CONFIG TEEIO_ASSERT_DEADLOOP
#endif

void teeio_assert(const char *file_name, int line_number, const char *description)
void debug_lib_assert(const char* which_assert, const char *file_name, int line_number, const char *description)
{
printf("TEEIO_ASSERT: %s(%d): %s\n", file_name, (int32_t)(uint32_t)line_number,
printf("%s: %s(%d): %s\n", which_assert, file_name, (int32_t)(uint32_t)line_number,
description);

#if (IDE_ASSERT_CONFIG == TEEIO_ASSERT_DEADLOOP)
Expand All @@ -116,4 +116,9 @@ void teeio_assert(const char *file_name, int line_number, const char *descriptio

assert(false);
}

void teeio_assert(const char *file_name, int line_number, const char *description)
{
debug_lib_assert("TEEIO_ASSERT", file_name, line_number, description);
}
#endif /* TEEIO_ASSERT_ENABLE */
3 changes: 0 additions & 3 deletions teeio-validator/teeio_validator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ SET(src_teeio_validator
cmdline.c
ide_test_ini.c
ide_test.c
teeio_debug.c
## test cases
test_case/test_case_query.c
test_case/test_case_ksetgo_1.c
Expand Down Expand Up @@ -83,7 +82,6 @@ SET(teeio_validator_LIBRARY
SET(src_lside
tools/lside.c
tools/ide_common.c
teeio_debug.c
utils.c
pci_ide.c
scan_pci.c
Expand All @@ -96,7 +94,6 @@ SET(lside_LIBRARY
SET(src_setide
tools/setide.c
tools/ide_common.c
teeio_debug.c
utils.c
pci_ide.c
scan_pci.c
Expand Down
1 change: 1 addition & 0 deletions teeio-validator/teeio_validator/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern int g_top_id;
extern int g_config_id;
extern char g_test_case[MAX_CASE_NAME_LENGTH];
extern TEEIO_DEBUG_LEVEL g_debug_level;
extern bool g_libspdm_log;
extern uint8_t g_scan_bus;
extern bool g_run_test_suite;

Expand Down
6 changes: 6 additions & 0 deletions teeio-validator/teeio_validator/ide_test_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,12 @@ void ParseMainSection(void *context, IDE_TEST_CONFIG *test_config)
test_config->main_config.pci_log = data32 == 1;
}

sprintf(entry_name, "libspdm_log");
if (GetDecimalUint32FromDataFile(context, (uint8_t *)section_name, (uint8_t *)entry_name, &data32))
{
test_config->main_config.libspdm_log = data32 == 1;
}

sprintf(entry_name, "debug_level");
if (!GetStringFromDataFile(context, (uint8_t *)section_name, (uint8_t *)entry_name, &entry_value))
{
Expand Down
2 changes: 2 additions & 0 deletions teeio-validator/teeio_validator/teeio_validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ char g_test_case[MAX_CASE_NAME_LENGTH] = {0};
bool g_run_test_suite = true;

TEEIO_DEBUG_LEVEL g_debug_level = TEEIO_DEBUG_WARN;
bool g_libspdm_log = false;
uint8_t g_scan_bus = INVALID_SCAN_BUS;

FILE* m_logfile = NULL;
Expand Down Expand Up @@ -80,6 +81,7 @@ int main(int argc, char *argv[])
goto MainDone;
}
g_pci_log = ide_test_config.main_config.pci_log;
g_libspdm_log = ide_test_config.main_config.libspdm_log;

if(debug_level == TEEIO_DEBUG_NUM) {
g_debug_level = ide_test_config.main_config.debug_level;
Expand Down
1 change: 1 addition & 0 deletions teeio-validator/teeio_validator/tools/lside.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DEVCIES_CONTEXT devices_context = {0};
bool g_run_test_suite = false;

TEEIO_DEBUG_LEVEL g_debug_level = TEEIO_DEBUG_WARN;
bool g_libspdm_log = false;
uint8_t g_scan_bus = INVALID_SCAN_BUS;
FILE* m_logfile = NULL;

Expand Down
1 change: 1 addition & 0 deletions teeio-validator/teeio_validator/tools/setide.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ IDE_OPERATION g_ide_operation = IDE_OPERATION_CLEAR;
bool g_run_test_suite = false;

TEEIO_DEBUG_LEVEL g_debug_level = TEEIO_DEBUG_WARN;
bool g_libspdm_log = false;
uint8_t g_scan_bus = INVALID_SCAN_BUS;
FILE* m_logfile = NULL;

Expand Down