From: Jarkko Sakkinen <jarkko@kernel.org>
To: Shuah Khan <shuah@kernel.org>
Cc: linux-sgx@vger.kernel.org, dave.hansen@intel.com,
Jarkko Sakkinen <jarkko@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] selftests/sgx: Report kselftest results
Date: Thu, 6 May 2021 04:32:00 +0300 [thread overview]
Message-ID: <20210506013201.126612-2-jarkko@kernel.org> (raw)
In-Reply-To: <20210506013201.126612-1-jarkko@kernel.org>
Use ksft API documented in tools/testing/selftests/kselftest.h to count
succeeded and failed tests and print all the debug output with
ksft_print_msg(), as advised by the documentation.
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
tools/testing/selftests/sgx/main.c | 45 +++++++++++++++++-------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index d3e1db9ee4bc..b5f17076b0c3 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -20,6 +20,8 @@
#include "main.h"
#include "../kselftest.h"
+#define NR_KSELFTESTS 3
+
static const uint64_t MAGIC = 0x1122334455667788ULL;
vdso_sgx_enter_enclave_t sgx_enter_enclave;
@@ -107,34 +109,35 @@ static Elf64_Sym *vdso_symtab_get(struct vdso_symtab *symtab, const char *name)
return NULL;
}
-bool report_results(struct sgx_enclave_run *run, int ret, uint64_t result,
- const char *test)
+bool update_ksft(struct sgx_enclave_run *run, int ret, uint64_t result, const char *test)
{
bool valid = true;
if (ret) {
- printf("FAIL: %s() returned: %d\n", test, ret);
+ ksft_print_msg("%s: ret = %d\n", test, ret);
valid = false;
}
if (run->function != EEXIT) {
- printf("FAIL: %s() function, expected: %u, got: %u\n", test, EEXIT,
- run->function);
+ ksft_print_msg("%s: function, expected: %u, got: %u\n", test, EEXIT, run->function);
valid = false;
}
if (result != MAGIC) {
- printf("FAIL: %s(), expected: 0x%lx, got: 0x%lx\n", test, MAGIC,
- result);
+ ksft_print_msg("%s: expected: 0x%lx, got: 0x%lx\n", test, MAGIC, result);
valid = false;
}
if (run->user_data) {
- printf("FAIL: %s() user data, expected: 0x0, got: 0x%llx\n",
- test, run->user_data);
+ ksft_print_msg("%s: user data, expected: 0x0, got: 0x%llx\n", test, run->user_data);
valid = false;
}
+ if (valid)
+ ksft_test_result_pass("%s: PASS");
+ else
+ ksft_test_result_fail("%s: FAIL");
+
return valid;
}
@@ -156,6 +159,9 @@ int main(int argc, char *argv[])
void *addr;
int ret;
+ ksft_print_header();
+ ksft_set_plan(NR_KSELFTESTS);
+
memset(&run, 0, sizeof(run));
if (!encl_load("test_encl.elf", &encl)) {
@@ -178,8 +184,8 @@ int main(int argc, char *argv[])
addr = mmap((void *)encl.encl_base + seg->offset, seg->size,
seg->prot, MAP_SHARED | MAP_FIXED, encl.fd, 0);
if (addr == MAP_FAILED) {
- perror("mmap() segment failed");
- exit(KSFT_FAIL);
+ ksft_print_msg("mmap() segment: %s", strerror(errno));
+ goto err;
}
}
@@ -200,32 +206,31 @@ int main(int argc, char *argv[])
sgx_enter_enclave = addr + sgx_enter_enclave_sym->st_value;
+ /* 1: unclobbered vDSO */
ret = sgx_enter_enclave_unclobbered((void *)&MAGIC, &result, 0, EENTER,
NULL, NULL, &run);
- if (!report_results(&run, ret, result, "sgx_enter_enclave_unclobbered"))
+ if (!update_ksft(&run, ret, result, "unclobbered"))
goto err;
-
- /* Invoke the vDSO directly. */
+ /* 2: clobbered vDSO */
result = 0;
ret = sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result,
0, EENTER, 0, 0, &run);
- if (!report_results(&run, ret, result, "sgx_enter_enclave"))
+ if (!update_ksft(&run, ret, result, "sgx_enter_enclave"))
goto err;
- /* And with an exit handler. */
+ /* 3: clobbered vDSO with a callback. */
run.user_handler = (__u64)user_handler;
run.user_data = 0xdeadbeef;
ret = sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result,
0, EENTER, 0, 0, &run);
- if (!report_results(&run, ret, result, "user_handler"))
+ if (!update_ksft(&run, ret, result, "user_handler"))
goto err;
- printf("SUCCESS\n");
encl_delete(&encl);
- exit(KSFT_PASS);
+ ksft_exit_pass();
err:
encl_delete(&encl);
- exit(KSFT_FAIL);
+ ksft_exit_fail();
}
--
2.31.1
next prev parent reply other threads:[~2021-05-06 1:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-06 1:31 [PATCH 1/2] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso' Jarkko Sakkinen
2021-05-06 1:32 ` Jarkko Sakkinen [this message]
2021-05-06 1:40 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210506013201.126612-2-jarkko@kernel.org \
--to=jarkko@kernel.org \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).