33#  Runs a series of sample programs in QEMU and checks that the standard output
44#  is as expected.
55
6- rustup target add armv7r-none-eabi
7- rustup target add armv7r-none-eabihf
8- rustup target add armv7a-none-eabi
9- rustup component add rust-src
10- 
116#  Set this to 1 to exit on the first error
127EXIT_FAST=0
138
@@ -25,8 +20,8 @@ fail() {
2520
2621mkdir -p ./target
2722
28- versatile_ab_cargo=" --manifest-path examples/versatileab/Cargo.toml " 
29- mps3_an536_cargo=" --manifest-path examples/mps3-an536/Cargo.toml " 
23+ versatile_ab_cargo=" " 
24+ mps3_an536_cargo=" " 
3025
3126my_diff () {
3227    file_a=$1 
@@ -46,101 +41,39 @@ my_diff() {
4641    fi 
4742}
4843
49- #  armv7r-none-eabi tests
50- cargo build ${versatile_ab_cargo}  --target=armv7r-none-eabi ||  exit  1
51- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
52-     filename=${bin_path##*/ } 
53-     binary=${filename% .rs} 
54-     cargo run ${versatile_ab_cargo}  --target=armv7r-none-eabi --bin $binary  >  ./target/$binary -armv7r-none-eabi.out
55-     my_diff ./examples/versatileab/reference/$binary -armv7r-none-eabi.out ./target/$binary -armv7r-none-eabi.out ||  fail $binary  " armv7r-none-eabi" 
56- done 
57- 
58- #  armv7r-none-eabihf tests
59- cargo build ${versatile_ab_cargo}  --target=armv7r-none-eabihf ||  exit  1
60- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
61-     filename=${bin_path##*/ } 
62-     binary=${filename% .rs} 
63-     cargo run ${versatile_ab_cargo}  --target=armv7r-none-eabihf --bin $binary  >  ./target/$binary -armv7r-none-eabihf.out
64-     my_diff ./examples/versatileab/reference/$binary -armv7r-none-eabihf.out ./target/$binary -armv7r-none-eabihf.out ||  fail $binary  " armv7r-none-eabihf" 
65- done 
66- 
67- #  armv7a-none-eabi tests
68- cargo build ${versatile_ab_cargo}  --target=armv7a-none-eabi ||  exit  1
69- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
70-     filename=${bin_path##*/ } 
71-     binary=${filename% .rs} 
72-     cargo run ${versatile_ab_cargo}  --target=armv7a-none-eabi --bin $binary  >  ./target/$binary -armv7a-none-eabi.out
73-     my_diff ./examples/versatileab/reference/$binary -armv7a-none-eabi.out ./target/$binary -armv7a-none-eabi.out ||  fail $binary  " armv7a-none-eabi" 
74- done 
75- 
76- #  armv7a-none-eabihf tests
77- RUSTC_BOOTSTRAP=1 cargo build ${versatile_ab_cargo}  --target=armv7a-none-eabihf ||  exit  1
78- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
79-     filename=${bin_path##*/ } 
80-     binary=${filename% .rs} 
81-     RUSTC_BOOTSTRAP=1 cargo run ${versatile_ab_cargo}  --target=armv7a-none-eabihf --bin $binary  >  ./target/$binary -armv7a-none-eabihf.out
82-     my_diff ./examples/versatileab/reference/$binary -armv7a-none-eabihf.out ./target/$binary -armv7a-none-eabihf.out ||  fail $binary  " armv7a-none-eabihf" 
83- done 
84- 
85- #  armv7a-none-eabihf double-precision tests
86- RUSTC_BOOTSTRAP=1 RUSTFLAGS=" -Ctarget-feature=+d32"   cargo build ${versatile_ab_cargo}  --target=armv7a-none-eabihf  --features=fpu-d32 ||  exit  1
87- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
88-     filename=${bin_path##*/ } 
89-     binary=${filename% .rs} 
90-     RUSTC_BOOTSTRAP=1 RUSTFLAGS=" -Ctarget-feature=+d32"   cargo run ${versatile_ab_cargo}  --target=armv7a-none-eabihf --bin $binary  --features=fpu-d32 >  ./target/$binary -armv7a-none-eabihf-dp.out
91-     my_diff ./examples/versatileab/reference/$binary -armv7a-none-eabihf.out ./target/$binary -armv7a-none-eabihf-dp.out ||  fail $binary  " armv7a-none-eabihf" 
92- done 
93- 
94- #  armv5te-none-eabi tests
95- RUSTC_BOOTSTRAP=1 cargo build ${versatile_ab_cargo}  --target=armv5te-none-eabi
96- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
97-     filename=${bin_path##*/ } 
98-     binary=${filename% .rs} 
99-     RUSTC_BOOTSTRAP=1 cargo run ${versatile_ab_cargo}  --target=armv5te-none-eabi --bin $binary  >  ./target/$binary -armv5te-none-eabi.out
100-     my_diff ./examples/versatileab/reference/$binary -armv5te-none-eabi.out ./target/$binary -armv5te-none-eabi.out ||  fail $binary  " armv5te-none-eabi" 
101- done 
102- 
103- #  thumbv5te-none-eabi tests
104- RUSTC_BOOTSTRAP=1 cargo build ${versatile_ab_cargo}  --target=thumbv5te-none-eabi
105- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
106-     filename=${bin_path##*/ } 
107-     binary=${filename% .rs} 
108-     RUSTC_BOOTSTRAP=1 cargo run ${versatile_ab_cargo}  --target=thumbv5te-none-eabi --bin $binary  >  ./target/$binary -thumbv5te-none-eabi.out
109-     my_diff ./examples/versatileab/reference/$binary -thumbv5te-none-eabi.out ./target/$binary -thumbv5te-none-eabi.out ||  fail $binary  " thumbv5te-none-eabi" 
110- done 
111- 
112- #  armv4t-none-eabi tests
113- RUSTC_BOOTSTRAP=1 cargo build ${versatile_ab_cargo}  --target=armv4t-none-eabi
114- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
115-     filename=${bin_path##*/ } 
116-     binary=${filename% .rs} 
117-     RUSTC_BOOTSTRAP=1 cargo run ${versatile_ab_cargo}  --target=armv4t-none-eabi --bin $binary  >  ./target/$binary -armv4t-none-eabi.out
118-     my_diff ./examples/versatileab/reference/$binary -armv4t-none-eabi.out ./target/$binary -armv4t-none-eabi.out ||  fail $binary  " armv4t-none-eabi" 
119- done 
120- 
121- #  thumbv4t-none-eabi tests
122- RUSTC_BOOTSTRAP=1 cargo build ${versatile_ab_cargo}  --target=thumbv4t-none-eabi
123- for  bin_path  in  $( ls examples/versatileab/src/bin/* .rs) ;  do 
124-     filename=${bin_path##*/ } 
125-     binary=${filename% .rs} 
126-     RUSTC_BOOTSTRAP=1 cargo run ${versatile_ab_cargo}  --target=thumbv4t-none-eabi --bin $binary  >  ./target/$binary -thumbv4t-none-eabi.out
127-     my_diff ./examples/versatileab/reference/$binary -thumbv4t-none-eabi.out ./target/$binary -thumbv4t-none-eabi.out ||  fail $binary  " thumbv4t-none-eabi" 
128- done 
129- 
130- #  These tests only run on QEMU 9 or higher.
131- #  Ubuntu 24.04 supplies QEMU 8, which doesn't support the machine we have configured for this target
132- RUSTC_BOOTSTRAP=1 cargo build ${mps3_an536_cargo}  --target=armv8r-none-eabihf ||  exit  1
133- if  qemu-system-arm --version |  grep " version \(9\|10\)" ;  then 
134-     #  armv8r-none-eabihf tests
135-     for  bin_path  in  $( ls examples/mps3-an536/src/bin/* .rs) ;  do 
136-         filename=${bin_path##*/ } 
44+ run_tests () {
45+     directory=$1 
46+     target=" $2 " 
47+     flags=$3 
48+     echo  " Running directory=$directory  target=$target  flags=$flags " 
49+     pushd  $directory 
50+     cargo build --target=$target  $flags  ||  exit  1
51+     for  bin_path  in  src/bin/* .rs;  do 
52+         filename=$( basename $bin_path ) 
13753        binary=${filename% .rs} 
138-         RUSTC_BOOTSTRAP=1  cargo run ${mps3_an536_cargo}   --target=armv8r-none-eabihf  --bin $binary  >  ./target/$binary -armv8r-none-eabihf .out
139-         my_diff ./examples/mps3-an536/ reference/$binary -armv8r-none-eabihf .out ./target/$binary -armv8r-none-eabihf .out ||  fail $binary  " armv8r-none-eabihf " 
54+         cargo run --target=$target  --bin $binary  $flags   >  ./target/$binary -$target .out
55+         my_diff ./reference/$binary -$target .out ./target/$binary -$target .out ||  fail $binary  $target 
14056    done 
141-     RUSTC_BOOTSTRAP=1 cargo run ${mps3_an536_cargo}  --target=armv8r-none-eabihf --bin smp_test -- -smp 2 >  ./target/smp_test-armv8r-none-eabihf_smp2.out
142-     my_diff ./examples/mps3-an536/reference/smp_test-armv8r-none-eabihf_smp2.out ./target/smp_test-armv8r-none-eabihf_smp2.out ||  fail smp_test " armv8r-none-eabihf" 
143- fi 
57+     popd 
58+ }
59+ 
60+ run_tests examples/versatileab armv7r-none-eabi " " 
61+ run_tests examples/versatileab armv7r-none-eabihf " " 
62+ run_tests examples/versatileab armv7a-none-eabi " " 
63+ run_tests examples/versatileab armv7a-none-eabihf " " 
64+ RUSTFLAGS=" -Ctarget-feature=+d32"   run_tests examples/versatileab armv7a-none-eabihf " --features=fpu-d32" 
65+ run_tests examples/versatileab armv5te-none-eabi " -Zbuild-std=core" 
66+ run_tests examples/versatileab armv4t-none-eabi " -Zbuild-std=core" 
67+ run_tests examples/versatileab thumbv5te-none-eabi " -Zbuild-std=core" 
68+ run_tests examples/versatileab thumbv4t-none-eabi " -Zbuild-std=core" 
69+ run_tests examples/mps3-an536 armv8r-none-eabihf " " 
70+ RUSTFLAGS=" -Ctarget-cpu=cortex-r52"   run_tests examples/mps3-an536 armv8r-none-eabihf " --features=fpu-d32" 
71+ 
72+ #  Special case the SMP test. You can't run the normal examples with two CPUs because nothing stops the second CPU from running :/
73+ pushd  examples/mps3-an536
74+ cargo run --target=armv8r-none-eabihf --bin smp_test -- --smp 2 >  ./target/smp_test-armv8r-none-eabihf_smp2.out
75+ my_diff ./reference/smp_test-armv8r-none-eabihf_smp2.out ./target/smp_test-armv8r-none-eabihf_smp2.out ||  fail smp_test armv8r-none-eabihf
76+ popd 
14477
14578if  [ " $FAILURE "   ==  " 1"   ];  then 
14679    echo  " ***************************************************" 
0 commit comments