def METHOD_NAME(p):
  p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
  p.set_can_loopback(True)
  for i in range(250):
    sent_msgs = defaultdict(set)
    for _ in range(random.randrange(10)):
      to_send = get_random_can_messages(random.randrange(100))
      for m in to_send:
        sent_msgs[m[3]].add((m[0], m[2]))
      p.can_send_many(to_send, timeout=0)
    start_time = time.monotonic()
    while time.monotonic() - start_time < 2 and any(len(sent_msgs[bus]) for bus in range(3)):
      recvd = p.can_recv()
      for msg in recvd:
        if msg[3] >= 128:
          k = (msg[0], bytes(msg[2]))
          bus = msg[3]-128
          assert k in sent_msgs[bus], f"message {k} was never sent on bus {bus}"
          sent_msgs[msg[3]-128].discard(k)
    # if a set isn't empty, messages got dropped
    for bus in range(3):
      assert not len(sent_msgs[bus]), f"loop {i}: bus {bus} missing {len(sent_msgs[bus])} messages"
  print("Got all messages intact")