diff options
author | 2025-03-11 08:05:31 -0400 | |
---|---|---|
committer | 2025-03-11 10:28:07 -0400 | |
commit | f6b4221943c5aefd8f6dda7909703149b8c19d76 (patch) | |
tree | 6e53b97dc0811409ccb7c159b0fe0a8c7d9f28ef /extras | |
parent | e128af1690ae77e0232cf814fb6bddd5185fd340 (diff) |
hs-test: shutdown VPP cleanly when finishing a testcase
Good practice in general, but especially helpful when SIGKILL'd VPP
can't write out coverage data.
Type: fix
Change-Id: I7e7261b6f2e63fd4a6b24a3832c32800c71493c2
Signed-off-by: Semir Sionek <ssionek@cisco.com>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/hs-test/Makefile | 2 | ||||
-rw-r--r-- | extras/hs-test/hs_test.sh | 8 | ||||
-rw-r--r-- | extras/hs-test/infra/container.go | 7 | ||||
-rw-r--r-- | extras/hs-test/infra/hst_suite.go | 3 | ||||
-rw-r--r-- | extras/hs-test/infra/vppinstance.go | 8 |
5 files changed, 25 insertions, 3 deletions
diff --git a/extras/hs-test/Makefile b/extras/hs-test/Makefile index 69d9fb26da8..5d0940102e8 100644 --- a/extras/hs-test/Makefile +++ b/extras/hs-test/Makefile @@ -148,7 +148,7 @@ wipe-lcov: .PHONY: test-cov test-cov: FORCE_BUILD=false test-cov: .deps.ok .build.cov.ok wipe-lcov - @bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \ + @bash ./hs_test.sh --coverage=true --persist=$(PERSIST) --verbose=$(VERBOSE) \ --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \ --vppsrc=$(VPPSRC) --cpu0=$(CPU0) --dryrun=$(DRYRUN) --skip=$(SKIP) --no_color=$(NO_COLOR); \ ./script/compress.sh $$? diff --git a/extras/hs-test/hs_test.sh b/extras/hs-test/hs_test.sh index f333b60203d..e67eb7d20ef 100644 --- a/extras/hs-test/hs_test.sh +++ b/extras/hs-test/hs_test.sh @@ -6,6 +6,7 @@ args= focused_test=0 persist_set=0 dryrun_set=0 +coverage_set=0 unconfigure_set=0 debug_set=0 leak_check_set=0 @@ -26,6 +27,13 @@ case "${i}" in persist_set=1 fi ;; + --coverage=*) + coverage="${i#*=}" + if [ "$coverage" = "true" ]; then + args="$args -coverage" + coverage_set=1 + fi + ;; --debug=*) debug="${i#*=}" if [ "$debug" = "true" ]; then diff --git a/extras/hs-test/infra/container.go b/extras/hs-test/infra/container.go index 6605c866939..918c19e669e 100644 --- a/extras/hs-test/infra/container.go +++ b/extras/hs-test/infra/container.go @@ -533,12 +533,15 @@ func (c *Container) stop() error { if c.VppInstance != nil && c.VppInstance.ApiStream != nil { c.VppInstance.saveLogs() c.VppInstance.Disconnect() + c.VppInstance.Stop() } + timeout := 0 c.VppInstance = nil c.saveLogs() - c.Suite.Log("Stopping container " + c.Name) - timeout := 0 + if c.Suite.CoverageRun { + timeout = 3 + } if err := c.Suite.Docker.ContainerStop(c.ctx, c.ID, containerTypes.StopOptions{Timeout: &timeout}); err != nil { return err } diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go index d91958e33d9..d44b76f3e1f 100644 --- a/extras/hs-test/infra/hst_suite.go +++ b/extras/hs-test/infra/hst_suite.go @@ -34,6 +34,7 @@ const ( var IsPersistent = flag.Bool("persist", false, "persists topology config") var IsVerbose = flag.Bool("verbose", false, "verbose test output") +var IsCoverage = flag.Bool("coverage", false, "use coverage run config") var IsUnconfiguring = flag.Bool("unconfigure", false, "remove topology") var IsVppDebug = flag.Bool("debug", false, "attach gdb to vpp") var NConfiguredCpus = flag.Int("cpus", 1, "number of CPUs assigned to vpp") @@ -62,6 +63,7 @@ type HstSuite struct { Logger *log.Logger LogFile *os.File Docker *client.Client + CoverageRun bool } type colors struct { @@ -170,6 +172,7 @@ func (s *HstSuite) SetupSuite() { Fail("failed to init cpu allocator: " + fmt.Sprint(err)) } s.CpuCount = *NConfiguredCpus + s.CoverageRun = *IsCoverage } func (s *HstSuite) AllocateCpus(containerName string) []int { diff --git a/extras/hs-test/infra/vppinstance.go b/extras/hs-test/infra/vppinstance.go index d9aa418c5ec..370d2be38d1 100644 --- a/extras/hs-test/infra/vppinstance.go +++ b/extras/hs-test/infra/vppinstance.go @@ -242,6 +242,14 @@ func (vpp *VppInstance) Start() error { return nil } +func (vpp *VppInstance) Stop() { + pid := strings.TrimSpace(vpp.Container.Exec(false, "pidof vpp")) + // Stop VPP only if it's still running + if len(pid) > 0 { + vpp.Container.Exec(false, "bash -c \"kill -15 "+pid+"\"") + } +} + func (vpp *VppInstance) Vppctl(command string, arguments ...any) string { vppCliCommand := fmt.Sprintf(command, arguments...) containerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s", |