1
0
Fork 0

firmware: add unit tests for exception sync

This commit is contained in:
abdul124 2024-08-21 17:18:31 +08:00
parent c0ab42d52d
commit a7dbfe506e
2 changed files with 34 additions and 3 deletions

View File

@ -13,7 +13,7 @@
#![allow(non_camel_case_types)]
use core::mem;
use cslice::CSlice;
use cslice::{AsCSlice, CSlice};
use unwind as uw;
use libc::{c_int, c_void, uintptr_t};
use log::{trace, error};
@ -218,8 +218,6 @@ pub unsafe fn artiq_personality(_state: uw::_Unwind_State,
}
pub unsafe extern fn raise(exception: *const Exception) -> ! {
use cslice::AsCSlice;
let count = EXCEPTION_BUFFER.exception_count;
let stack = &mut EXCEPTION_BUFFER.exception_stack;
let diff = exception as isize - EXCEPTION_BUFFER.exceptions.as_ptr() as isize;
@ -461,3 +459,29 @@ macro_rules! artiq_raise {
artiq_raise!($name, $message, 0, 0, 0)
});
}
/// 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" 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) };
}

View File

@ -280,6 +280,13 @@ pub fn resolve(required: &[u8]) -> Option<u32> {
}
api!(yn = yn)
},
/*
* 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.language.embedding`)
* match the `EXCEPTION_ID_LOOKUP` defined in the firmware (`libksupport::src::eh_artiq`)
*/
api!(test_exception_id_sync = eh_artiq::test_exception_id_sync)
];
api.iter()
.find(|&&(exported, _)| exported.as_bytes() == required)