|
| 1 | +use tockloader_lib::{board_settings::BoardSettings, command_impl::reshuffle_apps::*}; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn install_new_c_app() { |
| 5 | + let settings: &BoardSettings = &BoardSettings { |
| 6 | + arch: Some("cortex-m4".to_string()), |
| 7 | + start_address: 0x00040000, |
| 8 | + page_size: 512, |
| 9 | + ram_start_address: 0x20000000, |
| 10 | + }; |
| 11 | + |
| 12 | + let c_app_1: TockApp = TockApp::Flexible(FlexibleApp { |
| 13 | + installed: true, |
| 14 | + idx: None, |
| 15 | + size: 0x2000, |
| 16 | + }); |
| 17 | + |
| 18 | + let c_app_2: TockApp = TockApp::Flexible(FlexibleApp { |
| 19 | + installed: true, |
| 20 | + idx: None, |
| 21 | + size: 0x2000, |
| 22 | + }); |
| 23 | + |
| 24 | + let c_app_3: TockApp = TockApp::Flexible(FlexibleApp { |
| 25 | + installed: false, |
| 26 | + idx: None, |
| 27 | + size: 0x2000, |
| 28 | + }); |
| 29 | + |
| 30 | + let apps: Vec<TockApp> = vec![c_app_1, c_app_2, c_app_3]; |
| 31 | + |
| 32 | + let reshuffled_apps = reshuffle_apps(settings, apps); |
| 33 | + |
| 34 | + let correct_config: Option<Vec<Index>> = Some(vec![ |
| 35 | + Index { |
| 36 | + installed: true, |
| 37 | + idx: Some(0x0), |
| 38 | + ram_address: None, |
| 39 | + address: 0x40000, |
| 40 | + size: 0x2000, |
| 41 | + }, |
| 42 | + Index { |
| 43 | + installed: true, |
| 44 | + idx: Some(0x1), |
| 45 | + ram_address: None, |
| 46 | + address: 0x42000, |
| 47 | + size: 0x2000, |
| 48 | + }, |
| 49 | + Index { |
| 50 | + installed: false, |
| 51 | + idx: Some(0x2), |
| 52 | + ram_address: None, |
| 53 | + address: 0x44000, |
| 54 | + size: 0x2000, |
| 55 | + }, |
| 56 | + ]); |
| 57 | + assert_eq!(reshuffled_apps, correct_config); |
| 58 | +} |
| 59 | + |
| 60 | +#[test] |
| 61 | +fn install_new_rust_app() { |
| 62 | + let settings: &BoardSettings = &BoardSettings { |
| 63 | + arch: Some("cortex-m4".to_string()), |
| 64 | + start_address: 0x00040000, |
| 65 | + page_size: 512, |
| 66 | + ram_start_address: 0x20000000, |
| 67 | + }; |
| 68 | + |
| 69 | + let rust_app: TockApp = TockApp::Fixed(FixedApp { |
| 70 | + installed: false, |
| 71 | + idx: None, |
| 72 | + compatible_addresses: vec![ |
| 73 | + Some((0x40000, 0x20008000)), |
| 74 | + Some((0x42000, 0x2000a000)), |
| 75 | + Some((0x48000, 0x20010000)), |
| 76 | + Some((0x80000, 0x20006000)), |
| 77 | + Some((0x88000, 0x2000e000)), |
| 78 | + ], |
| 79 | + size: 0x2000, |
| 80 | + }); |
| 81 | + |
| 82 | + let apps: Vec<TockApp> = vec![rust_app]; |
| 83 | + |
| 84 | + let reshuffled_apps = reshuffle_apps(settings, apps); |
| 85 | + |
| 86 | + let correct_config: Option<Vec<Index>> = Some(vec![Index { |
| 87 | + installed: false, |
| 88 | + idx: Some(0x0), |
| 89 | + ram_address: Some(0x20008000), |
| 90 | + address: 0x40000, |
| 91 | + size: 0x2000, |
| 92 | + }]); |
| 93 | + assert_eq!(reshuffled_apps, correct_config); |
| 94 | +} |
| 95 | + |
| 96 | +#[test] |
| 97 | +fn install_more_rust_apps() { |
| 98 | + let settings: &BoardSettings = &BoardSettings { |
| 99 | + arch: Some("cortex-m4".to_string()), |
| 100 | + start_address: 0x00040000, |
| 101 | + page_size: 512, |
| 102 | + ram_start_address: 0x20000000, |
| 103 | + }; |
| 104 | + |
| 105 | + let rust_app_1: TockApp = TockApp::Fixed(FixedApp { |
| 106 | + installed: true, |
| 107 | + idx: None, |
| 108 | + compatible_addresses: vec![Some((0x40000, 0x20008000))], |
| 109 | + size: 0x2000, |
| 110 | + }); |
| 111 | + |
| 112 | + let rust_app_2: TockApp = TockApp::Fixed(FixedApp { |
| 113 | + installed: true, |
| 114 | + idx: None, |
| 115 | + compatible_addresses: vec![Some((0x42000, 0x2000a000))], |
| 116 | + size: 0x2000, |
| 117 | + }); |
| 118 | + |
| 119 | + let rust_app_3: TockApp = TockApp::Fixed(FixedApp { |
| 120 | + installed: false, |
| 121 | + idx: None, |
| 122 | + compatible_addresses: vec![ |
| 123 | + Some((0x40000, 0x20008000)), |
| 124 | + Some((0x42000, 0x2000a000)), |
| 125 | + Some((0x48000, 0x20010000)), |
| 126 | + Some((0x80000, 0x20006000)), |
| 127 | + Some((0x88000, 0x2000e000)), |
| 128 | + ], |
| 129 | + size: 0x2000, |
| 130 | + }); |
| 131 | + |
| 132 | + let apps: Vec<TockApp> = vec![rust_app_1, rust_app_2, rust_app_3]; |
| 133 | + |
| 134 | + let reshuffled_apps = reshuffle_apps(settings, apps); |
| 135 | + |
| 136 | + let correct_config: Option<Vec<Index>> = Some(vec![ |
| 137 | + Index { |
| 138 | + installed: true, |
| 139 | + idx: Some(0x0), |
| 140 | + ram_address: Some(0x20008000), |
| 141 | + address: 0x40000, |
| 142 | + size: 0x2000, |
| 143 | + }, |
| 144 | + Index { |
| 145 | + installed: true, |
| 146 | + idx: Some(0x1), |
| 147 | + ram_address: Some(0x2000a000), |
| 148 | + address: 0x42000, |
| 149 | + size: 0x2000, |
| 150 | + }, |
| 151 | + // padding |
| 152 | + Index { |
| 153 | + installed: false, |
| 154 | + idx: None, |
| 155 | + ram_address: None, |
| 156 | + address: 0x44000, |
| 157 | + size: 0x4000, |
| 158 | + }, |
| 159 | + Index { |
| 160 | + installed: false, |
| 161 | + idx: Some(0x2), |
| 162 | + ram_address: Some(0x20010000), |
| 163 | + address: 0x48000, |
| 164 | + size: 0x2000, |
| 165 | + }, |
| 166 | + ]); |
| 167 | + assert_eq!(reshuffled_apps, correct_config); |
| 168 | +} |
| 169 | + |
| 170 | +#[test] |
| 171 | +fn insert_c_app_between_rust_apps() { |
| 172 | + let settings: &BoardSettings = &BoardSettings { |
| 173 | + arch: Some("cortex-m4".to_string()), |
| 174 | + start_address: 0x00040000, |
| 175 | + page_size: 512, |
| 176 | + ram_start_address: 0x20000000, |
| 177 | + }; |
| 178 | + |
| 179 | + let rust_app_1: TockApp = TockApp::Fixed(FixedApp { |
| 180 | + installed: true, |
| 181 | + idx: None, |
| 182 | + compatible_addresses: vec![Some((0x40000, 0x20008000))], |
| 183 | + size: 0x2000, |
| 184 | + }); |
| 185 | + |
| 186 | + let rust_app_2: TockApp = TockApp::Fixed(FixedApp { |
| 187 | + installed: true, |
| 188 | + idx: None, |
| 189 | + compatible_addresses: vec![Some((0x42000, 0x2000a000))], |
| 190 | + size: 0x2000, |
| 191 | + }); |
| 192 | + |
| 193 | + let rust_app_3: TockApp = TockApp::Fixed(FixedApp { |
| 194 | + installed: true, |
| 195 | + idx: None, |
| 196 | + compatible_addresses: vec![Some((0x48000, 0x20010000))], |
| 197 | + size: 0x2000, |
| 198 | + }); |
| 199 | + |
| 200 | + let c_app_1: TockApp = TockApp::Flexible(FlexibleApp { |
| 201 | + installed: false, |
| 202 | + idx: None, |
| 203 | + size: 0x2000, |
| 204 | + }); |
| 205 | + |
| 206 | + let apps: Vec<TockApp> = vec![rust_app_1, rust_app_2, rust_app_3, c_app_1]; |
| 207 | + |
| 208 | + let reshuffled_apps = reshuffle_apps(settings, apps); |
| 209 | + |
| 210 | + let correct_config: Option<Vec<Index>> = Some(vec![ |
| 211 | + Index { |
| 212 | + installed: true, |
| 213 | + idx: Some(0x0), |
| 214 | + ram_address: Some(0x20008000), |
| 215 | + address: 0x40000, |
| 216 | + size: 0x2000, |
| 217 | + }, |
| 218 | + Index { |
| 219 | + installed: true, |
| 220 | + idx: Some(0x1), |
| 221 | + ram_address: Some(0x2000a000), |
| 222 | + address: 0x42000, |
| 223 | + size: 0x2000, |
| 224 | + }, |
| 225 | + Index { |
| 226 | + installed: false, |
| 227 | + idx: Some(0x3), |
| 228 | + ram_address: None, |
| 229 | + address: 0x44000, |
| 230 | + size: 0x2000, |
| 231 | + }, |
| 232 | + // padding |
| 233 | + Index { |
| 234 | + installed: false, |
| 235 | + idx: None, |
| 236 | + ram_address: None, |
| 237 | + address: 0x46000, |
| 238 | + size: 0x2000, |
| 239 | + }, |
| 240 | + Index { |
| 241 | + installed: true, |
| 242 | + idx: Some(0x2), |
| 243 | + ram_address: Some(0x20010000), |
| 244 | + address: 0x48000, |
| 245 | + size: 0x2000, |
| 246 | + }, |
| 247 | + ]); |
| 248 | + assert_eq!(reshuffled_apps, correct_config); |
| 249 | +} |
0 commit comments