Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reenable cmsis tests #219

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;