hs-test: parse bytes/sec in TcpWithLoss tests 98/43598/2
authorAdrian Villin <[email protected]>
Wed, 27 Aug 2025 10:39:53 +0000 (12:39 +0200)
committerAdrian Villin <[email protected]>
Wed, 27 Aug 2025 12:02:45 +0000 (12:02 +0000)
Type: test

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

index 0d6c5eb..3dada0e 100644 (file)
@@ -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)
        }
 }
index c00cb9b..e63b8e4 100644 (file)
@@ -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`)
 }