[PATCH for_v23 12/16] selftests/x86/sgx: Move existing sub-test to a separate helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move the basic test of running the enclave using the vDSO to a separate
helper in preparation for introducing new sub-tests and variations on
the existing test.

Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
---
 tools/testing/selftests/x86/sgx/main.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c
index b7b32cf144f4..93b8d7781782 100644
--- a/tools/testing/selftests/x86/sgx/main.c
+++ b/tools/testing/selftests/x86/sgx/main.c
@@ -307,14 +307,28 @@ void load_sigstruct(const char *path, struct sgx_sigstruct *sigstruct)
 int sgx_call(void *rdi, void *rsi, long rdx, long rcx, long r8, long r9,
 	     void *tcs, struct sgx_enclave_exception *ei, void *cb);
 
-int main(int argc, char *argv[], char *envp[])
+/*
+ * Test the vDSO API, __vdso_sgx_enter_enclave(), without an exit handler.
+ */
+static void test_vdso_no_exit_handler(struct sgx_secs *secs)
 {
 	struct sgx_enclave_exception exception;
+	uint64_t result = 0;
+
+	memset(&exception, 0, sizeof(exception));
+
+	/* Verify the enclave copies MAGIC to result. */
+	sgx_call((void *)&MAGIC, &result, 0, 0, 0, 0, (void *)secs->base,
+		 &exception, NULL);
+	ASSERT_EQ(result, MAGIC);
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
 	struct sgx_sigstruct sigstruct;
 	struct vdso_symtab symtab;
 	Elf64_Sym *eenter_sym;
 	struct sgx_secs secs;
-	uint64_t result = 0;
 	off_t bin_size;
 	void *bin;
 	void *addr;
@@ -323,8 +337,6 @@ int main(int argc, char *argv[], char *envp[])
 
 	load_sigstruct("encl.ss", &sigstruct);
 
-	memset(&exception, 0, sizeof(exception));
-
 	addr = vdso_get_base_addr();
 	ASSERT_NE(addr, NULL);
 
@@ -337,10 +349,7 @@ int main(int argc, char *argv[], char *envp[])
 
 	encl_build(&secs, bin, bin_size, &sigstruct);
 
-	sgx_call((void *)&MAGIC, &result, 0, 0, 0, 0, (void *)secs.base,
-		 &exception, NULL);
-
-	ASSERT_EQ(result, MAGIC);
+	test_vdso_no_exit_handler(&secs);
 
 	printf("All tests passed!\n");
 	exit(0);
-- 
2.22.0




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux