mirror of https://github.com/m-labs/artiq.git
firmware/ksupport: add exception unittests
This commit is contained in:
parent
d8386f2c2b
commit
de6f83b009
|
@ -167,4 +167,11 @@ static mut API: &'static [(&'static str, *const ())] = &[
|
|||
api!(spi_set_config = ::nrt_bus::spi::set_config),
|
||||
api!(spi_write = ::nrt_bus::spi::write),
|
||||
api!(spi_read = ::nrt_bus::spi::read),
|
||||
|
||||
/*
|
||||
* syscall for unit tests
|
||||
* Used in `artiq.tests.coredevice.test_exceptions.ExceptionTest.test_raise_exceptions_kernel`
|
||||
* `EmbeddingMap` (`artiq.compiler.embedding`) and `EXCEPTION_ID_LOOKUP` (`artiq.firmware.ksupport.eh_artiq`)
|
||||
*/
|
||||
api!(test_exception_id_sync = ::eh_artiq::test_exception_id_sync)
|
||||
];
|
||||
|
|
|
@ -333,7 +333,7 @@ extern fn stop_fn(_version: c_int,
|
|||
}
|
||||
}
|
||||
|
||||
// Must be kept in sync with `artq.compiler.embedding`
|
||||
// Must be kept in sync with `artiq.compiler.embedding`
|
||||
static EXCEPTION_ID_LOOKUP: [(&str, u32); 19] = [
|
||||
("RTIOUnderflow", 0),
|
||||
("RTIOOverflow", 1),
|
||||
|
@ -365,3 +365,25 @@ pub fn get_exception_id(name: &str) -> u32 {
|
|||
unimplemented!("unallocated internal exception id")
|
||||
}
|
||||
|
||||
// Performs a reverse lookup on `EXCEPTION_ID_LOOKUP`
|
||||
// Unconditionally raises an exception given its id
|
||||
#[no_mangle]
|
||||
#[unwind(allowed)]
|
||||
pub extern fn test_exception_id_sync(exn_id: u32) {
|
||||
let message = EXCEPTION_ID_LOOKUP
|
||||
.iter()
|
||||
.find_map(|&(name, id)| if id == exn_id { Some(name) } else { None })
|
||||
.unwrap_or("Unknown exception ID");
|
||||
|
||||
let exn = Exception {
|
||||
id: exn_id,
|
||||
file: file!().as_c_slice(),
|
||||
line: 0,
|
||||
column: 0,
|
||||
function: "test_exception_id_sync".as_c_slice(),
|
||||
message: message.as_c_slice(),
|
||||
param: [0, 0, 0]
|
||||
};
|
||||
unsafe { raise(&exn) };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue