Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: tests/minsfi/test_initializer.c

Issue 539683002: MinSFI: Add loader (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Fixed nits Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/minsfi/sandbox_dummy.c ('k') | tests/minsfi/test_memory_layout.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
7 /*
8 * This exercises the public interface of MinSFI.
9 *
10 * Internally, we verify that running the Initialize function changes the
11 * active sandbox and sets the memory base for the sandboxed code. Destroying
12 * the sandbox should reset both to NULL.
13 *
14 * For the public interface, we check that the Initialize, Invoke and Destroy
15 * functions behave correctly when called in the right context, and that they
16 * do not crash the program otherwise.
17 */
18
19 #include "native_client/src/include/minsfi.h"
20 #include "native_client/src/include/minsfi_priv.h"
21 #include "native_client/src/include/nacl_assert.h"
22
23 extern uint64_t __sfi_memory_base;
24
25 void helper_initialize(void) {
26 ASSERT_EQ(true, MinsfiInitializeSandbox());
27 ASSERT_NE(NULL, MinsfiGetActiveSandbox());
28 ASSERT_NE(0, __sfi_memory_base);
29 ASSERT_EQ(__sfi_memory_base, (uintptr_t) MinsfiGetActiveSandbox()->mem_base);
30 }
31
32 void helper_invoke_success(void) {
33 ASSERT_EQ((int) 0xCAFEBABE, MinsfiInvokeSandbox());
34 }
35
36 void helper_invoke_error(void) {
37 ASSERT_EQ(EXIT_FAILURE, MinsfiInvokeSandbox());
38 }
39
40 void helper_destroy(void) {
41 ASSERT_EQ(true, MinsfiDestroySandbox());
42 ASSERT_EQ(NULL, MinsfiGetActiveSandbox());
43 ASSERT_EQ(0, __sfi_memory_base);
44 }
45
46 int main(void) {
47 int i;
48
49 /* Test preconditions. There should be no active sandbox. */
50 ASSERT_EQ(NULL, MinsfiGetActiveSandbox());
51 ASSERT_EQ(0, __sfi_memory_base);
52
53 /*
54 * First, try invoking the sandbox without having initialized it.
55 * It should fail but not crash.
56 */
57 helper_invoke_error();
58
59 /* Initialize, invoke, destroy a couple of times. This should succeed. */
60 for (i = 0; i < 3; i++) {
61 helper_initialize();
62 helper_invoke_success();
63 helper_destroy();
64 }
65
66 /*
67 * Multiple initializations and invokes without destroying. This will leave
68 * the sandbox initialized.
69 */
70 for (i = 0; i < 3; i++) {
71 helper_initialize();
72 helper_invoke_success();
73 }
74
75 /* Now try destroying it multiple times. */
76 for (i = 0; i < 3; i++)
77 helper_destroy();
78
79 /* Finally, invoking the sandbox after it's been destroyed should fail. */
80 helper_invoke_error();
81 }
OLDNEW
« no previous file with comments | « tests/minsfi/sandbox_dummy.c ('k') | tests/minsfi/test_memory_layout.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698