@@ -3328,21 +3328,44 @@ 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 (
3345+ "Negative check for pkt on device %d, ports %s" ,
3346+ device_number , ports
3347+ )
3348+ start = time .time ()
3349+ while True :
3350+ remaining = timeout - (time .time () - start )
3351+ if remaining <= 0 :
3352+ return True # PASS - packet not observed within timeout window
3353+
3354+ for port in ports :
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 ("Unexpected packet received on device %d, port %d" % (device_number , port ))
3365+
3366+ # Small sleep to avoid busy-looping and excessive CPU usage.
3367+ # Also gives dataplane threads time to enqueue incoming packets.
3368+ time .sleep (0.001 )
33463369
33473370
33483371def verify_packets_any (
0 commit comments