From 8d2b2ee5c2ea2e7de7bb14aeaae2c6f3b75a0305 Mon Sep 17 00:00:00 2001 From: Hideki Sekine Date: Tue, 16 Oct 2018 20:56:02 +0900 Subject: [PATCH] [ci] run-make/thumb-none-qemu: add example crate. --- src/test/run-make/thumb-none-qemu/Makefile | 12 +++++++- .../thumb-none-qemu/example/Cargo.toml | 11 +++++++ .../run-make/thumb-none-qemu/example/memory.x | 23 ++++++++++++++ .../thumb-none-qemu/example/src/main.rs | 30 +++++++++++++++++++ src/test/run-make/thumb-none-qemu/script.sh | 11 +++---- 5 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 src/test/run-make/thumb-none-qemu/example/Cargo.toml create mode 100644 src/test/run-make/thumb-none-qemu/example/memory.x create mode 100644 src/test/run-make/thumb-none-qemu/example/src/main.rs diff --git a/src/test/run-make/thumb-none-qemu/Makefile b/src/test/run-make/thumb-none-qemu/Makefile index bf57bc5b3110..75c17372bc23 100644 --- a/src/test/run-make/thumb-none-qemu/Makefile +++ b/src/test/run-make/thumb-none-qemu/Makefile @@ -8,11 +8,21 @@ ifneq (,$(filter $(TARGET),thumbv6m-none-eabi thumbv7m-none-eabi)) # For cargo setting export RUSTC := $(RUSTC_ORIGINAL) -LD_LIBRARY_PATH := $(HOST_RPATH_DIR) +export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) # We need to be outside of 'src' dir in order to run cargo export WORK_DIR := $(TMPDIR) export HERE := $(shell pwd) +## clean up unused env variables which might cause harm. +# unexport RUSTC_LINKER +# unexport RUSTC_BOOTSTRAP +# unexport RUST_BUILD_STAGE +# unexport RUST_TEST_THREADS +# unexport RUST_TEST_TMPDIR +# unexport AR +# unexport CC +# unexport CXX + all: bash script.sh else diff --git a/src/test/run-make/thumb-none-qemu/example/Cargo.toml b/src/test/run-make/thumb-none-qemu/example/Cargo.toml new file mode 100644 index 000000000000..499553304c68 --- /dev/null +++ b/src/test/run-make/thumb-none-qemu/example/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "example" +version = "0.1.0" +authors = ["Hideki Sekine "] +# edition = "2018" + +[dependencies] +cortex-m = "0.5.4" +cortex-m-rt = "=0.5.4" +panic-halt = "0.2.0" +cortex-m-semihosting = "0.3.1" diff --git a/src/test/run-make/thumb-none-qemu/example/memory.x b/src/test/run-make/thumb-none-qemu/example/memory.x new file mode 100644 index 000000000000..dc7ad967a42a --- /dev/null +++ b/src/test/run-make/thumb-none-qemu/example/memory.x @@ -0,0 +1,23 @@ +/* Device specific memory layout */ + +/* This file is used to build the cortex-m-rt examples, + but not other applications using cortex-m-rt. */ + +MEMORY +{ + /* FLASH and RAM are mandatory memory regions */ + /* Update examples/data_overflow.rs if you change these sizes. */ + FLASH : ORIGIN = 0x00000000, LENGTH = 256K + RAM : ORIGIN = 0x20000000, LENGTH = 64K + + /* More memory regions can declared: for example this is a second RAM region */ + /* CCRAM : ORIGIN = 0x10000000, LENGTH = 8K */ +} + +/* The location of the stack can be overridden using the `_stack_start` symbol. + By default it will be placed at the end of the RAM region */ +/* _stack_start = ORIGIN(CCRAM) + LENGTH(CCRAM); */ + +/* The location of the .text section can be overridden using the `_stext` symbol. + By default it will place after .vector_table */ +/* _stext = ORIGIN(FLASH) + 0x40c; */ \ No newline at end of file diff --git a/src/test/run-make/thumb-none-qemu/example/src/main.rs b/src/test/run-make/thumb-none-qemu/example/src/main.rs new file mode 100644 index 000000000000..e94aa74de588 --- /dev/null +++ b/src/test/run-make/thumb-none-qemu/example/src/main.rs @@ -0,0 +1,30 @@ +// #![feature(stdsimd)] +#![no_main] +#![no_std] + +extern crate cortex_m; + +extern crate cortex_m_rt as rt; +extern crate cortex_m_semihosting as semihosting; +extern crate panic_halt; + +use core::fmt::Write; +use cortex_m::asm; +use rt::entry; + +entry!(main); + +fn main() -> ! { + let x = 42; + + loop { + asm::nop(); + + // write something through semihosting interface + let mut hstdout = semihosting::hio::hstdout().unwrap(); + write!(hstdout, "x = {}\n", x); + + // exit from qemu + semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS); + } +} \ No newline at end of file diff --git a/src/test/run-make/thumb-none-qemu/script.sh b/src/test/run-make/thumb-none-qemu/script.sh index 022f1cef6319..5c46c4bd26dc 100644 --- a/src/test/run-make/thumb-none-qemu/script.sh +++ b/src/test/run-make/thumb-none-qemu/script.sh @@ -1,16 +1,13 @@ set -exuo pipefail -CRATE=cortex-m-rt -CRATE_URL=https://github.com/rust-embedded/cortex-m-rt -CRATE_SHA1=62972c8a89ff54b76f9ef0d600c1fcf7a233aabd +CRATE=example env | sort mkdir -p $WORK_DIR pushd $WORK_DIR rm -rf $CRATE || echo OK - bash -x $HERE/../git_clone_sha1.sh $CRATE $CRATE_URL $CRATE_SHA1 + cp -a $HERE/example . pushd $CRATE - $CARGO run --target $TARGET --example qemu | grep "x = 42" - $CARGO run --target $TARGET --example qemu --release | grep "x = 42" + $CARGO run --target $TARGET popd -popd \ No newline at end of file +popd