@@ -3328,21 +3328,47 @@ def verify_packets(test, pkt, ports=[], device_number=0, timeout=None, n_timeout
33283328 verify_no_other_packets (test , device_number = device_number , timeout = n_timeout )
33293329
33303330
3331- def verify_no_packet_any (test , pkt , ports = [], device_number = 0 , timeout = None ):
3331+ def verify_no_packet_any (test , pkt , ports = [], device_number = 0 , timeout = 1 ):
33323332 """
3333- Check that a packet is NOT received on _any_ of the specified ports belonging to
3334- the given device (default device_number is 0).
3333+ Verify that a packet is NOT received on any of the specified ports belonging to
3334+ the given device within the given timeout. Uses a single global timeout and repeatedly
3335+ polls all ports with zero per-port timeout.
3336+ Raises:
3337+ test.fail if the packet is received on any of the specified ports.
33353338 """
33363339 test .assertTrue (
33373340 len (ports ) != 0 ,
33383341 "No port available to validate receiving packet on device %d, " % device_number ,
33393342 )
3340- for device , port in ptf_ports ():
3341- if device != device_number :
3342- continue
3343- if port in ports :
3344- print ("verifying packet on port device" , device_number , "port" , port )
3345- verify_no_packet (test , pkt , (device , port ), timeout = timeout )
3343+ ports = list (ports )
3344+ logging .debug ("Negative check for pkt on device %d, ports %s" , device_number , ports )
3345+ start = time .monotonic ()
3346+ while True :
3347+ remaining = timeout - (time .monotonic () - start )
3348+ if remaining <= 0 :
3349+ return # PASS - packet not observed within timeout window
3350+
3351+ for device , port in ptf_ports ():
3352+ if device != device_number or port not in ports :
3353+ continue
3354+
3355+ result = dp_poll (
3356+ test ,
3357+ device_number = device_number ,
3358+ port_number = port ,
3359+ timeout = 0 , # non-blocking poll
3360+ exp_pkt = pkt ,
3361+ )
3362+
3363+ if isinstance (result , test .dataplane .PollSuccess ):
3364+ test .fail (
3365+ "Unexpected packet received on device %d, port %d"
3366+ % (device_number , port )
3367+ )
3368+
3369+ # Small sleep to avoid busy-looping and excessive CPU usage.
3370+ # Also gives dataplane threads time to enqueue incoming packets.
3371+ time .sleep (0.05 )
33463372
33473373
33483374def verify_packets_any (
0 commit comments