diff mbox series

[for_v23,10/16] selftests/x86/sgx: Handle setup failures via test assertions

Message ID 20191008044613.12350-11-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series x86/vdso: sgx: Major vDSO cleanup | expand

Commit Message

Sean Christopherson Oct. 8, 2019, 4:46 a.m. UTC
Use the recently added assertion framework to report errors and exit
instead of propagating the error back up the stack.  Using assertions
reduces code and provides more detailed error messages, and has no
downsides as all errors lead to exit(1) anyways, i.e. an assertion
isn't blocking forward progress.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 tools/testing/selftests/x86/sgx/main.c | 170 +++++++++----------------
 1 file changed, 59 insertions(+), 111 deletions(-)

Comments

Jarkko Sakkinen Oct. 15, 2019, 10:16 a.m. UTC | #1
On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> Use the recently added assertion framework to report errors and exit
> instead of propagating the error back up the stack.  Using assertions
> reduces code and provides more detailed error messages, and has no
> downsides as all errors lead to exit(1) anyways, i.e. an assertion
> isn't blocking forward progress.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

I'm also dropping all of this. Was too hazy with it because of rush last
week.

You shoud use EXCEPT_* macros instead of your home baked ones:

https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html

I don't know what you are talking about in this commit message.
"Recently added" tells me absolutely nothing. All I see that you
are adding your own ad hoc crap.

/Jarkko
Jarkko Sakkinen Oct. 15, 2019, 10:24 a.m. UTC | #2
On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > Use the recently added assertion framework to report errors and exit
> > instead of propagating the error back up the stack.  Using assertions
> > reduces code and provides more detailed error messages, and has no
> > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > isn't blocking forward progress.
> > 
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> I'm also dropping all of this. Was too hazy with it because of rush last
> week.
> 
> You shoud use EXCEPT_* macros instead of your home baked ones:
> 
> https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> 
> I don't know what you are talking about in this commit message.
> "Recently added" tells me absolutely nothing. All I see that you
> are adding your own ad hoc crap.

E.g.

1. WTH the new thing is.
2. Why is it overriding the macros already defined for kselftest
   (see the documentation).
3. Before vDSO commits please provide a patch set that does the
   migration with clear explanation what is going on.

/Jarkko
Jarkko Sakkinen Oct. 15, 2019, 10:25 a.m. UTC | #3
On Tue, Oct 15, 2019 at 01:24:08PM +0300, Jarkko Sakkinen wrote:
> On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> > On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > > Use the recently added assertion framework to report errors and exit
> > > instead of propagating the error back up the stack.  Using assertions
> > > reduces code and provides more detailed error messages, and has no
> > > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > > isn't blocking forward progress.
> > > 
> > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > 
> > I'm also dropping all of this. Was too hazy with it because of rush last
> > week.
> > 
> > You shoud use EXCEPT_* macros instead of your home baked ones:
> > 
> > https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> > 
> > I don't know what you are talking about in this commit message.
> > "Recently added" tells me absolutely nothing. All I see that you
> > are adding your own ad hoc crap.
> 
> E.g.
> 
> 1. WTH the new thing is.
> 2. Why is it overriding the macros already defined for kselftest
>    (see the documentation).
> 3. Before vDSO commits please provide a patch set that does the
>    migration with clear explanation what is going on.

See kselftest_harness.h.

/Jarkko
Jarkko Sakkinen Oct. 15, 2019, 11:03 a.m. UTC | #4
On Tue, Oct 15, 2019 at 01:25:55PM +0300, Jarkko Sakkinen wrote:
> On Tue, Oct 15, 2019 at 01:24:08PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> > > On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > > > Use the recently added assertion framework to report errors and exit
> > > > instead of propagating the error back up the stack.  Using assertions
> > > > reduces code and provides more detailed error messages, and has no
> > > > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > > > isn't blocking forward progress.
> > > > 
> > > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > > 
> > > I'm also dropping all of this. Was too hazy with it because of rush last
> > > week.
> > > 
> > > You shoud use EXCEPT_* macros instead of your home baked ones:
> > > 
> > > https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> > > 
> > > I don't know what you are talking about in this commit message.
> > > "Recently added" tells me absolutely nothing. All I see that you
> > > are adding your own ad hoc crap.
> > 
> > E.g.
> > 
> > 1. WTH the new thing is.
> > 2. Why is it overriding the macros already defined for kselftest
> >    (see the documentation).
> > 3. Before vDSO commits please provide a patch set that does the
> >    migration with clear explanation what is going on.
> 
> See kselftest_harness.h.

For me this all seems like unnecessary stuff done just before patch set
release. It is no in anyway necessary for v23 or even for merging SGX to
mainline. You seriously cannot stuff like this being merged quickly. It
will take a number of days to discuss all this through. My mistake was
to merge it before enough consideration.

Sometimes it is better just to do the *necessary*. Especially when it
is time to release something (e.g. just the minimal changes for vDSO
stuff).

I replaced all of this with v22 selftest and I'm in the process of
adding EENTER call path and splitting that to two commits.

/Jarkko
Sean Christopherson Oct. 15, 2019, 4:18 p.m. UTC | #5
On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > Use the recently added assertion framework to report errors and exit
> > instead of propagating the error back up the stack.  Using assertions
> > reduces code and provides more detailed error messages, and has no
> > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > isn't blocking forward progress.
> > 
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> I'm also dropping all of this. Was too hazy with it because of rush last
> week.
> 
> You shoud use EXCEPT_* macros instead of your home baked ones:
> 
> https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> 
> I don't know what you are talking about in this commit message.
> "Recently added" tells me absolutely nothing.

It's a fairly common way to refer to changes introduced in prior patches
of the same series.

> All I see that you are adding your own ad hoc crap.

Yo, same team.  A simple "hey, there's already macros for this!" would
suffice.
Sean Christopherson Oct. 15, 2019, 4:27 p.m. UTC | #6
On Tue, Oct 15, 2019 at 02:03:48PM +0300, Jarkko Sakkinen wrote:
> On Tue, Oct 15, 2019 at 01:25:55PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Oct 15, 2019 at 01:24:08PM +0300, Jarkko Sakkinen wrote:
> > > On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> > > > On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > > > > Use the recently added assertion framework to report errors and exit
> > > > > instead of propagating the error back up the stack.  Using assertions
> > > > > reduces code and provides more detailed error messages, and has no
> > > > > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > > > > isn't blocking forward progress.
> > > > > 
> > > > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > > > 
> > > > I'm also dropping all of this. Was too hazy with it because of rush last
> > > > week.
> > > > 
> > > > You shoud use EXCEPT_* macros instead of your home baked ones:
> > > > 
> > > > https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> > > > 
> > > > I don't know what you are talking about in this commit message.
> > > > "Recently added" tells me absolutely nothing. All I see that you
> > > > are adding your own ad hoc crap.
> > > 
> > > E.g.
> > > 
> > > 1. WTH the new thing is.
> > > 2. Why is it overriding the macros already defined for kselftest
> > >    (see the documentation).
> > > 3. Before vDSO commits please provide a patch set that does the
> > >    migration with clear explanation what is going on.
> > 
> > See kselftest_harness.h.
> 
> For me this all seems like unnecessary stuff done just before patch set
> release. It is no in anyway necessary for v23 or even for merging SGX to
> mainline. You seriously cannot stuff like this being merged quickly. It
> will take a number of days to discuss all this through.

I never requested that this be merged quickly.  I sent patches to improve
the coverage of the selftests and make them easier to debug, no more, no
less.
Jarkko Sakkinen Oct. 16, 2019, 10:19 a.m. UTC | #7
On Tue, Oct 15, 2019 at 09:18:39AM -0700, Sean Christopherson wrote:
> On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> > On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > > Use the recently added assertion framework to report errors and exit
> > > instead of propagating the error back up the stack.  Using assertions
> > > reduces code and provides more detailed error messages, and has no
> > > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > > isn't blocking forward progress.
> > > 
> > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > 
> > I'm also dropping all of this. Was too hazy with it because of rush last
> > week.
> > 
> > You shoud use EXCEPT_* macros instead of your home baked ones:
> > 
> > https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> > 
> > I don't know what you are talking about in this commit message.
> > "Recently added" tells me absolutely nothing.
> 
> It's a fairly common way to refer to changes introduced in prior patches
> of the same series.
> 
> > All I see that you are adding your own ad hoc crap.
> 
> Yo, same team.  A simple "hey, there's already macros for this!" would
> suffice.

Since apologies, was over the top with this.

/Jarkko
Jarkko Sakkinen Oct. 16, 2019, 10:20 a.m. UTC | #8
On Tue, Oct 15, 2019 at 09:27:53AM -0700, Sean Christopherson wrote:
> On Tue, Oct 15, 2019 at 02:03:48PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Oct 15, 2019 at 01:25:55PM +0300, Jarkko Sakkinen wrote:
> > > On Tue, Oct 15, 2019 at 01:24:08PM +0300, Jarkko Sakkinen wrote:
> > > > On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> > > > > On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > > > > > Use the recently added assertion framework to report errors and exit
> > > > > > instead of propagating the error back up the stack.  Using assertions
> > > > > > reduces code and provides more detailed error messages, and has no
> > > > > > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > > > > > isn't blocking forward progress.
> > > > > > 
> > > > > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > > > > 
> > > > > I'm also dropping all of this. Was too hazy with it because of rush last
> > > > > week.
> > > > > 
> > > > > You shoud use EXCEPT_* macros instead of your home baked ones:
> > > > > 
> > > > > https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> > > > > 
> > > > > I don't know what you are talking about in this commit message.
> > > > > "Recently added" tells me absolutely nothing. All I see that you
> > > > > are adding your own ad hoc crap.
> > > > 
> > > > E.g.
> > > > 
> > > > 1. WTH the new thing is.
> > > > 2. Why is it overriding the macros already defined for kselftest
> > > >    (see the documentation).
> > > > 3. Before vDSO commits please provide a patch set that does the
> > > >    migration with clear explanation what is going on.
> > > 
> > > See kselftest_harness.h.
> > 
> > For me this all seems like unnecessary stuff done just before patch set
> > release. It is no in anyway necessary for v23 or even for merging SGX to
> > mainline. You seriously cannot stuff like this being merged quickly. It
> > will take a number of days to discuss all this through.
> 
> I never requested that this be merged quickly.  I sent patches to improve
> the coverage of the selftests and make them easier to debug, no more, no
> less.

OK, sorry I was over the top with this. Sincere apologies from my
part :-)

/Jarkko
Sean Christopherson Oct. 16, 2019, 8:21 p.m. UTC | #9
On Tue, Oct 15, 2019 at 01:25:55PM +0300, Jarkko Sakkinen wrote:
> On Tue, Oct 15, 2019 at 01:24:08PM +0300, Jarkko Sakkinen wrote:
> > On Tue, Oct 15, 2019 at 01:16:35PM +0300, Jarkko Sakkinen wrote:
> > > On Mon, Oct 07, 2019 at 09:46:07PM -0700, Sean Christopherson wrote:
> > > > Use the recently added assertion framework to report errors and exit
> > > > instead of propagating the error back up the stack.  Using assertions
> > > > reduces code and provides more detailed error messages, and has no
> > > > downsides as all errors lead to exit(1) anyways, i.e. an assertion
> > > > isn't blocking forward progress.
> > > > 
> > > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > > 
> > > I'm also dropping all of this. Was too hazy with it because of rush last
> > > week.
> > > 
> > > You shoud use EXCEPT_* macros instead of your home baked ones:
> > > 
> > > https://www.kernel.org/doc/html/v4.15/dev-tools/kselftest.html
> > > 
> > > I don't know what you are talking about in this commit message.
> > > "Recently added" tells me absolutely nothing. All I see that you
> > > are adding your own ad hoc crap.
> > 
> > E.g.
> > 
> > 1. WTH the new thing is.
> > 2. Why is it overriding the macros already defined for kselftest
> >    (see the documentation).
> > 3. Before vDSO commits please provide a patch set that does the
> >    migration with clear explanation what is going on.
> 
> See kselftest_harness.h.

I spent a bit of time looking at kselftest_harness.h.  It's simply not
designed to handle testing things like SGX and KVM where the nature of the
thing being tested requires a substantial amount of setup, or where a
non-trivial amount of work is done in a callback, e.g. the guest in KVM
and the vDSO callback in SGX.

And IMO "designed" is a strong word.  The macros are just someone else's
ad hoc code that got hoisted into the top-level selftests directory.

  commit 0b40808a10842131742b1646a465b877a277168a
  Author: Mickaël Salaün <mic@digikod.net>
  Date:   Fri May 26 20:43:56 2017 +0200

    selftests: Make test_harness.h more generally available

    The seccomp/test_harness.h file contains useful helpers to build tests.
    Moving it to the selftest directory should benefit to other test
    components.

    Keep seccomp maintainers for this file.

It's gained two non-seccomp users in the 2+ years since being hoisted, so
it's not exactly a kernel-wide standard.

  seccomp/seccomp_bpf.c:TEST_HARNESS_MAIN
  uevent/uevent_filtering.c:TEST_HARNESS_MAIN
  net/tls.c:TEST_HARNESS_MAIN

The SGX selftest can be massaged/butchered to work with kselftest_harness,
but the error messages are still unhelpful and the resulting code is a
mess.

What I do think makes sense is to use the ksft_test_* helpers that are
provided by kselftest.h.  I'd still like to add ASSERT_* macros to cut
down on the amount of boilerplate code, but the result should be much less
ad hoc than this version.
diff mbox series

Patch

diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c
index 0c964bc1fca0..5b7575a948ba 100644
--- a/tools/testing/selftests/x86/sgx/main.c
+++ b/tools/testing/selftests/x86/sgx/main.c
@@ -66,6 +66,17 @@  do {									     \
 		    #a, #b, #a, (unsigned long)__a, #b, (unsigned long)__b); \
 } while (0)
 
+#define ASSERT_NE(a, b)							     \
+do {									     \
+	typeof(a) __a = (a);						     \
+	typeof(b) __b = (b);						     \
+	test_assert(__a != __b, NULL, __FILE__, __LINE__,		     \
+		    "%s != %s failed.\n"				     \
+		    "\t%s is %#lx\n"					     \
+		    "\t%s is %#lx",					     \
+		    #a, #b, #a, (unsigned long)__a, #b, (unsigned long)__b); \
+} while (0)
+
 void *eenter;
 
 struct vdso_symtab {
@@ -103,23 +114,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)
@@ -157,7 +163,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;
@@ -173,10 +179,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);
 
@@ -186,16 +189,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;
+	TEST_ASSERT(!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;
@@ -212,15 +210,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;
+	TEST_ASSERT(!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;
@@ -231,13 +224,9 @@  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;
-	}
+	TEST_ASSERT(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)
@@ -246,108 +235,72 @@  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;
-	}
+	TEST_ASSERT(!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;
-	}
+	TEST_ASSERT(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;
-	}
+	TEST_ASSERT(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;
 }
 
-bool get_file_size(const char *path, off_t *bin_size)
+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;
+	TEST_ASSERT(!ret, "stat() %s failed: %s\n", path, strerror(errno));
+
+	TEST_ASSERT(sb.st_size && !(sb.st_size & 0xfff),
+		    "Invalid blob size: %llu", sb.st_size);
+
+	return sb.st_size;
 }
 
-bool encl_data_map(const char *path, void **bin, off_t *bin_size)
+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;
-	}
+	TEST_ASSERT(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);
+	TEST_ASSERT(bin != MAP_FAILED, "mmap() %s failed: %s\n",
+		    path, strerror(errno));
 
 	close(fd);
-	return true;
-
-err_out:
-	close(fd);
-	return false;
+	return bin;
 }
 
-bool load_sigstruct(const char *path, void *sigstruct)
+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;
-	}
+	TEST_ASSERT(fd >= 0, "open() %s failed: %s\n", path, strerror(errno));
+
+	nr_read = read(fd, sigstruct, sizeof(struct sgx_sigstruct));
+	TEST_ASSERT(nr_read == sizeof(struct sgx_sigstruct),
+		    "read() %s failed: %s\n", path, strerror(errno));
 
 	close(fd);
-	return true;
 }
 
 int sgx_call(void *rdi, void *rsi, long rdx, void *rcx, void *r8, void *r9,
@@ -365,28 +318,23 @@  int main(int argc, char *argv[], char *envp[])
 	void *bin;
 	void *addr;
 
-	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);
 
 	memset(&exception, 0, sizeof(exception));
 
 	addr = vdso_get_base_addr();
-	if (!addr)
-		exit(1);
+	ASSERT_NE(addr, NULL);
 
-	if (!vdso_get_symtab(addr, &symtab))
-		exit(1);
+	vdso_get_symtab(addr, &symtab);
 
 	eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave");
-	if (!eenter_sym)
-		exit(1);
+	ASSERT_NE(eenter_sym, NULL);
+
 	eenter = addr + eenter_sym->st_value;
 
-	if (!encl_build(&secs, bin, bin_size, &sigstruct))
-		exit(1);
+	encl_build(&secs, bin, bin_size, &sigstruct);
 
 	sgx_call((void *)&MAGIC, &result, 0, NULL, NULL, NULL,
 		 (void *)secs.base, &exception, NULL);