blob: c536b0a514b38a5f5ecdaa4758f2a886a4b986a0 [file] [log] [blame]
David Browndd2b1182017-11-02 15:39:21 -06001//! Core tests
2//!
3//! Run the existing testsuite as a Rust unit test.
4
David Brownc3898d62019-08-05 14:20:02 -06005use bootsim::{
6 DepTest, DepType, UpgradeInfo,
7 ImagesBuilder,
8 NO_DEPS,
9 testlog,
10};
David Browndd2b1182017-11-02 15:39:21 -060011
David Brownc3898d62019-08-05 14:20:02 -060012/// A single test, after setting up logging and such. Within the $body,
13/// $arg will be bound to each device.
14macro_rules! test_shell {
15 ($name:ident, $arg: ident, $body:expr) => {
David Browna4167ef2017-11-06 14:30:05 -070016 #[test]
17 fn $name() {
18 testlog::setup();
David Brownc3898d62019-08-05 14:20:02 -060019 ImagesBuilder::each_device(|$arg| {
20 $body;
David Browna4167ef2017-11-06 14:30:05 -070021 });
David Browndd2b1182017-11-02 15:39:21 -060022 }
David Brownc3898d62019-08-05 14:20:02 -060023 }
24}
25
26/// A typical test calls a particular constructor, and runs a given test on
27/// that constructor.
28macro_rules! sim_test {
29 ($name:ident, $maker:ident($($margs:expr),*), $test:ident($($targs:expr),*)) => {
30 test_shell!($name, r, {
31 let image = r.$maker($($margs),*);
32 assert!(!image.$test($($targs),*));
33 });
David Browna4167ef2017-11-06 14:30:05 -070034 };
David Browndd2b1182017-11-02 15:39:21 -060035}
David Browna4167ef2017-11-06 14:30:05 -070036
David Browneebf5022019-07-30 15:01:07 -060037sim_test!(bad_secondary_slot, make_bad_secondary_slot_image(), run_signfail_upgrade());
David Brownc3898d62019-08-05 14:20:02 -060038sim_test!(norevert_newimage, make_no_upgrade_image(&NO_DEPS), run_norevert_newimage());
39sim_test!(basic_revert, make_image(&NO_DEPS, true), run_basic_revert());
40sim_test!(revert_with_fails, make_image(&NO_DEPS, false), run_revert_with_fails());
41sim_test!(perm_with_fails, make_image(&NO_DEPS, true), run_perm_with_fails());
42sim_test!(perm_with_random_fails, make_image(&NO_DEPS, true), run_perm_with_random_fails(5));
43sim_test!(norevert, make_image(&NO_DEPS, true), run_norevert());
44sim_test!(status_write_fails_complete, make_image(&NO_DEPS, true), run_with_status_fails_complete());
45sim_test!(status_write_fails_with_reset, make_image(&NO_DEPS, true), run_with_status_fails_with_reset());
46
47// Test various combinations of incorrect dependencies.
48test_shell!(dependency_combos, r, {
49 // Only test setups with two images.
50 if r.num_images() != 2 {
51 return;
52 }
53
54 for dep in TEST_DEPS {
55 let image = r.clone().make_image(&dep, true);
56 assert!(!image.run_check_deps(&dep));
57 }
58});
59
60/// These are the variants of dependencies we will test.
61pub static TEST_DEPS: &[DepTest] = &[
62 // First is a sanity test, no dependencies should upgrade.
63 DepTest {
64 depends: [DepType::Nothing, DepType::Nothing],
65 upgrades: [UpgradeInfo::Upgraded, UpgradeInfo::Upgraded],
66 },
67
68 // If all of the dependencies are unmet, there should be no upgrades.
69 // TODO: Disabled because it fails.
70 /*
71 DepTest {
72 depends: [DepType::Newer, DepType::Newer],
73 upgrades: [UpgradeInfo::Held, UpgradeInfo::Held],
74 },
75 */
76];