Skip to content

Commit 5bf5959

Browse files
authored
Merge pull request #25 from jjs-dev/ci-matrix
Use build matrix in CI tests
2 parents 0e6a3ed + 82de9f3 commit 5bf5959

File tree

6 files changed

+129
-38
lines changed

6 files changed

+129
-38
lines changed

.github/workflows/rust.yml

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,32 @@ jobs:
3333
- name: Run clippy
3434
run: |
3535
cargo clippy --workspace -- -Dclippy::all -Dwarnings
36-
check-platform-support:
37-
runs-on: ubuntu-latest
38-
steps:
39-
- uses: actions/checkout@v2
40-
- uses: actions-rs/toolchain@v1.0.6
41-
with:
42-
toolchain: stable
43-
- name: Remove cargo config
44-
run: rm -rf .cargo
45-
- name: Check musl
46-
run: |
47-
rustup target add x86_64-unknown-linux-musl
48-
cargo check -p minion -p minion-ffi -p minion-cli --target x86_64-unknown-linux-musl
49-
tests:
50-
runs-on: ubuntu-latest
36+
tests-linux:
37+
strategy:
38+
matrix:
39+
os:
40+
- 'ubuntu-latest'
41+
- 'macos-latest'
42+
rust-target:
43+
- 'x86_64-unknown-linux-gnu'
44+
- 'x86_64-unknown-linux-musl'
45+
cgroups:
46+
- 'cgroup-v1'
47+
- 'cgroup-v2'
48+
runs-on: ${{ matrix.os }}
5149
steps:
5250
- uses: actions/checkout@v2
5351
- uses: actions-rs/toolchain@v1.0.6
5452
with:
55-
toolchain: nightly
53+
toolchain: stable
5654
override: true
57-
- name: Compile tests
58-
run: |
59-
rm -rf .cargo
60-
cd minion-tests
61-
TARGET=x86_64-unknown-linux-musl
62-
rustup target add $TARGET
63-
cargo build -Zunstable-options --out-dir=../out --target=$TARGET
64-
- name: Run tests
65-
run: |
66-
sudo ./out/minion-tests --trace
67-
timeout-minutes: 3
55+
- name: Test
56+
run: bash ci/linux.sh
57+
timeout-minutes: 10
58+
env:
59+
CI_TARGET: ${{ matrix.rust-target }}
60+
CI_CGROUPS: ${{ matrix.cgroups }}
61+
CI_OS: ${{ matrix.os }}
6862
- name: Collect logs
6963
if: always()
7064
run: |
@@ -75,6 +69,7 @@ jobs:
7569
with:
7670
path: /tmp/logs
7771
name: tests-trace
72+
7873
nightly-checks:
7974
runs-on: ubuntu-latest
8075
steps:

ci/linux.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
set -euo pipefail
2+
echo "::group::Info"
3+
echo "Target: $CI_TARGET"
4+
echo "Cgroup version: $CI_CGROUPS"
5+
echo "Operating system: $CI_OS"
6+
7+
echo "this is hack, ignore this file" >> ./stracez-dummy
8+
9+
if [[ $CI_OS == "ubuntu-latest" ]]; then
10+
if [[ $CI_CGROUPS == "cgroup-v2" ]]; then
11+
echo "Skipping: cgroup v2 runs in macos"
12+
exit 0
13+
fi
14+
fi
15+
if [[ $CI_OS == "macos-latest" ]]; then
16+
if [[ $CI_CGROUPS == "cgroup-v1" ]]; then
17+
echo "Skipping: cgroup v1 does not need virtualization"
18+
exit 0
19+
fi
20+
if [[ $CI_TARGET == "x86_64-unknown-linux-gnu" ]]; then
21+
echo "Skipping: we will not run test on gnu targets anyway"
22+
exit 0
23+
fi
24+
fi
25+
26+
echo "::group::Preparing"
27+
28+
if [[ $CI_CGROUPS == "cgroup-v2" ]] && [ -z "${CI_VM+set}" ]; then
29+
echo "::group::Preparing virtual machine"
30+
vagrant --version
31+
cat > Vagrantfile <<EOF
32+
Vagrant.configure("2") do |config|
33+
config.vm.box = "fedora/32-cloud-base"
34+
35+
config.vm.provider "virtualbox" do |vb|
36+
vb.memory = "900"
37+
end
38+
end
39+
EOF
40+
top -l 1
41+
cat Vagrantfile
42+
sudo vagrant up
43+
echo "::group::Installing packages"
44+
sudo vagrant ssh --command "sudo dnf install -y gcc gcc-c++ strace"
45+
echo "::group::Installing rust"
46+
sudo vagrant ssh --command "curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable"
47+
echo "::group::Entering VM"
48+
sudo vagrant ssh --command "bash -c 'cd /vagrant && CI_OS=$CI_OS CI_CGROUPS=$CI_CGROUPS CI_TARGET=$CI_TARGET CI_VM=1 bash ci/linux.sh'"
49+
exit 0
50+
fi
51+
52+
rustup target add $CI_TARGET
53+
54+
if [[ $CI_CGROUPS == "cgroup-v2" ]]; then
55+
echo "::group::Some cgroup hacks"
56+
sudo mkdir /sys/fs/cgroup/minion
57+
echo "+cpu +memory +pids" | sudo tee /sys/fs/cgroup/cgroup.subtree_control | sudo tee /sys/fs/cgroup/minion/cgroup.subtree_control
58+
fi
59+
60+
echo "::group::Compiling tests"
61+
echo '[build]
62+
rustflags=["--cfg", "minion_ci"]' > .cargo/config
63+
64+
export RUSTC_BOOTSTRAP=1
65+
cargo build -p minion-tests -Zunstable-options --out-dir=./out --target=$CI_TARGET
66+
67+
echo "::group::Skip running if needed"
68+
if [[ $CI_TARGET == "x86_64-unknown-linux-gnu" ]]; then
69+
echo "skipping: static binary required on linux"
70+
exit 0
71+
fi
72+
73+
echo "::group::Running tests"
74+
sudo --preserve-env ./out/minion-tests --trace
75+

minion-tests/src/master.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ fn execute_single_test(case: &dyn TestCase, exec_opts: ExecuteOptions) -> Outcom
8484
};
8585

8686
cmd.env_clear();
87+
if cfg!(minion_ci) {
88+
if let Ok(cgroups) = std::env::var("CI_CGROUPS") {
89+
cmd.env("CI_CGROUPS", cgroups);
90+
}
91+
}
8792
cmd.env(crate::WORKER_ENV_NAME, "1");
8893
cmd.env("TEST", case.name());
8994
let status = cmd.status().unwrap();

src/linux/cgroup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ impl Driver {
7373
pub(in crate::linux) fn new(
7474
settings: &crate::linux::Settings,
7575
) -> Result<Driver, crate::linux::Error> {
76-
let cgroup_version = detect::CgroupVersion::detect();
76+
// TODO: take cgroupfs as prefix
77+
let (cgroup_version, cgroupfs_path) = detect::CgroupVersion::detect(None);
7778
let mut cgroup_prefix = Vec::new();
7879
for comp in settings.cgroup_prefix.components() {
7980
if let std::path::Component::Normal(n) = comp {
8081
cgroup_prefix.push(n.to_os_string());
8182
}
8283
}
83-
let cgroupfs_path = "/sys/fs/cgroup".into();
8484
Ok(Driver {
8585
version: cgroup_version,
8686
cgroup_prefix,
@@ -92,7 +92,7 @@ impl Driver {
9292
cgroup_id: &str,
9393
limits: &ResourceLimits,
9494
) -> JoinHandle {
95-
match CgroupVersion::detect() {
95+
match self.version {
9696
CgroupVersion::V1 => JoinHandle::V1(self.setup_cgroups_v1(limits, cgroup_id)),
9797
CgroupVersion::V2 => JoinHandle::V2(self.setup_cgroups_v2(limits, cgroup_id)),
9898
}

src/linux/cgroup/detect.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//! This module is responsible for CGroup version detection
2+
3+
use std::path::PathBuf;
4+
25
#[derive(Eq, PartialEq, Debug)]
36
pub(in crate::linux) enum CgroupVersion {
47
/// Legacy
@@ -8,21 +11,34 @@ pub(in crate::linux) enum CgroupVersion {
811
}
912

1013
impl CgroupVersion {
11-
pub(in crate::linux) fn detect() -> CgroupVersion {
12-
let stat = nix::sys::statfs::statfs("/sys/fs/cgroup")
13-
.expect("/sys/fs/cgroup is not root of cgroupfs");
14+
pub(in crate::linux) fn detect(hint: Option<PathBuf>) -> (CgroupVersion, PathBuf) {
15+
let path = hint
16+
.or_else(|| Some(std::env::var_os("MINION_CGROUPFS")?.into()))
17+
.unwrap_or_else(|| "/sys/fs/cgroup".into());
18+
let stat = nix::sys::statfs::statfs(&path)
19+
.unwrap_or_else(|_| panic!("{} is not root of cgroupfs", path.display()));
1420
let ty = stat.filesystem_type();
1521
// man 2 statfs
1622
match ty.0 {
17-
0x0027_e0eb => return CgroupVersion::V1,
18-
0x6367_7270 => return CgroupVersion::V2,
23+
0x0027_e0eb => return (CgroupVersion::V1, path),
24+
0x6367_7270 => return (CgroupVersion::V2, path),
1925
_ => (),
2026
};
21-
let p = std::path::Path::new("/sys/fs/cgroup");
22-
if p.join("cgroup.subtree_control").exists() {
27+
let vers = if path.join("cgroup.subtree_control").exists() {
2328
CgroupVersion::V2
2429
} else {
2530
CgroupVersion::V1
31+
};
32+
33+
if cfg!(minion_ci) {
34+
let expected_version = match std::env::var("CI_CGROUPS").unwrap().as_str() {
35+
"cgroup-v1" => CgroupVersion::V1,
36+
"cgroup-v2" => CgroupVersion::V2,
37+
_ => panic!(),
38+
};
39+
40+
assert_eq!(vers, expected_version);
2641
}
42+
(vers, path)
2743
}
2844
}

src/linux/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn find_lca<'a>(a: &'a [String], b: &'a [String]) -> &'a [String] {
7878

7979
/// `crate::check()` on linux
8080
pub fn check() -> Result<(), String> {
81-
if CgroupVersion::detect() == CgroupVersion::V1 {
81+
if CgroupVersion::detect(None).0 == CgroupVersion::V1 {
8282
if unsafe { libc::geteuid() } != 0 {
8383
return Err("Root is required to use legacy cgroups".to_string());
8484
}

0 commit comments

Comments
 (0)