From nobody Wed Nov 02 13:18:09 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 4N2SB92G4mz4h8Ct; Wed, 2 Nov 2022 13:18:09 +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 4N2SB91k6zz49m7; Wed, 2 Nov 2022 13:18:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667395089; 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=h2Z6v0PjynyP5FbYND8OggbuR7rUVp/3fLxajSFClXU=; b=OjPSs/GNum/MlPZ9hDfBm8zX+HUhtk8a6qRK6W1ad5dCaclJtPtge247JHAbslteTd7KG3 cw77q8QxxKEOTSA8foqPkO23cmx5Pg9VuOssHcMroBxGaEow/jFgc71wbObEtICjSEX14S AewNP1nbIpCoaz8DkNm359uGWmA+RWI+ZS285fZF22mRlJPgwu0f53B2hbqTCUZ5a3mnLO s4hen1zoyoDWpZQbtCEgzBxJz24fkMRX/IeiDsTJUyadiNIwLM46AoesW7/oEtzzr3uxoS uD6NfDDlYrwi+ZI5TiONck9JfO/PFKPJgodzM3KN+eELvHl8ti2YWlqjhudijA== 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 4N2SB90mGKzxPR; Wed, 2 Nov 2022 13:18:09 +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 2A2DI9NL038272; Wed, 2 Nov 2022 13:18:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A2DI9TY038271; Wed, 2 Nov 2022 13:18:09 GMT (envelope-from git) Date: Wed, 2 Nov 2022 13:18:09 GMT Message-Id: <202211021318.2A2DI9TY038271@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 67557372dfef - main - 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/main X-Git-Reftype: branch X-Git-Commit: 67557372dfef87eb94681a97a4157198efe21992 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667395089; 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=h2Z6v0PjynyP5FbYND8OggbuR7rUVp/3fLxajSFClXU=; b=Rv7cvJwrkwzBlwZsx1g6JaIBarjEzEibMCYgxhRzf/nmQg6jSN2+/Qsbst7640GIgYf3/G 9N8/2LoLryJWLMSiSfK+iys6jy3/kEdQus0hW2NhgFb8KO4HTbaRLoqefZVbInpyT9oKZS XiCSct+YnsCSbJBP9UCxUX4FKVjxHbvZq8fjfarPSFMZ8lua4TWV1ugwW3RSzJh48xTb9o IKCnz07QThBzXaLPQ66N5OKaY5hW6g9f3SepYD4mqK9krDDbCKl1wtO/DYqY3mErr1siUR wWdYvnm2WZozit1x7ouswlPkGcWDH1Jwe51r2lE+yWs9nRBpeAA3GQhcoJw7VQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667395089; a=rsa-sha256; cv=none; b=Ix5LYxRviwEerm3GXbSrvL/rC4DAL2sl312bSjUsJCeRCOJLHvJbc/NkVyWIdF9CefCvv/ b8xsbgBN/PRI3Kzl8NMh72J9Gci80RpXCnqw9swNzlzcHFaqIXGqhYotrAbdBZxGGPmlK9 PbQZ0J6vN8CDhoY2Vy3rB64L/B/q6KSboeW0Xu3Ma+9K+M4sNvFb30xyepnyJb3Tp6XSft rsCmB2MevaBwvS3i1VimXHkBcteOg+1ufgDGHKvC2uu1xxYfHSrhOiuFYAQWzVRQK2Gmql 9n13XTlmJK3fDTUAKKu5UrPeDfWJ/+gIef9PaS5tm2wNvFphyHWNHFgWHHzzBA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=67557372dfef87eb94681a97a4157198efe21992 commit 67557372dfef87eb94681a97a4157198efe21992 Author: Kristof Provost AuthorDate: 2022-11-02 10:55:39 +0000 Commit: Kristof Provost CommitDate: 2022-11-02 10:59:10 +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") --- 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)