fixed llmp test, moved to xxh3 const

This commit is contained in:
Dominik Maier 2020-11-27 21:54:01 +01:00
parent 91ab778f9e
commit 634cdcf217
6 changed files with 27 additions and 29 deletions

View File

@ -17,7 +17,7 @@ std = []
hashbrown = { version = "0.9", features = ["serde"] } # A faster hashmap, nostd compatible
libc = "0.2" # For (*nix) libc
num = "*"
xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust
xxhash-rust = { version = "0.8.0-beta.5", features = ["const_xxh3"] } # xxh3 hashing for rust
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
typetag = "0.1"
postcard = "0.5.1" # no_std compatible serde serialization fromat

View File

@ -80,7 +80,7 @@ unsafe fn test_adder_clientloop(client: *mut llmp_client, _data: *mut c_void) ->
}
unsafe fn broker_message_hook(
_broker: *mut llmp_broker,
_broker: *mut LlmpBroker,
client_metadata: *mut llmp_broker_client_metadata,
message: *mut llmp_message,
_data: *mut c_void,
@ -118,33 +118,18 @@ fn main() {
counter_thread_count
);
let mut broker = llmp_broker {
last_msg_sent: ptr::null_mut(),
broadcast_map_count: 0,
broadcast_maps: ptr::null_mut(),
msg_hook_count: 0,
msg_hooks: ptr::null_mut(),
llmp_client_count: 0,
llmp_clients: ptr::null_mut(),
};
unsafe {
llmp_broker_init(&mut broker).expect("Could not init");
let mut broker = LlmpBroker::new().expect("Failed to create llmp broker");
for i in 0..counter_thread_count {
println!("Adding client {}", i);
broker.register_childprocess_clientloop(
llmp_test_clientloop,
ptr::null_mut(),
)
.expect("could not add child clientloop");
broker
.register_childprocess_clientloop(llmp_test_clientloop, ptr::null_mut())
.expect("could not add child clientloop");
}
broker.register_childprocess_clientloop(
test_adder_clientloop,
ptr::null_mut(),
)
.expect("Error registering childprocess");
broker
.register_childprocess_clientloop(test_adder_clientloop, ptr::null_mut())
.expect("Error registering childprocess");
println!("Spawning broker");

View File

@ -1,7 +1,7 @@
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use core::any::{Any, TypeId};
use core::any::Any;
use core::cell::RefCell;
use core::convert::Into;
use core::default::Default;

View File

@ -160,7 +160,7 @@ const LLMP_CLIENT_TYPE_CHILD_PROCESS: LlmpClientType = 2;
/// A share mem page, as used by llmp internally
#[derive(Copy, Clone)]
#[repr(C, packed)]
struct llmp_page {
pub struct llmp_page {
pub sender: u32,
pub save_to_unmap: c_ushort,
pub sender_dead: c_ushort,
@ -342,7 +342,7 @@ unsafe fn llmp_recv(page: *mut llmp_page, last_msg: *mut llmp_message) -> *mut l
}
/* Blocks/spins until the next message gets posted to the page,
then returns that message. */
unsafe fn llmp_recv_blocking(
pub unsafe fn llmp_recv_blocking(
page: *mut llmp_page,
last_msg: *mut llmp_message,
) -> *mut llmp_message {

View File

@ -19,6 +19,7 @@ use alloc::string::String;
use core::fmt;
#[cfg(feature = "std")]
use std::io;
use xxhash_rust::const_xxh3::xxh3_64_with_seed;
/// Main error struct for AFL
#[derive(Debug)]
@ -78,3 +79,8 @@ mod tests {
assert_eq!(2 + 2, 4);
}
}
#[no_mangle]
pub extern "C" fn test_xxh3_hash() -> u64 {
xxh3_64_with_seed(b"test", 0)
}

View File

@ -4,12 +4,12 @@ use alloc::rc::Rc;
use core::cell::RefCell;
use core::debug_assert;
use core::fmt::Debug;
use xxhash_rust::xxh3::xxh3_64_with_seed;
use xxhash_rust::const_xxh3::xxh3_64_with_seed;
#[cfg(feature = "std")]
use std::time::{SystemTime, UNIX_EPOCH};
pub type StdRand = XorShift64Rand;
pub type StdRand = Xoshiro256StarRand;
/// Ways to get random around here
pub trait Rand: Debug {
@ -303,6 +303,8 @@ pub const fn next_pow2(val: u64) -> u64 {
#[cfg(test)]
mod tests {
use xxhash_rust::const_xxh3::xxh3_64_with_seed;
use crate::utils::{next_pow2, Rand, StdRand};
#[test]
@ -337,4 +339,9 @@ mod tests {
assert_eq!(next_pow2(1000), 1024);
assert_eq!(next_pow2(0xFFFFFFFF as u64), (0xFFFFFFFF as u64) + 1);
}
#[test]
fn test_xxh3_hash() {
assert_eq!(xxh3_64_with_seed(b"test", 0), 0);
}
}