Index: tests/minsfi/test_initializer.c |
diff --git a/tests/minsfi/test_initializer.c b/tests/minsfi/test_initializer.c |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1705cda01d88b7da7e7e7b3f9187dc73718807c6 |
--- /dev/null |
+++ b/tests/minsfi/test_initializer.c |
@@ -0,0 +1,64 @@ |
+/* |
+ * Copyright (c) 2014 The Native Client Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
jvoung (off chromium)
2014/09/08 23:18:47
Short description of what this tests?
dbrazdil
2014/09/09 00:57:53
Done.
|
+#include "native_client/src/include/minsfi.h" |
+#include "native_client/src/include/minsfi_priv.h" |
+#include "native_client/src/include/nacl_assert.h" |
+ |
+extern uint64_t __sfi_memory_base; |
+ |
+void helper_initialize(void) { |
+ ASSERT_EQ(true, MinsfiInitializeSandbox()); |
+ ASSERT_NE(NULL, MinsfiGetActiveSandbox()); |
+ ASSERT_NE(0, __sfi_memory_base); |
+ ASSERT_EQ(__sfi_memory_base, (uintptr_t) MinsfiGetActiveSandbox()->mem_base); |
+} |
+ |
+void helper_invoke_success(void) { |
+ ASSERT_EQ((int) 0xCAFEBABE, MinsfiInvokeSandbox()); |
+} |
+ |
+void helper_invoke_error(void) { |
+ ASSERT_EQ(EXIT_FAILURE, MinsfiInvokeSandbox()); |
+} |
+ |
+void helper_destroy(void) { |
+ ASSERT_EQ(true, MinsfiDestroySandbox()); |
+ ASSERT_EQ(NULL, MinsfiGetActiveSandbox()); |
+ ASSERT_EQ(0, __sfi_memory_base); |
+} |
+ |
+int main(void) { |
+ int i; |
+ |
+ /* Test preconditions. */ |
+ ASSERT_EQ(NULL, MinsfiGetActiveSandbox()); |
+ ASSERT_EQ(0, __sfi_memory_base); |
+ |
+ /* First, try invoking the sandbox without having initialized it. */ |
+ helper_invoke_error(); |
+ |
+ /* Initialize, invoke, destroy a couple of times. */ |
+ for (i = 0; i < 3; i++) { |
+ helper_initialize(); |
+ helper_invoke_success(); |
+ helper_destroy(); |
+ } |
+ |
+ /* Multiple initializations and invokes without destroying. This will leave |
+ * the sandbox initialized. */ |
+ for (i = 0; i < 3; i++) { |
+ helper_initialize(); |
+ helper_invoke_success(); |
+ } |
+ |
+ /* Now try destroying it multiple times. */ |
+ for (i = 0; i < 3; i++) |
+ helper_destroy(); |
+ |
+ /* Finally, try invoking the sandbox after it's been destroyed. */ |
+ helper_invoke_error(); |
+} |