forked from M-Labs/artiq
1
0
Fork 0

firmware: sync exception ids and names

This commit is contained in:
abdul124 2024-08-30 14:21:55 +08:00 committed by Sébastien Bourdeauducq
parent 8c6a41eb39
commit f913e2740f
2 changed files with 27 additions and 2 deletions

View File

@ -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)

View File

@ -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) };
}