1 /*
2  * Copyright 2019 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include "hf/dlog.h"
10 
11 #include "vmapi/hf/call.h"
12 
13 #include "primary_with_secondary.h"
14 #include "test/hftest.h"
15 #include "test/vmapi/exception_handler.h"
16 #include "test/vmapi/ffa.h"
17 
TEAR_DOWN(boot)18 TEAR_DOWN(boot)
19 {
20 	EXPECT_FFA_ERROR(ffa_rx_release(), FFA_DENIED);
21 }
22 
23 /**
24  * The VM gets its memory size on boot, and can access it all.
25  */
TEST(boot,memory_size)26 TEST(boot, memory_size)
27 {
28 	struct ffa_value run_res;
29 	struct mailbox_buffers mb = set_up_mailbox();
30 
31 	SERVICE_SELECT(SERVICE_VM1, "boot_memory", mb.send);
32 
33 	run_res = ffa_run(SERVICE_VM1, 0);
34 	EXPECT_EQ(run_res.func, FFA_YIELD_32);
35 }
36 
37 /**
38  * Accessing memory outside the given range traps the VM and yields.
39  */
TEST(boot,beyond_memory_size)40 TEST(boot, beyond_memory_size)
41 {
42 	struct ffa_value run_res;
43 	struct mailbox_buffers mb = set_up_mailbox();
44 
45 	SERVICE_SELECT(SERVICE_VM1, "boot_memory_overrun", mb.send);
46 
47 	run_res = ffa_run(SERVICE_VM1, 0);
48 	EXPECT_EQ(exception_handler_receive_exception_count(&run_res, mb.recv),
49 		  1);
50 }
51 
52 /**
53  * Accessing memory before the start of the image traps the VM and yields.
54  */
TEST(boot,memory_before_image)55 TEST(boot, memory_before_image)
56 {
57 	struct ffa_value run_res;
58 	struct mailbox_buffers mb = set_up_mailbox();
59 
60 	SERVICE_SELECT(SERVICE_VM1, "boot_memory_underrun", mb.send);
61 
62 	run_res = ffa_run(SERVICE_VM1, 0);
63 	EXPECT_EQ(exception_handler_receive_exception_count(&run_res, mb.recv),
64 		  1);
65 }
66