From: Matus Fabian Date: Mon, 16 Jun 2025 12:17:02 +0000 (-0400) Subject: hs-test: WaitForCoreDump improvement X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=6628ef6647a7a985e14cbdcb10f2ad12a6cd5795;p=vpp.git hs-test: WaitForCoreDump improvement - multiple core files support - choose correct app binary in gdb bt (before vpp only) - paltform independent solib-search-path (before x86_64 only) Type: test Change-Id: I70f48defcdfc6821e321b4b15ba95ad245407db0 Signed-off-by: Matus Fabian --- diff --git a/extras/hs-test/hs_test.sh b/extras/hs-test/hs_test.sh index 0254d0b5a9a..96d287a6589 100644 --- a/extras/hs-test/hs_test.sh +++ b/extras/hs-test/hs_test.sh @@ -204,9 +204,8 @@ Suite: Message:\n" + ( if .ReportEntries? then - (.ReportEntries[] | select(.Name == "VPP Backtrace") | - "\tVPP crashed -Full Back Trace: + (.ReportEntries[] | select(.Name | contains("Backtrace")) | + "\tFull Back Trace: \(.Value.Representation | ltrimstr("{{red}}") | rtrimstr("{{/}}"))" ) // "\(.Failure.Message)" else diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go index 039d0047f9c..dc06934e4cb 100644 --- a/extras/hs-test/infra/hst_suite.go +++ b/extras/hs-test/infra/hst_suite.go @@ -299,8 +299,13 @@ func (s *HstSuite) SkipIfArm() { } } +type coreInfo struct { + file string + binPath string +} + func (s *HstSuite) WaitForCoreDump() bool { - var filename string + var coreFiles []coreInfo dir, err := os.Open(s.getLogDirPath()) if err != nil { s.Log(err) @@ -314,15 +319,21 @@ func (s *HstSuite) WaitForCoreDump() bool { return false } for _, file := range files { - if strings.Contains(file, "core") { - filename = file + coreBin, isCore := s.GetCoreProcessName(s.getLogDirPath() + file) + if isCore { + coreFiles = append(coreFiles, coreInfo{file, coreBin}) } } timeout := 60 waitTime := 5 - if filename != "" { - corePath := s.getLogDirPath() + filename + if len(coreFiles) == 0 { + return false + } + arch, _ := exechelper.Output("uname -m") + archStr := strings.TrimSpace(string(arch)) + for _, core := range coreFiles { + corePath := s.getLogDirPath() + core.file s.Log(fmt.Sprintf("WAITING FOR CORE DUMP (%s)", corePath)) for i := waitTime; i <= timeout; i += waitTime { fileInfo, err := os.Stat(corePath) @@ -340,13 +351,33 @@ func (s *HstSuite) WaitForCoreDump() bool { if *IsDebugBuild { debug = "_debug" } - vppBinPath := fmt.Sprintf("../../build-root/build-vpp%s-native/vpp/bin/vpp", debug) - pluginsLibPath := fmt.Sprintf("build-root/build-vpp%s-native/vpp/lib/x86_64-linux-gnu/vpp_plugins", debug) - cmd := fmt.Sprintf("sudo gdb %s -c %s -ex 'set solib-search-path %s/%s' -ex 'bt full' -batch", vppBinPath, corePath, *VppSourceFileDir, pluginsLibPath) + var binPath, libPath string + if strings.Contains(core.binPath, "vpp") { + binPath = fmt.Sprintf("../../build-root/build-vpp%s-native/vpp/bin/vpp", debug) + libPath = fmt.Sprintf("build-root/build-vpp%s-native/vpp/lib/%s-linux-gnu/vpp_plugins", debug, archStr) + + } else { + binPath = core.binPath + // this was most likely LDP and we want symbol table + libPath = fmt.Sprintf("build-root/build-vpp%s-native/vpp/lib/%s-linux-gnu", debug, archStr) + } + cmd := fmt.Sprintf("sudo gdb %s -c %s -ex 'set solib-search-path %s/%s' -ex 'bt full' -batch", binPath, corePath, *VppSourceFileDir, libPath) s.Log(cmd) output, _ := exechelper.Output(cmd) - AddReportEntry("VPP Backtrace", StringerStruct{Label: string(output)}) - os.WriteFile(s.getLogDirPath()+"backtrace.log", output, os.FileMode(0644)) + if strings.Contains(core.binPath, "vpp") { + AddReportEntry("VPP Backtrace", StringerStruct{Label: string(output)}) + } else { + AddReportEntry("APP Backtrace", StringerStruct{Label: string(output)}) + } + f, err := os.OpenFile(s.getLogDirPath()+"backtrace.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, os.FileMode(0644)) + if err != nil { + s.Log("Error opening backtrace.log: " + fmt.Sprint(err)) + } else { + if _, err := f.Write(output); err != nil { + s.Log("Error writing backtrace.log: " + fmt.Sprint(err)) + } + f.Close() + } if RunningInCi { err = os.Remove(corePath) if err == nil { @@ -355,11 +386,11 @@ func (s *HstSuite) WaitForCoreDump() bool { s.Log(err) } } - return true + break } } } - return false + return true } func (s *HstSuite) ResetContainers() { diff --git a/extras/hs-test/infra/utils.go b/extras/hs-test/infra/utils.go index 8be7fb510c7..e320345d5ab 100644 --- a/extras/hs-test/infra/utils.go +++ b/extras/hs-test/infra/utils.go @@ -12,6 +12,8 @@ import ( "os/exec" "strings" "time" + + "github.com/edwarnicke/exechelper" ) const networkTopologyDir string = "topo-network/" @@ -308,3 +310,20 @@ func (s *HstSuite) StartClientApp(c *Container, cmd string, clnRes <- o } } + +func (s *HstSuite) GetCoreProcessName(file string) (string, bool) { + cmd := fmt.Sprintf("sudo file -b %s", file) + output, _ := exechelper.Output(cmd) + outputStr := string(output) + // ELF 64-bit LSB core file, x86-64, version 1 (SYSV), SVR4-style, from 'vpp -c /tmp/server/etc/vpp/startup.conf', real uid: 0, effective uid: 0, real gid: 0, effective gid: 0, execfn: '/usr/bin/vpp', platform: 'x86_64' + if !strings.Contains(outputStr, "core file") { + return "", false + } + soutputSplit := strings.Split(outputStr, ",") + for _, tmp := range soutputSplit { + if strings.Contains(tmp, "execfn:") { + return strings.Trim(strings.Split(tmp, ": ")[1], "'"), true + } + } + return "", false +}