Skip to content

Commit

Permalink
tests: Add test for auto-init when auto-init debug is active
Browse files Browse the repository at this point in the history
Merges: #48
  • Loading branch information
chrysn authored Feb 22, 2023
2 parents 076a080 + dc5c989 commit 6b4f5d4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ fn main() {
let bindgen_output = std::fs::read_to_string(bindgen_output_file)
.expect("Failed to read BINDGEN_OUTPUT_FILE");

if bindgen_output.contains("pub const CONFIG_AUTO_INIT_ENABLE_DEBUG: u32 = 1;") {
// Whether or not the extra space is there depends on whether or not rustfmt is installed.
// FIXME: Find a better way to extract that information
if bindgen_output.contains("pub const CONFIG_AUTO_INIT_ENABLE_DEBUG: u32 = 1;")
|| bindgen_output.contains("pub const CONFIG_AUTO_INIT_ENABLE_DEBUG : u32 = 1 ;")
{
println!("cargo:rustc-cfg=marker_config_auto_init_enable_debug");
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/auto_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl AutoInitModule {
result = Self(riot_sys::auto_init_module_t {
init: Some(init_function),
prio: priority,
name: name.as_ptr(),
name: name.as_ptr() as _,
});
}
#[cfg(not(marker_config_auto_init_enable_debug))]
Expand Down
1 change: 1 addition & 0 deletions tests/auto-init-debug/Cargo.toml
3 changes: 3 additions & 0 deletions tests/auto-init-debug/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CFLAGS += -DCONFIG_AUTO_INIT_ENABLE_DEBUG=1

include ../auto-init/Makefile
1 change: 1 addition & 0 deletions tests/auto-init-debug/src
19 changes: 19 additions & 0 deletions tests/auto-init-debug/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

import os
import sys
from testrunner import run

def test(child):
# avoiding parentheses in the numbers -- these are regexps!
child.expect("auto_init: auto_early .1.")
child.expect("Early auto initialization")
child.expect("auto_init: auto_late .65535.")
child.expect("Late auto initialization")
child.expect("Main running")

if __name__ == "__main__":
if os.environ['BOARD'] != 'native':
print("Automated test only works on native (other boards' early output is lost)", file=sys.stderr)
sys.exit(1)
sys.exit(run(test))

0 comments on commit 6b4f5d4

Please sign in to comment.