|
| 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::{HfError, MgsRequest, SpError, SpResponse}; |
| 20 | + |
| 21 | +#[test] |
| 22 | +fn read_host_flash() { |
| 23 | + let request = MgsRequest::ReadHostFlash { slot: 0, addr: 0 }; |
| 24 | + assert_serialized(&[47, 0, 0, 0, 0, 0, 0], &request); |
| 25 | + |
| 26 | + let request = MgsRequest::StartHostFlashHash { slot: 0 }; |
| 27 | + assert_serialized(&[48, 0, 0], &request); |
| 28 | + |
| 29 | + let request = MgsRequest::GetHostFlashHash { slot: 0 }; |
| 30 | + assert_serialized(&[49, 0, 0], &request); |
| 31 | + |
| 32 | + let response = SpResponse::ReadHostFlash; |
| 33 | + assert_serialized(&[49], &response); |
| 34 | + |
| 35 | + let response = SpResponse::StartHostFlashHashAck; |
| 36 | + assert_serialized(&[50], &response); |
| 37 | + |
| 38 | + let response = SpResponse::HostFlashHash([0; 32]); |
| 39 | + assert_serialized( |
| 40 | + &[ |
| 41 | + 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 42 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 43 | + ], |
| 44 | + &response, |
| 45 | + ); |
| 46 | + |
| 47 | + for (i, e) in [ |
| 48 | + HfError::NotMuxedToSp, |
| 49 | + HfError::BadAddress, |
| 50 | + HfError::QspiTimeout, |
| 51 | + HfError::QspiTransferError, |
| 52 | + HfError::HashUncalculated, |
| 53 | + HfError::RecalculateHash, |
| 54 | + HfError::HashInProgress, |
| 55 | + ] |
| 56 | + .into_iter() |
| 57 | + .enumerate() |
| 58 | + { |
| 59 | + let request = SpError::Hf(e); |
| 60 | + assert_serialized(&[38, i as u8], &request); |
| 61 | + } |
| 62 | +} |
0 commit comments