• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use fixture::vm::Config;
6 use fixture::vm::TestVm;
7 
8 #[test]
boot_test_vm() -> anyhow::Result<()>9 fn boot_test_vm() -> anyhow::Result<()> {
10     let mut vm = TestVm::new(Config::new()).unwrap();
11     assert_eq!(vm.exec_in_guest("echo 42")?.trim(), "42");
12     Ok(())
13 }
14 
15 #[cfg(unix)]
16 #[test]
boot_test_vm_odirect()17 fn boot_test_vm_odirect() {
18     let mut vm = TestVm::new(Config::new().o_direct()).unwrap();
19     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
20 }
21 
22 #[cfg(unix)]
23 #[test]
boot_test_vm_config_file()24 fn boot_test_vm_config_file() {
25     let mut vm = TestVm::new_with_config_file(Config::new()).unwrap();
26     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
27 }
28 
29 #[cfg(unix)]
30 #[test]
boot_test_suspend_resume()31 fn boot_test_suspend_resume() {
32     // There is no easy way for us to check if the VM is actually suspended. But at
33     // least exercise the code-path.
34     let mut vm = TestVm::new(Config::new()).unwrap();
35     vm.suspend().unwrap();
36     vm.resume().unwrap();
37     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
38 }
39 
40 #[cfg(unix)]
41 #[test]
boot_test_vm_disable_sandbox()42 fn boot_test_vm_disable_sandbox() {
43     let mut vm = TestVm::new(Config::new().disable_sandbox()).unwrap();
44     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
45 }
46 
47 #[cfg(unix)]
48 #[test]
boot_test_vm_disable_sandbox_odirect()49 fn boot_test_vm_disable_sandbox_odirect() {
50     let mut vm = TestVm::new(Config::new().disable_sandbox().o_direct()).unwrap();
51     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
52 }
53 
54 #[cfg(unix)]
55 #[test]
boot_test_vm_disable_sandbox_config_file()56 fn boot_test_vm_disable_sandbox_config_file() {
57     let mut vm = TestVm::new_with_config_file(Config::new().disable_sandbox()).unwrap();
58     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
59 }
60 
61 #[cfg(unix)]
62 #[test]
boot_test_disable_sandbox_suspend_resume()63 fn boot_test_disable_sandbox_suspend_resume() {
64     // There is no easy way for us to check if the VM is actually suspended. But at
65     // least exercise the code-path.
66     let mut vm = TestVm::new(Config::new().disable_sandbox()).unwrap();
67     vm.suspend().unwrap();
68     vm.resume().unwrap();
69     assert_eq!(vm.exec_in_guest("echo 42").unwrap().trim(), "42");
70 }
71