Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / minsfi / test_exit.c
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 #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 static int argc_exit_with_syscall = 1;
12 static int argc_exit_with_return = 2;
13 static char *argv[] = { "foo", "bar" };
14
15 /*
16  * In this test, the sandboxed code invokes the exit() MinSFI syscall.
17  * We verify that it jumps back to the Invoke function and that it returns
18  * the same status code that the sandbox terminated with.
19  */
20 static void test_exit_with_syscall(void) {
21   int ret_val;
22
23   MinsfiInitializeSandbox();
24   ret_val = MinsfiInvokeSandbox(argc_exit_with_syscall, argv);
25   ASSERT_EQ(ret_val, (int) 0xDEADC0DE);
26   MinsfiDestroySandbox();
27 }
28
29 /*
30  * In this test, the sandbox does not invoke the exit() syscall, but rather
31  * returns the status code 0xDEADFA11 from the entry function. That is not
32  * a legal way of terminating the sandbox and the Invoke function should report
33  * failure.
34  */
35 static void test_exit_with_return(void) {
36   int ret_val;
37
38   MinsfiInitializeSandbox();
39   ret_val = MinsfiInvokeSandbox(argc_exit_with_return, argv);
40   ASSERT_EQ(ret_val, EXIT_FAILURE);
41   MinsfiDestroySandbox();
42 }
43
44 int main(void) {
45   test_exit_with_return();
46   test_exit_with_syscall();
47   return 0;
48 }