Skip to content

Commit

Permalink
CI: fix data_overflow test
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
newAM committed Jun 30, 2024
1 parent 2fe5473 commit 7424ccb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cortex-m-rt/ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ main() {
cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" --release -- $linker
done
for ex in "${fail_examples[@]}"; do
! cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" -- $linker
! cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" --release -- $linker
cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" -- $linker && exit 1
cargo rustc --target "$TARGET" --example "$ex" --features "${needed_features}" --release -- $linker && exit 1
done
cargo rustc --target "$TARGET" --example device --features "device,${needed_features}" -- $linker
cargo rustc --target "$TARGET" --example device --features "device,${needed_features}" --release -- $linker
Expand Down
11 changes: 6 additions & 5 deletions cortex-m-rt/examples/data_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ extern crate cortex_m_rt as rt;
extern crate panic_halt;

use core::ptr;

use rt::entry;

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

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

#[entry]
fn main() -> ! {
unsafe {
let _bigdata = ptr::read_volatile(ptr::addr_of!(RODATA));
let _bigdata = ptr::read_volatile(ptr::addr_of!(DATA));
let _bigdata: u8 = ptr::read_volatile(ptr::addr_of!(RODATA) as *const u8);
let _bigdata: u8 = ptr::read_volatile(ptr::addr_of!(DATA) as *const u8);
}

loop {}
Expand Down

0 comments on commit 7424ccb

Please sign in to comment.