Move the basic and vDSO tests to their own helper functions to improve readability and prepare for using the kselftest helpers to signal pass/fail. Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> --- tools/testing/selftests/x86/sgx/main.c | 59 ++++++++++++++++---------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c index 2510cacb5154..140dffe9c765 100644 --- a/tools/testing/selftests/x86/sgx/main.c +++ b/tools/testing/selftests/x86/sgx/main.c @@ -332,12 +332,44 @@ static bool setup_vdso(void) return true; } -int main(int argc, char *argv[], char *envp[]) +static void test_sgx_basic(struct sgx_secs *secs) +{ + uint64_t result = 0; + + printf("Input: 0x%lx\n", MAGIC); + + sgx_call_eenter((void *)&MAGIC, &result, (void *)secs->base); + if (result != MAGIC) { + fprintf(stderr, "0x%lx != 0x%lx\n", result, MAGIC); + exit(1); + } + + printf("Output: 0x%lx\n", result); +} + +static void test_sgx_vdso(struct sgx_secs *secs) { struct sgx_enclave_exception exception; + uint64_t result = 0; + + memset(&exception, 0, sizeof(exception)); + + printf("Input: 0x%lx\n", MAGIC); + + sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL, + (void *)secs->base, &exception, NULL); + if (result != MAGIC) { + fprintf(stderr, "0x%lx != 0x%lx\n", result, MAGIC); + exit(1); + } + + printf("Output: 0x%lx\n", result); +} + +int main(int argc, char *argv[], char *envp[]) +{ struct sgx_sigstruct sigstruct; struct sgx_secs secs; - uint64_t result = 0; off_t bin_size; void *bin; @@ -350,31 +382,12 @@ int main(int argc, char *argv[], char *envp[]) if (!encl_build(&secs, bin, bin_size, &sigstruct)) exit(1); - printf("Input: 0x%lx\n", MAGIC); - - sgx_call_eenter((void *)&MAGIC, &result, (void *)secs.base); - if (result != MAGIC) { - fprintf(stderr, "0x%lx != 0x%lx\n", result, MAGIC); - exit(1); - } - - printf("Output: 0x%lx\n", result); + test_sgx_basic(&secs); if (!setup_vdso()) exit(1); - memset(&exception, 0, sizeof(exception)); - - printf("Input: 0x%lx\n", MAGIC); - - sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL, - (void *)secs.base, &exception, NULL); - if (result != MAGIC) { - fprintf(stderr, "0x%lx != 0x%lx\n", result, MAGIC); - exit(1); - } - - printf("Output: 0x%lx\n", result); + test_sgx_vdso(&secs); exit(0); } -- 2.22.0