mirror of https://github.com/m-labs/artiq.git
firmware: sync exception ids and names
This commit is contained in:
parent
8c6a41eb39
commit
f913e2740f
|
@ -177,7 +177,7 @@ static mut API: &'static [(&'static str, *const ())] = &[
|
|||
/*
|
||||
* syscall for unit tests
|
||||
* Used in `artiq.tests.coredevice.test_exceptions.ExceptionTest.test_raise_exceptions_kernel`
|
||||
* This syscall checks that the exception IDs used in the Python `EmbeddingMap` (in `artiq.compiler.embedding`)
|
||||
* This syscall checks that the exception IDs used in the Python `EmbeddingMap` (in `artiq.language.embedding_map`)
|
||||
* match the `EXCEPTION_ID_LOOKUP` defined in the firmware (`artiq::firmware::ksupport::eh_artiq`)
|
||||
*/
|
||||
api!(test_exception_id_sync = ::eh_artiq::test_exception_id_sync)
|
||||
|
|
|
@ -328,7 +328,7 @@ extern fn stop_fn(_version: c_int,
|
|||
}
|
||||
}
|
||||
|
||||
// Must be kept in sync with `artiq.compiler.embedding`
|
||||
// Must be kept in sync with `artiq.language.embedding_map`
|
||||
static EXCEPTION_ID_LOOKUP: [(&str, u32); 22] = [
|
||||
("RTIOUnderflow", 0),
|
||||
("RTIOOverflow", 1),
|
||||
|
@ -389,3 +389,28 @@ pub extern "C-unwind" fn test_exception_id_sync(exn_id: u32) {
|
|||
unsafe { raise(&exn) };
|
||||
}
|
||||
|
||||
/// Takes as input exception id from host
|
||||
/// Generates a new exception with:
|
||||
/// * `id` set to `exn_id`
|
||||
/// * `message` set to corresponding exception name from `EXCEPTION_ID_LOOKUP`
|
||||
///
|
||||
/// The message is matched on host to ensure correct exception is being referred
|
||||
/// This test checks the synchronization of exception ids for runtime errors
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" 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("unallocated internal 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