From 0b9d283cff9ecc0fcae17a3ad8c0bde5cf4b5574 Mon Sep 17 00:00:00 2001 From: Catalin Dumitru Date: Thu, 29 Jul 2021 16:01:18 +0300 Subject: [PATCH] Create local rust crate and update config path In order to be able to run the CI on rust-vmm-ci we needed to make it a rust crate. Also the path to the coverage config file needed to be updated in test_coverage.py so that the path does not depend on the crate; a breadth-first search was used to guarantee that the config file belongs to the crate that is being tested. Signed-off-by: Catalin Dumitru --- Cargo.toml | 5 +++++ coverage_config_x86_64.json | 5 +++++ integration_tests/test_coverage.py | 26 ++++++++++++++++++++++---- src/lib.rs | 3 +++ 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 Cargo.toml create mode 100644 coverage_config_x86_64.json create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..42bd971 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "rust-vmm-ci" +version = "0.1.0" + +[dependencies] diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json new file mode 100644 index 0000000..d80d206 --- /dev/null +++ b/coverage_config_x86_64.json @@ -0,0 +1,5 @@ +{ + "coverage_score": 33.3, + "exclude_path": "", + "crate_features": "" +} diff --git a/integration_tests/test_coverage.py b/integration_tests/test_coverage.py index ffd307a..65ccc23 100644 --- a/integration_tests/test_coverage.py +++ b/integration_tests/test_coverage.py @@ -7,11 +7,29 @@ import pytest from utils import get_repo_root_path + +def get_coverage_config_path(): + machine = platform.machine() + target_file = f"coverage_config_{machine}.json" + # We use a breadth-first search to guarantee that the config file + # belongs to the crate that is being tested. Otherwise we might end + # up wrongfully using the config file in the rust-vmm-ci submodule. + # os.walkdir() offers a depth-first search and couldn't be used here. + dirs = [os.getcwd()] + while len(dirs): + nextDirs = [] + for dir in dirs: + for file in os.listdir(dir): + file_path = os.path.join(dir, file) + if os.path.isdir(file_path): + nextDirs.append(file_path) + elif file == target_file: + return file_path + dirs = nextDirs + + REPO_ROOT_PATH = get_repo_root_path() -if platform.machine() == "x86_64": - COVERAGE_CONFIG_PATH = os.path.join(REPO_ROOT_PATH, "coverage_config_x86_64.json") -elif platform.machine() == "aarch64": - COVERAGE_CONFIG_PATH = os.path.join(REPO_ROOT_PATH, "coverage_config_aarch64.json") +COVERAGE_CONFIG_PATH = get_coverage_config_path() def _read_test_config(): diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a285917 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub fn main() { + println!("It works!"); +}