}
}
+struct Pipe {
+ pipe_fd: [i32; 2],
+}
+
+impl Pipe {
+ fn new() -> Pipe {
+ let mut pipe_fd = [-1i32; 2];
+
+ unsafe {
+ extern {
+ fn pipe(pipefd: *mut i32) -> i32;
+ }
+
+ pipe(pipe_fd.as_mut_ptr());
+ }
+
+ Pipe {
+ pipe_fd: pipe_fd,
+ }
+ }
+
+ fn read_fd(&self) -> i32 {
+ self.pipe_fd[0]
+ }
+
+ fn write_fd(&self) -> i32 {
+ self.pipe_fd[1]
+ }
+}
+
// Runs a couple of recordings on fully erased flash memory.
#[test]
fn first_recording() {
buf: *const u8,
_bufsiz: usize,
count: usize) -> isize {
- let _final_buffer = user_data as *mut [u8; 8192];
- let final_buffer = unsafe { &mut * _final_buffer };
+ let _file = user_data as *mut std::fs::File;
unsafe {
- core::ptr::copy_nonoverlapping(buf, final_buffer.as_mut_ptr(), count);
+ let file = &mut * _file;
+
+ file.write_all(std::slice::from_raw_parts(buf, count)).unwrap();
}
count as isize
// Verifies that Logger::get_recording() detects unknown recording IDs.
#[test]
fn get_recording_invalid() {
- let mut final_buffer = [0u8; 8192];
+ let pipe = Pipe::new();
+
+ let mut file = unsafe { std::fs::File::from_raw_fd(pipe.write_fd()) };
let mut yenc_buffer_space = [0u8; 8192];
let mut yenc_buffer = Buffer::alloc();
- let user_data = (&mut final_buffer as *mut [u8; 8192]) as *mut BufferUserData;
+ let user_data = (&mut file as *mut std::fs::File) as *mut BufferUserData;
yenc_buffer.init(yenc_buffer_space.as_mut_ptr(),
yenc_buffer_space.len(),
flush_write_buffer,
user_data);
+
let mut fake_storage = FakeStorage::new();
let mut logger = Logger::new(&mut fake_storage);
// Verifies that Logger::get_recording() can retrieve finished recordings.
#[test]
fn get_recording_valid() {
- let mut final_buffer = [0u8; 8192];
+ let pipe = Pipe::new();
+
+ let mut file = unsafe { std::fs::File::from_raw_fd(pipe.write_fd()) };
let mut yenc_buffer_space = [0u8; 8192];
let mut yenc_buffer = Buffer::alloc();
- let user_data = (&mut final_buffer as *mut [u8; 8192]) as *mut BufferUserData;
+ let user_data = (&mut file as *mut std::fs::File) as *mut BufferUserData;
yenc_buffer.init(yenc_buffer_space.as_mut_ptr(),
yenc_buffer_space.len(),