| 
16 | 16 | //! tests can be removed as we will stop supporting $VERSION.  | 
17 | 17 | 
  | 
18 | 18 | use super::assert_serialized;  | 
 | 19 | +use gateway_messages::ImageError;  | 
 | 20 | +use gateway_messages::SpStateV3;  | 
 | 21 | +use gateway_messages::UpdateError;  | 
19 | 22 | use gateway_messages::{HfError, MgsRequest, SpError, SpResponse};  | 
20 | 23 | 
 
  | 
21 | 24 | #[test]  | 
@@ -60,3 +63,84 @@ fn read_host_flash() {  | 
60 | 63 |         assert_serialized(&[38, i as u8], &request);  | 
61 | 64 |     }  | 
62 | 65 | }  | 
 | 66 | + | 
 | 67 | +#[test]  | 
 | 68 | +fn sp_response() {  | 
 | 69 | +    let response = SpResponse::SpStateV3(SpStateV3 {  | 
 | 70 | +        hubris_archive_id: [1, 2, 3, 4, 5, 6, 7, 8],  | 
 | 71 | +        serial_number: [  | 
 | 72 | +            9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,  | 
 | 73 | +            26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,  | 
 | 74 | +        ],  | 
 | 75 | +        model: [  | 
 | 76 | +            41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,  | 
 | 77 | +            58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,  | 
 | 78 | +        ],  | 
 | 79 | +        revision: 0xf0f1f2f3,  | 
 | 80 | +        base_mac_address: [73, 74, 75, 76, 77, 78],  | 
 | 81 | +        power_state: gateway_messages::PowerState::A0,  | 
 | 82 | +    });  | 
 | 83 | + | 
 | 84 | +    #[rustfmt::skip]  | 
 | 85 | +    let expected = vec![  | 
 | 86 | +        44, // SpStateV3  | 
 | 87 | +        1, 2, 3, 4, 5, 6, 7, 8, // hubris_archive_id  | 
 | 88 | + | 
 | 89 | +        9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,  | 
 | 90 | +        24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,  | 
 | 91 | +        39, 40, // serial_number  | 
 | 92 | + | 
 | 93 | +        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,  | 
 | 94 | +        56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,  | 
 | 95 | +        71, 72, // model  | 
 | 96 | + | 
 | 97 | +        0xf3, 0xf2, 0xf1, 0xf0, // revision  | 
 | 98 | +        73, 74, 75, 76, 77, 78, // base_mac_address  | 
 | 99 | +        0, // power_state  | 
 | 100 | +    ];  | 
 | 101 | + | 
 | 102 | +    assert_serialized(&expected, &response);  | 
 | 103 | +}  | 
 | 104 | + | 
 | 105 | +#[test]  | 
 | 106 | +fn host_request() {  | 
 | 107 | +    let request = MgsRequest::VersionedRotBootInfo { version: 3 };  | 
 | 108 | + | 
 | 109 | +    #[rustfmt::skip]  | 
 | 110 | +    let expected = vec![  | 
 | 111 | +        45, // VersionedRotBootInfo  | 
 | 112 | +        3, // version  | 
 | 113 | +    ];  | 
 | 114 | + | 
 | 115 | +    assert_serialized(&expected, &request);  | 
 | 116 | +}  | 
 | 117 | + | 
 | 118 | +#[test]  | 
 | 119 | +fn error_enums() {  | 
 | 120 | +    let response: [ImageError; 13] = [  | 
 | 121 | +        ImageError::Unchecked,  | 
 | 122 | +        ImageError::FirstPageErased,  | 
 | 123 | +        ImageError::PartiallyProgrammed,  | 
 | 124 | +        ImageError::InvalidLength,  | 
 | 125 | +        ImageError::HeaderNotProgrammed,  | 
 | 126 | +        ImageError::BootloaderTooSmall,  | 
 | 127 | +        ImageError::BadMagic,  | 
 | 128 | +        ImageError::HeaderImageSize,  | 
 | 129 | +        ImageError::UnalignedLength,  | 
 | 130 | +        ImageError::UnsupportedType,  | 
 | 131 | +        ImageError::ResetVectorNotThumb2,  | 
 | 132 | +        ImageError::ResetVector,  | 
 | 133 | +        ImageError::Signature,  | 
 | 134 | +    ];  | 
 | 135 | +    let expected = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];  | 
 | 136 | +    assert_serialized(&expected, &response);  | 
 | 137 | + | 
 | 138 | +    let response: [UpdateError; 4] = [  | 
 | 139 | +        UpdateError::BlockOutOfOrder,  | 
 | 140 | +        UpdateError::InvalidComponent,  | 
 | 141 | +        UpdateError::InvalidSlotIdForOperation,  | 
 | 142 | +        UpdateError::InvalidPreferredSlotId,  | 
 | 143 | +    ];  | 
 | 144 | +    let expected = vec![27, 28, 29, 34];  | 
 | 145 | +    assert_serialized(&expected, &response);  | 
 | 146 | +}  | 
0 commit comments