mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Merge #554
554: finish implementation of wasi::fd_seek, fix bug in filestat r=syrusakbary a=MarkMcCaskey Co-authored-by: Mark McCaskey <mark@wasmer.io> Co-authored-by: Syrus <me@syrusakbary.com>
This commit is contained in:
commit
608bb272dc
@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file.
|
|||||||
Blocks of changes will separated by version increments.
|
Blocks of changes will separated by version increments.
|
||||||
|
|
||||||
## **[Unreleased]**
|
## **[Unreleased]**
|
||||||
|
- [#554](https://github.com/wasmerio/wasmer/pull/554) Finish implementation of `wasi::fd_seek`, fix bug in filestat
|
||||||
|
|
||||||
## 0.5.5
|
## 0.5.5
|
||||||
- [#541](https://github.com/wasmerio/wasmer/pull/541) Fix dependency graph by making separate test crates; ABI implementations should not depend on compilers. Add Cranelift fork as git submodule of clif-backend
|
- [#541](https://github.com/wasmerio/wasmer/pull/541) Fix dependency graph by making separate test crates; ABI implementations should not depend on compilers. Add Cranelift fork as git submodule of clif-backend
|
||||||
|
@ -32,7 +32,6 @@ pub fn compile(file: &str, ignores: &HashSet<String>) -> Option<String> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Command::new("rustc")
|
Command::new("rustc")
|
||||||
.arg("+nightly")
|
|
||||||
.arg(file)
|
.arg(file)
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
.arg(&normalized_name)
|
.arg(&normalized_name)
|
||||||
@ -85,7 +84,7 @@ pub fn compile(file: &str, ignores: &HashSet<String>) -> Option<String> {
|
|||||||
out_str.push_str("vec![");
|
out_str.push_str("vec![");
|
||||||
for (alias, real_dir) in args.mapdir {
|
for (alias, real_dir) in args.mapdir {
|
||||||
out_str.push_str(&format!(
|
out_str.push_str(&format!(
|
||||||
"(\"{}\".to_string(), \"{}\".to_string()),",
|
"(\"{}\".to_string(), ::std::path::PathBuf::from(\"{}\")),",
|
||||||
alias, real_dir
|
alias, real_dir
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
13
lib/wasi-tests/tests/wasitests/fseek.rs
Normal file
13
lib/wasi-tests/tests/wasitests/fseek.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#[test]
|
||||||
|
fn test_fseek() {
|
||||||
|
assert_wasi_output!(
|
||||||
|
"../../wasitests/fseek.wasm",
|
||||||
|
"fseek",
|
||||||
|
vec![(
|
||||||
|
".".to_string(),
|
||||||
|
::std::path::PathBuf::from("wasitests/test_fs/hamlet")
|
||||||
|
),],
|
||||||
|
vec![],
|
||||||
|
"../../wasitests/fseek.out"
|
||||||
|
);
|
||||||
|
}
|
@ -3,7 +3,10 @@ fn test_mapdir() {
|
|||||||
assert_wasi_output!(
|
assert_wasi_output!(
|
||||||
"../../wasitests/mapdir.wasm",
|
"../../wasitests/mapdir.wasm",
|
||||||
"mapdir",
|
"mapdir",
|
||||||
vec![],
|
vec![(
|
||||||
|
".".to_string(),
|
||||||
|
::std::path::PathBuf::from("wasitests/test_fs/hamlet")
|
||||||
|
),],
|
||||||
vec![],
|
vec![],
|
||||||
"../../wasitests/mapdir.out"
|
"../../wasitests/mapdir.out"
|
||||||
);
|
);
|
||||||
|
@ -9,6 +9,7 @@ mod create_dir;
|
|||||||
mod envvar;
|
mod envvar;
|
||||||
mod file_metadata;
|
mod file_metadata;
|
||||||
mod fs_sandbox_test;
|
mod fs_sandbox_test;
|
||||||
|
mod fseek;
|
||||||
mod hello;
|
mod hello;
|
||||||
mod mapdir;
|
mod mapdir;
|
||||||
mod quine;
|
mod quine;
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
lib/wasi-tests/wasitests/fseek.out
Normal file
11
lib/wasi-tests/wasitests/fseek.out
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
SCENE III. A room in Polonius' h
|
||||||
|
ouse.
|
||||||
|
|
||||||
|
Enter LAERTES and OPH
|
||||||
|
And, sister, as the winds gi
|
||||||
|
r talk with the Lord Hamlet.
|
||||||
|
|
||||||
|
uits,
|
||||||
|
Breathing like sanctif
|
||||||
|
is is for all:
|
||||||
|
I would not,
|
47
lib/wasi-tests/wasitests/fseek.rs
Normal file
47
lib/wasi-tests/wasitests/fseek.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Args:
|
||||||
|
// mapdir: .:wasitests/test_fs/hamlet
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
#[cfg(not(target_os = "wasi"))]
|
||||||
|
let mut base = PathBuf::from("wasitests/test_fs/hamlet");
|
||||||
|
#[cfg(target_os = "wasi")]
|
||||||
|
let mut base = PathBuf::from(".");
|
||||||
|
|
||||||
|
base.push("act1/scene3.txt");
|
||||||
|
|
||||||
|
let mut file = fs::File::open(&base).expect("Could not open file");
|
||||||
|
|
||||||
|
let mut buffer = [0u8; 32];
|
||||||
|
|
||||||
|
assert_eq!(file.read(&mut buffer).unwrap(), 32);
|
||||||
|
let str_val = std::str::from_utf8(&buffer[..]).unwrap();
|
||||||
|
println!("{}", str_val);
|
||||||
|
|
||||||
|
assert_eq!(file.read(&mut buffer).unwrap(), 32);
|
||||||
|
let str_val = std::str::from_utf8(&buffer[..]).unwrap();
|
||||||
|
println!("{}", str_val);
|
||||||
|
|
||||||
|
assert_eq!(file.seek(SeekFrom::Start(123)).unwrap(), 123);
|
||||||
|
assert_eq!(file.read(&mut buffer).unwrap(), 32);
|
||||||
|
let str_val = std::str::from_utf8(&buffer[..]).unwrap();
|
||||||
|
println!("{}", str_val);
|
||||||
|
|
||||||
|
assert_eq!(file.seek(SeekFrom::End(-123)).unwrap(), 6617);
|
||||||
|
assert_eq!(file.read(&mut buffer).unwrap(), 32);
|
||||||
|
let str_val = std::str::from_utf8(&buffer[..]).unwrap();
|
||||||
|
println!("{}", str_val);
|
||||||
|
|
||||||
|
assert_eq!(file.seek(SeekFrom::Current(-250)).unwrap(), 6399);
|
||||||
|
assert_eq!(file.read(&mut buffer).unwrap(), 32);
|
||||||
|
let str_val = std::str::from_utf8(&buffer[..]).unwrap();
|
||||||
|
println!("{}", str_val);
|
||||||
|
|
||||||
|
assert_eq!(file.seek(SeekFrom::Current(50)).unwrap(), 6481);
|
||||||
|
assert_eq!(file.read(&mut buffer).unwrap(), 32);
|
||||||
|
let str_val = std::str::from_utf8(&buffer[..]).unwrap();
|
||||||
|
println!("{}", str_val);
|
||||||
|
}
|
BIN
lib/wasi-tests/wasitests/fseek.wasm
Executable file
BIN
lib/wasi-tests/wasitests/fseek.wasm
Executable file
Binary file not shown.
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
"wasitests/test_fs/hamlet/README.md"
|
"./README.md"
|
||||||
"wasitests/test_fs/hamlet/act1"
|
"./act1"
|
||||||
"wasitests/test_fs/hamlet/act2"
|
"./act2"
|
||||||
"wasitests/test_fs/hamlet/act3"
|
"./act3"
|
||||||
"wasitests/test_fs/hamlet/act4"
|
"./act4"
|
||||||
"wasitests/test_fs/hamlet/act5"
|
"./act5"
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(not(target = "wasi"))]
|
// #[cfg(not(target_os = "wasi"))]
|
||||||
let read_dir = fs::read_dir("wasitests/test_fs/hamlet").unwrap();
|
// let read_dir = fs::read_dir("wasitests/test_fs/hamlet").unwrap();
|
||||||
#[cfg(target = "wasi")]
|
// #[cfg(target_os = "wasi")]
|
||||||
let read_dir = fs::read_dir(".").unwrap();
|
let read_dir = fs::read_dir(".").unwrap();
|
||||||
let mut out = vec![];
|
let mut out = vec![];
|
||||||
for entry in read_dir {
|
for entry in read_dir {
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -903,7 +903,28 @@ pub fn fd_seek(
|
|||||||
// TODO: handle case if fd is a dir?
|
// TODO: handle case if fd is a dir?
|
||||||
match whence {
|
match whence {
|
||||||
__WASI_WHENCE_CUR => fd_entry.offset = (fd_entry.offset as i64 + offset) as u64,
|
__WASI_WHENCE_CUR => fd_entry.offset = (fd_entry.offset as i64 + offset) as u64,
|
||||||
__WASI_WHENCE_END => unimplemented!("__WASI__WHENCE_END in wasi::fd_seek"),
|
__WASI_WHENCE_END => {
|
||||||
|
use std::io::SeekFrom;
|
||||||
|
match state.fs.inodes[fd_entry.inode].kind {
|
||||||
|
Kind::File { ref mut handle } => {
|
||||||
|
let end = wasi_try!(handle.seek(SeekFrom::End(0)).ok().ok_or(__WASI_EIO));
|
||||||
|
// TODO: handle case if fd_entry.offset uses 64 bits of a u64
|
||||||
|
fd_entry.offset = (end as i64 + offset) as u64;
|
||||||
|
}
|
||||||
|
Kind::Symlink { .. } => {
|
||||||
|
unimplemented!("wasi::fd_seek not implemented for symlinks")
|
||||||
|
}
|
||||||
|
Kind::Dir { .. } => {
|
||||||
|
// TODO: check this
|
||||||
|
return __WASI_EINVAL;
|
||||||
|
}
|
||||||
|
Kind::Buffer { .. } => {
|
||||||
|
// seeking buffers probably makes sense
|
||||||
|
// TODO: implement this
|
||||||
|
return __WASI_EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
__WASI_WHENCE_SET => fd_entry.offset = offset as u64,
|
__WASI_WHENCE_SET => fd_entry.offset = offset as u64,
|
||||||
_ => return __WASI_EINVAL,
|
_ => return __WASI_EINVAL,
|
||||||
}
|
}
|
||||||
@ -1235,6 +1256,7 @@ pub fn path_filestat_get(
|
|||||||
let last_segment = path_vec.last().unwrap();
|
let last_segment = path_vec.last().unwrap();
|
||||||
cumulative_path.push(last_segment);
|
cumulative_path.push(last_segment);
|
||||||
|
|
||||||
|
// read it from wasi FS cache first, otherwise check host system
|
||||||
if entries.contains_key(last_segment) {
|
if entries.contains_key(last_segment) {
|
||||||
state.fs.inodes[entries[last_segment]].stat
|
state.fs.inodes[entries[last_segment]].stat
|
||||||
} else {
|
} else {
|
||||||
@ -1244,7 +1266,25 @@ pub fn path_filestat_get(
|
|||||||
}
|
}
|
||||||
let final_path_metadata =
|
let final_path_metadata =
|
||||||
wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO));
|
wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO));
|
||||||
wasi_try!(get_stat_for_kind(&state.fs.inodes[inode].kind).ok_or(__WASI_EIO))
|
let kind = if final_path_metadata.is_file() {
|
||||||
|
let file =
|
||||||
|
wasi_try!(std::fs::File::open(&cumulative_path).ok().ok_or(__WASI_EIO));
|
||||||
|
Kind::File {
|
||||||
|
handle: WasiFile::HostFile(file),
|
||||||
|
}
|
||||||
|
} else if final_path_metadata.is_dir() {
|
||||||
|
Kind::Dir {
|
||||||
|
parent: Some(inode),
|
||||||
|
// TODO: verify that this doesn't cause issues with relative paths
|
||||||
|
path: cumulative_path.clone(),
|
||||||
|
entries: Default::default(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: check this
|
||||||
|
return __WASI_EINVAL;
|
||||||
|
};
|
||||||
|
|
||||||
|
wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
Reference in New Issue
Block a user