Skip to content

Commit

Permalink
Refine output information for teeio_validator
Browse files Browse the repository at this point in the history
Signed-off-by: Min Xu <min.m.xu@intel.com>
  • Loading branch information
mxu9 committed Apr 10, 2024
1 parent cfdb7d2 commit d2d9a3b
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 55 deletions.
4 changes: 2 additions & 2 deletions teeio-validator/include/teeio_validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
19 changes: 17 additions & 2 deletions teeio-validator/teeio_validator/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ide_test.ini> : The file name of test configuration. For example ide_test.ini\n"));
TEEIO_PRINT((" -t <top_id> : topology id which is to be tested. For example 1\n"));
TEEIO_PRINT((" -c <config_id> : configuration id which is to be tested. For example 1\n"));
Expand All @@ -60,13 +62,26 @@ 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);
TEEIO_ASSERT(file_name != NULL);
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':
Expand Down
16 changes: 0 additions & 16 deletions teeio-validator/teeio_validator/device_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
{
Expand Down
27 changes: 12 additions & 15 deletions teeio-validator/teeio_validator/doe_read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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. */
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion teeio-validator/teeio_validator/ide_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
33 changes: 19 additions & 14 deletions teeio-validator/teeio_validator/teeio_validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
6 changes: 4 additions & 2 deletions teeio-validator/teeio_validator/test_case/test_case_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ 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,
group_context->upper_port.ide_id,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion teeio-validator/teeio_validator/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "teeio_debug.h"

#define MAX_SUPPORT_DEVICE_NUM 32
extern FILE* m_logfile;

bool IsValidDecimalString(
uint8_t *Decimal,
Expand Down Expand Up @@ -786,4 +787,18 @@ bool convert_hex_str_to_uint8(char* str, uint8_t* data8)

*data8 = (uint8_t)result;
return true;
}
}

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

0 comments on commit d2d9a3b

Please sign in to comment.