|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +//! This source file is named after the protocol version being tested, |
| 6 | +//! e.g. v01.rs implements tests for protocol version 1. |
| 7 | +//! The tested protocol version is represented by "$VERSION" below. |
| 8 | +//! |
| 9 | +//! The tests in this module check that the serialized form of messages from MGS |
| 10 | +//! protocol version $VERSION have not changed. |
| 11 | +//! |
| 12 | +//! If a test in this module fails, _do not change the test_! This means you |
| 13 | +//! have changed, deleted, or reordered an existing message type or enum |
| 14 | +//! variant, and you should revert that change. This will remain true until we |
| 15 | +//! bump the `version::MIN` to a value higher than $VERSION, at which point these |
| 16 | +//! tests can be removed as we will stop supporting $VERSION. |
| 17 | +
|
| 18 | +use super::assert_serialized; |
| 19 | +use gateway_messages::Fwid; |
| 20 | +use gateway_messages::ImageError; |
| 21 | +use gateway_messages::MgsRequest; |
| 22 | +use gateway_messages::RotBootInfo; |
| 23 | +use gateway_messages::RotSlotId; |
| 24 | +use gateway_messages::RotStateV3; |
| 25 | +use gateway_messages::SpResponse; |
| 26 | +use gateway_messages::SpStateV3; |
| 27 | +use gateway_messages::UpdateError; |
| 28 | + |
| 29 | +#[test] |
| 30 | +fn sp_response() { |
| 31 | + let response = SpResponse::SpStateV3(SpStateV3 { |
| 32 | + hubris_archive_id: [1, 2, 3, 4, 5, 6, 7, 8], |
| 33 | + serial_number: [ |
| 34 | + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, |
| 35 | + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
| 36 | + ], |
| 37 | + model: [ |
| 38 | + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, |
| 39 | + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, |
| 40 | + ], |
| 41 | + revision: 0xf0f1f2f3, |
| 42 | + base_mac_address: [73, 74, 75, 76, 77, 78], |
| 43 | + power_state: gateway_messages::PowerState::A0, |
| 44 | + }); |
| 45 | + |
| 46 | + #[rustfmt::skip] |
| 47 | + let expected = vec![ |
| 48 | + 44, // SpStateV3 |
| 49 | + 1, 2, 3, 4, 5, 6, 7, 8, // hubris_archive_id |
| 50 | + |
| 51 | + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, |
| 52 | + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, |
| 53 | + 39, 40, // serial_number |
| 54 | + |
| 55 | + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, |
| 56 | + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, |
| 57 | + 71, 72, // model |
| 58 | + |
| 59 | + 0xf3, 0xf2, 0xf1, 0xf0, // revision |
| 60 | + 73, 74, 75, 76, 77, 78, // base_mac_address |
| 61 | + 0, // power_state |
| 62 | + ]; |
| 63 | + |
| 64 | + assert_serialized(&expected, &response); |
| 65 | +} |
| 66 | + |
| 67 | +#[test] |
| 68 | +fn host_request() { |
| 69 | + let request = MgsRequest::VersionedRotBootInfo { version: 3 }; |
| 70 | + |
| 71 | + #[rustfmt::skip] |
| 72 | + let expected = vec![ |
| 73 | + 45, // VersionedRotBootInfo |
| 74 | + 3, // version |
| 75 | + ]; |
| 76 | + |
| 77 | + assert_serialized(&expected, &request); |
| 78 | +} |
| 79 | + |
| 80 | +#[test] |
| 81 | +fn error_enums() { |
| 82 | + let response: [ImageError; 13] = [ |
| 83 | + ImageError::Unchecked, |
| 84 | + ImageError::FirstPageErased, |
| 85 | + ImageError::PartiallyProgrammed, |
| 86 | + ImageError::InvalidLength, |
| 87 | + ImageError::HeaderNotProgrammed, |
| 88 | + ImageError::BootloaderTooSmall, |
| 89 | + ImageError::BadMagic, |
| 90 | + ImageError::HeaderImageSize, |
| 91 | + ImageError::UnalignedLength, |
| 92 | + ImageError::UnsupportedType, |
| 93 | + ImageError::ResetVectorNotThumb2, |
| 94 | + ImageError::ResetVector, |
| 95 | + ImageError::Signature, |
| 96 | + ]; |
| 97 | + let expected = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; |
| 98 | + assert_serialized(&expected, &response); |
| 99 | + |
| 100 | + let response: [UpdateError; 4] = [ |
| 101 | + UpdateError::BlockOutOfOrder, |
| 102 | + UpdateError::InvalidComponent, |
| 103 | + UpdateError::InvalidSlotIdForOperation, |
| 104 | + UpdateError::InvalidPreferredSlotId, |
| 105 | + ]; |
| 106 | + let expected = vec![27, 28, 29, 34]; |
| 107 | + assert_serialized(&expected, &response); |
| 108 | +} |
0 commit comments