Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
tests: modify kill tests to support Darwin
Browse files Browse the repository at this point in the history
SIGPWR is not supported on Darwin. This patch
adds new kill_linux_test.go to use SIGPWR and
kill_darwin_test.go that does not use SIGPWR.

In addition SIGSTKFLT was removed from the tests.

Signed-off-by: Salvador Fuentes <[email protected]>
  • Loading branch information
chavafg committed Sep 7, 2018
1 parent 91bee22 commit 99e348d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 38 deletions.
15 changes: 15 additions & 0 deletions integration/docker/kill_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

package docker

import (
"syscall"

. "github.com/onsi/ginkgo/extensions/table"
)

func withOSSignals(signalsMap map[syscall.Signal]bool) []TableEntry {
return withGenericSignals(signalsMap)
}
16 changes: 16 additions & 0 deletions integration/docker/kill_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

package docker

import (
"syscall"

. "github.com/onsi/ginkgo/extensions/table"
)

func withOSSignals(signalsMap map[syscall.Signal]bool) []TableEntry {
signalsMap[syscall.SIGPWR] = canBeTrapped
return withGenericSignals(signalsMap)
}
81 changes: 43 additions & 38 deletions integration/docker/kill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,32 @@ const (
canBeTrapped = true
)

func withSignal(signal syscall.Signal, trap bool) TableEntry {
expectedExitCode := int(signal)
if !trap {
// 128 -> command interrupted by a signal
// http://www.tldp.org/LDP/abs/html/exitcodes.html
expectedExitCode += 128
}

return Entry(fmt.Sprintf("with '%d'(%s) signal", signal, syscall.Signal(signal)), signal, expectedExitCode, true)
var genericSignalMap = map[syscall.Signal]bool{
syscall.SIGHUP: canBeTrapped,
syscall.SIGINT: canBeTrapped,
syscall.SIGQUIT: canBeTrapped,
syscall.SIGILL: canBeTrapped,
syscall.SIGTRAP: canBeTrapped,
syscall.SIGIOT: canBeTrapped,
syscall.SIGFPE: canBeTrapped,
syscall.SIGUSR1: canBeTrapped,
syscall.SIGSEGV: canBeTrapped,
syscall.SIGUSR2: canBeTrapped,
syscall.SIGPIPE: canBeTrapped,
syscall.SIGALRM: canBeTrapped,
syscall.SIGTERM: canBeTrapped,
syscall.SIGCHLD: canBeTrapped,
syscall.SIGCONT: canBeTrapped,
syscall.SIGTSTP: canBeTrapped,
syscall.SIGTTIN: canBeTrapped,
syscall.SIGTTOU: canBeTrapped,
syscall.SIGURG: canBeTrapped,
syscall.SIGXCPU: canBeTrapped,
syscall.SIGXFSZ: canBeTrapped,
syscall.SIGVTALRM: canBeTrapped,
syscall.SIGPROF: canBeTrapped,
syscall.SIGWINCH: canBeTrapped,
syscall.SIGIO: canBeTrapped,
}

func withoutSignal() TableEntry {
Expand All @@ -43,6 +60,22 @@ func withSignalNotExitCode(signal syscall.Signal) TableEntry {
return Entry(fmt.Sprintf("with '%d' (%s) signal, don't change the exit code", signal, signal), signal, 0, false)
}

func withGenericSignals(signalsMap map[syscall.Signal]bool) []TableEntry {
var table []TableEntry
var expectedExitCode int
for signal, trap := range signalsMap {
expectedExitCode = int(signal)
if !trap {
// 128 -> command interrupted by a signal
// http://www.tldp.org/LDP/abs/html/exitcodes.html
expectedExitCode += 128

}
table = append(table, Entry(fmt.Sprintf("with '%d'(%s) signal", int(signal), signal), signal, expectedExitCode, true))
}
return append(table, withoutSignal(), withSignalNotExitCode(syscall.SIGSTOP))
}

var _ = Describe("docker kill", func() {
var (
args []string
Expand Down Expand Up @@ -119,34 +152,6 @@ var _ = Describe("docker kill", func() {
Expect(err).ToNot(HaveOccurred())
Expect(exitCode).To(Equal(expectedExitCode))
},
withSignal(syscall.SIGHUP, canBeTrapped),
withSignal(syscall.SIGINT, canBeTrapped),
withSignal(syscall.SIGQUIT, canBeTrapped),
withSignal(syscall.SIGILL, canBeTrapped),
withSignal(syscall.SIGTRAP, canBeTrapped),
withSignal(syscall.SIGIOT, canBeTrapped),
withSignal(syscall.SIGFPE, canBeTrapped),
withSignal(syscall.SIGUSR1, canBeTrapped),
withSignal(syscall.SIGSEGV, canBeTrapped),
withSignal(syscall.SIGUSR2, canBeTrapped),
withSignal(syscall.SIGPIPE, canBeTrapped),
withSignal(syscall.SIGALRM, canBeTrapped),
withSignal(syscall.SIGTERM, canBeTrapped),
withSignal(syscall.SIGSTKFLT, canBeTrapped),
withSignal(syscall.SIGCHLD, canBeTrapped),
withSignal(syscall.SIGCONT, canBeTrapped),
withSignalNotExitCode(syscall.SIGSTOP),
withSignal(syscall.SIGTSTP, canBeTrapped),
withSignal(syscall.SIGTTIN, canBeTrapped),
withSignal(syscall.SIGTTOU, canBeTrapped),
withSignal(syscall.SIGURG, canBeTrapped),
withSignal(syscall.SIGXCPU, canBeTrapped),
withSignal(syscall.SIGXFSZ, canBeTrapped),
withSignal(syscall.SIGVTALRM, canBeTrapped),
withSignal(syscall.SIGPROF, canBeTrapped),
withSignal(syscall.SIGWINCH, canBeTrapped),
withSignal(syscall.SIGIO, canBeTrapped),
withSignal(syscall.SIGPWR, canBeTrapped),
withoutSignal(),
withOSSignals(genericSignalMap)...,
)
})

0 comments on commit 99e348d

Please sign in to comment.