Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed May 5, 2022
1 parent 87d8b04 commit 0b207d0
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cortex-m-rt/examples/divergent-default-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -13,6 +13,6 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) -> ! {
unsafe fn DefaultHandler(_irqn: Vector) -> ! {
loop {}
}
8 changes: 3 additions & 5 deletions cortex-m-rt/examples/override-exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate panic_halt;

use cortex_m::asm;
use rt::{entry, exception, ExceptionFrame};
use cortex_m::{asm, peripheral::scb::Vector};
use cortex_m_rt::{entry, exception, ExceptionFrame};

#[entry]
fn main() -> ! {
loop {}
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {
unsafe fn DefaultHandler(_irqn: Vector) {
asm::bkpt();
}

Expand Down
4 changes: 2 additions & 2 deletions cortex-m-rt/examples/unsafe-default-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -13,4 +13,4 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_irqn: Vector) {}
4 changes: 2 additions & 2 deletions cortex-m-rt/examples/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception, ExceptionFrame};

#[entry]
Expand All @@ -17,7 +17,7 @@ unsafe fn main() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {
unsafe fn DefaultHandler(_irqn: Vector) {
foo();
}

Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
&& f.sig.inputs.len() == 1
&& match &f.sig.inputs[0] {
FnArg::Typed(arg) => match arg.ty.as_ref() {
Type::Path(t) => true,
Type::Path(_) => true,
_ => false,
},
_ => false,
Expand Down
3 changes: 2 additions & 1 deletion cortex-m-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,11 @@ pub use macros::entry;
/// - Setting the default handler
///
/// ```
/// use cortex_m::peripheral::scb::Vector;
/// use cortex_m_rt::exception;
///
/// #[exception]
/// unsafe fn DefaultHandler(irqn: i16) {
/// unsafe fn DefaultHandler(irqn: Vector) {
/// println!("IRQn = {}", irqn);
/// }
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,5 +14,5 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16, undef: u32) {}
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
unsafe fn DefaultHandler(_irqn: Vector, undef: u32) {}
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(Vector) [-> !]`
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,7 +14,7 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) -> u32 {
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
unsafe fn DefaultHandler(_irqn: Vector) -> u32 {
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(Vector) [-> !]`
0
}
6 changes: 4 additions & 2 deletions cortex-m-rt/tests/compile-fail/default-handler-hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m_rt::{entry, exception};
use cortex_m_rt::entry;

#[entry]
fn foo() -> ! {
loop {}
}

mod hidden {
use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::exception;

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_irqn: Vector) {}
}
7 changes: 5 additions & 2 deletions cortex-m-rt/tests/compile-fail/default-handler-twice.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,11 +14,12 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_irqn: Vector) {}

pub mod reachable {
use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::exception;

#[exception] //~ ERROR symbol `DefaultHandler` is already defined
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_irqn: Vector) {}
}
4 changes: 3 additions & 1 deletion cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,7 +14,7 @@ fn foo() -> ! {
}

#[exception]
fn DefaultHandler(_irq: i16) {}
fn DefaultHandler(_irq: Vector) {}
//~^ ERROR defining a `DefaultHandler` is unsafe and requires an `unsafe fn`

#[exception]
Expand Down
4 changes: 3 additions & 1 deletion cortex-m-rt/tests/compile-fail/unsafe-init-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception, interrupt};

#[allow(non_camel_case_types)]
Expand All @@ -29,7 +31,7 @@ fn SVCall() {
}

#[exception]
unsafe fn DefaultHandler(_irq: i16) {
unsafe fn DefaultHandler(_irq: Vector) {
static mut X: u32 = init(); //~ ERROR requires unsafe
}

Expand Down

0 comments on commit 0b207d0

Please sign in to comment.