OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
jvoung (off chromium)
2014/09/08 23:18:47
Short description of what this tests?
dbrazdil
2014/09/09 00:57:53
Done.
| |
7 #include "native_client/src/include/minsfi.h" | |
8 #include "native_client/src/include/minsfi_priv.h" | |
9 #include "native_client/src/include/nacl_assert.h" | |
10 | |
11 extern uint64_t __sfi_memory_base; | |
12 | |
13 void helper_initialize(void) { | |
14 ASSERT_EQ(true, MinsfiInitializeSandbox()); | |
15 ASSERT_NE(NULL, MinsfiGetActiveSandbox()); | |
16 ASSERT_NE(0, __sfi_memory_base); | |
17 ASSERT_EQ(__sfi_memory_base, (uintptr_t) MinsfiGetActiveSandbox()->mem_base); | |
18 } | |
19 | |
20 void helper_invoke_success(void) { | |
21 ASSERT_EQ((int) 0xCAFEBABE, MinsfiInvokeSandbox()); | |
22 } | |
23 | |
24 void helper_invoke_error(void) { | |
25 ASSERT_EQ(EXIT_FAILURE, MinsfiInvokeSandbox()); | |
26 } | |
27 | |
28 void helper_destroy(void) { | |
29 ASSERT_EQ(true, MinsfiDestroySandbox()); | |
30 ASSERT_EQ(NULL, MinsfiGetActiveSandbox()); | |
31 ASSERT_EQ(0, __sfi_memory_base); | |
32 } | |
33 | |
34 int main(void) { | |
35 int i; | |
36 | |
37 /* Test preconditions. */ | |
38 ASSERT_EQ(NULL, MinsfiGetActiveSandbox()); | |
39 ASSERT_EQ(0, __sfi_memory_base); | |
40 | |
41 /* First, try invoking the sandbox without having initialized it. */ | |
42 helper_invoke_error(); | |
43 | |
44 /* Initialize, invoke, destroy a couple of times. */ | |
45 for (i = 0; i < 3; i++) { | |
46 helper_initialize(); | |
47 helper_invoke_success(); | |
48 helper_destroy(); | |
49 } | |
50 | |
51 /* Multiple initializations and invokes without destroying. This will leave | |
52 * the sandbox initialized. */ | |
53 for (i = 0; i < 3; i++) { | |
54 helper_initialize(); | |
55 helper_invoke_success(); | |
56 } | |
57 | |
58 /* Now try destroying it multiple times. */ | |
59 for (i = 0; i < 3; i++) | |
60 helper_destroy(); | |
61 | |
62 /* Finally, try invoking the sandbox after it's been destroyed. */ | |
63 helper_invoke_error(); | |
64 } | |
OLD | NEW |