From nobody Wed Nov 9 12:09:49 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N6kL621FGz4dByR; Wed, 9 Nov 2022 12:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N6kL61QgWz3w1D; Wed, 9 Nov 2022 12:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667995790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6XWo06zRSLQQjp5dRtEr5Fhx5WFf2nt12ShlWncoHM0=; b=dbWPBAYa9ythC4REr/rSbYt0s4kVQU95xC0G4W08TorvhAp3I35wQlvK321hWxs05+GWfp niYBj88oKYEoUIZ0sjHq4iuBfMTgo8EL7gS6vnmKBdp+Peu1oXSN8YV5wANOeLpJA49B89 U7hh8lSxJ7bxs0PeykUhVrMp3n+DBYtEyaKOWHk+NRpLrzMsE2SGkbZybThSl9clRLxFr+ B6g1iGt/zbjB2EfPEw9zWohfppx4GfcWAViinHBihNufMh4BqXpbIXsq0aJ6YRo4XMO7ar j2oVT35BlpLbSN9KZ3CBLH+U3Sz0Qthm54Ka3JpUD2IINS6RG700Tz5F8KOBdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667995790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6XWo06zRSLQQjp5dRtEr5Fhx5WFf2nt12ShlWncoHM0=; b=vZ2Blmuuqc1Uy8504QLd8bONnQfhgwVJs4G3Ofq7bJKvg+cN8qZVpO0zgReHyWZstRvrbT 7Gpej2kcprpR2k9zYaQoWfjN4y7pF2UfnhaNYbt3IDrAYnrWKUXbJA3i4FMDtvTgm4weKo EWSzQt9iIQwvfQQGAvZcR7Yy7Q3DNN79pfdqklrejz1+VkqVzCbc4e5MVt6SArxKHg1wgR TAMmESkvju9zfB4c/P+xWKZXte6zbqTcM/GI49qjk+QmdcqBHBl0DwUPEMUAJw5AIvcxK8 XVEOUMdCIQD71nldLJ7Tlvg0qgEWC2Q/G9AvV2Rea5R3sAwb9dq1qK09cveHvg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667995790; a=rsa-sha256; cv=none; b=x7vXDouyKsfwjENVdnfY/f5t8SQ4OQHNXo+ZaHSmk/0RIyvIotqlil8kByVmEu9+XfF+Ul uQpjt5HJ185Si4pjLYntuihYFyG/ZMI7I1VTiEL0JZy14hlc8cpVjfVkiJmiW5Ik7dr7KG xjOf+JjpfFTbLGJ81QiRNA4uqJmuRueSmuEksBKtOz0nBLIn5rAufLmwNVN3ivSJJyRCSg H1TBKUTUhD1A5jwCT8dL0ABslpt31GGl0cBQH58MeKO3Yr5RVLlr2abkLIc6kIYMIkv6Py ZPQBXaPC6jN6tYZ5z5h4JcjiaEodc5uycohuRV57z0uOH7zaU284kL9fMoJk6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4N6kL60L4wzLqm; Wed, 9 Nov 2022 12:09:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2A9C9nHi047303; Wed, 9 Nov 2022 12:09:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A9C9nNa047302; Wed, 9 Nov 2022 12:09:49 GMT (envelope-from git) Date: Wed, 9 Nov 2022 12:09:49 GMT Message-Id: <202211091209.2A9C9nNa047302@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 1b43f8cd07fc - stable/13 - tests: make sniffer more robust List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1b43f8cd07fc186652ad369ea189498308ce1b4e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=1b43f8cd07fc186652ad369ea189498308ce1b4e commit 1b43f8cd07fc186652ad369ea189498308ce1b4e Author: Kristof Provost AuthorDate: 2022-11-02 10:55:39 +0000 Commit: Kristof Provost CommitDate: 2022-11-09 08:17:00 +0000 tests: make sniffer more robust The Sniffer class is often used by test tools such as pft_ping to verify that packets actually get sent where they're expected. It starts a background thread to capture packets, but this thread needs some time to start, leading to intermittent test failures when the capture doesn't start before the relevant packet is sent. Add a semaphore to ensure the Sniffer constructor doesn't return until the capture is actually running. PR: 260461 MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 67557372dfef87eb94681a97a4157198efe21992) --- tests/sys/netpfil/common/sniffer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/sys/netpfil/common/sniffer.py b/tests/sys/netpfil/common/sniffer.py index a7ebfc122573..5e09a2e4db37 100644 --- a/tests/sys/netpfil/common/sniffer.py +++ b/tests/sys/netpfil/common/sniffer.py @@ -34,6 +34,7 @@ class Sniffer(threading.Thread): def __init__(self, args, check_function, recvif=None, timeout=3): threading.Thread.__init__(self) + self._sem = threading.Semaphore(0) self._args = args self._timeout = timeout if recvif is not None: @@ -44,6 +45,8 @@ class Sniffer(threading.Thread): self.foundCorrectPacket = False self.start() + if not self._sem.acquire(timeout=30): + raise Exception("Failed to start sniffer") def _checkPacket(self, packet): ret = self._check_function(self._args, packet) @@ -51,10 +54,14 @@ class Sniffer(threading.Thread): self.foundCorrectPacket = True return ret + def _startedCb(self): + self._sem.release() + def run(self): self.packets = [] try: self.packets = sp.sniff(iface=self._recvif, - stop_filter=self._checkPacket, timeout=self._timeout) + stop_filter=self._checkPacket, timeout=self._timeout, + started_callback=self._startedCb) except Exception as e: print(e, file=sys.stderr)