@@ -18,7 +18,6 @@ import (
1818 "context"
1919 "fmt"
2020 "io"
21- "math"
2221 "sort"
2322 "sync"
2423 "testing"
@@ -73,15 +72,15 @@ const (
7372 isisRoutev6 = "2001:db8::203:0:113:1"
7473 startingISISRouteIPv4 = "199.0.0.1/32"
7574 startingISISRouteIPv6 = "2001:db8::203:0:113:1/128"
76- aftConvergenceTime = 20 * time .Minute
75+ aftConvergenceTime = 40 * time .Minute
7776 bgpTimeout = 10 * time .Minute
78- bgpRouteCountIPv4LowScale = 1500
79- bgpRouteCountIPv6LowScale = 5000
80- bgpRouteCountIPv4Default = 2000
81- bgpRouteCountIPv6Default = 1000
77+ bgpRouteCountIPv4LowScale = 1250000
78+ bgpRouteCountIPv6LowScale = 500000
79+ bgpRouteCountIPv4Default = 2000000
80+ bgpRouteCountIPv6Default = 1000000
8281 policyStatementID = "id-1"
83- cpuPctThreshold = 5 .0
84- memPctThreshold = 2 .0
82+ cpuPctThreshold = 80 .0
83+ memPctThreshold = 80 .0
8584 usagePollingInterval = 5 * time .Second
8685)
8786
@@ -613,13 +612,13 @@ func (tc *testCase) verifyInitialAFT(t *testing.T, ctx1 context.Context, aftSess
613612}
614613
615614type usageRecord struct {
616- time time.Time
617- process string
618- metric string
619- before float64
620- after float64
621- changePct float64
622- desc string
615+ time time.Time
616+ process string
617+ metric string
618+ before float64
619+ after float64
620+ usedPct float64
621+ desc string
623622}
624623
625624type usageHistory struct {
@@ -648,11 +647,11 @@ func (h *usageHistory) print(t *testing.T) {
648647 })
649648
650649 t .Log ("Usage Summary Table:" )
651- t .Logf ("%-25s | %-15s | %-10s | %-10s | %-10s | %-10s | %s" , "Time" , "Process" , "Metric" , "Before" , "After" , "Change (%)" , "Description" )
652- t .Log ("-----------------------------------------------------------------------------------------------------------------------------" )
650+ t .Logf ("%-25s | %-15s | %-10s | %-10s | %-10s | %-10s | %s" , "Time" , "Process" , "Metric" , "Before" , "After" , "Used (%)" , "Description" )
651+ t .Log ("------------------------------------------------------------------------------------------------------------------------------------------------- " )
653652 for _ , r := range h .records {
654653 t .Logf ("%-25s | %-15s | %-10s | %-10.2f | %-10.2f | %-10.2f | %s" ,
655- r .time .Format ("15:04:05.000" ), r .process , r .metric , r .before , r .after , r .changePct , r .desc )
654+ r .time .Format ("15:04:05.000" ), r .process , r .metric , r .before , r .after , r .usedPct , r .desc )
656655 }
657656}
658657
@@ -661,6 +660,8 @@ func (h *usageHistory) print(t *testing.T) {
661660func checkMemoryUsage (t * testing.T , dut * ondatra.DUTDevice , history * usageHistory , memBefore uint64 , desc string , procName ... string ) uint64 {
662661 t .Helper ()
663662 var memAfter uint64
663+ var totalMem uint64
664+ var usedMemPct float64
664665 // TODO: Add memory usage check for Default case.
665666 pName := "system"
666667 if len (procName ) > 0 && procName [0 ] != "" {
@@ -671,39 +672,36 @@ func checkMemoryUsage(t *testing.T, dut *ondatra.DUTDevice, history *usageHistor
671672 case ondatra .ARISTA :
672673 t .Logf ("Checking memory usage %s." , desc )
673674 memAfter = gnmi .Get (t , dut , gnmi .OC ().System ().Memory ().Used ().State ())
675+ totalMem = gnmi .Get (t , dut , gnmi .OC ().System ().Memory ().Physical ().State ())
676+ usedMemPct = (float64 (memAfter ) / float64 (totalMem )) * 100
674677 case ondatra .CISCO :
675678 if pName == "system" {
676679 t .Fatal ("Process name must be provided for Cisco memory check." )
677680 }
678681 pid := getProcessPid (t , dut , pName )
679682 t .Logf ("Checking memory usage for %s process (PID: %d) %s." , pName , pid , desc )
680683 memAfter = uint64 (gnmi .Get (t , dut , gnmi .OC ().System ().Process (pid ).MemoryUtilization ().State ()))
684+ usedMemPct = float64 (memAfter ) // Cisco returns percentage directly
681685 default :
682686 t .Logf ("Skipping memory usage check for non-ARISTA and non-CISCO device: %v." , dut .Vendor ())
683687 return memBefore // Return previous value to not break chaining.
684688 }
685689
686- var increase float64
687- if memBefore == 0 {
688- increase = float64 (memAfter )
690+ if usedMemPct > memPctThreshold {
691+ t .Errorf ("Memory usage for process %s is %.2f%% of total memory, which is more than the %.f%% threshold." , pName , usedMemPct , memPctThreshold )
689692 } else {
690- increase = (float64 (memAfter ) - float64 (memBefore )) / float64 (memBefore ) * 100
691- }
692- changePct := math .Max (0 , increase )
693- if increase > memPctThreshold {
694- t .Errorf ("Memory usage for process %s increased by %.2f%%, which is more than the %.f%% threshold." , pName , increase , memPctThreshold )
695- } else {
696- t .Logf ("Memory usage change for process %s is %.2f%%, which is within the %.f%% threshold." , pName , changePct , memPctThreshold )
693+ t .Logf ("Memory usage for process %s is %.2f%% of total memory, which is within the %.f%% threshold." , pName , usedMemPct , memPctThreshold )
697694 }
695+
698696 if history != nil {
699697 history .add (usageRecord {
700- time : time .Now (),
701- process : pName ,
702- metric : "Memory" ,
703- before : float64 (memBefore ),
704- after : float64 (memAfter ),
705- changePct : changePct ,
706- desc : desc ,
698+ time : time .Now (),
699+ process : pName ,
700+ metric : "Memory" ,
701+ before : float64 (memBefore ),
702+ after : float64 (memAfter ),
703+ usedPct : usedMemPct ,
704+ desc : desc ,
707705 })
708706 }
709707 return memAfter
@@ -743,6 +741,7 @@ func getCPUComponents(t *testing.T, dut *ondatra.DUTDevice) []string {
743741func checkCPUUsage (t * testing.T , dut * ondatra.DUTDevice , history * usageHistory , cpuBefore uint64 , desc string , cpuComponent string , procName ... string ) uint64 {
744742 t .Helper ()
745743 var cpuAfter uint64
744+ var usedCPUPct float64
746745 var pName string // Identifier for logging: component name for Arista, process name for Cisco.
747746
748747 switch dut .Vendor () {
@@ -765,28 +764,21 @@ func checkCPUUsage(t *testing.T, dut *ondatra.DUTDevice, history *usageHistory,
765764 t .Logf ("Skipping CPU usage check for non-ARISTA and non-CISCO device: %v." , dut .Vendor ())
766765 return cpuBefore // Return previous value to not break chaining.
767766 }
768-
769- var increase float64
770- if cpuBefore == 0 {
771- increase = float64 (cpuAfter )
772- } else {
773- increase = (float64 (cpuAfter ) - float64 (cpuBefore )) / float64 (cpuBefore ) * 100
774- }
775- changePct := math .Max (0 , increase )
776- if increase > cpuPctThreshold {
777- t .Errorf ("CPU usage for process %s increased by %.2f%%, which is more than the %.f%% threshold." , pName , increase , cpuPctThreshold )
767+ usedCPUPct = float64 (cpuAfter )
768+ if usedCPUPct > cpuPctThreshold {
769+ t .Errorf ("CPU usage for process %s increased by %.2f%%, which is more than the %.f%% threshold." , pName , usedCPUPct , cpuPctThreshold )
778770 } else {
779- t .Logf ("CPU usage change for process %s is %.2f%%, which is within the %.f%% threshold." , pName , changePct , cpuPctThreshold )
771+ t .Logf ("CPU usage change for process %s is %.2f%%, which is within the %.f%% threshold." , pName , usedCPUPct , cpuPctThreshold )
780772 }
781773 if history != nil {
782774 history .add (usageRecord {
783- time : time .Now (),
784- process : pName ,
785- metric : "CPU" ,
786- before : float64 (cpuBefore ),
787- after : float64 (cpuAfter ),
788- changePct : changePct ,
789- desc : desc ,
775+ time : time .Now (),
776+ process : pName ,
777+ metric : "CPU" ,
778+ before : float64 (cpuBefore ),
779+ after : float64 (cpuAfter ),
780+ usedPct : float64 ( usedCPUPct ) ,
781+ desc : desc ,
790782 })
791783 }
792784 return cpuAfter
0 commit comments