selftests/x86/sgx: Improve tests
Subsystems (6)
v2 cover selftests/x86/sgx: Improve tests
The bulk of this series is comprised of the selftest portion of the vDSO cleanup[*]. The big difference from the full vDSO series is to reuse as much of the existing selftest code as possible. There is still a bit of homebrew code in defining the low level assertion macro, but much less so than in the previous from-scratch version.
Cc'd Andy, who also happens to be a reviewer for the harness code, on the off chance he has bandwidth to weigh in.
Tagged for_v2? to make it clear that this doesn't need to be rushed into v23.
Passing case:
TAP version 13
1..4
ok 1 test_sgx_basic: Passed
ok 2 test_sgx_vdso: Passed
ok 3 test_sgx_vdso_exit_handler: Passed
ok 4 test_sgx_vdso_exception_handler: Passed
# Pass 4 Fail 0 Xfail 0 Xpass 0 Skip 0 Error 0
Failing case:
TAP version 13
1..4
not ok 1 Expected 'result (1234605616436508552) != MAGIC (1234605616436508552)' at main.c:324 ok 2 test_sgx_vdso: Passed
ok 3 test_sgx_vdso_exit_handler: Passed
ok 4 test_sgx_vdso_exception_handler: Passed
# Pass 3 Fail 1 Xfail 0 Xpass 0 Skip 0 Error 0
[*] https://patchwork.kernel.org/cover/11178771/
Sean Christopherson (14):
selftests/x86/sgx: Fix a benign linker warning selftests/x86/sgx: Use getauxval() to retrieve the vDSO base address selftests/x86/sgx: Sanitize the types for sgx_vdso_call()'s input
params
selftests/x86/sgx: Mark helper functions as static selftests/x86/sgx: Move vDSO setup to a helper function selftests/x86/sgx: Move individual tests into helper functions selftests/x86/sgx: Use standard helper function to signal pass/fail selftests/harness: Move operator macros to their own header file selftests/x86/sgx: Use kselftest operators to check test results selftests/x86/sgx: Handle setup failures via kselftest assertions selftests/x86/sgx: Add a check on the vDSO exception reporting
mechanism
selftests/x86/sgx: Add test of vDSO with basic exit handler selftests/x86/sgx: Add check to verify exit handler stack alignment selftests/x86/sgx: Add test for exception behavior with exit handler
Documentation/dev-tools/kselftest.rst | 9 +- MAINTAINERS | 1 + tools/testing/selftests/kselftest_harness.h | 246 +--------- tools/testing/selftests/kselftest_operators.h | 255 +++++++++++ tools/testing/selftests/x86/sgx/Makefile | 2 +- tools/testing/selftests/x86/sgx/defines.h | 7 + tools/testing/selftests/x86/sgx/main.c | 426 +++++++++++------- tools/testing/selftests/x86/sgx/sgx_call.h | 3 +- 8 files changed, 541 insertions(+), 408 deletions(-) create mode 100644 tools/testing/selftests/kselftest_operators.h
Signature · 1 line
2.22.0
PATCH v2 1/14 selftests/x86/sgx: Fix a benign linker warning
Pass a build id of "none" to the linker to suppress a warning about the build id being ignored:
/usr/bin/ld: warning: .note.gnu.build-id section discarded, --build-id ignored.
--- tools/testing/selftests/x86/sgx/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/Makefile +1 -1
@@ -27,7 +27,7 @@ $(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign $(OBJCOPY) -O binary $< $@ $(OUTPUT)/encl.elf: encl.lds encl.c encl_bootstrap.S - $(CC) $(ENCL_CFLAGS) -T $^ -o $@ + $(CC) $(ENCL_CFLAGS) -T $^ -o $@ -Wl,--build-id=none $(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin $(OUTPUT)/sgxsign signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
Signature · 1 line
2.22.0
PATCH v2 2/14 selftests/x86/sgx: Use getauxval() to retrieve the vDSO base address
In reply to Sean ChristophersonReplace the open coded ELF fun with a simple getauxval() call.
--- tools/testing/selftests/x86/sgx/main.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
tools/testing/selftests/x86/sgx/main.c +5 -16
@@ -15,6 +15,8 @@#include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> +#include <sys/auxv.h> +#include "defines.h" #include "../../../../../arch/x86/kernel/cpu/sgx/arch.h" #include "../../../../../arch/x86/include/uapi/asm/sgx.h"
@@ -31,22 +33,9 @@ struct vdso_symtab {Elf64_Word *elf_hashtab; }; -static void *vdso_get_base_addr (char *envp[]) +static void *vdso_get_base_addr (void ) { -Elf64_auxv_t *auxv; -int i; - -for (i =0 ; envp[i]; i++) - ; - - auxv = (Elf64_auxv_t *)&envp[i +1 ]; - -for (i =0 ; auxv[i].a_type !=AT_NULL ; i++) { -if (auxv[i].a_type ==AT_SYSINFO_EHDR ) -return (void *)auxv[i].a_un.a_val; - } - -return NULL ; +return (void *)getauxval (AT_SYSINFO_EHDR ); }static Elf64_Dyn *vdso_get_dyntab (void *addr)
@@ -353,7 +342,7 @@ int main(int argc, char *argv[], char *envp[])memset (&exception,0 ,sizeof (exception)); - addr =vdso_get_base_addr (envp); + addr =vdso_get_base_addr ();if (!addr)exit (1 );
Signature · 1 line
2.22.0
PATCH v2 3/14 selftests/x86/sgx: Sanitize the types for sgx_vdso_call()'s input params
In reply to Sean ChristophersonConvert the @rdx parameter for sgx_vdso_call() from 'long' to 'void *' to make it consistent with all other register params.
--- tools/testing/selftests/x86/sgx/main.c | 2 +- tools/testing/selftests/x86/sgx/sgx_call.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/x86/sgx/main.c +1 -1
@@ -356,7 +356,7 @@ int main(int argc, char *argv[], char *envp[])printf ("Input: 0x%lx\n" ,MAGIC ); -sgx_call_vdso ((void *)&MAGIC , &result,0 ,NULL ,NULL ,NULL , +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 );
tools/testing/selftests/x86/sgx/sgx_call.h +2 -1
@@ -8,7 +8,8 @@void sgx_call_eenter (void *rdi,void *rsi,void *entry); -int sgx_call_vdso (void *rdi,void *rsi,long rdx,void *rcx,void *r8,void *r9, + +int sgx_call_vdso (void *rdi,void *rsi,void *rdx,void *rcx,void *r8,void *r9,void *tcs,struct sgx_enclave_exception *ei,void *cb);#endif /* SGX_CALL_H */
Signature · 1 line
2.22.0
PATCH v2 4/14 selftests/x86/sgx: Mark helper functions as static
In reply to Sean ChristophersonTag a handful of local helper functions as static.
--- tools/testing/selftests/x86/sgx/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/x86/sgx/main.c +3 -3
@@ -241,7 +241,7 @@ static bool encl_build(struct sgx_secs *secs, void *bin,return false; } -bool get_file_size (const char *path,off_t *bin_size) +static bool get_file_size (const char *path,off_t *bin_size) {struct stat sb;int ret;
@@ -261,7 +261,7 @@ bool get_file_size(const char *path, off_t *bin_size)return true; } -bool encl_data_map (const char *path,void **bin,off_t *bin_size) +static bool encl_data_map (const char *path,void **bin,off_t *bin_size) {int fd;
@@ -288,7 +288,7 @@ bool encl_data_map(const char *path, void **bin, off_t *bin_size)return false; } -bool load_sigstruct (const char *path,void *sigstruct) +static bool load_sigstruct (const char *path,void *sigstruct) {int fd;
Signature · 1 line
2.22.0
PATCH v2 5/14 selftests/x86/sgx: Move vDSO setup to a helper function
In reply to Sean ChristophersonMove the vDSO setup code to a helper function so that it is more obvious that it's run-once setup, and that setting eenter is the end goal of the code.
--- tools/testing/selftests/x86/sgx/main.c | 41 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-)
tools/testing/selftests/x86/sgx/main.c +26 -15
@@ -309,16 +309,36 @@ static bool load_sigstruct(const char *path, void *sigstruct)return true; } +static bool setup_vdso (void ) +{ +struct vdso_symtab symtab; +Elf64_Sym *eenter_sym; +void *addr; + + addr =vdso_get_base_addr (); +if (!addr) +return false; + +if (!vdso_get_symtab (addr, &symtab)) +return false; + + eenter_sym =vdso_symtab_get (&symtab,"__vdso_sgx_enter_enclave" ); +if (!eenter_sym) +return false; + +/* eenter is used by sgx_call_vdso() to call into the vDSO. */ + eenter = addr + eenter_sym->st_value; + +return true; +} +int main (int argc,char *argv[],char *envp[]) {struct sgx_enclave_exception exception;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 *addr;void *bin;if (!encl_data_map ("encl.bin" , &bin, &bin_size))
@@ -340,20 +360,11 @@ int main(int argc, char *argv[], char *envp[])printf ("Output: 0x%lx\n" , result); +if (!setup_vdso ()) +exit (1 ); +memset (&exception,0 ,sizeof (exception)); - addr =vdso_get_base_addr (); -if (!addr) -exit (1 ); - -if (!vdso_get_symtab (addr, &symtab)) -exit (1 ); - - eenter_sym =vdso_symtab_get (&symtab,"__vdso_sgx_enter_enclave" ); -if (!eenter_sym) -exit (1 ); - eenter = addr + eenter_sym->st_value; -printf ("Input: 0x%lx\n" ,MAGIC ); sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL,
Signature · 1 line
2.22.0
PATCH v2 6/14 selftests/x86/sgx: Move individual tests into helper functions
In reply to Sean ChristophersonMove the basic and vDSO tests to their own helper functions to improve readability and prepare for using the kselftest helpers to signal pass/fail.
--- tools/testing/selftests/x86/sgx/main.c | 59 ++++++++++++++++---------- 1 file changed, 36 insertions(+), 23 deletions(-)
tools/testing/selftests/x86/sgx/main.c +36 -23
@@ -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 ); }
Signature · 1 line
2.22.0
PATCH v2 7/14 selftests/x86/sgx: Use standard helper function to signal pass/fail
In reply to Sean ChristophersonUse the various helpers provided by kselftest.h to configure the test and signal/pass failure.
--- tools/testing/selftests/x86/sgx/main.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
tools/testing/selftests/x86/sgx/main.c +12 -13
@@ -17,6 +17,8 @@#include <sys/types.h> #include <sys/auxv.h> +#include "../../kselftest.h" +#include "defines.h" #include "../../../../../arch/x86/kernel/cpu/sgx/arch.h" #include "../../../../../arch/x86/include/uapi/asm/sgx.h"
@@ -336,15 +338,12 @@ 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 ); +ksft_test_result_error ("0x%lx != 0x%lx\n" , result,MAGIC ); +return ; } - -printf ("Output: 0x%lx\n" , result); +ksft_test_result_pass ("%s: Passed\n" , __func__); }static void test_sgx_vdso (struct sgx_secs *secs)
@@ -354,16 +353,13 @@ static void test_sgx_vdso(struct sgx_secs *secs)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 ); +ksft_test_result_error ("0x%lx != 0x%lx\n" , result,MAGIC ); +return ; } - -printf ("Output: 0x%lx\n" , result); +ksft_test_result_pass ("%s: Passed\n" , __func__); }int main (int argc,char *argv[],char *envp[])
@@ -373,6 +369,9 @@ int main(int argc, char *argv[], char *envp[])off_t bin_size;void *bin; +ksft_print_header (); +ksft_set_plan (2 ); +if (!encl_data_map ("encl.bin" , &bin, &bin_size))exit (1 );
@@ -389,5 +388,5 @@ int main(int argc, char *argv[], char *envp[])test_sgx_vdso (&secs); -exit (0 ); +return ksft_exit_pass (); }
Signature · 1 line
2.22.0
PATCH v2 8/14 selftests/harness: Move operator macros to their own header file
In reply to Sean ChristophersonMove the operator macros, ASSERT_* and EXTEND_*, to a standalone header so that they can be reused by other selftests without pulling in the full harness framework, which is cumbersome to use for testing features that require a substantial amount of setup, need callbacks, etc...
--- Documentation/dev-tools/kselftest.rst | 9 +- MAINTAINERS | 1 + tools/testing/selftests/kselftest_harness.h | 246 +---------------- tools/testing/selftests/kselftest_operators.h | 255 ++++++++++++++++++ 4 files changed, 259 insertions(+), 252 deletions(-) create mode 100644 tools/testing/selftests/kselftest_operators.h
Documentation/dev-tools/kselftest.rst +1 -8
@@ -290,12 +290,5 @@ Helpers Operators --------- -.. kernel-doc:: tools/testing/selftests/kselftest_harness.h - :doc: operators +.. kernel-doc:: tools/testing/selftests/kselftest_operators.h -.. kernel-doc:: tools/testing/selftests/kselftest_harness.h - :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE - ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE - ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT - EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE - EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
MAINTAINERS +1 -0
@@ -14514,6 +14514,7 @@ F: include/uapi/linux/seccomp.h F: include/linux/seccomp.h F: tools/testing/selftests/seccomp/* F: tools/testing/selftests/kselftest_harness.h +F: tools/testing/selftests/kselftest_operators.h F: Documentation/userspace-api/seccomp_filter.rst K: \bsecure_computing K: \bTIF_SECCOMP\b
tools/testing/selftests/kselftest_harness.h +2 -244
258 lines not on this page · raw message
tools/testing/selftests/kselftest_operators.h new file +255 -0
255 lines not on this page · raw message
Signature · 1 line
2.22.0
Re: [PATCH for_v2? v2 08/14] selftests/harness: Move operator macros to their own header file
Quoted 6 lines · Sean Christopherson
Move the operator macros, ASSERT_* and EXTEND_*, to a standalone header so that they can be reused by other selftests without pulling in the full harness framework, which is cumbersome to use for testing features that require a substantial amount of setup, need callbacks, etc...
Signed-off-by Sean Christopherson <[email protected]>
Is it possible to just use a "dull" selftest and not go into this before the code is upstreamed? If yes, lets go with that. Do not mind using frameworky stuff later on. Just trying to avoid new intersects with other subsystems, that's all.
/Jarkko
Re: [PATCH for_v2? v2 08/14] selftests/harness: Move operator macros to their own header file
Quoted 10 lines · Jarkko Sakkinen
Quoted 6 lines · Sean Christopherson
Move the operator macros, ASSERT_* and EXTEND_*, to a standalone header so that they can be reused by other selftests without pulling in the full harness framework, which is cumbersome to use for testing features that require a substantial amount of setup, need callbacks, etc...
Signed-off-by Sean Christopherson <[email protected]>Is it possible to just use a "dull" selftest and not go into this before the code is upstreamed? If yes, lets go with that.
It's certainly possible, but the code is verbose and ugly (IMO), which means it will be harder for other to review.
Quoted 2 lines
Do not mind using frameworky stuff later on. Just trying to avoid new intersects with other subsystems, that's all.
Understood, but IMO this particular change is safe-ish:
- We're already intersecting with selftests
- The odds of a conflict are very low
- Andy is already involved in SGX
There are also other options:
1. Use kselftest_harness.h as-is via #undef __EXPECT. I actually would have gone with this option except the header also defines a function and we end up with a compiler error due to an unused function :-(
2. Upstream the change separately from SGX, similar to the FEATURE_CONTROL handling. E.g. I think the KVM selftests could use the operators, so there would even be concrete usage.
Re: [PATCH for_v2? v2 08/14] selftests/harness: Move operator macros to their own header file
Quoted 7 lines · Sean Christopherson
Quoted 6 lines · Jarkko Sakkinen
Quoted 5 lines · Sean Christopherson
Move the operator macros, ASSERT_* and EXTEND_*, to a standalone header so that they can be reused by other selftests without pulling in the full harness framework, which is cumbersome to use for testing features that require a substantial amount of setup, need callbacks, etc...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Sean Christopherson <[email protected]>Is it possible to just use a "dull" selftest and not go into this before the code is upstreamed? If yes, lets go with that.
It's certainly possible, but the code is verbose and ugly (IMO), which means it will be harder for other to review.
Ok, I'll try to explain in more verbose terms how I see this.
Not all selftests use the harness and I'm not yet confident that SGX has to. Unfortunately, ugly is for me something that I cannot put metrics on. Also, often "ugly" is actually better than layering because it is more transparent.
The test is comprised of simple POSIX calls that everyone knows whereas using kselftest harness requires learning new framework. Less macros makes code also easier to debug and pair compare to dissembly when required. I've done the latter at least a few times.
It will also add a requirement for code reviewers who are simply looking for a code example how SGX works also to learn the harness. In the scope of the patch set the selftest serves as a such example.
/Jarkko
Re: [PATCH for_v2? v2 08/14] selftests/harness: Move operator macros to their own header file
Quoted 23 lines · Jarkko Sakkinen
Quoted 7 lines · Sean Christopherson
Quoted 6 lines · Jarkko Sakkinen
Quoted 5 lines · Sean Christopherson
Move the operator macros, ASSERT_* and EXTEND_*, to a standalone header so that they can be reused by other selftests without pulling in the full harness framework, which is cumbersome to use for testing features that require a substantial amount of setup, need callbacks, etc...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Sean Christopherson <[email protected]>Is it possible to just use a "dull" selftest and not go into this before the code is upstreamed? If yes, lets go with that.
It's certainly possible, but the code is verbose and ugly (IMO), which means it will be harder for other to review.
Ok, I'll try to explain in more verbose terms how I see this.
Not all selftests use the harness and I'm not yet confident that SGX has to. Unfortunately, ugly is for me something that I cannot put metrics on. Also, often "ugly" is actually better than layering because it is more transparent.
Quoted 8 lines
The test is comprised of simple POSIX calls that everyone knows whereas using kselftest harness requires learning new framework. Less macros makes code also easier to debug and pair compare to dissembly when required. I've done the latter at least a few times.
It will also add a requirement for code reviewers who are simply looking for a code example how SGX works also to learn the harness. In the scope of the patch set the selftest serves as a such example.
Eh, if SGX were actually using any of the harness stuff, sure, but I'd hope most reviewers intuitively understand what ASSERT_EQ does.
PATCH v2 9/14 selftests/x86/sgx: Use kselftest operators to check test results
In reply to Sean ChristophersonUse kselftest's operators, e.g. ASSERT_EQ, EXPECT_EQ, etc... to check test results. Implement a custom __EXPECT() macro instead of using the framework defined in kselftest_harness.h. The harness framework is designed for tests that are short and sweet, e.g. true unit tests, and don't work well with SGX's need for a large, run-once setup. The harness code will also be problematic when tests for the vDSO's callback code are added in the future.
--- tools/testing/selftests/x86/sgx/main.c | 52 ++++++++++++++++++++------ 1 file changed, 40 insertions(+), 12 deletions(-)
tools/testing/selftests/x86/sgx/main.c +40 -12
@@ -18,6 +18,7 @@#include <sys/auxv.h> #include "../../kselftest.h" +#include "../../kselftest_operators.h" #include "defines.h" #include "../../../../../arch/x86/kernel/cpu/sgx/arch.h"
@@ -26,6 +27,41 @@#define PAGE_SIZE 4096 +#define EXPECT_FAILED (_assert, fmt, ...) \ +do { \ + if (_assert) \ + ksft_exit_fail_msg(fmt, ##__VA_ARGS__); \ + else \ + ksft_test_result_fail(fmt, ##__VA_ARGS__); \ +} while (0) + +#define __EXPECT (_expected, _expected_str, _seen, _seen_str, _t, _assert) \ +do { \ +/* Avoid multiple evaluation of the cases */ \ +__typeof__ (_expected) __exp = (_expected); \ +__typeof__ (_seen) __seen = (_seen); \ + if (passed && !(__exp _t __seen)) { \ +unsigned long long __exp_print = (uintptr_t )__exp; \ +unsigned long long __seen_print = (uintptr_t )__seen; \ +EXPECT_FAILED (_assert, \ +"Expected '%s (%llu) %s %s (%llu)' at %s:%u\n" , \ + _expected_str, __exp_print, #_t, _seen_str, \ + __seen_print, __FILE__, __LINE__); \ + passed = false; \ + } \ +} while (0) + +#define RUN_TEST (test_name) \ +({ \ + passed = true; \ + \ + test_name(&secs); \ + if (passed) \ + ksft_test_result_pass("%s: Passed\n", #test_name); \ +}) + +static bool passed = true; +static const uint64_t MAGIC =0x1122334455667788ULL ;void *eenter;
@@ -339,11 +375,7 @@ static void test_sgx_basic(struct sgx_secs *secs)uint64_t result =0 ;sgx_call_eenter ((void *)&MAGIC , &result, (void *)secs->base); -if (result !=MAGIC ) { -ksft_test_result_error ("0x%lx != 0x%lx\n" , result,MAGIC ); -return ; - } -ksft_test_result_pass ("%s: Passed\n" , __func__); +EXPECT_EQ (result,MAGIC ); }static void test_sgx_vdso (struct sgx_secs *secs)
@@ -355,11 +387,7 @@ static void test_sgx_vdso(struct sgx_secs *secs)sgx_call_vdso ((void *)&MAGIC , &result,NULL ,NULL ,NULL ,NULL , (void *)secs->base, &exception,NULL ); -if (result !=MAGIC ) { -ksft_test_result_error ("0x%lx != 0x%lx\n" , result,MAGIC ); -return ; - } -ksft_test_result_pass ("%s: Passed\n" , __func__); +EXPECT_EQ (result,MAGIC ); }int main (int argc,char *argv[],char *envp[])
@@ -381,12 +409,12 @@ int main(int argc, char *argv[], char *envp[])if (!encl_build (&secs, bin, bin_size, &sigstruct))exit (1 ); -test_sgx_basic (&secs); +RUN_TEST (test_sgx_basic);if (!setup_vdso ())exit (1 ); -test_sgx_vdso (&secs); +RUN_TEST (test_sgx_vdso);return ksft_exit_pass (); }
Signature · 1 line
2.22.0
PATCH v2 10/14 selftests/x86/sgx: Handle setup failures via kselftest assertions
In reply to Sean ChristophersonUse kselftest's assertion operators to report errors and exit instead of propagating errors up the stack. Using assertions reduces code and provides more detailed error messages, and all existing errors lead to exit(1) anyways, i.e. asserting isn't blocking forward progress.
--- tools/testing/selftests/x86/sgx/main.c | 174 +++++++++---------------- 1 file changed, 58 insertions(+), 116 deletions(-)
tools/testing/selftests/x86/sgx/main.c +58 -116
@@ -51,6 +51,14 @@ do { \ } \ } while (0) +#define ASSERT_RAW (_cond, fmt, ...) \ +do { \ + if (!(_cond)) { \ + fprintf(stderr, " %s:%u: ", __FILE__, __LINE__); \ + ksft_exit_fail_msg(fmt, ##__VA_ARGS__); \ + } \ +} while (0) +#define RUN_TEST (test_name) \ ({ \ passed = true; \
@@ -100,23 +108,18 @@ static void *vdso_get_dyn(void *addr, Elf64_Dyn *dyntab, Elf64_Sxword tag)return NULL ; } -static bool vdso_get_symtab (void *addr,struct vdso_symtab *symtab) +static void vdso_get_symtab (void *addr,struct vdso_symtab *symtab) {Elf64_Dyn *dyntab =vdso_get_dyntab (addr); symtab->elf_symtab =vdso_get_dyn (addr, dyntab,DT_SYMTAB ); -if (!symtab->elf_symtab) -return false; +ASSERT_NE (symtab->elf_symtab,NULL ); symtab->elf_symstrtab =vdso_get_dyn (addr, dyntab,DT_STRTAB ); -if (!symtab->elf_symstrtab) -return false; +ASSERT_NE (symtab->elf_symstrtab,NULL ); symtab->elf_hashtab =vdso_get_dyn (addr, dyntab,DT_HASH ); -if (!symtab->elf_hashtab) -return false; - -return true; +ASSERT_NE (symtab->elf_hashtab,NULL ); }static unsigned long elf_sym_hash (const char *name)
@@ -154,7 +157,7 @@ static Elf64_Sym *vdso_symtab_get(struct vdso_symtab *symtab, const char *name)return NULL ; } -static bool encl_create (int dev_fd,unsigned long bin_size, +static void encl_create (int dev_fd,unsigned long bin_size,struct sgx_secs *secs) {struct sgx_enclave_create ioc;
@@ -170,10 +173,7 @@ static bool encl_create(int dev_fd, unsigned long bin_size, secs->size <<=1 ; area =mmap (NULL , secs->size *2 ,PROT_NONE ,MAP_SHARED , dev_fd,0 ); -if (area ==MAP_FAILED ) { -perror ("mmap" ); -return false; - } +ASSERT_NE (area,MAP_FAILED ); secs->base = ((uint64_t )area + secs->size -1 ) & ~(secs->size -1 );
@@ -183,16 +183,11 @@ static bool encl_create(int dev_fd, unsigned long bin_size, ioc.src = (unsigned long )secs; rc =ioctl (dev_fd,SGX_IOC_ENCLAVE_CREATE , &ioc); -if (rc) { -fprintf (stderr,"ECREATE failed rc=%d, err=%d.\n" , rc, errno); -munmap ((void *)secs->base, secs->size); -return false; - } - -return true; +ASSERT_RAW (!rc,"ECREATE failed rc=%d, errno=%s.\n" , + rc,strerror (errno)); } -static bool encl_add_page (int dev_fd,unsigned long addr,void *data, +static void encl_add_page (int dev_fd,unsigned long addr,void *data,uint64_t flags) {struct sgx_enclave_add_page ioc;
@@ -209,15 +204,10 @@ static bool encl_add_page(int dev_fd, unsigned long addr, void *data,memset (ioc.reserved,0 ,sizeof (ioc.reserved)); rc =ioctl (dev_fd,SGX_IOC_ENCLAVE_ADD_PAGE , &ioc); -if (rc) { -fprintf (stderr,"EADD failed rc=%d.\n" , rc); -return false; - } - -return true; +ASSERT_RAW (!rc,"EADD failed rc=%d.\n" , rc); } -static bool encl_build (struct sgx_secs *secs,void *bin, +static void encl_build (struct sgx_secs *secs,void *bin,unsigned long bin_size,struct sgx_sigstruct *sigstruct) {struct sgx_enclave_init ioc;
@@ -228,13 +218,10 @@ static bool encl_build(struct sgx_secs *secs, void *bin,int rc; dev_fd =open ("/dev/sgx/enclave" ,O_RDWR ); -if (dev_fd <0 ) { -fprintf (stderr,"Unable to open /dev/sgx\n" ); -return false; - } +ASSERT_RAW (dev_fd >=0 ,"Unable to open /dev/sgx: %s\n" , +strerror (errno)); -if (!encl_create (dev_fd, bin_size, secs)) - goto out_dev_fd; +encl_create (dev_fd, bin_size, secs);for (offset =0 ; offset < bin_size; offset +=0x1000 ) {if (!offset)
@@ -243,131 +230,90 @@ static bool encl_build(struct sgx_secs *secs, void *bin, flags =SGX_SECINFO_REG |SGX_SECINFO_R |SGX_SECINFO_W |SGX_SECINFO_X ; -if (!encl_add_page (dev_fd, secs->base + offset, - bin + offset, flags)) - goto out_map; +encl_add_page (dev_fd, secs->base + offset, bin + offset, flags); } ioc.sigstruct = (uint64_t )sigstruct; rc =ioctl (dev_fd,SGX_IOC_ENCLAVE_INIT , &ioc); -if (rc) { -printf ("EINIT failed rc=%d\n" , rc); - goto out_map; - } +ASSERT_RAW (!rc,"EINIT failed rc=%d, errno=%s.\n" , rc,strerror (errno)); addr =mmap ((void *)secs->base,PAGE_SIZE ,PROT_READ |PROT_WRITE ,MAP_SHARED |MAP_FIXED , dev_fd,0 ); -if (addr ==MAP_FAILED ) { -fprintf (stderr,"mmap() failed on TCS, errno=%d.\n" , errno); -return false; - } +ASSERT_RAW (addr !=MAP_FAILED ,"mmap() failed on TCS: %s\n" , +strerror (errno)); addr =mmap ((void *)(secs->base +PAGE_SIZE ), bin_size -PAGE_SIZE ,PROT_READ |PROT_WRITE |PROT_EXEC ,MAP_SHARED |MAP_FIXED , dev_fd,0 ); -if (addr ==MAP_FAILED ) { -fprintf (stderr,"mmap() failed, errno=%d.\n" , errno); -return false; - } +ASSERT_RAW (addr !=MAP_FAILED ,"mmap() failed on REG page: %s\n" , +strerror (errno));close (dev_fd); -return true; -out_map: -munmap ((void *)secs->base, secs->size); -out_dev_fd: -close (dev_fd); -return false; } -static bool get_file_size (const char *path,off_t *bin_size) +static off_t get_file_size (const char *path) {struct stat sb;int ret; ret =stat (path, &sb); -if (ret) { -perror ("stat" ); -return false; - } - -if (!sb.st_size || sb.st_size &0xfff ) { -fprintf (stderr,"Invalid blob size %lu\n" , sb.st_size); -return false; - } - - *bin_size = sb.st_size; -return true; +ASSERT_RAW (!ret,"stat() %s failed: %s\n" , path,strerror (errno)); + +ASSERT_RAW (sb.st_size && !(sb.st_size &0xfff ), +"Invalid blob size: %llu" , sb.st_size); + +return sb.st_size; } -static bool encl_data_map (const char *path,void **bin,off_t *bin_size) +static void *encl_data_map (const char *path,off_t *bin_size) { +void *bin;int fd; fd =open (path,O_RDONLY ); -if (fd ==-1 ) { -fprintf (stderr,"open() %s failed, errno=%d.\n" , path, errno); -return false; - } +ASSERT_RAW (fd >=0 ,"open() %s failed: %s\n" , path,strerror (errno)); -if (!get_file_size (path, bin_size)) - goto err_out; + *bin_size =get_file_size (path); - *bin =mmap (NULL , *bin_size,PROT_READ ,MAP_PRIVATE , fd,0 ); -if (*bin ==MAP_FAILED ) { -fprintf (stderr,"mmap() %s failed, errno=%d.\n" , path, errno); - goto err_out; - } + bin =mmap (NULL , *bin_size,PROT_READ ,MAP_PRIVATE , fd,0 ); +ASSERT_RAW (bin !=MAP_FAILED ,"mmap() %s failed: %s\n" , + path,strerror (errno));close (fd); -return true; - -err_out: -close (fd); -return false; +return bin; } -static bool load_sigstruct (const char *path,void *sigstruct) +static void load_sigstruct (const char *path,struct sgx_sigstruct *sigstruct) { +ssize_t nr_read;int fd; fd =open (path,O_RDONLY ); -if (fd ==-1 ) { -fprintf (stderr,"open() %s failed, errno=%d.\n" , path, errno); -return false; - } - -if (read (fd, sigstruct,sizeof (struct sgx_sigstruct )) != -sizeof (struct sgx_sigstruct )) { -fprintf (stderr,"read() %s failed, errno=%d.\n" , path, errno); -close (fd); -return false; - } +ASSERT_RAW (fd >0 ,"open() %s failed: %s\n" , path,strerror (errno)); + + nr_read =read (fd, sigstruct,sizeof (struct sgx_sigstruct )); +ASSERT_RAW (nr_read ==sizeof (struct sgx_sigstruct ), +"read() %s failed: %s\n" , path,strerror (errno));close (fd); -return true; } -static bool setup_vdso (void ) +static void setup_vdso (void ) {struct vdso_symtab symtab;Elf64_Sym *eenter_sym;void *addr; addr =vdso_get_base_addr (); -if (!addr) -return false; +ASSERT_NE (addr,NULL ); -if (!vdso_get_symtab (addr, &symtab)) -return false; +vdso_get_symtab (addr, &symtab); eenter_sym =vdso_symtab_get (&symtab,"__vdso_sgx_enter_enclave" ); -if (!eenter_sym) -return false; +ASSERT_NE (eenter_sym,NULL );/* eenter is used by sgx_call_vdso() to call into the vDSO. */ eenter = addr + eenter_sym->st_value; - -return true; }static void test_sgx_basic (struct sgx_secs *secs)
@@ -400,19 +346,15 @@ int main(int argc, char *argv[], char *envp[])ksft_print_header ();ksft_set_plan (2 ); -if (!encl_data_map ("encl.bin" , &bin, &bin_size)) -exit (1 ); + bin =encl_data_map ("encl.bin" , &bin_size); -if (!load_sigstruct ("encl.ss" , &sigstruct)) -exit (1 ); +load_sigstruct ("encl.ss" , &sigstruct); -if (!encl_build (&secs, bin, bin_size, &sigstruct)) -exit (1 ); +encl_build (&secs, bin, bin_size, &sigstruct);RUN_TEST (test_sgx_basic); -if (!setup_vdso ()) -exit (1 ); +setup_vdso ();RUN_TEST (test_sgx_vdso);
Signature · 1 line
2.22.0
PATCH v2 11/14 selftests/x86/sgx: Add a check on the vDSO exception reporting mechanism
In reply to Sean ChristophersonAdd a check to verify that an exception on EENTER is correctly reported. Although the type of exception doesn't truly matter, e.g. a page fault is no more or less interesting than a general protection fault, use an unaligned TCS to trigger a #GP to avoid complications on platforms that report EPCM related #PFs as #GPs, e.g. SGX1 systems.
--- tools/testing/selftests/x86/sgx/defines.h | 4 ++++ tools/testing/selftests/x86/sgx/main.c | 6 ++++++ 2 files changed, 10 insertions(+)
tools/testing/selftests/x86/sgx/defines.h +4 -0
@@ -36,4 +36,8 @@ typedef uint64_t u64;#include "../../../../../arch/x86/kernel/cpu/sgx/arch.h" #include "../../../../../arch/x86/include/uapi/asm/sgx.h" +#define ENCLU_EENTER 2 + +#define GP_VECTOR 13 +#endif /* DEFINES_H */
tools/testing/selftests/x86/sgx/main.c +6 -0
@@ -334,6 +334,12 @@ static void test_sgx_vdso(struct sgx_secs *secs)sgx_call_vdso ((void *)&MAGIC , &result,NULL ,NULL ,NULL ,NULL , (void *)secs->base, &exception,NULL );EXPECT_EQ (result,MAGIC ); + +/* Verify a #GP is reported if the TCS isn't 4k aligned. */ +sgx_call_vdso ((void *)&MAGIC , &result,NULL ,NULL ,NULL ,NULL , + (void *)(secs->base |0xfff ), &exception,NULL ); +EXPECT_EQ (exception.trapnr,GP_VECTOR ); +EXPECT_EQ (exception.leaf,ENCLU_EENTER ); }int main (int argc,char *argv[],char *envp[])
Signature · 1 line
2.22.0
PATCH v2 12/14 selftests/x86/sgx: Add test of vDSO with basic exit handler
In reply to Sean ChristophersonAdd a test to verify that nothing explodes when using an exit handler to control the flow of the vDSO.
--- tools/testing/selftests/x86/sgx/main.c | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/main.c +27 -1
@@ -342,6 +342,31 @@ static void test_sgx_vdso(struct sgx_secs *secs)EXPECT_EQ (exception.leaf,ENCLU_EENTER ); } +static int basic_exit_handler (long rdi,long rsi,long rdx,long ursp, +long r8,long r9,void *tcs,int ret, +struct sgx_enclave_exception *e) +{ +ASSERT_EQ (ret,0 ); +return 0 ; +} + +/* +* Test the vDSO API, __vdso_sgx_enter_enclave(), with an exit handler. +*/ +static void test_sgx_vdso_exit_handler (struct sgx_secs *secs) +{ +struct sgx_enclave_exception exception; +uint64_t result =0 ; +long ret; + +memset (&exception,0 ,sizeof (exception)); + + ret =sgx_call_vdso ((void *)&MAGIC , &result,NULL ,NULL ,NULL ,NULL , + (void *)secs->base, &exception, basic_exit_handler); +ASSERT_EQ (ret,0 ); +ASSERT_EQ (result,MAGIC ); +} +int main (int argc,char *argv[],char *envp[]) {struct sgx_sigstruct sigstruct;
@@ -350,7 +375,7 @@ int main(int argc, char *argv[], char *envp[])void *bin;ksft_print_header (); -ksft_set_plan (2 ); +ksft_set_plan (3 ); bin =encl_data_map ("encl.bin" , &bin_size);
@@ -363,6 +388,7 @@ int main(int argc, char *argv[], char *envp[])setup_vdso ();RUN_TEST (test_sgx_vdso); +RUN_TEST (test_sgx_vdso_exit_handler);return ksft_exit_pass (); }
Signature · 1 line
2.22.0
PATCH v2 13/14 selftests/x86/sgx: Add check to verify exit handler stack alignment
In reply to Sean ChristophersonAdd an assembly trampoline to the basic exit handler to snapshot the pre-CALL %rsp. Use the snapshot to verify that the stack is 16-byte aligned as required by the x86_64 ABI.
--- tools/testing/selftests/x86/sgx/defines.h | 1 + tools/testing/selftests/x86/sgx/main.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)
tools/testing/selftests/x86/sgx/defines.h +1 -0
@@ -15,6 +15,7 @@ typedef uint64_t u64;#define __aligned (x) __attribute__((__aligned__(x)))#define __packed __attribute__((packed)) +#define __used __attribute__((__used__))/* Derived from asm-generic/bitsperlong.h. */ #if __x86_64__
tools/testing/selftests/x86/sgx/main.c +17 -3
@@ -342,14 +342,28 @@ static void test_sgx_vdso(struct sgx_secs *secs)EXPECT_EQ (exception.leaf,ENCLU_EENTER ); } -static int basic_exit_handler (long rdi,long rsi,long rdx,long ursp, -long r8,long r9,void *tcs,int ret, -struct sgx_enclave_exception *e) +static int __used __basic_exit_handler (long rdi,long rsi,long rdx,long ursp, +long r8,long r9,void *tcs,int ret, +struct sgx_enclave_exception *e) { +ASSERT_RAW (!(r9 &0xf ),"Pre-CALL RSP not 16-byte aligned: %lx\n" , r9);ASSERT_EQ (ret,0 );return 0 ; } +extern void *basic_exit_handler; + +static void __used basic_exit_handler_trampoline (void ) +{ +/* Load the pre-CALL %rsp into %r9 to verify correct alignment. */ + asmvolatile ("1:\n\t" +"lea 0x8(%%rsp), %%r9\n\t" +"jmp __basic_exit_handler\n\t" +"basic_exit_handler: .quad 1b\n\t" +".global basic_exit_handler" + :::"memory" ); +} +/* * Test the vDSO API, __vdso_sgx_enter_enclave(), with an exit handler. */
Signature · 1 line
2.22.0
PATCH v2 14/14 selftests/x86/sgx: Add test for exception behavior with exit handler
In reply to Sean ChristophersonAdd a test to verify the kernel and vDSO provide the correct exception info when using an exit handler, e.g. leaf, trapnr and error_code, and that the vDSO correctly interprets the return from the exit handler. To do so, change the enclave's protections to PROT_NONE and iteratively fix the faults encountered, with various assertions along the way, e.g. the first fault should always be on the TCS, at least three total faults should occur, etc...
--- tools/testing/selftests/x86/sgx/defines.h | 2 + tools/testing/selftests/x86/sgx/main.c | 92 ++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/defines.h +2 -0
@@ -38,7 +38,9 @@ typedef uint64_t u64;#include "../../../../../arch/x86/include/uapi/asm/sgx.h" #define ENCLU_EENTER 2 +#define ENCLU_ERESUME 3#define GP_VECTOR 13 +#define PF_VECTOR 14#endif /* DEFINES_H */
tools/testing/selftests/x86/sgx/main.c +91 -1
110 lines not on this page · raw message
Signature · 1 line
2.22.0
Quoted 11 lines · Sean Christopherson
The bulk of this series is comprised of the selftest portion of the vDSO cleanup[*]. The big difference from the full vDSO series is to reuse as much of the existing selftest code as possible. There is still a bit of homebrew code in defining the low level assertion macro, but much less so than in the previous from-scratch version.
Cc'd Andy, who also happens to be a reviewer for the harness code, on the off chance he has bandwidth to weigh in.
Tagged
for_v2? to make it clear that this doesn't need to be rushed into v23.
No need for harness right now. Open coded tests are better for initial upstreaming.
/Jarkko
Quoted 7 lines · Jarkko Sakkinen
Quoted 6 lines · Sean Christopherson
The bulk of this series is comprised of the selftest portion of the vDSO cleanup[*]. The big difference from the full vDSO series is to reuse as much of the existing selftest code as possible. There is still a bit of homebrew code in defining the low level assertion macro, but much less so than in the previous from-scratch version.
Quoted 8 lines
Quoted 5 lines
Cc'd Andy, who also happens to be a reviewer for the harness code, on the off chance he has bandwidth to weigh in.
Tagged
for_v2? to make it clear that this doesn't need to be rushed into v23.No need for harness right now. Open coded tests are better for initial upstreaming.
Macros make code more productive to write but harder to read and debug. With only maybe three tests the cost of using them does not pay.
/Jarkko
Quoted 14 lines · Jarkko Sakkinen
Quoted 13 lines · Jarkko Sakkinen
Quoted 11 lines · Sean Christopherson
The bulk of this series is comprised of the selftest portion of the vDSO cleanup[*]. The big difference from the full vDSO series is to reuse as much of the existing selftest code as possible. There is still a bit of homebrew code in defining the low level assertion macro, but much less so than in the previous from-scratch version.
Cc'd Andy, who also happens to be a reviewer for the harness code, on the off chance he has bandwidth to weigh in.
Tagged
for_v2? to make it clear that this doesn't need to be rushed into v23.
Quoted 6 lines
Quoted 2 lines
No need for harness right now. Open coded tests are better for initial upstreaming.
Macros make code more productive to write but harder to read and debug. With only maybe three tests the cost of using them does not pay.
Harder to read is debatable, personally I find this
static void test_sgx_basic(struct sgx_secs *secs)
{
uint64_t result = 0;
sgx_call_eenter((void *)&MAGIC, &result, (void *)secs->base);
EXPECT_EQ(result, MAGIC);
}to be more intuitive than
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);
}but to each his own.
The debug argument I just don't buy. How is this
$ ./test_sgx TAP version 13 1..4 not ok 1 Expected 'result (0) == MAGIC (1234605616436508552)' at main.c:325 ok 2 test_sgx_vdso: Passed ok 3 test_sgx_vdso_exit_handler: Passed ok 4 test_sgx_vdso_exception_handler: Passed # Pass 3 Fail 1 Xfail 0 Xpass 0 Skip 0 Error 0
harder to debug than this?
$ ./test_sgx Input: 0x1122334455667788 0x0 != 0x1122334455667788
Except for the error status in the shell there's not even an explicit indicator that something went wrong, let alone any information about what test was being run, what exact check failed, etc...
Quoted 65 lines · Sean Christopherson
Quoted 14 lines · Jarkko Sakkinen
Quoted 13 lines · Jarkko Sakkinen
Quoted 11 lines · Sean Christopherson
The bulk of this series is comprised of the selftest portion of the vDSO cleanup[*]. The big difference from the full vDSO series is to reuse as much of the existing selftest code as possible. There is still a bit of homebrew code in defining the low level assertion macro, but much less so than in the previous from-scratch version.
Cc'd Andy, who also happens to be a reviewer for the harness code, on the off chance he has bandwidth to weigh in.
Tagged
for_v2? to make it clear that this doesn't need to be rushed into v23.Quoted 6 lines
Quoted 2 lines
No need for harness right now. Open coded tests are better for initial upstreaming.
Macros make code more productive to write but harder to read and debug. With only maybe three tests the cost of using them does not pay.
Harder to read is debatable, personally I find this
static void
test_sgx_basic(struct sgx_secs *secs){ uint64_t result = 0; sgx_call_eenter((void *)&MAGIC, &result, (void *)secs->base); EXPECT_EQ(result, MAGIC); }to be more intuitive than
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); }but to each his own.
The debug argument I just don't buy. How is this
$ ./test_sgx TAP version 13 1..4 not ok 1 Expected 'result (0) == MAGIC (1234605616436508552)' at main.c:325 ok 2 test_sgx_vdso: Passed ok 3 test_sgx_vdso_exit_handler: Passed ok 4 test_sgx_vdso_exception_handler: Passed # Pass 3 Fail 1 Xfail 0 Xpass 0 Skip 0 Error 0harder to debug than this?
Quoted 7 lines
$ ./test_sgx Input: 0x1122334455667788 0x0 != 0x1122334455667788Except for the error status in the shell there's not even an explicit indicator that something went wrong, let alone any information about what test was being run, what exact check failed, etc...
Lets consider this post upstreaming. For me it comes in the end not to add new twists to the patch set unless there is life and death reason to do so.
/Jarkko
Quoted 71 lines · Jarkko Sakkinen
Quoted 69 lines · Sean Christopherson
Quoted 14 lines · Jarkko Sakkinen
Quoted 13 lines · Jarkko Sakkinen
Quoted 11 lines · Sean Christopherson
The bulk of this series is comprised of the selftest portion of the vDSO cleanup[*]. The big difference from the full vDSO series is to reuse as much of the existing selftest code as possible. There is still a bit of homebrew code in defining the low level assertion macro, but much less so than in the previous from-scratch version.
Cc'd Andy, who also happens to be a reviewer for the harness code, on the off chance he has bandwidth to weigh in.
Tagged
for_v2? to make it clear that this doesn't need to be rushed into v23.Quoted 6 lines
Quoted 2 lines
No need for harness right now. Open coded tests are better for initial upstreaming.
Macros make code more productive to write but harder to read and debug. With only maybe three tests the cost of using them does not pay.
Harder to read is debatable, personally I find this
static void
test_sgx_basic(struct sgx_secs *secs){ uint64_t result = 0; sgx_call_eenter((void *)&MAGIC, &result, (void *)secs->base); EXPECT_EQ(result, MAGIC); }to be more intuitive than
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); }but to each his own.
The debug argument I just don't buy. How is this
$ ./test_sgx TAP version 13 1..4 not ok 1 Expected 'result (0) == MAGIC (1234605616436508552)' at main.c:325 ok 2 test_sgx_vdso: Passed ok 3 test_sgx_vdso_exit_handler: Passed ok 4 test_sgx_vdso_exception_handler: Passed # Pass 3 Fail 1 Xfail 0 Xpass 0 Skip 0 Error 0harder to debug than this?
$ ./test_sgx Input: 0x1122334455667788 0x0 != 0x1122334455667788
Quoted 8 lines
Quoted 3 lines
Except for the error status in the shell there's not even an explicit indicator that something went wrong, let alone any information about what test was being run, what exact check failed, etc...
Lets consider this post upstreaming. For me it comes in the end not to add new twists to the patch set unless there is life and death reason to do so.
I tend to agree.
For what it's worth, the main reason that I don't use any test harness in most of the x86 selftests is that I wrote them so early in the history of kselftests that there wasn't any infrastructure. I haven't looked to see what the best practice is now.