Skip to content

Commit bad069e

Browse files
committed
Use charp and invboll parameters in examples and tests
1 parent f473d6e commit bad069e

File tree

6 files changed

+83
-14
lines changed

6 files changed

+83
-14
lines changed

.github/workflows/ci.yaml

+13-5
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,26 @@ jobs:
156156
# Run
157157
- run: ${{ env.BUILD_DIR }}usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img
158158

159-
- run: qemu-system-${{ env.QEMU_ARCH }} -kernel ${{ env.BUILD_DIR }}${{ env.IMAGE_PATH }} -initrd qemu-initramfs.img -M ${{ env.QEMU_MACHINE }} -cpu ${{ env.QEMU_CPU }} -smp 2 -nographic -no-reboot -append '${{ env.QEMU_APPEND }} rust_example.my_i32=123321 rust_example_2.my_i32=234432' | tee qemu-stdout.log
159+
- run: qemu-system-${{ env.QEMU_ARCH }} -kernel ${{ env.BUILD_DIR }}${{ env.IMAGE_PATH }} -initrd qemu-initramfs.img -M ${{ env.QEMU_MACHINE }} -cpu ${{ env.QEMU_CPU }} -smp 2 -nographic -no-reboot -append '${{ env.QEMU_APPEND }} rust_example.my_i32=123321 rust_example.my_str=🦀mod rust_example.my_invbool=y rust_example_2.my_i32=234432' | tee qemu-stdout.log
160160

161161
# Check
162162
- run: grep -F '] Rust Example (init)' qemu-stdout.log
163163
- run: grep -F '] [2] Rust Example (init)' qemu-stdout.log
164164
- run: grep -F '] [3] Rust Example (init)' qemu-stdout.log
165165
- run: grep -F '] [4] Rust Example (init)' qemu-stdout.log
166166

167-
- run: "grep -F '] my_i32: 123321' qemu-stdout.log"
168-
- run: "grep -F '] [2] my_i32: 234432' qemu-stdout.log"
169-
- run: "grep -F '] [3] my_i32: 345543' qemu-stdout.log"
170-
- run: "grep -F '] [4] my_i32: 456654' qemu-stdout.log"
167+
- run: "grep -F '] my_i32: 123321' qemu-stdout.log"
168+
- run: "grep -F '] [2] my_i32: 234432' qemu-stdout.log"
169+
- run: "grep -F '] [3] my_i32: 345543' qemu-stdout.log"
170+
- run: "grep -F '] [4] my_i32: 456654' qemu-stdout.log"
171+
172+
- run: "grep -F '] my_invbool: false' qemu-stdout.log"
173+
- run: "grep -F '] [2] my_invbool: true' qemu-stdout.log"
174+
175+
- run: "grep '\\] my_str: Ok(\"🦀mod\")\\s*$' qemu-stdout.log"
176+
- run: "grep '\\] \\[2\\] my_str: Ok(\"default str val\")\\s*$' qemu-stdout.log"
177+
- run: "grep '\\] \\[3\\] my_str: Ok(\"🦀mod\")\\s*$' qemu-stdout.log"
178+
- run: "grep '\\] \\[4\\] my_str: Ok(\"default str val\")\\s*$' qemu-stdout.log"
171179

172180
- run: grep -F '] [3] Rust Example (exit)' qemu-stdout.log
173181
- run: grep -F '] [4] Rust Example (exit)' qemu-stdout.log

.github/workflows/qemu-init.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
busybox insmod rust_example_3.ko my_i32=345543
3+
busybox insmod rust_example_3.ko my_i32=345543 my_str=🦀mod
44
busybox insmod rust_example_4.ko my_i32=456654
55
busybox rmmod rust_example_3.ko
66
busybox rmmod rust_example_4.ko

drivers/char/rust_example.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ module! {
2525
permissions: 0o644,
2626
description: b"Example of i32",
2727
},
28+
my_str: str {
29+
default: b"default str val",
30+
permissions: 0o644,
31+
description: b"Example of a string param",
32+
},
33+
my_invbool: invbool {
34+
default: true,
35+
permissions: 0o644,
36+
description: b"Example of an inverted bool",
37+
},
2838
},
2939
}
3040

@@ -49,8 +59,13 @@ impl KernelModule for RustExample {
4959
println!("Rust Example (init)");
5060
println!("Am I built-in? {}", !cfg!(MODULE));
5161
println!("Parameters:");
52-
println!(" my_bool: {}", my_bool.read());
53-
println!(" my_i32: {}", my_i32.read());
62+
println!(" my_bool: {}", my_bool.read());
63+
println!(" my_i32: {}", my_i32.read());
64+
println!(
65+
" my_str: {:?}",
66+
core::str::from_utf8(my_str.read())
67+
);
68+
println!(" my_invbool: {}", my_invbool.read());
5469

5570
Ok(RustExample {
5671
message: "on the heap!".to_owned(),

drivers/char/rust_example_2.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ module! {
2222
permissions: 0o644,
2323
description: b"Example of i32",
2424
},
25+
my_str: str {
26+
default: b"default str val",
27+
permissions: 0o644,
28+
description: b"Example of a string param",
29+
},
30+
my_invbool: invbool {
31+
default: true,
32+
permissions: 0o644,
33+
description: b"Example of an inverted bool",
34+
},
2535
},
2636
}
2737

@@ -34,8 +44,13 @@ impl KernelModule for RustExample2 {
3444
println!("[2] Rust Example (init)");
3545
println!("[2] Am I built-in? {}", !cfg!(MODULE));
3646
println!("[2] Parameters:");
37-
println!("[2] my_bool: {}", my_bool.read());
38-
println!("[2] my_i32: {}", my_i32.read());
47+
println!("[2] my_bool: {}", my_bool.read());
48+
println!("[2] my_i32: {}", my_i32.read());
49+
println!(
50+
"[2] my_str: {:?}",
51+
core::str::from_utf8(my_str.read())
52+
);
53+
println!("[2] my_invbool: {}", my_invbool.read());
3954
Ok(RustExample2 {
4055
message: "on the heap!".to_owned(),
4156
})

drivers/char/rust_example_3.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ module! {
2222
permissions: 0o644,
2323
description: b"Example of i32",
2424
},
25+
my_str: str {
26+
default: b"default str val",
27+
permissions: 0o644,
28+
description: b"Example of a string param",
29+
},
30+
my_invbool: invbool {
31+
default: true,
32+
permissions: 0o644,
33+
description: b"Example of an inverted bool",
34+
},
2535
},
2636
}
2737

@@ -34,8 +44,14 @@ impl KernelModule for RustExample3 {
3444
println!("[3] Rust Example (init)");
3545
println!("[3] Am I built-in? {}", !cfg!(MODULE));
3646
println!("[3] Parameters:");
37-
println!("[3] my_bool: {}", my_bool.read());
38-
println!("[3] my_i32: {}", my_i32.read());
47+
println!("[3] my_bool: {}", my_bool.read());
48+
println!("[3] my_i32: {}", my_i32.read());
49+
println!(
50+
"[3] my_str: {:?}",
51+
core::str::from_utf8(my_str.read())
52+
);
53+
println!("[3] my_invbool: {}", my_invbool.read());
54+
3955
Ok(RustExample3 {
4056
message: "on the heap!".to_owned(),
4157
})

drivers/char/rust_example_4.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ module! {
2222
permissions: 0o644,
2323
description: b"Example of i32",
2424
},
25+
my_str: str {
26+
default: b"default str val",
27+
permissions: 0o644,
28+
description: b"Example of a string param",
29+
},
30+
my_invbool: invbool {
31+
default: true,
32+
permissions: 0o644,
33+
description: b"Example of an inverted bool",
34+
},
2535
},
2636
}
2737

@@ -34,8 +44,13 @@ impl KernelModule for RustExample4 {
3444
println!("[4] Rust Example (init)");
3545
println!("[4] Am I built-in? {}", !cfg!(MODULE));
3646
println!("[4] Parameters:");
37-
println!("[4] my_bool: {}", my_bool.read());
38-
println!("[4] my_i32: {}", my_i32.read());
47+
println!("[4] my_bool: {}", my_bool.read());
48+
println!("[4] my_i32: {}", my_i32.read());
49+
println!(
50+
"[4] my_str: {:?}",
51+
core::str::from_utf8(my_str.read())
52+
);
53+
println!("[4] my_invbool: {}", my_invbool.read());
3954
Ok(RustExample4 {
4055
message: "on the heap!".to_owned(),
4156
})

0 commit comments

Comments
 (0)