Skip to content

Commit 0b44970

Browse files
committed
Move test-features activation to Cargo.toml
1 parent d4d8ebe commit 0b44970

File tree

17 files changed

+52
-32
lines changed

17 files changed

+52
-32
lines changed

12_integrated_testing/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

12_integrated_testing/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ cortex-a = { version = "7.x.x" }
3535
[dev-dependencies]
3636
test-macros = { path = "test-macros" }
3737

38+
# The following line is a workaround, as suggested in [1], to enable a feature in test-builds only.
39+
# This allows building the library part of the kernel with specialized code for testing.
40+
#
41+
#
42+
# [1] https://github.com/rust-lang/cargo/issues/2911#issuecomment-749580481
43+
mingo = { path = ".", features = ["test_build"] }
44+
3845
# Unit tests are done in the library part of the kernel.
3946
[lib]
4047
name = "libkernel"

12_integrated_testing/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,13 @@ define test_prepare
284284
@chmod +x target/kernel_test_runner.sh
285285
endef
286286

287-
test_unit test_integration: FEATURES += --features test_build
288-
289287
##------------------------------------------------------------------------------
290288
## Run unit test(s)
291289
##------------------------------------------------------------------------------
292290
test_unit:
293291
$(call colorecho, "\nCompiling unit test(s) - $(BSP)")
294292
$(call test_prepare)
295-
RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
293+
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
296294

297295
##------------------------------------------------------------------------------
298296
## Run integration test(s)

12_integrated_testing/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub fn qemu_exit_success() -> ! {
324324
[Click here] in case you are interested in the implementation. Note that for the functions to work,
325325
the `-semihosting` flag must be added to the `QEMU` invocation.
326326

327-
You might have also noted the `#[cfg(feature = "test_build")]`. In the `Makefile`, we ensure that
327+
You might have also noted the `#[cfg(feature = "test_build")]`. In `Cargo.toml`, we ensure that
328328
this feature is only enabled when `cargo test` runs. This way, it is ensured that testing-specific
329329
code is conditionally compiled only for testing.
330330

@@ -411,8 +411,6 @@ define test_prepare
411411
@chmod +x target/kernel_test_runner.sh
412412
endef
413413

414-
test_unit test_integration: FEATURES += --features test_build
415-
416414
##------------------------------------------------------------------------------
417415
## Run unit test(s)
418416
##------------------------------------------------------------------------------
@@ -912,7 +910,7 @@ diff -uNr 11_exceptions_part1_groundwork/Cargo.toml 12_integrated_testing/Cargo.
912910
authors = ["Andre Richter <[email protected]>"]
913911
edition = "2021"
914912

915-
@@ -11,20 +11,50 @@
913+
@@ -11,20 +11,57 @@
916914
default = []
917915
bsp_rpi3 = ["tock-registers"]
918916
bsp_rpi4 = ["tock-registers"]
@@ -944,6 +942,13 @@ diff -uNr 11_exceptions_part1_groundwork/Cargo.toml 12_integrated_testing/Cargo.
944942
+[dev-dependencies]
945943
+test-macros = { path = "test-macros" }
946944
+
945+
+# The following line is a workaround, as suggested in [1], to enable a feature in test-builds only.
946+
+# This allows building the library part of the kernel with specialized code for testing.
947+
+#
948+
+#
949+
+# [1] https://github.com/rust-lang/cargo/issues/2911#issuecomment-749580481
950+
+mingo = { path = ".", features = ["test_build"] }
951+
+
947952
+# Unit tests are done in the library part of the kernel.
948953
+[lib]
949954
+name = "libkernel"
@@ -1023,7 +1028,7 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
10231028
$(call colorecho, "\n$(QEMU_MISSING_STRING)")
10241029

10251030
else # QEMU is supported.
1026-
@@ -253,6 +263,45 @@
1031+
@@ -253,6 +263,43 @@
10271032
$(call colorecho, "\nBoot test - $(BSP)")
10281033
@$(DOCKER_TEST) $(EXEC_TEST_DISPATCH) $(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
10291034

@@ -1049,15 +1054,13 @@ diff -uNr 11_exceptions_part1_groundwork/Makefile 12_integrated_testing/Makefile
10491054
+ @chmod +x target/kernel_test_runner.sh
10501055
+endef
10511056
+
1052-
+test_unit test_integration: FEATURES += --features test_build
1053-
+
10541057
+##------------------------------------------------------------------------------
10551058
+## Run unit test(s)
10561059
+##------------------------------------------------------------------------------
10571060
+test_unit:
10581061
+ $(call colorecho, "\nCompiling unit test(s) - $(BSP)")
10591062
+ $(call test_prepare)
1060-
+ RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
1063+
+ @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
10611064
+
10621065
+##------------------------------------------------------------------------------
10631066
+## Run integration test(s)

13_exceptions_part2_peripheral_IRQs/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

13_exceptions_part2_peripheral_IRQs/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ cortex-a = { version = "7.x.x" }
3535
[dev-dependencies]
3636
test-macros = { path = "test-macros" }
3737

38+
# The following line is a workaround, as suggested in [1], to enable a feature in test-builds only.
39+
# This allows building the library part of the kernel with specialized code for testing.
40+
#
41+
#
42+
# [1] https://github.com/rust-lang/cargo/issues/2911#issuecomment-749580481
43+
mingo = { path = ".", features = ["test_build"] }
44+
3845
# Unit tests are done in the library part of the kernel.
3946
[lib]
4047
name = "libkernel"

13_exceptions_part2_peripheral_IRQs/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ define test_prepare
284284
@chmod +x target/kernel_test_runner.sh
285285
endef
286286

287-
test_unit test_integration: FEATURES += --features test_build
288-
289287
##------------------------------------------------------------------------------
290288
## Run unit test(s)
291289
##------------------------------------------------------------------------------

13_exceptions_part2_peripheral_IRQs/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -758,19 +758,6 @@ diff -uNr 12_integrated_testing/Cargo.toml 13_exceptions_part2_peripheral_IRQs/C
758758
edition = "2021"
759759

760760

761-
diff -uNr 12_integrated_testing/Makefile 13_exceptions_part2_peripheral_IRQs/Makefile
762-
--- 12_integrated_testing/Makefile
763-
+++ 13_exceptions_part2_peripheral_IRQs/Makefile
764-
@@ -292,7 +292,7 @@
765-
test_unit:
766-
$(call colorecho, "\nCompiling unit test(s) - $(BSP)")
767-
$(call test_prepare)
768-
- RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
769-
+ @RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(TEST_CMD) --lib
770-
771-
##------------------------------------------------------------------------------
772-
## Run integration test(s)
773-
774761
diff -uNr 12_integrated_testing/src/_arch/aarch64/cpu/smp.rs 13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/cpu/smp.rs
775762
--- 12_integrated_testing/src/_arch/aarch64/cpu/smp.rs
776763
+++ 13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/cpu/smp.rs

14_virtual_mem_part2_mmio_remap/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

14_virtual_mem_part2_mmio_remap/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ cortex-a = { version = "7.x.x" }
3535
[dev-dependencies]
3636
test-macros = { path = "test-macros" }
3737

38+
# The following line is a workaround, as suggested in [1], to enable a feature in test-builds only.
39+
# This allows building the library part of the kernel with specialized code for testing.
40+
#
41+
#
42+
# [1] https://github.com/rust-lang/cargo/issues/2911#issuecomment-749580481
43+
mingo = { path = ".", features = ["test_build"] }
44+
3845
# Unit tests are done in the library part of the kernel.
3946
[lib]
4047
name = "libkernel"

0 commit comments

Comments
 (0)