diff options
author | David Tolnay <dtolnay@chromium.org> | 2019-04-05 11:56:44 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-12 14:49:56 -0700 |
commit | 1aca8b72694fcbefc4f31bf49f41e7491ad29db4 (patch) | |
tree | d72869d83287d9b3e384e0bfa15c969eb9fea0c1 /protos/tests | |
parent | fd67ec5ffc84d8726ebcb141ddb93e10a046ee72 (diff) | |
download | crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.tar crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.tar.gz crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.tar.bz2 crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.tar.lz crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.tar.xz crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.tar.zst crosvm-1aca8b72694fcbefc4f31bf49f41e7491ad29db4.zip |
protos: Compile protos for trunks daemon
The TPM device will need these protos to communicate TPM commands to the Trunks daemon and receive TPM responses. BUG=chromium:911799 TEST=cargo check TEST=cargo check --features tpm TEST=FEATURES=test emerge-nami crosvm TEST=FEATURES=test USE=crosvm-tpm emerge-nami crosvm TEST=local kokoro CQ-DEPEND=CL:1553610 CQ-DEPEND=CL:1553971 Change-Id: I1a67a7b4a3714236b20a790068ca19129446f71c Reviewed-on: https://chromium-review.googlesource.com/1554982 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'protos/tests')
-rw-r--r-- | protos/tests/common/mod.rs | 35 | ||||
-rw-r--r-- | protos/tests/trunks.rs | 22 |
2 files changed, 57 insertions, 0 deletions
diff --git a/protos/tests/common/mod.rs b/protos/tests/common/mod.rs new file mode 100644 index 0000000..a5aaf07 --- /dev/null +++ b/protos/tests/common/mod.rs @@ -0,0 +1,35 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +use protobuf::Message; + +/// Asserts that a given protobuf message object can be serialized to bytes and +/// read back into a value of the same type, preserving equality between the +/// original object and the one read back. +/// +/// This is helpful for confirming that proto files have been compiled +/// successfully and are exposed as intended by the public API of the parent +/// crate. It also lets us exercise the full set of methods we intend to use for +/// building particular proto objects so that we notice breakage early in the +/// event that a proto external to this repository would make a breaking change. +/// +/// Note: assumes that the given `message` is not just `T::new` so that we can +/// tell that deserialization has happened successfully. +/// +/// # Example +/// +/// ```ignore +/// let mut request = SendCommandRequest::new(); +/// request.set_command(b"...".to_vec()); +/// test_round_trip(request); +/// ``` +pub fn test_round_trip<T: Message + PartialEq>(message: T) { + let serialized = message.write_to_bytes().unwrap(); + + let mut back = T::new(); + assert_ne!(message, back); + + back.merge_from_bytes(&serialized).unwrap(); + assert_eq!(message, back); +} diff --git a/protos/tests/trunks.rs b/protos/tests/trunks.rs new file mode 100644 index 0000000..574c110 --- /dev/null +++ b/protos/tests/trunks.rs @@ -0,0 +1,22 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +mod common; + +use crate::common::test_round_trip; +use protos::trunks::{SendCommandRequest, SendCommandResponse}; + +#[test] +fn send_command_request() { + let mut request = SendCommandRequest::new(); + request.set_command(b"...".to_vec()); + test_round_trip(request); +} + +#[test] +fn send_command_response() { + let mut response = SendCommandResponse::new(); + response.set_response(b"...".to_vec()); + test_round_trip(response); +} |