Verified Commit e1ab6b44 authored by 4lDO2's avatar 4lDO2 🖖
Browse files

Futex test.

parent b5ccc437
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "acid"
version = "0.1.0"
dependencies = [
"redox_syscall 0.2.0 (git+https://gitlab.redox-os.org/redox-os/syscall.git)",
"strace 0.1.0 (git+https://gitlab.redox-os.org/redox-os/strace-redox)",
"x86 0.34.0 (registry+https://github.com/rust-lang/crates.io-index)",
"f80",
"redox_syscall 0.2.9 (git+https://gitlab.redox-os.org/redox-os/syscall.git)",
"strace",
"x86",
]
[[package]]
name = "bit_field"
version = "0.10.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4"
[[package]]
name = "bitflags"
version = "1.1.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cc"
version = "1.0.59"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787"
[[package]]
name = "f80"
version = "0.1.0"
source = "git+https://gitlab.redox-os.org/redox-os/f80#d8de286afe27934c6ac002153e1610f100853ef9"
[[package]]
name = "raw-cpuid"
version = "8.1.1"
version = "8.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fdf7d9dbd43f3d81d94a49c1c3df73cc2b3827995147e6cf7f89d4ec5483e73"
dependencies = [
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags",
"cc",
"rustc_version",
]
[[package]]
name = "redox_syscall"
version = "0.2.0"
source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#405964e4fb9d6e920d04226d60987ab4c7e70b85"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee"
dependencies = [
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags",
]
[[package]]
name = "redox_syscall"
version = "0.2.9"
source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#52fcd238db87354b6556eac9b05bb8ab2658426a"
dependencies = [
"bitflags",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"semver",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "strace"
version = "0.1.0"
source = "git+https://gitlab.redox-os.org/redox-os/strace-redox#d7f7921f50bb03fe855f27a439d2d9c2eac45646"
source = "git+https://gitlab.redox-os.org/redox-os/strace-redox#a2a6e95e8d3be09cd761feaa39cf051de4f45639"
dependencies = [
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.2.0 (git+https://gitlab.redox-os.org/redox-os/syscall.git)",
"bitflags",
"redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "x86"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c146cbc47471e076987378c159a7aa8fa434680c6fbddca59fe6f40f1591c819"
dependencies = [
"bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-cpuid 8.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field",
"bitflags",
"raw-cpuid",
]
[metadata]
"checksum bit_field 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a165d606cf084741d4ac3a28fb6e9b1eb0bd31f6cd999098cfddb0b2ab381dc0"
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
"checksum cc 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)" = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381"
"checksum raw-cpuid 8.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cee2c7710d96f9f90f56824fca5438b301dc0fb49ece4cf9dfa044e54067e10"
"checksum redox_syscall 0.2.0 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "<none>"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum strace 0.1.0 (git+https://gitlab.redox-os.org/redox-os/strace-redox)" = "<none>"
"checksum x86 0.34.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c146cbc47471e076987378c159a7aa8fa434680c6fbddca59fe6f40f1591c819"
......@@ -8,4 +8,4 @@ edition = "2018"
x86 = "0.34.0"
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" }
strace = { git = "https://gitlab.redox-os.org/redox-os/strace-redox", default-features = false }
#strace = { path = "../../strace/source", default-features = false }
f80 = { git = "https://gitlab.redox-os.org/redox-os/f80", default-features = false }
//!Acid testing program
#![feature(thread_local, llvm_asm)]
#![feature(array_map, atomic_mut_ptr, thread_local, llvm_asm)]
fn e<T, E: ToString>(error: Result<T, E>) -> Result<T, String> {
error.map_err(|e| e.to_string())
......@@ -311,10 +311,10 @@ pub fn ptrace() -> Result<(), String> {
e(next(&mut tracer, Flags::STOP_SINGLESTEP))?;
}
let regs = e(tracer.regs.get_float())?;
let f = regs.st_space_nth(0);
let fs = regs.st_space();
let fs = regs.st_space.map(|bits| f80::f80::from_bits(bits).to_f64());
let f = fs[0];
assert_eq!(fs, [f, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
assert!((f - 5.65685424949238).abs() < std::f64::EPSILON);
assert!((f - 5.65685424949238_f64).abs() < f64::EPSILON);
println!("Testing fork event");
assert_eq!(e(e(next(&mut tracer, Flags::STOP_PRE_SYSCALL | Flags::EVENT_CLONE))?.regs.get_int())?.rax, syscall::SYS_CLONE);
......@@ -615,6 +615,36 @@ fn tls_test() -> Result<(), String> {
Ok(())
}
fn futex_test() -> Result<(), String> {
use std::sync::{Arc, atomic::{AtomicU64, Ordering}};
use std::thread;
let mut regular_variable = 0xDEAD_BEEF_FED_FACE_usize;
assert_eq!(unsafe { syscall::syscall5(syscall::SYS_FUTEX, (&mut regular_variable) as *const usize as usize, 3, 0, 0, 0) }, Err(syscall::Error::new(syscall::EAGAIN)));
let semaphore = Arc::new(AtomicU64::new(1337));
let other_thread = {
let semaphore = Arc::clone(&semaphore);
thread::spawn(move || {
semaphore.fetch_add(1, Ordering::Relaxed);
unsafe {
syscall::syscall5(syscall::SYS_FUTEX, semaphore.as_mut_ptr() as usize, syscall::FUTEX_WAKE, 0, 0, 0).unwrap();
}
})
};
while semaphore.load(Ordering::Relaxed) == 1337 {
unsafe {
assert_eq!(syscall::syscall5(syscall::SYS_FUTEX, semaphore.as_mut_ptr() as usize, 3, 1337, 0, 0), Ok(0));
}
}
other_thread.join().unwrap();
// TODO: Expand test, e.g. cover the now-fixed bug where separate processes would notify each
// other if they would happen to use the same virtual address, but in different address spaces.
Ok(())
}
fn main() {
use std::collections::BTreeMap;
use std::{env, process};
......@@ -628,6 +658,7 @@ fn main() {
tests.insert("tcp_fin", tcp_fin_test);
tests.insert("thread", thread_test);
tests.insert("tls", tls_test);
tests.insert("futex", futex_test);
let mut ran_test = false;
for arg in env::args().skip(1) {
......
Supports Markdown
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