Add a uniq test module for yunq in rust.
This commit is contained in:
parent
c1db6cb11f
commit
4ee8dc924c
|
@ -1,13 +1,9 @@
|
||||||
package ex;
|
package ex;
|
||||||
|
|
||||||
message Basic {
|
message Basic {
|
||||||
u64 field;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Types {
|
|
||||||
u64 unsigned_int;
|
u64 unsigned_int;
|
||||||
i64 signed_int;
|
i64 signed_int;
|
||||||
string str;
|
string strn;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Cap {
|
message Cap {
|
||||||
|
|
|
@ -4,3 +4,6 @@ build-std = ["core", "compiler_builtins", "alloc"]
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
target = "x86_64-acadia-os.json"
|
target = "x86_64-acadia-os.json"
|
||||||
|
|
||||||
|
[alias]
|
||||||
|
test_pc = "test --target=x86_64-unknown-linux-gnu -Z build-std=std --lib"
|
||||||
|
|
|
@ -210,6 +210,16 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yunq-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"mammoth",
|
||||||
|
"yunq",
|
||||||
|
"yunq-derive",
|
||||||
|
"yunqc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yunqc"
|
name = "yunqc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
members = [ "lib/denali",
|
members = [ "lib/denali",
|
||||||
"lib/mammoth", "lib/victoriafalls", "lib/voyageurs", "lib/yellowstone", "lib/yunq", "lib/yunq-derive", "sys/teton", "sys/yellowstone", "usr/testbed",
|
"lib/mammoth", "lib/victoriafalls", "lib/voyageurs", "lib/yellowstone", "lib/yunq", "lib/yunq-derive", "lib/yunq-test", "sys/teton", "sys/yellowstone", "usr/testbed",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
|
|
|
@ -9,4 +9,6 @@ name = "mammoth"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
linked_list_allocator = "0.10.5"
|
linked_list_allocator = "0.10.5"
|
||||||
|
|
||||||
[build-dependencies]
|
[features]
|
||||||
|
hosted = []
|
||||||
|
default = ["hosted"]
|
||||||
|
|
|
@ -2,13 +2,17 @@ use crate::cap::Capability;
|
||||||
use crate::syscall;
|
use crate::syscall;
|
||||||
use crate::zion::ZError;
|
use crate::zion::ZError;
|
||||||
use alloc::slice;
|
use alloc::slice;
|
||||||
|
|
||||||
|
#[cfg(feature = "hosted")]
|
||||||
use linked_list_allocator::LockedHeap;
|
use linked_list_allocator::LockedHeap;
|
||||||
|
|
||||||
|
#[cfg(feature = "hosted")]
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||||
|
|
||||||
pub static mut CAN_ALLOC: bool = false;
|
pub static mut CAN_ALLOC: bool = false;
|
||||||
|
|
||||||
|
#[cfg(feature = "hosted")]
|
||||||
pub fn init_heap() {
|
pub fn init_heap() {
|
||||||
// 1 MiB
|
// 1 MiB
|
||||||
let size = 0x10_0000;
|
let size = 0x10_0000;
|
||||||
|
|
|
@ -5,6 +5,8 @@ use crate::zion;
|
||||||
use crate::zion::z_cap_t;
|
use crate::zion::z_cap_t;
|
||||||
use crate::zion::ZError;
|
use crate::zion::ZError;
|
||||||
use core::ffi::c_void;
|
use core::ffi::c_void;
|
||||||
|
|
||||||
|
#[cfg(feature = "hosted")]
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
@ -18,6 +20,7 @@ fn syscall<T>(id: u64, req: &T) -> Result<(), ZError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "hosted")]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -29,7 +29,13 @@ fn serialize_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenS
|
||||||
} else if path.is_ident("u64") {
|
} else if path.is_ident("u64") {
|
||||||
quote! {
|
quote! {
|
||||||
{
|
{
|
||||||
buf.write_at(yunq::message::field_offset(offset, #ind), self.#name as u64)?;
|
buf.write_at(yunq::message::field_offset(offset, #ind), self.#name)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if path.is_ident("i64") {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
buf.write_at(yunq::message::field_offset(offset, #ind), self.#name)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,6 +73,10 @@ fn parse_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenStrea
|
||||||
quote! {
|
quote! {
|
||||||
let #name = buf.at::<u64>(yunq::message::field_offset(offset, #ind))?;
|
let #name = buf.at::<u64>(yunq::message::field_offset(offset, #ind))?;
|
||||||
}
|
}
|
||||||
|
} else if path.is_ident("i64") {
|
||||||
|
quote! {
|
||||||
|
let #name = buf.at::<i64>(yunq::message::field_offset(offset, #ind))?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
let #name = {
|
let #name = {
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
[package]
|
||||||
|
name = "yunq-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mammoth = { path = "../mammoth", default-features = false}
|
||||||
|
yunq = {path = "../yunq", default-features = false}
|
||||||
|
yunq-derive = {path = "../yunq-derive"}
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
yunqc = {path = "../../../yunq/rust"}
|
||||||
|
|
||||||
|
[dev-dependencies]
|
|
@ -0,0 +1,14 @@
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input_file = "../../../lib/yunq/test/example/example.yunq";
|
||||||
|
|
||||||
|
println!("cargo::rerun-if-changed={input_file}");
|
||||||
|
|
||||||
|
let input = fs::read_to_string(input_file).expect("Failed to read input file");
|
||||||
|
|
||||||
|
let code = yunqc::codegen(&input).expect("Failed to generate yunq code.");
|
||||||
|
|
||||||
|
let out = std::env::var("OUT_DIR").unwrap() + "/yunq.rs";
|
||||||
|
fs::write(out, code).expect("Failed to write generated code.");
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
extern crate std;
|
||||||
|
use std::vec;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn basic_serialization() -> Result<(), ZError> {
|
||||||
|
let basic = Basic { unsigned_int: 82, signed_int: -1234, strn: "abc".to_string() };
|
||||||
|
|
||||||
|
let mut buf = ByteBuffer::<1024>::new();
|
||||||
|
let mut caps = Vec::new();
|
||||||
|
basic.serialize(&mut buf, 0, &mut caps)?;
|
||||||
|
|
||||||
|
let parsed = Basic::parse(&buf, 0, &caps)?;
|
||||||
|
|
||||||
|
assert!(parsed == basic);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn basic_serialization_as_request() -> Result<(), ZError> {
|
||||||
|
let basic = Basic { unsigned_int: 82, signed_int: -1234, strn: "abc".to_string() };
|
||||||
|
|
||||||
|
let mut buf = ByteBuffer::<1024>::new();
|
||||||
|
let mut caps = Vec::new();
|
||||||
|
let req_id = 12;
|
||||||
|
basic.serialize_as_request(req_id, &mut buf, &mut caps)?;
|
||||||
|
|
||||||
|
assert!(buf.at::<u64>(8)? == req_id);
|
||||||
|
|
||||||
|
let parsed = Basic::parse_from_request(&buf, &caps)?;
|
||||||
|
|
||||||
|
assert!(parsed == basic);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn capability_serialization() -> Result<(), ZError> {
|
||||||
|
let cap_id = 100;
|
||||||
|
let cap = Cap { cap: cap_id };
|
||||||
|
|
||||||
|
let mut buf = ByteBuffer::<1024>::new();
|
||||||
|
let mut caps = Vec::new();
|
||||||
|
cap.serialize(&mut buf, 0, &mut caps)?;
|
||||||
|
|
||||||
|
assert!(caps.len() == 1);
|
||||||
|
assert!(caps[0] == cap_id);
|
||||||
|
|
||||||
|
let parsed = Cap::parse(&buf, 0, &caps)?;
|
||||||
|
|
||||||
|
assert!(parsed == cap);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,5 +4,9 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mammoth = {path = "../mammoth"}
|
mammoth = {path = "../mammoth", default-features = false}
|
||||||
yunq-derive = {path = "../yunq-derive"}
|
yunq-derive = {path = "../yunq-derive"}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["hosted"]
|
||||||
|
hosted = ["mammoth/hosted"]
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn generate_message(message: &Message) -> TokenStream {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| Ident::new(f.field_type.rust_type(), Span::call_site()));
|
.map(|f| Ident::new(f.field_type.rust_type(), Span::call_site()));
|
||||||
quote! {
|
quote! {
|
||||||
#[derive(YunqMessage)]
|
#[derive(YunqMessage, PartialEq, Eq)]
|
||||||
pub struct #name {
|
pub struct #name {
|
||||||
#(pub #field_names: #field_types),*
|
#(pub #field_names: #field_types),*
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue