Skip to content

Commit d118eba

Browse files
committed
reenable cmsis tests
1 parent 835d32c commit d118eba

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
toolchain: stable
4242
profile: minimal
4343
override: true
44+
- name: Generate test for SVDs from cmsis-svd repository
45+
run: bash generate-tests.sh
4446
- uses: actions-rs/cargo@v1
4547
with:
4648
command: test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
[._]*.sw[a-p]
33
Cargo.lock
44
target
5+
cmsis-svd/
6+
tests/src/cmsis_tests.rs
7+
tests/src/cmsis_tests/

generate-tests.sh

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ elementIn() {
99
}
1010

1111
main() {
12+
git clone https://github.com/posborne/cmsis-svd || true
13+
1214
local tests_dir=$(pwd)/tests
13-
local cmsis_dir=$tests_dir/cmsis_tests
15+
local cmsis_dir=$tests_dir/src/cmsis_tests
1416
local blacklist=(
1517
# These SVD files have some registers with a `resetValue` bigger than the register itself
1618
Toshiba/M365
@@ -21,12 +23,14 @@ main() {
2123
SiliconLabs/SIM3L1x8_SVD
2224
)
2325

24-
rm -rf tests/cmsis_tests
25-
mkdir -p tests/cmsis_tests
26+
rm -rf $cmsis_dir
27+
mkdir -p $cmsis_dir
28+
>"$cmsis_dir/../cmsis_tests.rs"
2629

2730
local vendor_dir
2831
for vendor_dir in $(echo cmsis-svd/data/*); do
2932
local vendor=$(basename $vendor_dir)
33+
vendor=${vendor//-/_}
3034
cat >"$cmsis_dir/$vendor.rs" <<EOF
3135
#![allow(non_snake_case)]
3236
@@ -35,6 +39,7 @@ use svd_parser as svd;
3539
EOF
3640

3741
local device_path
42+
3843
for device_path in $(find $vendor_dir/* -name '*.svd'); do
3944
local device=$(basename $device_path)
4045
device=${device%.svd}
@@ -44,23 +49,25 @@ EOF
4449
fi
4550

4651
device=${device//./_}
52+
device=${device//-/_}
4753

4854
cat >>"$cmsis_dir/$vendor.rs" <<EOF
4955
#[test]
5056
fn $device() {
51-
let xml = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/$device_path"));
57+
use std::io::Read;
58+
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../$device_path");
59+
let mut file = std::fs::File::open(path).unwrap();
60+
let mut xml = String::new();
61+
file.read_to_string(&mut xml).unwrap();
5262
53-
svd::parse(xml).unwrap();
63+
svd::parse(&xml).unwrap();
5464
}
5565
EOF
5666
done
57-
cat >>"$cmsis_dir/mod.rs" <<EOF
67+
cat >>"$cmsis_dir/../cmsis_tests.rs" <<EOF
5868
pub mod $vendor;
5969
EOF
6070
done
61-
cat >"$tests_dir/cmsis.rs"<<EOF
62-
pub mod cmsis_tests;
63-
EOF
6471
}
6572

6673
main

tests/src/cmsis_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ mod interrupt;
5959
mod modifiedwritevalues;
6060
mod register;
6161
//mod registerproperties;
62+
mod cmsis_tests;
6263
mod usage;
6364
mod writeconstraint;

0 commit comments

Comments
 (0)