mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 10:10:41 +00:00
acpi_tables: Add test case for reading SDT data from files
Seemed like an easy test to add. BUG=b:171082843 TEST=This is a test Change-Id: I2a10c0965be2952cd3150965e4127a27a3ec6dff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2495844 Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org> Commit-Queue: Dennis Kempin <denniskempin@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Auto-Submit: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
parent
831b11e869
commit
a5262a177f
3 changed files with 22 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -26,6 +26,7 @@ name = "acpi_tables"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"data_model 0.1.0",
|
||||
"tempfile 3.0.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -6,3 +6,4 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
data_model = { path = "../data_model" }
|
||||
tempfile = { path = "../tempfile" }
|
||||
|
|
|
@ -114,6 +114,8 @@ impl SDT {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SDT;
|
||||
use std::io::Write;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
#[test]
|
||||
fn test_sdt() {
|
||||
|
@ -130,4 +132,22 @@ mod tests {
|
|||
.fold(0u8, |acc, x| acc.wrapping_add(*x));
|
||||
assert_eq!(sum, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sdt_read_write() -> Result<(), std::io::Error> {
|
||||
let temp_file = NamedTempFile::new()?;
|
||||
let expected_sdt = SDT::new(*b"TEST", 40, 1, *b"CROSVM", *b"TESTTEST", 1);
|
||||
|
||||
// Write SDT to file.
|
||||
{
|
||||
let mut writer = temp_file.as_file();
|
||||
writer.write_all(&expected_sdt.as_slice())?;
|
||||
}
|
||||
|
||||
// Read it back and verify.
|
||||
let actual_sdt = SDT::from_file(&temp_file.path().to_path_buf())?;
|
||||
assert!(actual_sdt.is_signature(b"TEST"));
|
||||
assert_eq!(actual_sdt.as_slice(), expected_sdt.as_slice());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue