hs-test: fix a runtime error 08/41908/2
authorAdrian Villin <[email protected]>
Thu, 12 Dec 2024 08:16:22 +0000 (09:16 +0100)
committerFlorin Coras <[email protected]>
Thu, 12 Dec 2024 16:46:35 +0000 (16:46 +0000)
- framework panicked if core_pattern was set to "core"

Type: test

Change-Id: I14211cc59779090a61e6e08a18d16fd7399b2bed
Signed-off-by: Adrian Villin <[email protected]>
extras/hs-test/infra/container.go

index f6ccd88..6605c86 100644 (file)
@@ -331,8 +331,12 @@ func (c *Container) getVolumesAsSlice() []string {
        if err == nil {
                if len(core_pattern) > 0 && core_pattern[0] != '|' {
                        index := strings.LastIndex(core_pattern, "/")
-                       core_pattern = core_pattern[:index]
-                       volumeSlice = append(volumeSlice, c.Suite.getLogDirPath()+":"+core_pattern)
+                       if index == -1 {
+                               c.Suite.Log("'core_pattern' isn't set to an absolute path. Core dump check will not work.")
+                       } else {
+                               core_pattern = core_pattern[:index]
+                               volumeSlice = append(volumeSlice, c.Suite.getLogDirPath()+":"+core_pattern)
+                       }
                } else {
                        c.Suite.Log(fmt.Sprintf("core_pattern \"%s\" starts with pipe, ignoring", core_pattern))
                }