Skip to content

Commit 3ada841

Browse files
committed
Add build.rs to compiletest, add github job
1 parent 9700217 commit 3ada841

File tree

8 files changed

+84
-7
lines changed

8 files changed

+84
-7
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
on:
77
push:
8-
branches: [ master, staging, trying ]
8+
branches: [ master, staging, trying, next ]
99
pull_request:
1010
merge_group:
1111

@@ -68,6 +68,26 @@ jobs:
6868
- name: Run cargo check for example
6969
run: cargo check --target ${{ matrix.target_and_example.target}} --no-default-features --features ${{matrix.log_kind}} --manifest-path ${{matrix.target_and_example.example}} --locked --all-targets
7070

71+
ui_tests:
72+
name: Compile Tests
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Checkout sources
76+
uses: actions/checkout@v4
77+
78+
- name: Install target
79+
uses: dtolnay/rust-toolchain@v1
80+
with:
81+
target: riscv32imac-unknown-none-elf
82+
toolchain: stable
83+
components: rust-src
84+
85+
- name: Cache Dependencies
86+
uses: Swatinem/rust-cache@v2.7.5
87+
88+
- name: Run Compile tests
89+
run: cd tests-build && cargo test
90+
7191
fmt:
7292
name: Rustfmt
7393
runs-on: ubuntu-latest

macros/src/attributes/tests/parse/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub(crate) fn parse_item(mut f: ItemFn) -> Result<Func, syn::Error> {
132132
if check_fn_sig(&f.sig).is_err() || f.sig.inputs.len() > 1 {
133133
return Err(parse::Error::new(
134134
f.sig.ident.span(),
135-
"`#[test]` function must have signature `async fn(state: &mut Type)` (async/parameter are optional)",
135+
"`#[test]` function must have signature `async fn(state: Type)` (async/parameter are optional)",
136136
));
137137
}
138138

src/export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{export, TestOutcome};
22

33
#[cfg_attr(feature = "std", path = "std.rs")]
4-
#[cfg_attr(not(feature = "std"), path = "semihosting.rs")]
4+
#[cfg_attr(feature = "semihosting", path = "semihosting.rs")]
55
pub mod hosting;
66

77
// Reexport the embassy stuff
@@ -33,7 +33,7 @@ pub fn check_outcome<T: TestOutcome>(outcome: T) -> ! {
3333
*/
3434

3535
#[export_name = "main"]
36-
unsafe extern "C" fn __embedded_test_entry() -> ! {
36+
pub unsafe extern "C" fn __embedded_test_entry() -> ! {
3737
ensure_linker_file_was_added_to_rustflags();
3838
}
3939

tests-build/cases/pass/embassy.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
```cargo
33
[dependencies]
44
embassy-executor = { version = "0.7", features = ["executor-thread", "arch-riscv32"] }
5+
esp-hal = { version = "0.23.1", features = ["esp32c6"] } # for critical section implementation
56
embedded-test = { path = "../../..", features = ["embassy"] }
67
78
[lib]
@@ -15,6 +16,7 @@ harness = false
1516
#[cfg(test)]
1617
#[embedded_test::tests]
1718
mod tests1 {
19+
use esp_hal::*; // needs to be in scope, to prevent linker error about missing `critical_section` implementation
1820

1921
struct Context;
2022

@@ -28,6 +30,11 @@ mod tests1 {
2830
assert!(true)
2931
}
3032

33+
#[test]
34+
fn takes_state2(_state: Context) {
35+
assert!(true)
36+
}
37+
3138
#[test]
3239
async fn takes_no_state() {
3340
assert!(true)
@@ -46,7 +53,7 @@ mod tests2 {
4653
}
4754

4855
#[test]
49-
async fn takes_state2(_state: Context) {
56+
async fn takes_state3(_state: Context) {
5057
assert!(true)
5158
}
5259

tests-build/cases/pass/embassy_custom_executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ harness = false
1717
#[cfg(test)]
1818
#[embedded_test::tests(executor=esp_hal_embassy::Executor::new())]
1919
mod tests {
20-
use esp_hal::*;
20+
//use esp_hal::*;
2121

2222
struct Context;
2323

tests-build/src/build_rs.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::path::Path;
2+
3+
pub(crate) struct BuildRs {
4+
linker_files: Vec<String>,
5+
}
6+
7+
impl BuildRs {
8+
pub fn new() -> Self {
9+
Self {
10+
linker_files: Vec::new(),
11+
}
12+
}
13+
14+
pub fn add_linker_file(&mut self, file: &str) {
15+
self.linker_files.push(file.to_string());
16+
}
17+
18+
pub fn write(&self, build_rs_path: &Path) -> anyhow::Result<()> {
19+
let statements = self.generate_linker_args();
20+
let contents = format!("fn main() {{ {statements} }}");
21+
std::fs::write(build_rs_path, contents)?;
22+
Ok(())
23+
}
24+
25+
pub fn generate_linker_args(&self) -> String {
26+
self.linker_files
27+
.iter()
28+
.map(|file| format!("cargo:rustc-link-arg=-T{}", file))
29+
.map(|arg| format!("println!(\"{}\");\n", arg))
30+
.collect::<Vec<String>>()
31+
.join("\n")
32+
}
33+
}

tests-build/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod build_rs;
12
mod manifest;
23

34
use crate::manifest::Manifest;
@@ -25,6 +26,17 @@ fn run_test(test_file: &Path, should_pass: bool) {
2526
let manifest_path = temp_dir.join("Cargo.toml");
2627
manifest.write(&manifest_path).unwrap();
2728

29+
//TODO: only link embedded-test.x for some tests, to check for errors if missing
30+
31+
let mut build_rs = build_rs::BuildRs::new();
32+
if manifest.dependencies.contains_key("esp-hal") {
33+
build_rs.add_linker_file("linkall.x");
34+
}
35+
build_rs.add_linker_file("embedded-test.x");
36+
37+
let build_rs_path = temp_dir.join("build.rs");
38+
build_rs.write(&build_rs_path).unwrap();
39+
2840
let output = Command::new("cargo")
2941
.args(&[
3042
"test",
@@ -39,6 +51,11 @@ fn run_test(test_file: &Path, should_pass: bool) {
3951
])
4052
.output()
4153
.unwrap();
54+
println!(
55+
"Running test {} in {}",
56+
test_file.display(),
57+
manifest_path.display()
58+
);
4259

4360
if should_pass {
4461
if output.status.success() {

tests-build/src/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) struct BinOrTest {
4141
#[derive(Serialize, Deserialize, Debug)]
4242
pub(crate) struct Manifest {
4343
package: Option<Package>,
44-
dependencies: Map<String, Dependency>,
44+
pub dependencies: Map<String, Dependency>,
4545
#[serde(skip_serializing_if = "Option::is_none")]
4646
lib: Option<Lib>,
4747
#[serde(rename = "bin", default, skip_serializing_if = "Vec::is_empty")]

0 commit comments

Comments
 (0)