From a651798373386f61c99974716736b9200c1befe9 Mon Sep 17 00:00:00 2001 From: Adrian Villin Date: Wed, 27 Aug 2025 12:39:53 +0200 Subject: [PATCH] hs-test: parse bytes/sec in TcpWithLoss tests Type: test Change-Id: I29ff3caa6a1f573a7e285c17416a24a74f4767f7 Signed-off-by: Adrian Villin --- extras/hs-test/echo_test.go | 6 +++--- extras/hs-test/infra/utils.go | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/extras/hs-test/echo_test.go b/extras/hs-test/echo_test.go index 0d6c5eb13a3..3dada0eda5d 100644 --- a/extras/hs-test/echo_test.go +++ b/extras/hs-test/echo_test.go @@ -170,7 +170,7 @@ func TcpWithLossTest(s *VethsSuite) { s.AssertNil(err) if !s.CoverageRun { - s.Log("\nBaseline: %v gbit/s\nWith loss: %v gbit/s", baseline, withLoss) + s.Log("\nBaseline: %.2f bytes/s\nWith loss: %.2f bytes/s", baseline, withLoss) s.AssertGreaterEqual(baseline, withLoss) s.AssertGreaterEqual(withLoss, baseline*0.2) } @@ -225,8 +225,8 @@ func TcpWithLoss6Test(s *Veths6Suite) { s.AssertNil(err) if !s.CoverageRun { - s.Log("Baseline: %v gbit/s\nWith loss: %v gbit/s", baseline, withLoss) + s.Log("\nBaseline: %.2f bytes/s\nWith loss: %.2f bytes/s", baseline, withLoss) s.AssertGreaterEqual(baseline, withLoss) - s.AssertGreaterEqual(withLoss, baseline*0.2) + s.AssertGreaterEqual(withLoss, baseline*0.15) } } diff --git a/extras/hs-test/infra/utils.go b/extras/hs-test/infra/utils.go index c00cb9bc401..e63b8e44a31 100644 --- a/extras/hs-test/infra/utils.go +++ b/extras/hs-test/infra/utils.go @@ -368,13 +368,19 @@ func (s *HstSuite) StartUdpEchoServer(addr string, port int) *net.UDPConn { return conn } -// Parses transfer speed from the last line ("N gbit/second full-duplex") +// Parses transfer speed ("N bytes/second full-duplex") func (s *HstSuite) ParseEchoClientTransfer(stats string) (float64, error) { lines := strings.Split(strings.TrimSpace(stats), "\n") - parts := strings.Fields(lines[len(lines)-1]) - if len(parts) == 0 { - return 0, errors.New("check format of stats") + for i := len(lines) - 1; i >= 0; i-- { + line := strings.TrimSpace(lines[i]) + if strings.Contains(line, "bytes/second") { + parts := strings.Fields(line) + if len(parts) == 0 { + return 0, errors.New("check format of stats") + } + num := strings.ReplaceAll(parts[0], ",", "") + return strconv.ParseFloat(num, 64) + } } - number, err := strconv.ParseFloat(parts[0], 64) - return number, err + return 0, errors.New(`"bytes/second" not found`) } -- 2.16.6