Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit b82edd9

Browse files
committed
Rejigger the way we write tests to integrate with cargo
1 parent 9eca3ee commit b82edd9

File tree

9 files changed

+36
-24
lines changed

9 files changed

+36
-24
lines changed

testlib/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "kernel-module-testlib"
3+
version = "0.1.0"
4+
authors = ["Alex Gaynor <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
File renamed without changes.

tests/chrdev-region-allocation/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ edition = "2018"
66

77
[lib]
88
crate-type = ["staticlib"]
9+
test = false
910

1011
[dependencies]
1112
linux-kernel-module = { path = "../.." }
13+
14+
[dev-dependencies]
15+
kernel-module-testlib = { path = "../../testlib" }

tests/chrdev-region-allocation/tests.rs renamed to tests/chrdev-region-allocation/tests/tests.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use kernel_module_tests::with_kernel_module;
21
use std::fs;
32

3+
use kernel_module_testlib::with_kernel_module;
4+
45
#[test]
56
fn test_proc_devices() {
67
with_kernel_module(|| {
@@ -16,10 +17,8 @@ fn test_proc_devices() {
1617
});
1718

1819
let devices = fs::read_to_string("/proc/devices").unwrap();
19-
assert!(
20-
devices
21-
.lines()
22-
.find(|l| l.ends_with("chrdev-region-allocation-tests"))
23-
.is_none()
24-
);
20+
assert!(devices
21+
.lines()
22+
.find(|l| l.ends_with("chrdev-region-allocation-tests"))
23+
.is_none());
2524
}

tests/printk/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ edition = "2018"
66

77
[lib]
88
crate-type = ["staticlib"]
9+
test = false
910

1011
[dependencies]
1112
linux-kernel-module = { path = "../.." }
13+
14+
[dev-dependencies]
15+
kernel-module-testlib = { path = "../../testlib" }

tests/printk/tests.rs renamed to tests/printk/tests/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::process::Command;
22

3-
use kernel_module_tests::with_kernel_module;
3+
use kernel_module_testlib::with_kernel_module;
44

55
fn assert_dmesg_contains(msgs: &[&[u8]]) {
66
let output = Command::new("dmesg").output().unwrap();

tests/run_tests.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ def run(*args, **kwargs):
1717

1818

1919
def main():
20-
run("rustc", "--crate-type=rlib", os.path.join(BASE_DIR, "testlib.rs"))
21-
2220
for path in os.listdir(BASE_DIR):
2321
if (
2422
not os.path.isdir(os.path.join(BASE_DIR, path)) or
25-
not os.path.exists(os.path.join(BASE_DIR, path, "tests.rs"))
23+
not os.path.exists(os.path.join(BASE_DIR, path, "tests"))
2624
):
2725
continue
2826

@@ -47,25 +45,21 @@ def main():
4745
path.replace("-", "_")
4846
),
4947
)
50-
run(
51-
"rustc",
52-
"--test",
53-
"-Dwarnings",
54-
"--edition", "2018",
55-
"--out-dir", os.path.join(BASE_DIR, path),
56-
os.path.join(BASE_DIR, path, "tests.rs"),
57-
"--extern", "kernel_module_tests=libtestlib.rlib",
58-
)
5948
# TODO: qemu
6049
run(
61-
os.path.join(BASE_DIR, path, "tests"), "--test-threads=1",
50+
"cargo", "test", "--", "--test-threads=1",
51+
cwd=os.path.join(BASE_DIR, path),
6252
environ=dict(
6353
os.environ,
64-
KERNEL_MODULE=os.path.join(BASE_DIR, "testmodule.ko")
54+
KERNEL_MODULE=os.path.join(BASE_DIR, "testmodule.ko"),
55+
RUSTFLAGS="-Dwarnings",
56+
CARGO_TARGET_DIR=os.path.relpath(
57+
os.path.join(BASE_DIR, "target"),
58+
os.path.join(BASE_DIR, path)
59+
),
6560
)
6661
)
6762

6863

69-
7064
if __name__ == "__main__":
7165
main()

tests/sysctl/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ edition = "2018"
66

77
[lib]
88
crate-type = ["staticlib"]
9+
test = false
910

1011
[dependencies]
1112
linux-kernel-module = { path = "../.." }
13+
14+
[dev-dependencies]
15+
kernel-module-testlib = { path = "../../testlib" }

tests/sysctl/tests.rs renamed to tests/sysctl/tests/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs;
22
use std::path::Path;
33

4-
use kernel_module_tests::with_kernel_module;
4+
use kernel_module_testlib::with_kernel_module;
55

66
#[test]
77
fn test_read_bool_default() {

0 commit comments

Comments
 (0)