Skip to content

Commit

Permalink
Add case dump func
Browse files Browse the repository at this point in the history
used by "echo list > /sys/kernel/debug/tdx/tdx-test"

Signed-off-by: DCyan_Elite <[email protected]>
  • Loading branch information
CrescentLove committed Oct 31, 2023
1 parent 6d0beb2 commit 29ade76
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions tdx-compliance/tdx-compliance.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ LIST_HEAD(cpuid_list);
#define OPMASK_CPUID 1
#define OPMASK_CR 2
#define OPMASK_MSR 4
#define OPMASK_DUMP 0x800
#define OPMASK_SINGLE 0x8000

#define CPUID_DUMP_PATTERN \
Expand Down Expand Up @@ -87,6 +88,17 @@ void parse_version(void)
spec_version = (VER1_0 | VER1_5);
}

static char* case_version(int ret) {
switch (ret) {
case VER1_0:
return "1.0";
case VER1_5:
return "1.5";
}

return "";
}

void parse_input(char* s)
{
memset(case_name, 0, sizeof(case_name));
Expand Down Expand Up @@ -206,6 +218,10 @@ static int run_all_msr(void)
for (i = 0; i < ARRAY_SIZE(msr_cases); i++, t++) {
if (operation & 0x8000 && strcmp(case_name, t->name) != 0)
continue;
else if (operation & 0x800 && spec_version & t->version) {
pr_buf("%s %s\n", t->name, case_version(t->version));
continue;
}

if (!(spec_version & t->version)) continue;

Expand Down Expand Up @@ -275,6 +291,10 @@ static int run_all_cpuid(void)

if (operation & 0x8000 && strcmp(case_name, t->name) != 0)
continue;
else if (operation & 0x800 && spec_version & t->version) {
pr_buf("%s %s\n", t->name, case_version(t->version));
continue;
}

if (!(spec_version & t->version)) continue;

Expand Down Expand Up @@ -346,6 +366,10 @@ static int run_all_cr(void)
for (i = 0; i < ARRAY_SIZE(cr_list); i++, t++) {
if (operation & 0x8000 && strcmp(case_name, t->name) != 0)
continue;
else if (operation & 0x800 && spec_version & t->version) {
pr_buf("%s %s\n", t->name, case_version(t->version));
continue;
}

if (!(spec_version & t->version)) continue;

Expand Down Expand Up @@ -409,6 +433,8 @@ tdx_tests_proc_write(struct file *file,
operation |= OPMASK_MSR;
else if (strstr(case_name, "all"))
operation |= OPMASK_CPUID | OPMASK_CR | OPMASK_MSR;
else if (strstr(case_name, "list"))
operation |= OPMASK_DUMP | OPMASK_CPUID | OPMASK_CR | OPMASK_MSR;
else
operation |= OPMASK_SINGLE | OPMASK_CPUID | OPMASK_CR | OPMASK_MSR;

Expand All @@ -426,9 +452,10 @@ tdx_tests_proc_write(struct file *file,
if (operation & OPMASK_MSR)
run_all_msr();

pr_buf("Total:%d, PASS:%d, FAIL:%d, SKIP:%d\n",
stat_total, stat_pass, stat_fail,
stat_total - stat_pass - stat_fail);
if (!(operation & OPMASK_DUMP))
pr_buf("Total:%d, PASS:%d, FAIL:%d, SKIP:%d\n",
stat_total, stat_pass, stat_fail,
stat_total - stat_pass - stat_fail);

kfree(str_input);
operation = 0;
Expand Down

0 comments on commit 29ade76

Please sign in to comment.