Fix signal tests

This commit is contained in:
root 2022-12-02 10:44:41 +08:00
parent fe0200e27a
commit a0e2bf4c58
4 changed files with 14 additions and 17 deletions

View File

@ -1,9 +1,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate alloc;
#[macro_use]
extern crate user_lib; extern crate user_lib;
use user_lib::console::getchar; use user_lib::console::getchar;
use user_lib::*; use user_lib::*;
@ -34,7 +31,7 @@ pub fn main() -> i32 {
println!("Got Char {}", c); println!("Got Char {}", c);
if c == LF || c == CR { if c == LF || c == CR {
return 0; break;
} }
} }
println!("sig_ctrlc: Done"); println!("sig_ctrlc: Done");

View File

@ -1,7 +1,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#[macro_use]
extern crate user_lib; extern crate user_lib;
// use user_lib::{sigaction, sigprocmask, SignalAction, SignalFlags, fork, exit, wait, kill, getpid, sleep, sigreturn}; // use user_lib::{sigaction, sigprocmask, SignalAction, SignalFlags, fork, exit, wait, kill, getpid, sleep, sigreturn};

View File

@ -1,13 +1,15 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#[macro_use]
extern crate user_lib; extern crate user_lib;
/*
use user_lib::{ use user_lib::{
exit, fork, getpid, kill, sigaction, sigprocmask, sigreturn, sleep, waitpid, SignalAction, exit, fork, getpid, kill, sigaction, sigprocmask, sigreturn, sleep, waitpid, SignalAction,
SignalFlags, SignalFlags,
}; };
*/
use user_lib::*;
fn func() { fn func() {
println!("user_sig_test succsess"); println!("user_sig_test succsess");
@ -23,7 +25,7 @@ pub fn main() -> i32 {
new.handler = func as usize; new.handler = func as usize;
println!("signal_simple2: child sigaction"); println!("signal_simple2: child sigaction");
if sigaction(10, &new, &old) < 0 { if sigaction(SIGUSR1, &new, &old) < 0 {
panic!("Sigaction failed!"); panic!("Sigaction failed!");
} }
sleep(1000); sleep(1000);
@ -32,7 +34,7 @@ pub fn main() -> i32 {
} else if pid > 0 { } else if pid > 0 {
println!("signal_simple2: parent kill child"); println!("signal_simple2: parent kill child");
sleep(500); sleep(500);
if kill(pid as usize, 1 << 10) < 0 { if kill(pid as usize, SIGUSR1) < 0 {
println!("Kill failed!"); println!("Kill failed!");
exit(1); exit(1);
} }

View File

@ -1,7 +1,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#[macro_use]
extern crate user_lib; extern crate user_lib;
// use user_lib::{sigaction, sigprocmask, SignalAction, SignalFlags, fork, exit, wait, kill, getpid, sleep, sigreturn}; // use user_lib::{sigaction, sigprocmask, SignalAction, SignalFlags, fork, exit, wait, kill, getpid, sleep, sigreturn};
@ -96,12 +95,12 @@ fn kernel_sig_test_ignore() {
fn kernel_sig_test_stop_cont() { fn kernel_sig_test_stop_cont() {
let pid = fork(); let pid = fork();
if pid == 0 { if pid == 0 {
kill(getpid() as usize, SignalFlags::SIGSTOP.bits()); kill(getpid() as usize, SIGSTOP);
sleep(1000); sleep(500);
exit(-1); exit(-1);
} else { } else {
sleep(5000); sleep(1000);
kill(pid as usize, SignalFlags::SIGCONT.bits()); kill(pid as usize, SIGCONT);
let mut exit_code = 0; let mut exit_code = 0;
wait(&mut exit_code); wait(&mut exit_code);
} }
@ -139,7 +138,7 @@ fn final_sig_test() {
if sigaction(SIGUSR1, &new, &old) < 0 { if sigaction(SIGUSR1, &new, &old) < 0 {
panic!("Sigaction failed!"); panic!("Sigaction failed!");
} }
if sigaction(14, &new2, &old2) < 0 { if sigaction(SIGUSR2, &new2, &old2) < 0 {
panic!("Sigaction failed!"); panic!("Sigaction failed!");
} }
if kill(getpid() as usize, SIGUSR1) < 0 { if kill(getpid() as usize, SIGUSR1) < 0 {
@ -147,13 +146,13 @@ fn final_sig_test() {
exit(-1); exit(-1);
} }
} else { } else {
sleep(1000); sleep(2000);
if kill(pid as usize, 1 << 14) < 0 { if kill(pid as usize, SIGUSR2) < 0 {
println!("Kill failed!"); println!("Kill failed!");
exit(-1); exit(-1);
} }
sleep(1000); sleep(1000);
kill(pid as usize, SignalFlags::SIGKILL.bits()); kill(pid as usize, SIGKILL);
} }
} }