Makefile: turn on race detection whenever it's available
Check if `go test` supports the -race flag on the build platform, and if so, use it for unit tests instead of just assuming that it's always available. Use sync/atomic to safely use a uint32 instead of a bool to keep track of whether or not the process we started for RUN has stopped. [NO NEW TESTS NEEDED] Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
parent
52dfdd7868
commit
a314d2a6ca
5
Makefile
5
Makefile
|
@ -10,6 +10,7 @@ BINDIR := $(PREFIX)/bin
|
|||
BASHINSTALLDIR = $(PREFIX)/share/bash-completion/completions
|
||||
BUILDFLAGS := -tags "$(BUILDTAGS)"
|
||||
BUILDAH := buildah
|
||||
RACEFLAGS := $(shell go test -race ./pkg/rusage > /dev/null 2>&1 && echo -race)
|
||||
|
||||
GO := go
|
||||
GO110 := 1.10
|
||||
|
@ -168,10 +169,10 @@ tests/testreport/testreport: tests/testreport/testreport.go
|
|||
|
||||
.PHONY: test-unit
|
||||
test-unit: tests/testreport/testreport
|
||||
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -race $(shell $(GO) list ./... | grep -v vendor | grep -v tests | grep -v cmd) -timeout 45m
|
||||
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover $(RACEFLAGS) $(shell $(GO) list ./... | grep -v vendor | grep -v tests | grep -v cmd) -timeout 45m
|
||||
tmp=$(shell mktemp -d) ; \
|
||||
mkdir -p $$tmp/root $$tmp/runroot; \
|
||||
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -race ./cmd/buildah -args --root $$tmp/root --runroot $$tmp/runroot --storage-driver vfs --signature-policy $(shell pwd)/tests/policy.json --registries-conf $(shell pwd)/tests/registries.conf
|
||||
$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover $(RACEFLAGS) ./cmd/buildah -args --root $$tmp/root --runroot $$tmp/runroot --storage-driver vfs --signature-policy $(shell pwd)/tests/policy.json --registries-conf $(shell pwd)/tests/registries.conf
|
||||
|
||||
vendor-in-container:
|
||||
podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src docker.io/library/golang:1.16 make vendor
|
||||
|
|
17
run_linux.go
17
run_linux.go
|
@ -17,6 +17,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
@ -891,7 +892,7 @@ func runUsingRuntime(isolation define.Isolation, options RunOptions, configureNe
|
|||
if err != nil {
|
||||
return 1, errors.Wrapf(err, "error parsing pid %s as a number", string(pidValue))
|
||||
}
|
||||
stopped := false
|
||||
var stopped uint32
|
||||
var reaping sync.WaitGroup
|
||||
reaping.Add(1)
|
||||
go func() {
|
||||
|
@ -902,7 +903,7 @@ func runUsingRuntime(isolation define.Isolation, options RunOptions, configureNe
|
|||
wstatus = 0
|
||||
options.Logger.Errorf("error waiting for container child process %d: %v\n", pid, err)
|
||||
}
|
||||
stopped = true
|
||||
atomic.StoreUint32(&stopped, 1)
|
||||
}()
|
||||
|
||||
if configureNetwork {
|
||||
|
@ -935,7 +936,7 @@ func runUsingRuntime(isolation define.Isolation, options RunOptions, configureNe
|
|||
return 1, errors.Wrapf(err, "error from %s starting container", runtime)
|
||||
}
|
||||
defer func() {
|
||||
if !stopped {
|
||||
if atomic.LoadUint32(&stopped) == 0 {
|
||||
if err2 := kill.Run(); err2 != nil {
|
||||
options.Logger.Infof("error from %s stopping container: %v", runtime, err2)
|
||||
}
|
||||
|
@ -952,7 +953,7 @@ func runUsingRuntime(isolation define.Isolation, options RunOptions, configureNe
|
|||
stat.Stderr = os.Stderr
|
||||
stateOutput, err := stat.Output()
|
||||
if err != nil {
|
||||
if stopped {
|
||||
if atomic.LoadUint32(&stopped) != 0 {
|
||||
// container exited
|
||||
break
|
||||
}
|
||||
|
@ -964,20 +965,20 @@ func runUsingRuntime(isolation define.Isolation, options RunOptions, configureNe
|
|||
switch state.Status {
|
||||
case "running":
|
||||
case "stopped":
|
||||
stopped = true
|
||||
atomic.StoreUint32(&stopped, 1)
|
||||
default:
|
||||
return 1, errors.Errorf("container status unexpectedly changed to %q", state.Status)
|
||||
}
|
||||
if stopped {
|
||||
if atomic.LoadUint32(&stopped) != 0 {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case <-finishedCopy:
|
||||
stopped = true
|
||||
atomic.StoreUint32(&stopped, 1)
|
||||
case <-time.After(time.Until(now.Add(100 * time.Millisecond))):
|
||||
continue
|
||||
}
|
||||
if stopped {
|
||||
if atomic.LoadUint32(&stopped) != 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue