David Brown | dd2b118 | 2017-11-02 15:39:21 -0600 | [diff] [blame] | 1 | //! Core tests |
| 2 | //! |
| 3 | //! Run the existing testsuite as a Rust unit test. |
| 4 | |
David Brown | c3898d6 | 2019-08-05 14:20:02 -0600 | [diff] [blame] | 5 | use bootsim::{ |
| 6 | DepTest, DepType, UpgradeInfo, |
| 7 | ImagesBuilder, |
| 8 | NO_DEPS, |
| 9 | testlog, |
| 10 | }; |
David Brown | dd2b118 | 2017-11-02 15:39:21 -0600 | [diff] [blame] | 11 | |
David Brown | c3898d6 | 2019-08-05 14:20:02 -0600 | [diff] [blame] | 12 | /// A single test, after setting up logging and such. Within the $body, |
| 13 | /// $arg will be bound to each device. |
| 14 | macro_rules! test_shell { |
| 15 | ($name:ident, $arg: ident, $body:expr) => { |
David Brown | a4167ef | 2017-11-06 14:30:05 -0700 | [diff] [blame] | 16 | #[test] |
| 17 | fn $name() { |
| 18 | testlog::setup(); |
David Brown | c3898d6 | 2019-08-05 14:20:02 -0600 | [diff] [blame] | 19 | ImagesBuilder::each_device(|$arg| { |
| 20 | $body; |
David Brown | a4167ef | 2017-11-06 14:30:05 -0700 | [diff] [blame] | 21 | }); |
David Brown | dd2b118 | 2017-11-02 15:39:21 -0600 | [diff] [blame] | 22 | } |
David Brown | c3898d6 | 2019-08-05 14:20:02 -0600 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | |
| 26 | /// A typical test calls a particular constructor, and runs a given test on |
| 27 | /// that constructor. |
| 28 | macro_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 Brown | a4167ef | 2017-11-06 14:30:05 -0700 | [diff] [blame] | 34 | }; |
David Brown | dd2b118 | 2017-11-02 15:39:21 -0600 | [diff] [blame] | 35 | } |
David Brown | a4167ef | 2017-11-06 14:30:05 -0700 | [diff] [blame] | 36 | |
David Brown | eebf502 | 2019-07-30 15:01:07 -0600 | [diff] [blame] | 37 | sim_test!(bad_secondary_slot, make_bad_secondary_slot_image(), run_signfail_upgrade()); |
David Brown | c3898d6 | 2019-08-05 14:20:02 -0600 | [diff] [blame] | 38 | sim_test!(norevert_newimage, make_no_upgrade_image(&NO_DEPS), run_norevert_newimage()); |
| 39 | sim_test!(basic_revert, make_image(&NO_DEPS, true), run_basic_revert()); |
| 40 | sim_test!(revert_with_fails, make_image(&NO_DEPS, false), run_revert_with_fails()); |
| 41 | sim_test!(perm_with_fails, make_image(&NO_DEPS, true), run_perm_with_fails()); |
| 42 | sim_test!(perm_with_random_fails, make_image(&NO_DEPS, true), run_perm_with_random_fails(5)); |
| 43 | sim_test!(norevert, make_image(&NO_DEPS, true), run_norevert()); |
| 44 | sim_test!(status_write_fails_complete, make_image(&NO_DEPS, true), run_with_status_fails_complete()); |
| 45 | sim_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. |
| 48 | test_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. |
| 61 | pub 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 | ]; |