example of test and calling C from rust
This commit is contained in:
parent
2675aa13c9
commit
3359073498
@ -1,15 +1,28 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
|
||||||
|
|
||||||
/// This function is called on panic.
|
/// This function is called on panic.
|
||||||
|
#[cfg(not(test))]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(_info: &PanicInfo) -> ! {
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn get_rust_u8() -> u8 {
|
pub extern "C" fn get_rust_u8() -> u8 {
|
||||||
9
|
//9
|
||||||
}
|
unsafe { get_c_u8() }
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn get_c_u8() -> u8;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(get_rust_u8(), 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -58,6 +58,10 @@
|
|||||||
|
|
||||||
#define MAX_LIST 20
|
#define MAX_LIST 20
|
||||||
|
|
||||||
|
uint8_t get_c_u8(void) {
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
|
||||||
struct glyph
|
struct glyph
|
||||||
{
|
{
|
||||||
int xoff;
|
int xoff;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user