Commit 43c562a9 authored by Jeremy Soller's avatar Jeremy Soller

0.1.55:

- deprecate chmod
- add tests
- CI using redoxer
parent ea1f9e09
Pipeline #5075 passed with stage
in 18 seconds
image: "redoxos/redoxer"
build:
script:
- redoxer build
[package]
name = "redox_syscall"
version = "0.1.54"
version = "0.1.55"
description = "A Rust library to access raw Redox system calls"
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
......
......@@ -43,6 +43,10 @@ pub fn chdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_CHDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}
#[deprecated(
since = "0.1.55",
note = "use fchmod instead"
)]
pub fn chmod<T: AsRef<[u8]>>(path: T, mode: usize) -> Result<usize> {
unsafe { syscall3(SYS_CHMOD, path.as_ref().as_ptr() as usize, path.as_ref().len(), mode) }
}
......
......@@ -192,7 +192,7 @@ impl DerefMut for StatVfs {
}
}
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[repr(C)]
pub struct TimeSpec {
pub tv_sec: i64,
......
#![cfg(target_os = "redox")]
#![feature(asm)]
#![feature(const_fn)]
#![no_std]
#![cfg_attr(not(test), no_std)]
#[cfg(test)]
extern crate core;
pub use self::arch::*;
pub use self::call::*;
......@@ -48,3 +51,6 @@ pub mod number;
/// A trait useful for scheme handlers
pub mod scheme;
#[cfg(test)]
mod tests;
#[test]
fn brk() {
unsafe {
let start = dbg!(crate::brk(0)).unwrap();
let end = start + 4 * 1024 * 1024;
assert_eq!(dbg!(crate::brk(end)), Ok(end));
}
}
#[test]
fn chdir() {
//TODO: Verify CWD
assert_eq!(dbg!(crate::chdir("file:/")), Ok(0));
assert_eq!(dbg!(crate::chdir("file:/root")), Ok(0));
}
//TODO: chmod
#[test]
fn clone() {
let expected_status = 42;
let pid_res = unsafe { crate::clone(0) };
if pid_res == Ok(0) {
crate::exit(expected_status).unwrap();
panic!("failed to exit");
} else {
let pid = dbg!(pid_res).unwrap();
let mut status = 0;
assert_eq!(dbg!(crate::waitpid(pid, &mut status, 0)), Ok(pid));
assert_eq!(dbg!(crate::wifexited(status)), true);
assert_eq!(dbg!(crate::wexitstatus(status)), expected_status);
}
}
//TODO: close
#[test]
fn clock_gettime() {
let mut tp = crate::TimeSpec::default();
assert_eq!(dbg!(
crate::clock_gettime(crate::CLOCK_MONOTONIC, &mut tp)
), Ok(0));
assert_ne!(dbg!(tp), crate::TimeSpec::default());
tp = crate::TimeSpec::default();
assert_eq!(dbg!(
crate::clock_gettime(crate::CLOCK_REALTIME, &mut tp)
), Ok(0));
assert_ne!(dbg!(tp), crate::TimeSpec::default());
}
//TODO: dup
//TODO: dup2
//TODO: exit (handled by clone?)
//TODO: fchmod
//TODO: fcntl
#[test]
fn fexec() {
let name = "/bin/ls";
let fd = dbg!(
crate::open(name, crate::O_RDONLY | crate::O_CLOEXEC)
).unwrap();
let args = &[
[name.as_ptr() as usize, name.len()]
];
let vars = &[];
let pid_res = unsafe { crate::clone(0) };
if pid_res == Ok(0) {
crate::fexec(fd, args, vars).unwrap();
panic!("failed to fexec");
} else {
assert_eq!(dbg!(crate::close(fd)), Ok(0));
let pid = dbg!(pid_res).unwrap();
let mut status = 0;
assert_eq!(dbg!(crate::waitpid(pid, &mut status, 0)), Ok(pid));
assert_eq!(dbg!(crate::wifexited(status)), true);
assert_eq!(dbg!(crate::wexitstatus(status)), 0);
}
}
#[test]
fn fmap() {
use std::slice;
let fd = dbg!(
crate::open(
"/tmp/syscall-tests-fmap",
crate::O_CREAT | crate::O_RDWR | crate::O_CLOEXEC
)
).unwrap();
let map = unsafe {
slice::from_raw_parts_mut(
dbg!(
crate::fmap(fd, &crate::Map {
offset: 0,
size: 128,
flags: crate::PROT_READ | crate::PROT_WRITE
})
).unwrap() as *mut u8,
128
)
};
// Maps should be available after closing
assert_eq!(dbg!(crate::close(fd)), Ok(0));
for i in 0..128 {
map[i as usize] = i;
assert_eq!(map[i as usize], i);
}
//TODO: add msync
unsafe {
assert_eq!(dbg!(
crate::funmap(map.as_mut_ptr() as usize)
), Ok(0));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment