add asm_check tool and one-off asm test#23
Conversation
Adds `tools/asm_check`, a Rust binary that checks assembly output against a TOML config file specifying per-function `must_contain` and `must_not_contain` regex patterns, with optional function exclude patterns. Provies a one-off asm test using `sh_binary` and a manually generated TOML config for `mod_layout`. Adds `anyhow`, `clap`, `regex`, `serde`, and `toml` to the `tool_crates` extension to support the new binary.
| write_file( | ||
| name = "mod_layout_asm_check_config", | ||
| out = "mod_layout_asm_check.toml", | ||
| content = [ | ||
| "[[check]]", | ||
| "functions = [\"mod_layout::tests::test_layout_(right|left)_mapping_stride_out_of_bounds\"]", | ||
| "must_contain = [\"bl[[:space:]]+_core::panicking::panic_fmt\"]", | ||
| "", | ||
| "[[check]]", | ||
| "functions = [\"mod_layout::.*\"]", | ||
| "exclude = [\"mod_layout::tests::test_layout_(right|left)_mapping_stride_out_of_bounds\"]", | ||
| "must_not_contain = [\"bl[[:space:]]+_core::panicking::panic_fmt\"]", | ||
| "", | ||
| ], | ||
| ) |
There was a problem hiding this comment.
Curiosity: Why does this need to be written by bazel?
There was a problem hiding this comment.
No reason. We could create the file and check it in instead of generating it.
There was a problem hiding this comment.
Oh okay. Maybe it'll read better and get syntax highlighting if we materialize it.
There was a problem hiding this comment.
I'll update this PR later and add the file.
| fn parse_functions<'a>(asm: &'a str) -> BTreeMap<&'a str, Vec<&'a str>> { | ||
| let mut chunks: Vec<Vec<&str>> = vec![]; | ||
|
|
||
| for line in asm.lines() { | ||
| let is_label = line.ends_with(':') && !line.starts_with(|c: char| c.is_whitespace()); | ||
|
|
||
| if is_label { | ||
| chunks.push(vec![line]); | ||
| } else if let Some(chunk) = chunks.last_mut() { | ||
| chunk.push(line); | ||
| } | ||
| } | ||
|
|
||
| for i in (1..chunks.len()).rev() { | ||
| if chunks[i][0].trim_end_matches(':').starts_with("Lloh") { | ||
| let lloh = chunks.remove(i); | ||
| chunks[i - 1].extend(lloh); | ||
| } | ||
| } | ||
|
|
||
| chunks | ||
| .into_iter() | ||
| .map(|mut chunk| { | ||
| let name = chunk.remove(0).trim_end_matches(':'); | ||
| (name, chunk) | ||
| }) | ||
| .collect() | ||
| } |
There was a problem hiding this comment.
I based this on the ASM on my machine. This will probably differ for Linux and bare-metal targets.
| .cfi_endproc | ||
|
|
||
| .p2align 2 | ||
| "#; |
There was a problem hiding this comment.
The last function is copy/pasted from the asm on my machine. The ones above were generated by Claude.
@mickvangelderen can you add a function based on the output of your machine?
Adds
tools/asm_check, a Rust binary that checks assembly output against a TOML config file specifying per-functionmust_containandmust_not_containregex patterns, with optional function exclude patterns.Provies a one-off asm test using
sh_binaryand a manually generated TOML config formod_layout.Adds
anyhow,clap,regex,serde, andtomlto thetool_cratesextension to support the new binary.