github.com/ericwq/aprilsh@v0.0.0-20240517091432-958bc568daa0/frontend/signal_linux_test.go (about) 1 // Copyright 2022~2023 wangqi. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package frontend 6 7 import ( 8 "os" 9 "syscall" 10 "testing" 11 ) 12 13 func TestGotSignal(t *testing.T) { 14 tc := []os.Signal{ 15 syscall.SIGABRT, syscall.SIGALRM, syscall.SIGBUS, syscall.SIGCHLD, syscall.SIGCLD, 16 syscall.SIGCONT, syscall.SIGFPE, syscall.SIGHUP, syscall.SIGILL, syscall.SIGINT, 17 syscall.SIGIO, syscall.SIGIOT, syscall.SIGKILL, syscall.SIGPIPE, syscall.SIGPOLL, 18 syscall.SIGPROF, syscall.SIGPWR, syscall.SIGQUIT, syscall.SIGSEGV, syscall.SIGSTKFLT, 19 syscall.SIGSTOP, syscall.SIGSYS, syscall.SIGTERM, syscall.SIGTRAP, syscall.SIGTSTP, 20 syscall.SIGTTIN, syscall.SIGTTOU, syscall.SIGUNUSED, syscall.SIGURG, syscall.SIGUSR1, 21 syscall.SIGUSR2, syscall.SIGVTALRM, syscall.SIGWINCH, syscall.SIGXCPU, syscall.SIGXFSZ, 22 } 23 24 result := []bool{ 25 true, true, true, true, false, 26 true, true, true, true, true, 27 true, false, true, true, false, 28 true, true, true, true, true, 29 true, true, true, true, true, 30 true, true, false, true, true, 31 true, true, true, true, true, 32 } 33 34 /* 35 syscall.SIGPOLL and syscall.SIGIO has conflict value 36 syscall.SIGIOT and syscall.SIGABRT has conflict value 37 syscall.SIGUNUSED and syscall.SIGSYS has conflict value 38 */ 39 40 // initialize Signals array 41 var s Signals 42 for i := range tc { 43 s.Handler(tc[i]) 44 } 45 46 // validate GotSignal() 47 for i := range tc { 48 ss := tc[i].(syscall.Signal) 49 got := s.GotSignal(ss) 50 if got != result[i] { 51 t.Errorf("#test GotSignal() %q %x expect %t, got %t\n", tc[i], int(ss), result[i], got) 52 } 53 } 54 }