-
Notifications
You must be signed in to change notification settings - Fork 55
/
generate-tests.sh
66 lines (54 loc) · 1.37 KB
/
generate-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
set -e
elementIn() {
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0
done
return 1
}
main() {
local tests_dir=$(pwd)/tests
local cmsis_dir=$tests_dir/cmsis_tests
local blacklist=(
# These SVD files have some registers with a `resetValue` bigger than the register itself
Toshiba/M365
Toshiba/M367
Toshiba/M368
Toshiba/M369
Toshiba/M36B
SiliconLabs/SIM3L1x8_SVD
)
rm -rf tests/cmsis_tests
mkdir -p tests/cmsis_tests
local vendor_dir
for vendor_dir in $(echo cmsis-svd/data/*); do
local vendor=$(basename $vendor_dir)
cat >"$cmsis_dir/$vendor.rs" <<EOF
#![allow(non_snake_case)]
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}
if elementIn "$vendor/$device" "${blacklist[@]}"; then
continue
fi
device=${device//./_}
cat >>"$cmsis_dir/$vendor.rs" <<EOF
#[test]
fn $device() {
let xml = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/$device_path"));
svd::parse(xml).unwrap();
}
EOF
done
cat >>"$cmsis_dir/mod.rs" <<EOF
pub mod $vendor;
EOF
done
cat >"$tests_dir/cmsis.rs"<<EOF
pub mod cmsis_tests;
EOF
}
main