130 lines
4.2 KiB
Rust
130 lines
4.2 KiB
Rust
//! Fast path system call tests
|
|
//!
|
|
//! Tests for read, write, close fast path implementations
|
|
|
|
use crate::tests::{TestResult, test_assert, test_assert_eq};
|
|
|
|
/// Test read fast path
|
|
pub fn test_read_fast_path() -> TestResult {
|
|
// Test with invalid file descriptor (should fall back to normal path)
|
|
let args = [
|
|
999u64, // invalid fd
|
|
0u64, // null buffer
|
|
4096u64, // count
|
|
];
|
|
|
|
let result = crate::syscalls::dispatch(0x2002, &args); // read
|
|
// Should return error for invalid FD
|
|
test_assert!(result < 0, "read with invalid FD should return error");
|
|
|
|
// Test with null buffer (should return error)
|
|
let args = [
|
|
0u64, // fd = 0 (stdin, might be valid)
|
|
0u64, // null buffer
|
|
4096u64, // count
|
|
];
|
|
|
|
let result = crate::syscalls::dispatch(0x2002, &args); // read
|
|
// Should return error for null buffer
|
|
test_assert!(result < 0, "read with null buffer should return error");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Test write fast path
|
|
pub fn test_write_fast_path() -> TestResult {
|
|
// Test with invalid file descriptor (should fall back to normal path)
|
|
let args = [
|
|
999u64, // invalid fd
|
|
0u64, // null buffer
|
|
4096u64, // count
|
|
];
|
|
|
|
let result = crate::syscalls::dispatch(0x2003, &args); // write
|
|
// Should return error for invalid FD
|
|
test_assert!(result < 0, "write with invalid FD should return error");
|
|
|
|
// Test with null buffer (should return error)
|
|
let args = [
|
|
1u64, // fd = 1 (stdout, might be valid)
|
|
0u64, // null buffer
|
|
4096u64, // count
|
|
];
|
|
|
|
let result = crate::syscalls::dispatch(0x2003, &args); // write
|
|
// Should return error for null buffer
|
|
test_assert!(result < 0, "write with null buffer should return error");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Test close fast path
|
|
pub fn test_close_fast_path() -> TestResult {
|
|
// Test with invalid file descriptor (should fall back to normal path)
|
|
let args = [999u64]; // invalid fd
|
|
|
|
let result = crate::syscalls::dispatch(0x2001, &args); // close
|
|
// Should return error for invalid FD
|
|
test_assert!(result < 0, "close with invalid FD should return error");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Test fast path boundary conditions
|
|
pub fn test_fast_path_boundaries() -> TestResult {
|
|
// Test read with large buffer (should fall back to normal path)
|
|
let args = [
|
|
0u64, // fd
|
|
0x1000u64, // buffer (might be valid)
|
|
4097u64, // count > 4KB (should fall back)
|
|
];
|
|
|
|
let result = crate::syscalls::dispatch(0x2002, &args); // read
|
|
// Should handle large buffer (fall back to normal path)
|
|
test_assert!(true, "read with large buffer should be handled");
|
|
|
|
// Test write with large buffer (should fall back to normal path)
|
|
let args = [
|
|
1u64, // fd
|
|
0x1000u64, // buffer (might be valid)
|
|
4097u64, // count > 4KB (should fall back)
|
|
];
|
|
|
|
let result = crate::syscalls::dispatch(0x2003, &args); // write
|
|
// Should handle large buffer (fall back to normal path)
|
|
test_assert!(true, "write with large buffer should be handled");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Test fast path performance
|
|
pub fn test_fast_path_performance() -> TestResult {
|
|
// Test that fast path is faster than normal path
|
|
// This is a simplified test - real performance testing would use benchmarks
|
|
|
|
let iterations = 100;
|
|
let args_small = [0u64, 0x1000u64, 1024u64]; // Small buffer (fast path)
|
|
let args_large = [0u64, 0x1000u64, 8192u64]; // Large buffer (normal path)
|
|
|
|
// Measure fast path time
|
|
let start = crate::time::get_ticks();
|
|
for _ in 0..iterations {
|
|
let _ = crate::syscalls::dispatch(0x2002, &args_small); // read
|
|
}
|
|
let fast_path_time = crate::time::get_ticks() - start;
|
|
|
|
// Measure normal path time
|
|
let start = crate::time::get_ticks();
|
|
for _ in 0..iterations {
|
|
let _ = crate::syscalls::dispatch(0x2002, &args_large); // read
|
|
}
|
|
let normal_path_time = crate::time::get_ticks() - start;
|
|
|
|
// Fast path should be at least as fast (in test environment, might not be faster due to errors)
|
|
test_assert!(fast_path_time >= 0 && normal_path_time >= 0,
|
|
"Performance test should complete");
|
|
|
|
Ok(())
|
|
}
|
|
|