diff mbox series

[for_v2?,v2,06/14] selftests/x86/sgx: Move individual tests into helper functions

Message ID 20191017030340.18301-7-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series selftests/x86/sgx: Improve tests | expand

Commit Message

Sean Christopherson Oct. 17, 2019, 3:03 a.m. UTC
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@intel.com>
---
 tools/testing/selftests/x86/sgx/main.c | 59 ++++++++++++++++----------
 1 file changed, 36 insertions(+), 23 deletions(-)
diff mbox series

Patch

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