From nobody Wed Nov 9 12:09:48 2022 X-Original-To: dev-commits-src-all@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 4N6kL51nmTz4dCBC; Wed, 9 Nov 2022 12:09:49 +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 4N6kL51H46z3vrv; Wed, 9 Nov 2022 12:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667995789; 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=Inid9bHbqQvWZ1XVHo9jM6aaxfe3G4k50aDeZqCt8Lk=; b=fzd8kapPOQmXUCrXkcB4GsTN/5/hCT4Alr2UiJFMsJw4EyPs9uxvoE2YWos5SjV8CNEFsu b2wEo+J442rbuW9wFwUTY2lGgvE0Y87mqZROB4r/fuxi/k+mJke72muH738cIzabqwm6d3 HJDg/R+QpcHNDIo659qe14J6xhVaeHmLDhh9/0HeJrYjv+ryrfeUPrwo7vy6/4TQeM/dEz x0KEv6tKPY/bM3MIja9v7mZVMZji8Al15HkMBCJIuKwDvCoyTrBOvPZF+JgCzG6GTvbZUG 8ngCwV8f4sNxU0OW3MMJYpjgcVzbH1krsdKo1/LmNh2wF6d1O+eWerpQC3WQ/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667995789; 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=Inid9bHbqQvWZ1XVHo9jM6aaxfe3G4k50aDeZqCt8Lk=; b=H5simKSAkEDq8t6JpgG7bN1nn0ha0IjSvxKkgSq6K5wvyDt1bsDwwcvVAycN8bLPo+v/AJ 3YEtWUbBLcdpDerbMhDniesRvToiepbVSyYdyiL9rGHokI+8Gd9FuhMcaMJ5rY3hpLWyKl B+IiDkkO8aFvRdbX11J26fu7fMKYERKZ/743RP1MtKtXyx+LOG5n4Zik3kT6m1nvUzsILa CmYll595wd7g4penPSs9hr4tSkDlWRkziWgJKo6vpKZ/Lscs4/bLjSUvk3l3tHfy+W3h5s ytCx+JhYVPWEyvOKifbUiccvgsDanGBhWKLutxMmgGEMF7nb91ERoiYntsIpkg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667995789; a=rsa-sha256; cv=none; b=rXMuFJVGUlgb9EkNBwrTBGf7bgpYTxvhUnHnY9AEHUTXZIs7Whi49KDISr3sjUCUvGgje+ 8xEsQWKZ9WVvVw+ZiLqseWc0zT21bkcGMw2nb9TRtPzsKIRsgTri3TNUT+zPpAc8Hc8bGe EsTFFD+1KnBOXWqHf+oMqoXR795Huc1FgzQvEMlMhJ26innYl7dBnwcZdw2IOk6BsCuUra WdMYLN+mXGNGRkUw8OrCF7wnW1hlqSwvGH6PsSPo/u0XcpCS990BL2oWHvymbko++KCZly Ngq6nJkRKvyRXRBLYF62uP9gfzBZbLWpmm8mg/dvSfovpUen66t1hlI9h8FWag== 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 4N6kL507C5zLql; Wed, 9 Nov 2022 12:09:49 +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 2A9C9mgH047219; Wed, 9 Nov 2022 12:09:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A9C9mUK047218; Wed, 9 Nov 2022 12:09:48 GMT (envelope-from git) Date: Wed, 9 Nov 2022 12:09:48 GMT Message-Id: <202211091209.2A9C9mUK047218@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: 97967fc8e63f - stable/12 - tests: make sniffer more robust List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/12 X-Git-Reftype: branch X-Git-Commit: 97967fc8e63fb9ce65efe62cb87f89e45711dd3c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=97967fc8e63fb9ce65efe62cb87f89e45711dd3c commit 97967fc8e63fb9ce65efe62cb87f89e45711dd3c Author: Kristof Provost AuthorDate: 2022-11-02 10:55:39 +0000 Commit: Kristof Provost CommitDate: 2022-11-09 08:16:57 +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)