Skip to content

Commit

Permalink
Many updates and clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
sheref-sidarous committed Apr 24, 2024
1 parent 810952e commit 57ed187
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 59 deletions.
3 changes: 1 addition & 2 deletions FreeRTOS-Qemu-Demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ $(OUTPUT_DIR)/$(IMAGE): ./mps2_m3.ld $(OBJS_OUTPUT) Makefile rust-app-lib
-L$(OUTPUT_DIR) -lrust_app \
-Xlinker --gc-sections -Xlinker -T ./mps2_m3.ld \
-Xlinker -Map=$(OUTPUT_DIR)/RTOSDemo_mangled.map -specs=nano.specs \
-Wl,--no-merge-exidx-entries \
-specs=nosys.specs -specs=rdimon.specs -o $(OUTPUT_DIR)/$(IMAGE)
cat $(OUTPUT_DIR)/RTOSDemo_mangled.map | rustfilt > $(OUTPUT_DIR)/RTOSDemo.map
# $(OBJDUMP) -S $(OUTPUT_DIR)/$(IMAGE) | rustfilt > $(OUTPUT_DIR)/RTOSDemo.dsm
Expand All @@ -126,7 +125,7 @@ $(DEP_OUTPUT):
include $(wildcard $(DEP_OUTPUT))

clean:
rm -f $(OUTPUT_DIR)/*
rm -rf $(OUTPUT_DIR)/*


rust-app-lib:
Expand Down
2 changes: 1 addition & 1 deletion rust-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/target
target/
7 changes: 0 additions & 7 deletions rust-app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 1 addition & 17 deletions rust-app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
#![feature(restricted_std)]
#![allow(unused_imports)]

#![allow(dead_code)]
#![feature(once_cell_try)]

use core::ffi::c_char;
use core::ffi::c_int;

use std::thread;
use std::time::Duration;
use std::time::Instant;
use core::fmt::Arguments;

use std::sync::{
atomic::{AtomicBool, Ordering},
mpsc::{channel, Sender},
Arc, Barrier,
OnceLock,
};
use cortex_m_semihosting::debug::{self, EXIT_SUCCESS};

use cortex_m_semihosting::debug::{self, EXIT_SUCCESS, EXIT_FAILURE};

#[allow(non_snake_case)]
#[no_mangle]
Expand Down
1 change: 1 addition & 0 deletions rust-unwind-toolchain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rust/
37 changes: 37 additions & 0 deletions rust-unwind-toolchain/build-unwind-toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/bash
TOOLCHAIN_NAME="local-1.76-unwind"
set -e

if [[ $(rustup toolchain list | grep $TOOLCHAIN_NAME) ]]
then
echo "ERROR: There is already a toolchain linked under the name $TOOLCHAIN_NAME"
echo "Uninstall it via \"rustup uninstall $TOOLCHAIN_NAME\" and retry"
exit 1
fi

# Clone and patch the Rust repo
if [[ -e rust ]]
then
cd rust
if [[ $(git describe)=1.76.0 && -z $(git diff | diff --ignore-all-space ../setup-unwind-for-thumbv7m-target.patch -) ]]
then
echo "Rust repo is already cloned and patched, skipping this step"
else
echo "Unexpected contents in rust subfolder, delete it and retry"
exit 1
fi
else
echo "Cloning and Patching Rust repo"
git clone --depth=1 --branch=1.76.0 https://github.com/rust-lang/rust.git
cd rust
git apply ../setup-unwind-for-thumbv7m-target.patch
fi

# Build the toolchain
echo "Building the toolchain"
./x build --config ../config.toml --target thumbv7m-none-eabi

# link it
rustup toolchain link $TOOLCHAIN_NAME build/host/stage1
echo "The built toolchain is linked as $TOOLCHAIN_NAME, you can now use it for building"
echo "example: cargo +$TOOLCHAIN_NAME build"
2 changes: 2 additions & 0 deletions rust-unwind-toolchain/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
profile = "compiler"
change-id = 118703
20 changes: 20 additions & 0 deletions rust-unwind-toolchain/setup-unwind-for-thumbv7m-target.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/compiler/rustc_target/src/spec/targets/thumbv7m_none_eabi.rs b/compiler/rustc_target/src/spec/targets/thumbv7m_none_eabi.rs
index f9ab3ce1..d6d64081 100644
--- a/compiler/rustc_target/src/spec/targets/thumbv7m_none_eabi.rs
+++ b/compiler/rustc_target/src/spec/targets/thumbv7m_none_eabi.rs
@@ -1,6 +1,6 @@
// Targets the Cortex-M3 processor (ARMv7-M)

-use crate::spec::{base, Target, TargetOptions};
+use crate::spec::{base, Target, TargetOptions, PanicStrategy};

pub fn target() -> Target {
Target {
@@ -12,6 +12,7 @@ pub fn target() -> Target {
options: TargetOptions {
abi: "eabi".into(),
max_atomic_width: Some(32),
+ panic_strategy: PanicStrategy::Unwind,
..base::thumb::opts()
},
}
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
assets/
__pycache__/
report.*
2 changes: 2 additions & 0 deletions tests/rust/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "thumbv7m-none-eabi"
7 changes: 0 additions & 7 deletions tests/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions tests/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#![feature(restricted_std)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![feature(once_cell_try)]

use std::thread;


use cortex_m_semihosting::debug::{self, EXIT_SUCCESS, EXIT_FAILURE};

mod sync_tests;
mod std_tests;

mod test_function;

#[allow(non_snake_case)]
Expand Down
60 changes: 40 additions & 20 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def prepend_mod_path(mod_path, fn_list) :
"std_tests::sync::mpsc::oneshot_single_thread_close_port_first",
"std_tests::sync::mpsc::oneshot_single_thread_close_chan_first",
"std_tests::sync::mpsc::oneshot_single_thread_send_port_close",
# "std_tests::sync::mpsc::oneshot_single_thread_recv_chan_close", needs panic unwind
"std_tests::sync::mpsc::oneshot_single_thread_send_then_recv",
"std_tests::sync::mpsc::oneshot_single_thread_try_send_open",
"std_tests::sync::mpsc::oneshot_single_thread_try_send_closed",
Expand All @@ -53,9 +52,7 @@ def prepend_mod_path(mod_path, fn_list) :
"std_tests::sync::mpsc::oneshot_single_thread_peek_close",
"std_tests::sync::mpsc::oneshot_single_thread_peek_open",
"std_tests::sync::mpsc::oneshot_multi_task_recv_then_send",
# "std_tests::sync::mpsc::oneshot_multi_task_recv_then_close", needs panic unwind
"std_tests::sync::mpsc::oneshot_multi_thread_close_stress",
#"std_tests::sync::mpsc::oneshot_multi_thread_send_close_stress", needs panic unwind
"std_tests::sync::mpsc::oneshot_multi_thread_recv_close_stress",
"std_tests::sync::mpsc::oneshot_multi_thread_send_recv_stress",
"std_tests::sync::mpsc::stream_send_recv_stress",
Expand All @@ -78,24 +75,34 @@ def prepend_mod_path(mod_path, fn_list) :
"std_tests::sync::mpsc::issue_39364",
]

mutex_tests = [ "std_tests::sync::mutex::" + fn_name for fn_name in [
# Those tests need panic unwind support to pass
mpsc_tests_panics = [
"std_tests::sync::mpsc::oneshot_single_thread_recv_chan_close",
"std_tests::sync::mpsc::oneshot_multi_task_recv_then_close",
"std_tests::sync::mpsc::oneshot_multi_thread_send_close_stress",
]

mutex_tests = prepend_mod_path("std_tests::sync::mutex", [
"smoke",
"lots_and_lots",
"try_lock",
"test_case_into_inner",
"test_case_into_inner_drop",
# "test_case_into_inner_poison", needs panic unwind
"test_case_get_mut",
#"test_case_get_mut_poison", needs panic unwind
"test_case_mutex_arc_condvar",
#"test_case_arc_condvar_poison", needs panic unwind
#"test_case_mutex_arc_poison", needs panic unwind
"test_case_mutex_arc_nested",
#"test_case_mutex_arc_access_in_unwind", needs panic unwind
"test_case_mutex_unsized",
]]
])

mutex_tests_panics = prepend_mod_path("std_tests::sync::mutex", [
"test_case_into_inner_poison",
"test_case_get_mut_poison",
"test_case_arc_condvar_poison",
"test_case_mutex_arc_poison",
"test_case_mutex_arc_access_in_unwind",
])

once_lock_tests = [ "std_tests::sync::once_lock::" + fn_name for fn_name in [
once_lock_tests = prepend_mod_path("std_tests::sync::once_lock", [
"sync_once_cell",
"sync_once_cell_get_mut",
# "sync_once_cell_get_unchecked", relies on internal API
Expand All @@ -110,14 +117,14 @@ def prepend_mod_path(mod_path, fn_list) :
"eval_once_macro",
"sync_once_cell_does_not_leak_partially_constructed_boxes",
"dropck",
]]
])

once_tests = [ "std_tests::sync::once::" + fn_name for fn_name in [
once_tests = prepend_mod_path("std_tests::sync::once", [
"smoke_once",
"stampede_once",
"poison_bad",
"wait_for_force_to_finish",
]]
])

remutex_tests = prepend_mod_path("std_tests::sync::remutex", [
"smoke",
Expand Down Expand Up @@ -151,18 +158,13 @@ def prepend_mod_path(mod_path, fn_list) :
#"test_invalid_named_thread", [should_panic] is not supported yet
"test_run_basic",
"test_is_finished",
#"test_join_panic", Needs panic unwind support
"test_spawn_sched",
"test_spawn_sched_childs_on_default_sched",
"test_avoid_copying_the_body_spawn",
"test_avoid_copying_the_body_thread_spawn",
"test_avoid_copying_the_body_join",
"test_child_doesnt_ref_parent",
"test_simple_newsched_spawn",
#"test_try_panic_message_string_literal", Needs panic unwind support
#"test_try_panic_any_message_owned_str", Needs panic unwind support
#"test_try_panic_any_message_any", Needs panic unwind support
#"test_try_panic_any_message_unit_struct", Needs panic unwind support
"test_park_unpark_before",
"test_park_unpark_called_other_thread",
"test_park_timeout_unpark_before",
Expand All @@ -177,6 +179,14 @@ def prepend_mod_path(mod_path, fn_list) :
# "scope_join_race", miri specific
])

thread_tests_panics = prepend_mod_path( "std_tests::thread", [
"test_join_panic", # Needs panic unwind support
"test_try_panic_message_string_literal", #Needs panic unwind support
"test_try_panic_any_message_owned_str", #Needs panic unwind support
"test_try_panic_any_message_any", #Needs panic unwind support
"test_try_panic_any_message_unit_struct", #Needs panic unwind support
])

extra_sync_tests = prepend_mod_path("sync_tests", [
"test_join",
"test_sleep",
Expand All @@ -190,7 +200,17 @@ def prepend_mod_path(mod_path, fn_list) :
"run_all_tests",
])

all_tests = barrier_tests + condvar_tests + mpsc_tests + mutex_tests + once_lock_tests + extra_sync_tests + thread_tests #+ remutex_tests + rwlock_tests
panics_tests = mpsc_tests_panics + mutex_tests_panics + thread_tests_panics
all_tests = barrier_tests \
+ condvar_tests \
+ mpsc_tests \
+ mutex_tests \
+ once_lock_tests \
+ extra_sync_tests \
+ thread_tests
# + panics_tests
# + remutex_tests
# + rwlock_tests

@pytest.mark.parametrize("test_function", all_tests)
def test_function(test_function):
Expand Down

0 comments on commit 57ed187

Please sign in to comment.