From 57f95f505147e7da4822a91c874f3c6a15e3844c Mon Sep 17 00:00:00 2001 From: Min M Xu Date: Tue, 9 Apr 2024 22:28:35 -0400 Subject: [PATCH] Refine output information for teeio_validator Signed-off-by: Min Xu --- teeio-validator/include/teeio_validator.h | 4 +-- teeio-validator/teeio_validator/cmdline.c | 19 +++++++++-- teeio-validator/teeio_validator/device_pci.c | 16 --------- .../teeio_validator/doe_read_write.c | 27 +++++++-------- teeio-validator/teeio_validator/ide_test.c | 3 +- .../teeio_validator/teeio_validator.c | 33 +++++++++++-------- .../test_case/test_case_full.c | 6 ++-- .../test_case/test_case_full_keyrefresh.c | 6 ++-- teeio-validator/teeio_validator/utils.c | 17 +++++++++- 9 files changed, 76 insertions(+), 55 deletions(-) diff --git a/teeio-validator/include/teeio_validator.h b/teeio-validator/include/teeio_validator.h index ffa1626..8b9ad61 100644 --- a/teeio-validator/include/teeio_validator.h +++ b/teeio-validator/include/teeio_validator.h @@ -29,6 +29,8 @@ #define TEEIO_VALIDATOR_NAME "teeio_validator" #define TEEIO_VALIDATOR_VERSION "0.1.0" +#define LOGFILE "./teeio_log.txt" + typedef struct { size_t cert_chain_size; uint8_t cert_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE]; @@ -71,6 +73,4 @@ libspdm_return_t pci_doe_process_session_test(void *spdm_context, uint32_t sessi bool libspdm_write_output_file(const char *file_name, const void *file_data, size_t file_size); -#define LOGFILE "./spdm_log.txt" - #endif diff --git a/teeio-validator/teeio_validator/cmdline.c b/teeio-validator/teeio_validator/cmdline.c index 485d9df..25ed235 100644 --- a/teeio-validator/teeio_validator/cmdline.c +++ b/teeio-validator/teeio_validator/cmdline.c @@ -39,11 +39,13 @@ bool is_valid_test_case(const char* test_case_name); void print_usage() { - TEEIO_PRINT(("\nUsage:\n")); + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Usage:\n")); TEEIO_PRINT((" teeio_validator -f ide_test.ini\n")); TEEIO_PRINT((" teeio_validator -f ide_test.ini -t 1 -c 1 -s Test.IdeStream\n")); - TEEIO_PRINT(("\nOptions:\n")); + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Options:\n")); TEEIO_PRINT((" -f : The file name of test configuration. For example ide_test.ini\n")); TEEIO_PRINT((" -t : topology id which is to be tested. For example 1\n")); TEEIO_PRINT((" -c : configuration id which is to be tested. For example 1\n")); @@ -60,6 +62,8 @@ bool parse_cmdline_option(int argc, char *argv[], char* file_name, IDE_TEST_CONF { int opt, v; uint8_t data8; + char buf[MAX_LINE_LENGTH] = {0}; + int pos = 0; TEEIO_ASSERT(argc > 0); TEEIO_ASSERT(argv != NULL); @@ -67,6 +71,17 @@ bool parse_cmdline_option(int argc, char *argv[], char* file_name, IDE_TEST_CONF TEEIO_ASSERT(ide_test_config != NULL); TEEIO_ASSERT(print_usage != NULL); + // first print the raw command line + for(int i = 0; i < argc; i++) { + if(pos + strlen(argv[i]) + 1 >= MAX_LINE_LENGTH) { + break; + } + + sprintf(buf + pos, "%s ", argv[i]); + pos = strlen(buf); + } + TEEIO_PRINT(("%s\n", buf)); + while ((opt = getopt(argc, argv, "f:t:c:s:l:b:h")) != -1) { switch (opt) { case 'f': diff --git a/teeio-validator/teeio_validator/device_pci.c b/teeio-validator/teeio_validator/device_pci.c index 84e8ae4..df153b4 100644 --- a/teeio-validator/teeio_validator/device_pci.c +++ b/teeio-validator/teeio_validator/device_pci.c @@ -36,7 +36,6 @@ uint32_t g_aer_extended_offset = 0; int m_dev_fp = 0; -FILE* m_logfile = NULL; void dump_ecap( int fd, @@ -45,21 +44,6 @@ void dump_ecap( TEST_IDE_TYPE ide_type ); -bool log_file_init(const char* filepath){ - m_logfile = fopen(filepath, "w"); - if(!m_logfile){ - TEEIO_DEBUG((TEEIO_DEBUG_ERROR, "failed to open %s to write!\n", LOGFILE)); - return false; - } - return true; -} - -void log_file_close(){ - if(!m_logfile){ - fclose(m_logfile); - } -} - // more info please check file - new_cambria_core_regs_RWF_FM85.doc.xml void check_pcie_advance_error() { diff --git a/teeio-validator/teeio_validator/doe_read_write.c b/teeio-validator/teeio_validator/doe_read_write.c index 830552d..e11b77d 100644 --- a/teeio-validator/teeio_validator/doe_read_write.c +++ b/teeio-validator/teeio_validator/doe_read_write.c @@ -37,9 +37,6 @@ size_t m_send_receive_buffer_size; void check_pcie_advance_error(); -extern FILE* m_logfile; -#define log_message_to_file(format, ...) do { fprintf(m_logfile, format, ##__VA_ARGS__); fflush(m_logfile); }while(false) - uint32_t device_pci_doe_control_read_32 () { return device_pci_read_32 (g_doe_extended_offset + PCI_EXPRESS_REG_DOE_CONTROL_OFFSET, m_dev_fp); @@ -159,16 +156,16 @@ libspdm_return_t device_doe_send_message( if (!is_doe_busy_asserted()) { /* Write the entire data object a DWORD at a time via the DOE Write Data Mailbox register. */ TEEIO_DEBUG ((TEEIO_DEBUG_INFO, "[device_doe_send_message] 'DOE Busy' bit is cleared. Start writing Mailbox ...\n")); - log_message_to_file("Requester: "); + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"Requester: \n")); for (index = 0; index < data_object_count; index++) { device_pci_doe_write_mailbox_write_32 (data_object_buffer[index]); TEEIO_DEBUG((TEEIO_DEBUG_INFO, "mailbox: 0x%08x\n", data_object_buffer[index])); - log_message_to_file("%02x %02x %02x %02x ", *((uint8_t*)(data_object_buffer + index) + 0), + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"%02x %02x %02x %02x \n", *((uint8_t*)(data_object_buffer + index) + 0), *((uint8_t*)(data_object_buffer + index) + 1), *((uint8_t*)(data_object_buffer + index) + 2), - *((uint8_t*)(data_object_buffer + index) + 3)); + *((uint8_t*)(data_object_buffer + index) + 3))); } - log_message_to_file("\n"); + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"\n")); /* Write 1b to the DOE Go bit. */ TEEIO_DEBUG ((TEEIO_DEBUG_INFO, "[device_doe_send_message] Set 'DOE Go' bit, the instance start consuming the data object.\n")); @@ -258,7 +255,7 @@ libspdm_return_t device_doe_receive_message( /* Poll the Data Object Ready bit. */ if (is_doe_data_object_ready_asserted()) { TEEIO_DEBUG ((TEEIO_DEBUG_INFO, "[device_doe_receive_message] 'Data Object Ready' bit is set. Start reading Mailbox ...\n")); - log_message_to_file("Responder: "); + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"Responder: \n")); /* Get DataObjectHeader1. */ data_object_buffer[0] = device_pci_doe_read_mailbox_read_32 (); /* Write to the DOE Read Data Mailbox to indicate a successful read. */ @@ -273,14 +270,14 @@ libspdm_return_t device_doe_receive_message( } TEEIO_DEBUG ((TEEIO_DEBUG_INFO, "[device_doe_receive_message] data_object_count = 0x%x\n", data_object_count)); - log_message_to_file("%02x %02x %02x %02x ", *((uint8_t*)(data_object_buffer + 0) + 0), + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"%02x %02x %02x %02x \n", *((uint8_t*)(data_object_buffer + 0) + 0), *((uint8_t*)(data_object_buffer + 0) + 1), *((uint8_t*)(data_object_buffer + 0) + 2), - *((uint8_t*)(data_object_buffer + 0) + 3)); - log_message_to_file("%02x %02x %02x %02x ", *((uint8_t*)(data_object_buffer + 1) + 0), + *((uint8_t*)(data_object_buffer + 0) + 3))); + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"%02x %02x %02x %02x \n", *((uint8_t*)(data_object_buffer + 1) + 0), *((uint8_t*)(data_object_buffer + 1) + 1), *((uint8_t*)(data_object_buffer + 1) + 2), - *((uint8_t*)(data_object_buffer + 1) + 3)); + *((uint8_t*)(data_object_buffer + 1) + 3))); if (data_object_count * sizeof(uint32_t) > *response_size) { *response_size = data_object_count * sizeof(uint32_t); @@ -294,12 +291,12 @@ libspdm_return_t device_doe_receive_message( data_object_buffer[index] = device_pci_doe_read_mailbox_read_32 (); /* Write to the DOE Read Data Mailbox to indicate a successful read. */ device_pci_doe_read_mailbox_write_32 (data_object_buffer[index]); - log_message_to_file("%02x %02x %02x %02x ", *((uint8_t*)(data_object_buffer + index) + 0), + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"%02x %02x %02x %02x \n", *((uint8_t*)(data_object_buffer + index) + 0), *((uint8_t*)(data_object_buffer + index) + 1), *((uint8_t*)(data_object_buffer + index) + 2), - *((uint8_t*)(data_object_buffer + index) + 3)); + *((uint8_t*)(data_object_buffer + index) + 3))); } - log_message_to_file("\n"); + TEEIO_DEBUG ((TEEIO_DEBUG_INFO,"\n")); break; } else { diff --git a/teeio-validator/teeio_validator/ide_test.c b/teeio-validator/teeio_validator/ide_test.c index 2eb58d6..1780624 100644 --- a/teeio-validator/teeio_validator/ide_test.c +++ b/teeio-validator/teeio_validator/ide_test.c @@ -789,7 +789,8 @@ bool do_run_test_suite(ide_run_test_suite_t *run_test_suite) run_test_config = run_test_config->next; } - TEEIO_PRINT(("\n\n")); + TEEIO_PRINT(("\n")); + return true; } diff --git a/teeio-validator/teeio_validator/teeio_validator.c b/teeio-validator/teeio_validator/teeio_validator.c index 48be678..0b4375a 100644 --- a/teeio-validator/teeio_validator/teeio_validator.c +++ b/teeio-validator/teeio_validator/teeio_validator.c @@ -25,7 +25,7 @@ char g_test_case[MAX_CASE_NAME_LENGTH] = {0}; TEEIO_DEBUG_LEVEL g_debug_level = TEEIO_DEBUG_WARN; uint8_t g_scan_bus = INVALID_SCAN_BUS; -extern FILE* m_logfile; +FILE* m_logfile = NULL; bool log_file_init(const char* filepath); void log_file_close(); @@ -40,51 +40,56 @@ bool update_test_config_with_given_top_config_id(IDE_TEST_CONFIG *test_config, i int main(int argc, char *argv[]) { - TEEIO_PRINT(("%s version %s\n", TEEIO_VALIDATOR_NAME, TEEIO_VALIDATOR_VERSION)); - char ide_test_ini_file[MAX_FILE_NAME] = {0}; bool to_print_usage = false; + int ret = -1; + + if (!log_file_init(LOGFILE)){ + TEEIO_PRINT(("Failed to init log file!\n")); + return -1; + } + + TEEIO_PRINT(("%s version %s\n", TEEIO_VALIDATOR_NAME, TEEIO_VALIDATOR_VERSION)); // parse command line optioins if(!parse_cmdline_option(argc, argv, ide_test_ini_file, &ide_test_config, &to_print_usage)) { print_usage(); - return -1; + goto MainDone; } if(to_print_usage) { print_usage(); - return 0; + ret = 0; + goto MainDone; } if(ide_test_ini_file[0] == 0) { TEEIO_PRINT(("-f parameter is missing.\n")); print_usage(); - return -1; + goto MainDone; } if(!parse_ide_test_init(&ide_test_config, ide_test_ini_file)) { TEEIO_PRINT(("Parse %s failed.\n", ide_test_ini_file)); - return -1; + goto MainDone; } g_pci_log = ide_test_config.main_config.pci_log; // if g_top_ids is valid, then we go into xxx mode if(g_top_id != 0 && g_config_id != 0) { if(!update_test_config_with_given_top_config_id(&ide_test_config, g_top_id, g_config_id, g_test_case)) { - return -1; + goto MainDone; } } srand((unsigned int)time(NULL)); - if (!log_file_init(LOGFILE)){ - TEEIO_PRINT(("Failed to init log file!\n")); - return -1; - } - run(&ide_test_config); + ret = 0; + +MainDone: log_file_close(); - return 0; + return ret; } diff --git a/teeio-validator/teeio_validator/test_case/test_case_full.c b/teeio-validator/teeio_validator/test_case/test_case_full.c index 17956b5..1967881 100644 --- a/teeio-validator/teeio_validator/test_case/test_case_full.c +++ b/teeio-validator/teeio_validator/test_case/test_case_full.c @@ -76,7 +76,8 @@ bool test_full_1_run(void *test_context) } // dump registers - TEEIO_PRINT(("\nPrint host registers.\n")); + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Print host registers.\n")); dump_host_registers(group_context->upper_port.mapped_kcbar_addr, group_context->rp_stream_index, group_context->upper_port.cfg_space_fd, @@ -84,7 +85,8 @@ bool test_full_1_run(void *test_context) group_context->upper_port.ecap_offset, ide_type); - TEEIO_PRINT(("\nPrint device registers.\n")); + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Print device registers.\n")); dump_dev_registers(group_context->lower_port.cfg_space_fd, group_context->lower_port.ide_id, group_context->lower_port.ecap_offset, diff --git a/teeio-validator/teeio_validator/test_case/test_case_full_keyrefresh.c b/teeio-validator/teeio_validator/test_case/test_case_full_keyrefresh.c index 3d8f46d..af1dab8 100644 --- a/teeio-validator/teeio_validator/test_case/test_case_full_keyrefresh.c +++ b/teeio-validator/teeio_validator/test_case/test_case_full_keyrefresh.c @@ -103,7 +103,8 @@ bool test_full_keyrefresh_run(void *test_context) bool res = true; while(true){ - TEEIO_PRINT(("\nCurrent KeySet=%d. Check the registers below.\n", mKeySet)); + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Current KeySet=%d. Check the registers below.\n", mKeySet)); TEEIO_PRINT(("Print host registers.\n")); dump_host_registers(group_context->upper_port.mapped_kcbar_addr, group_context->rp_stream_index, @@ -112,7 +113,8 @@ bool test_full_keyrefresh_run(void *test_context) group_context->upper_port.ecap_offset, ide_type); - TEEIO_PRINT(("\nPrint device registers.\n")); + TEEIO_PRINT(("\n")); + TEEIO_PRINT(("Print device registers.\n")); dump_dev_registers(group_context->lower_port.cfg_space_fd, group_context->lower_port.ide_id, group_context->lower_port.ecap_offset, diff --git a/teeio-validator/teeio_validator/utils.c b/teeio-validator/teeio_validator/utils.c index 7f4285c..7f422a5 100644 --- a/teeio-validator/teeio_validator/utils.c +++ b/teeio-validator/teeio_validator/utils.c @@ -23,6 +23,7 @@ #include "teeio_debug.h" #define MAX_SUPPORT_DEVICE_NUM 32 +extern FILE* m_logfile; bool IsValidDecimalString( uint8_t *Decimal, @@ -786,4 +787,18 @@ bool convert_hex_str_to_uint8(char* str, uint8_t* data8) *data8 = (uint8_t)result; return true; -} \ No newline at end of file +} + +bool log_file_init(const char* filepath){ + m_logfile = fopen(filepath, "w"); + if(!m_logfile){ + return false; + } + return true; +} + +void log_file_close(){ + if(!m_logfile){ + fclose(m_logfile); + } +}