diff --git a/artiq/firmware/ksupport/api.rs b/artiq/firmware/ksupport/api.rs index 435eaef73..a4744dab3 100644 --- a/artiq/firmware/ksupport/api.rs +++ b/artiq/firmware/ksupport/api.rs @@ -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) diff --git a/artiq/firmware/ksupport/eh_artiq.rs b/artiq/firmware/ksupport/eh_artiq.rs index 92806d7b2..68994af0a 100644 --- a/artiq/firmware/ksupport/eh_artiq.rs +++ b/artiq/firmware/ksupport/eh_artiq.rs @@ -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) }; +}