Skip to content

Commit

Permalink
Added lseek test
Browse files Browse the repository at this point in the history
  • Loading branch information
jounathaen committed Feb 5, 2025
1 parent 08a6e75 commit 696de23
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/fs-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod common;
use std::{fs::read_to_string, path::PathBuf};

use byte_unit::{Byte, Unit};
use common::{build_hermit_bin, check_result, remove_file_if_exists};
use common::{build_hermit_bin, check_result, remove_file_if_exists, run_simple_vm};
use uhyvelib::{
params::{Output, Params},
vm::UhyveVm,
Expand Down Expand Up @@ -67,3 +67,11 @@ fn uhyvefilemap_test() {
check_result(&res);
verify_file_equals(&output_path, "Hello, world!");
}

#[test]
fn lseek_test() {
env_logger::try_init().ok();
let bin_path = build_hermit_bin("lseek");
let res = run_simple_vm(bin_path);
check_result(&res);
}
30 changes: 30 additions & 0 deletions tests/test-kernels/src/bin/lseek.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::{
fs::OpenOptions,
io::{prelude::*, SeekFrom},
};

#[cfg(target_os = "hermit")]
use hermit as _;

fn main() {
let mut buf: [u8; 10] = [0; 10];
println!("Initial Buffer: {buf:?}");
let mut f = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open("/root/foo.txt")
.unwrap();
f.write(&[
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
])
.unwrap();
f.read(&mut buf).unwrap();
assert_eq!(buf, [0; 10]);
println!("file pre-seek: {buf:?}");

f.seek(SeekFrom::Start(5)).unwrap();
f.read(&mut buf).unwrap();
println!("file post-seek: {buf:?}");
assert_eq!(buf, [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);
}

0 comments on commit 696de23

Please sign in to comment.