Skip to content

Commit 192e2f7

Browse files
committed
CI: fix data_overflow test
Long story: * This test was introduced * `ci/script.sh` did not correctly check for failures, [SC2251] * Thanks rust-embedded#404 for the tip! * The FLASH size was increased, and the test incorrectly passed, but nobody noticed. * I modified the test in rust-embedded#505 which made it fail again, but for the wrong reason. `ptr::read_volatile(ptr::addr_of!(RODATA))` reads the entire array, which is not equivalent to the original code `ptr::read_volatile(&RODATA as *const u8)` which read a single element of the array. * The test now failed, but the stack related overflow takes rustc a LONG time to compile, and pushed our CI times to >30m. These changes fix ci/scripts.sh to exit with a non-zero code if data_overflow is passing, and makes data_overflow fail to compile for the original reason, updating RODATA to reflect the increased FLASH size. [SC2251]: https://www.shellcheck.net/wiki/SC2251
1 parent 2fe5473 commit 192e2f7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

cortex-m-rt/ci/script.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ main() {
5555
cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" --release -- $linker
5656
done
5757
for ex in "${fail_examples[@]}"; do
58-
! cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" -- $linker
59-
! cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" --release -- $linker
58+
cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" -- $linker && exit 1
59+
cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" --release -- $linker && exit 1
6060
done
6161
cargo rustc --target "$TARGET" --example device --features "device,${needed_features}" -- $linker
6262
cargo rustc --target "$TARGET" --example device --features "device,${needed_features}" --release -- $linker

cortex-m-rt/examples/data_overflow.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ extern crate cortex_m_rt as rt;
99
extern crate panic_halt;
1010

1111
use core::ptr;
12-
1312
use rt::entry;
1413

1514
// This large static array uses most of .rodata
16-
static RODATA: [u8; 48 * 1024] = [1u8; 48 * 1024];
15+
const RODATA_SIZE: usize = 250 * 1024;
16+
static RODATA: [u8; RODATA_SIZE] = [1u8; RODATA_SIZE];
1717

1818
// This large mutable array causes .data to use the rest of FLASH
1919
// without also overflowing RAM.
20-
static mut DATA: [u8; 16 * 1024] = [1u8; 16 * 1024];
20+
const DATA_SIZE: usize = 8 * 1024;
21+
static mut DATA: [u8; DATA_SIZE] = [1u8; DATA_SIZE];
2122

2223
#[entry]
2324
fn main() -> ! {
2425
unsafe {
25-
let _bigdata = ptr::read_volatile(ptr::addr_of!(RODATA));
26-
let _bigdata = ptr::read_volatile(ptr::addr_of!(DATA));
26+
let _bigdata: u8 = ptr::read_volatile(ptr::addr_of!(RODATA) as *const u8);
27+
let _bigdata: u8 = ptr::read_volatile(ptr::addr_of!(DATA) as *const u8);
2728
}
2829

2930
loop {}

0 commit comments

Comments
 (0)