rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
707 stars 150 forks source link

More extensive testing #45

Closed japaric closed 7 years ago

japaric commented 7 years ago

Once #43 lands, I think we should be ready to test generating all the peripherals that a SVD contains. svd2rust -i $svd would give us the full list of peripheral then we can use svd2rust -i $svd $peripheral for each peripheral in that list.

We could even repeat this approach for several SVD files in the cmsis-svd repo. We should be careful to not overdo ourselves and end up with unreasonable test times though.

japaric commented 7 years ago

Here's a script I used to smoke test svd2rust against posborne/cmsis-svd.

set -ex

main() {
    local url='https://github.com/posborne/cmsis-svd/archive/python-0.4.tar.gz'
    local data_dir=$(mktemp -d)

    curl -L $url | tar -C $data_dir --strip-components 1 -xz

    local errors=()
    set +ex
    find $data_dir -type f -name '*.svd' -print0 | \
        while IFS= read -r -d $'\0' line; do
            svd2rust -i $line >/dev/null 2>&1 || \
                echo $(basename $line)
        done

    set -ex

    rm -rf $data_dir
}

main

These svd2rust failed to generate code from these files:

M36B.svd - BAD SVD - svd-parser-0.5.1/src/lib.rs:216
M369.svd - PARSER? - svd-parser-0.5.1/src/lib.rs:216
M368.svd - PARSER? - svd-parser-0.5.1/src/lib.rs:216
M367.svd - PARSER? - svd-parser-0.5.1/src/lib.rs:216
M365.svd - PARSER? - svd-parser-0.5.1/src/lib.rs:216
SIM3L1x8_SVD.svd - PARSER? - svd-parser-0.5.1/src/lib.rs:58
LPC408x_7x_v0.7.svd - BAD SVD - error: Register P0_12 has no reset value
LPC178x_7x_v0.8.svd - BAD SVD - error: Register P0_12 has no reset value
LPC178x_7x.svd - BAD SVD - error: Register P0_12 has no reset value
LPC176x5x_v0.2.svd - BUG? - error: EnumeratedValue RESERVED has no <value> field
LPC11Axxv0.6.svd - BAD SVD - error: Register PIO0_4 has no reset value
ATSAMA5D35.svd - BAD SVD - error: Register CR has no reset value
ATSAMA5D34.svd - BAD SVD - error: Register CR has no reset value
ATSAMA5D33.svd - BAD SVD - error: Register CR has no reset value
ATSAMA5D31.svd - BAD SVD - error: Register CR has no reset value
ATSAM4SD32C.svd - BAD SVD - error: Register CR has no reset value
ATSAM4SD32B.svd - BAD SVD - error: Register CR has no reset value
ATSAM4S8C.svd - BAD SVD - error: Register CR has no reset value
ATSAM4S8B.svd - BAD SVD - error: Register CR has no reset value
ATSAM4S16C.svd - BAD SVD - error: Register CR has no reset value
ATSAM4S16B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3X8E.svd - BAD SVD - error: Register CR has no reset value
ATSAM3X8C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3X4E.svd - BAD SVD - error: Register CR has no reset value
ATSAM3X4C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3U4E.svd - BAD SVD - error: Register CR has no reset value
ATSAM3U4C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3U2E.svd - BAD SVD - error: Register CR has no reset value
ATSAM3U2C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3U1E.svd - BAD SVD - error: Register CR has no reset value
ATSAM3U1C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3SD8C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3SD8B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S8C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S8B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S4C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S4B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S4A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S2C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S2B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S2A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S1C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S1B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3S1A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N4C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N4B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N4A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N2C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N2B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N2A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N1C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N1B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N1A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N0C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N0B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N0A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N00B.svd - BAD SVD - error: Register CR has no reset value
ATSAM3N00A.svd - BAD SVD - error: Register CR has no reset value
ATSAM3A8C.svd - BAD SVD - error: Register CR has no reset value
ATSAM3A4C.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9X35.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9X25.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9N12.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9M11.svd - BAD SVD - error: Register LUTENTRY[%s] has no reset value
AT91SAM9M10.svd - BAD SVD - error: Register LUTENTRY[%s] has no reset value
AT91SAM9G35.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9G25.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9G20.svd - BAD SVD - error: Register CCR0 has no reset value
AT91SAM9G15.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9G10.svd - BAD SVD - error: Register LUTENTRY[%s] has no reset value
AT91SAM9CN12.svd - BAD SVD - error: Register CR has no reset value
AT91SAM9CN11.svd - BAD SVD - error: Register CR has no reset value

I have yet to investigate the cause of the errors. The error rate is 71 out of 490 or about 14.49%.

japaric commented 7 years ago

I have now classified all the 71 errors. Most of them are caused by the SVD not being valid. As per the specification all registers must have a reset value but the SVD listed above are missing reset values in some registers.

japaric commented 7 years ago

Updated script to detect SVD files for which svd2rust does generate code without crashing but the generated code doesn't compile:

set -ex

main() {
    local url='https://github.com/posborne/cmsis-svd/archive/python-0.4.tar.gz'
    local cargo_dir=$(mktemp -d)
    local data_dir=$(mktemp -d)

    curl -L $url | tar -C $data_dir --strip-components 1 -xz

    cargo init --lib --name device $cargo_dir
    ( cd $cargo_dir && cargo add cortex-m vcell )

    local errors=()
    set +ex
    find $data_dir -type f -name '*.svd' -print0 | \
        while IFS= read -r -d $'\0' line; do
            svd2rust -i $line >$cargo_dir/src/lib.rs 2>/dev/null || \
                ( echo "I: $(basename $line)" && continue )

            cargo check --manifest-path $cargo_dir/Cargo.toml >/dev/null 2>&1 || \
                echo "II: $(basename $line)"
        done

    set -ex

    rm -rf $cargo_dir
    rm -rf $data_dir
}

main

The compile errors are referred to as class II errors, and the generation errors are referred to as class I errors.

Here's the list of class II errors I have seen so far. (The script is still running on my machine; it's taking a while to test all the SVD files). The errors have already been classified:

(up to this point these errors are not due to svd2rust bugs)

japaric commented 7 years ago

Testing all the SVD files in cmsis-svd takes a few hours on my laptop so it seems very unlikely that will be able to run it as part of the CI testing of this repo. I think we should sample some files, specially those listed above that are causing trouble today, from the database and just use those in our test suite. At the very least we should pick on SVD file per microcontroller vendor.

pftbest commented 7 years ago

Also there are some new svd files in cmsis-svd repo (on master branch) that are not present in 0.4 archive.

japaric commented 7 years ago

@pftbest thanks for the heads up. I'll re-run the test script on the diff between HEAD and v0.4.0.

japaric commented 7 years ago

I'll re-run the test script on the diff between HEAD and v0.4.0.

I have now tested and classified the extra files. All the TM4C files fail (svd2rust works but compilation errors) due to #97. The rest work fine.

japaric commented 7 years ago

Done in #101

japaric commented 7 years ago

The ci/script.sh file is now keeping track of the SVD files that are not working due to missing feature is svd2rust. Each of those files has been classified and issues have been filed under the 'cmsis-svd' milestone.