Skip to content
Snippets Groups Projects
Commit 946fd79e authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Test for BadFile

parent dd280a5d
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,12 @@ use super::{Error, Result};
/// Read syscall
pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
println!("Read {}: {}", fd, buf.len());
Ok(0)
if let Some(file) = unsafe { &mut ::context::CONTEXT }.files.get(fd) {
println!("{:?}", file);
Ok(0)
} else {
Err(Error::BadFile)
}
}
/// Write syscall
......
use arch::interrupt::{enable_interrupts, halt};
use syscall;
use syscall::{self, Error};
/// Test halting
#[test]
fn halt_with_interrupts() {
unsafe {
enable_interrupts();
halt();
//enable_interrupts();
//halt();
}
}
/// Test stdio
#[test]
fn open_stdio() {
fn stdio() {
// Test opening stdin
assert_eq!(syscall::open(b"debug:", 0), Ok(0));
......@@ -29,3 +31,10 @@ fn open_stdio() {
let stderr_str = b"STDERR";
assert_eq!(syscall::write(2, stderr_str), Ok(stderr_str.len()));
}
/// Test that invalid reads/writes cause errors
#[test]
fn invalid_path() {
assert_eq!(syscall::read(999, &mut []), Err(Error::BadFile));
assert_eq!(syscall::write(999, &[]), Err(Error::BadFile));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment