File: signal_linux_test.go

package info (click to toggle)
singularity-container 4.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,672 kB
  • sloc: asm: 3,857; sh: 2,125; ansic: 1,677; awk: 414; makefile: 110; python: 99
file content (75 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.

package signal

import (
	"testing"

	"golang.org/x/sys/unix"
)

var signalOK = []struct {
	tests  []string
	signal unix.Signal
}{
	{[]string{"SIGHUP", "HUP", "1"}, unix.SIGHUP},
	{[]string{"SIGINT", "INT", "2"}, unix.SIGINT},
	{[]string{"SIGQUIT", "QUIT", "3"}, unix.SIGQUIT},
	{[]string{"SIGILL", "ILL", "4"}, unix.SIGILL},
	{[]string{"SIGTRAP", "TRAP", "5"}, unix.SIGTRAP},
	{[]string{"SIGABRT", "ABRT", "6"}, unix.SIGABRT},
	{[]string{"SIGIOT", "IOT", "6"}, unix.SIGIOT},
	{[]string{"SIGBUS", "BUS", "7"}, unix.SIGBUS},
	{[]string{"SIGFPE", "FPE", "8"}, unix.SIGFPE},
	{[]string{"SIGKILL", "KILL", "9"}, unix.SIGKILL},
	{[]string{"SIGUSR1", "USR1", "10"}, unix.SIGUSR1},
	{[]string{"SIGSEGV", "SEGV", "11"}, unix.SIGSEGV},
	{[]string{"SIGUSR2", "USR2", "12"}, unix.SIGUSR2},
	{[]string{"SIGPIPE", "PIPE", "13"}, unix.SIGPIPE},
	{[]string{"SIGALRM", "ALRM", "14"}, unix.SIGALRM},
	{[]string{"SIGTERM", "TERM", "15"}, unix.SIGTERM},
	{[]string{"SIGCHLD", "CHLD", "17"}, unix.SIGCHLD},
	{[]string{"SIGCLD", "CLD", "17"}, unix.SIGCLD},
	{[]string{"SIGCONT", "CONT", "18"}, unix.SIGCONT},
	{[]string{"SIGSTOP", "STOP", "19"}, unix.SIGSTOP},
	{[]string{"SIGTSTP", "TSTP", "20"}, unix.SIGTSTP},
	{[]string{"SIGTTIN", "TTIN", "21"}, unix.SIGTTIN},
	{[]string{"SIGTTOU", "TTOU", "22"}, unix.SIGTTOU},
	{[]string{"SIGURG", "URG", "23"}, unix.SIGURG},
	{[]string{"SIGXCPU", "XCPU", "24"}, unix.SIGXCPU},
	{[]string{"SIGXFSZ", "XFSZ", "25"}, unix.SIGXFSZ},
	{[]string{"SIGVTALRM", "VTALRM", "26"}, unix.SIGVTALRM},
	{[]string{"SIGPROF", "PROF", "27"}, unix.SIGPROF},
	{[]string{"SIGWINCH", "WINCH", "28"}, unix.SIGWINCH},
	{[]string{"SIGIO", "IO", "29"}, unix.SIGIO},
	{[]string{"SIGPOLL", "POLL", "29"}, unix.SIGPOLL},
	{[]string{"SIGPWR", "PWR", "30"}, unix.SIGPWR},
	{[]string{"SIGSYS", "SYS", "31"}, unix.SIGSYS},
}

var signalKO = []struct {
	tests  []string
	signal unix.Signal
}{
	{[]string{"SIGNULL", "NULL", "0"}, 0},
}

func TestConvert(t *testing.T) {
	for _, test := range signalOK {
		for _, sig := range test.tests {
			if s, err := Convert(sig); s != test.signal && err != nil {
				t.Error(err)
			}
		}
	}
	for _, test := range signalKO {
		for _, sig := range test.tests {
			if s, err := Convert(sig); s != test.signal && err == nil {
				t.Error(err)
			}
		}
	}
}