hs-test: shutdown VPP cleanly when finishing a testcase 69/42469/2
authorSemir Sionek <[email protected]>
Tue, 11 Mar 2025 12:05:31 +0000 (08:05 -0400)
committerSemir Sionek <[email protected]>
Tue, 11 Mar 2025 14:28:07 +0000 (10:28 -0400)
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 <[email protected]>
extras/hs-test/Makefile
extras/hs-test/hs_test.sh
extras/hs-test/infra/container.go
extras/hs-test/infra/hst_suite.go
extras/hs-test/infra/vppinstance.go

index 69d9fb2..5d09401 100644 (file)
@@ -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 $$?
index f333b60..e67eb7d 100644 (file)
@@ -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
index 6605c86..918c19e 100644 (file)
@@ -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
        }
index d91958e..d44b76f 100644 (file)
@@ -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 {
index d9aa418..370d2be 100644 (file)
@@ -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",