Skip to content

Commit

Permalink
reenable cmsis tests
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Apr 2, 2023
1 parent 835d32c commit d118eba
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
toolchain: stable
profile: minimal
override: true
- name: Generate test for SVDs from cmsis-svd repository
run: bash generate-tests.sh
- uses: actions-rs/cargo@v1
with:
command: test
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
[._]*.sw[a-p]
Cargo.lock
target
cmsis-svd/
tests/src/cmsis_tests.rs
tests/src/cmsis_tests/
25 changes: 16 additions & 9 deletions generate-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ elementIn() {
}

main() {
git clone https://github.com/posborne/cmsis-svd || true

local tests_dir=$(pwd)/tests
local cmsis_dir=$tests_dir/cmsis_tests
local cmsis_dir=$tests_dir/src/cmsis_tests
local blacklist=(
# These SVD files have some registers with a `resetValue` bigger than the register itself
Toshiba/M365
Expand All @@ -21,12 +23,14 @@ main() {
SiliconLabs/SIM3L1x8_SVD
)

rm -rf tests/cmsis_tests
mkdir -p tests/cmsis_tests
rm -rf $cmsis_dir
mkdir -p $cmsis_dir
>"$cmsis_dir/../cmsis_tests.rs"

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

local device_path

for device_path in $(find $vendor_dir/* -name '*.svd'); do
local device=$(basename $device_path)
device=${device%.svd}
Expand All @@ -44,23 +49,25 @@ EOF
fi

device=${device//./_}
device=${device//-/_}

cat >>"$cmsis_dir/$vendor.rs" <<EOF
#[test]
fn $device() {
let xml = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/$device_path"));
use std::io::Read;
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../$device_path");
let mut file = std::fs::File::open(path).unwrap();
let mut xml = String::new();
file.read_to_string(&mut xml).unwrap();
svd::parse(xml).unwrap();
svd::parse(&xml).unwrap();
}
EOF
done
cat >>"$cmsis_dir/mod.rs" <<EOF
cat >>"$cmsis_dir/../cmsis_tests.rs" <<EOF
pub mod $vendor;
EOF
done
cat >"$tests_dir/cmsis.rs"<<EOF
pub mod cmsis_tests;
EOF
}

main
1 change: 1 addition & 0 deletions tests/src/cmsis_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ mod interrupt;
mod modifiedwritevalues;
mod register;
//mod registerproperties;
mod cmsis_tests;
mod usage;
mod writeconstraint;

0 comments on commit d118eba

Please sign in to comment.