prebuilts: move prebuilts tests under tests

BUG=b:246987526
TEST=presubmit

Change-Id: I86eed7c84f7e21eb7155695489ee9446f999dc1d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3936733
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
Vikram Auradkar 2022-10-06 20:17:00 +00:00 committed by crosvm LUCI
parent 3048738d9d
commit 1acc0a28d9
7 changed files with 67 additions and 68 deletions

3
Cargo.lock generated
View file

@ -456,6 +456,7 @@ dependencies = [
"net_util",
"once_cell",
"p9",
"prebuilts",
"protobuf",
"protos",
"rand",
@ -982,6 +983,7 @@ dependencies = [
"base",
"cfg-if",
"libc",
"prebuilts",
"tempfile",
]
@ -1399,7 +1401,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"cfg-if",
"tempfile",
]
[[package]]

View file

@ -259,6 +259,7 @@ cc = "*"
[dev-dependencies]
base = "*"
prebuilts = { path = "prebuilts" }
[patch.crates-io]
assertions = { path = "common/assertions" }

View file

@ -10,6 +10,7 @@ arch = { path = "../arch" }
base = "*"
cfg-if = "*"
libc = "0.2.65"
prebuilts = { path = "../prebuilts" }
tempfile = "3"
[features]

View file

@ -0,0 +1,63 @@
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::env;
use tempfile::TempDir;
use prebuilts::download_prebuilt;
use prebuilts::download_prebuilts;
static LIBRARY: &str = "prebuilts_test";
static PREBUILT_FILE1: &str = "prebuilt_test";
static PREBUILT_FILE2: &str = "prebuilt_test2";
static VERSION: u32 = 1;
fn setup_env(build_type: &str) -> TempDir {
let tempdir = tempfile::tempdir().unwrap();
if build_type == "debug" {
env::set_var("DEBUG", "");
} else {
env::remove_var("DEBUG");
}
env::set_var("CARGO_CFG_TARGET_FAMILY", "windows");
env::set_var("CARGO_CFG_TARGET_ARCH", "x86_64");
env::set_var("CARGO_CFG_TARGET_ENV", "gnu");
let deps = tempdir.path().join("deps");
std::fs::create_dir_all(&deps).unwrap();
let out_dir = tempdir.path().join("build").join("crate_name").join("out");
std::fs::create_dir_all(&out_dir).unwrap();
env::set_var("OUT_DIR", out_dir.as_os_str().to_str().unwrap());
tempdir
}
#[test]
fn test_download_prebuilt() {
for build_type in ["release", "debug"] {
let _tempdir = setup_env(build_type);
let file = download_prebuilt(LIBRARY, VERSION, PREBUILT_FILE1).unwrap();
assert!(file.exists());
assert_eq!(
std::fs::read_to_string(&file).unwrap(),
format!("hello world {}\n", build_type)
);
}
}
#[test]
fn test_download_prebuilt_files() {
for build_type in ["release", "debug"] {
let _tempdir = setup_env(build_type);
let files =
download_prebuilts(LIBRARY, VERSION, &[PREBUILT_FILE1, PREBUILT_FILE2]).unwrap();
for file in files {
assert!(file.exists());
assert_eq!(
std::fs::read_to_string(&file).unwrap(),
format!("hello world {}\n", build_type),
"failed for file {file:?}"
);
}
}
}

View file

@ -7,6 +7,3 @@ edition = "2021"
[dependencies]
anyhow = "*"
cfg-if = "*"
[dev-dependencies]
tempfile = "*"

View file

@ -91,66 +91,3 @@ pub fn download_prebuilts(library: &str, version: u32, filenames: &[&str]) -> Re
}
Ok(paths)
}
#[cfg(test)]
mod tests {
use std::env;
use tempfile::TempDir;
use super::download_prebuilt;
use super::download_prebuilts;
static LIBRARY: &str = "prebuilts_test";
static PREBUILT_FILE1: &str = "prebuilt_test";
static PREBUILT_FILE2: &str = "prebuilt_test2";
static VERSION: u32 = 1;
fn setup_env(build_type: &str) -> TempDir {
let tempdir = tempfile::tempdir().unwrap();
if build_type == "debug" {
env::set_var("DEBUG", "");
} else {
env::remove_var("DEBUG");
}
env::set_var("CARGO_CFG_TARGET_FAMILY", "windows");
env::set_var("CARGO_CFG_TARGET_ARCH", "x86_64");
env::set_var("CARGO_CFG_TARGET_ENV", "gnu");
let deps = tempdir.path().join("deps");
std::fs::create_dir_all(&deps).unwrap();
let out_dir = tempdir.path().join("build").join("crate_name").join("out");
std::fs::create_dir_all(&out_dir).unwrap();
env::set_var("OUT_DIR", out_dir.as_os_str().to_str().unwrap());
tempdir
}
#[test]
fn test_download_prebuilt() {
for build_type in ["release", "debug"] {
let _tempdir = setup_env(build_type);
let file = download_prebuilt(LIBRARY, VERSION, PREBUILT_FILE1).unwrap();
assert!(file.exists());
assert_eq!(
std::fs::read_to_string(&file).unwrap(),
format!("hello world {}\n", build_type)
);
}
}
#[test]
fn test_download_prebuilt_files() {
for build_type in ["release", "debug"] {
let _tempdir = setup_env(build_type);
let files =
download_prebuilts(LIBRARY, VERSION, &[PREBUILT_FILE1, PREBUILT_FILE2]).unwrap();
for file in files {
assert!(file.exists());
assert_eq!(
std::fs::read_to_string(&file).unwrap(),
format!("hello world {}\n", build_type),
"failed for file {file:?}"
);
}
}
}
}

View file

@ -129,7 +129,6 @@ CRATE_OPTIONS: Dict[str, List[TestOption]] = {
TestOption.DO_NOT_RUN_ARMHF,
],
"libvda": [TestOption.DO_NOT_BUILD], # b/202293971
"prebuilts": [TestOption.SINGLE_THREADED], # tests set and clear process wide env variable
"rutabaga_gfx": [TestOption.DO_NOT_BUILD_ARMHF], # b/210015864
"vhost": [TestOption.DO_NOT_RUN_ON_FOREIGN_KERNEL, TestOption.UNIT_AS_INTEGRATION_TEST],
"vm_control": [TestOption.DO_NOT_BUILD_ARMHF], # b/210015864