From patchwork Tue May 11 19:35:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1477295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=OeSuhcie; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=g23K0SXf; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ffp8Z5mP6z9sW5 for ; Wed, 12 May 2021 05:37:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=wMn6Q/WARiUOHBAXstsas5i4klhNciTpkNtGoa9DAJA=; b=OeSuhcieVfr7LgbhfE7VOFmaqC b9H64/kMw1LCpzlEJx1qgWd6colefEoncM00GtNjjgDsK29n8AJOKEOlx5mWY1iAW0fGZrojcMejH Wt40+/5ebM/8gbE2BeDu9WWP42nLO31hFSjG7Ss770DCS4iop41/DD05l7/nXJj9aDuxOZ7U+LSGx mju6sPHWAKI1e3Wodg1rHLRSW8FuNXAawX1vaK0vf99IhQ7dNcpP0Ckkc8LyGu7pqnzoL0GGdvbpq pEdUzwcOmeAh1ykr7Q1HIL4xv40vL0pk4C2FnLV3NstAWU0uOtHjzD7jPoAa8TMjzJFt4Tz3Osvun j9B4WiBg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgYAq-00190X-4V; Tue, 11 May 2021 19:36:08 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgYAe-0018zS-Pl for hostap@desiato.infradead.org; Tue, 11 May 2021 19:35:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=3QJfcCoqP3UxI9MRdmlUwcjFUfjey+tgXymc4ToBOZ0=; b=g23K0SXf9SPh+aBMddraq8DIt6 kf+2rWXWx4UNNkqjnreEXaUrFMHGTS6z7JgW/WpaJsfputovSuaZGzTJGbwuFoTqRrhPkA0d558lw SbEvd02pMOOInhRGpGqCeyEDNzewOTd8tP+bU/dB3AQ2U5BPImLOM076blqaNHVc3+QT49QFp4von Q+5jRWkea8uJgre15I2FxTWrLry1Q6JkfdC3ceuu1xBuPDYKN1eFeJXLHX+a3D7+b8rc+xa+25xHY zQczEO3tjk54uMQR8QprqZBH9LoajaUeRuz6O5HVnwqpVYkOdm6xHq5y8pWM9DtxlOAM0sDlml57C L70FY3Eg==; Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgYAb-009sPl-Tc for hostap@lists.infradead.org; Tue, 11 May 2021 19:35:55 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1lgYAY-007cub-0V; Tue, 11 May 2021 21:35:50 +0200 From: Johannes Berg To: hostap@lists.infradead.org Cc: Johannes Berg Subject: [PATCH] tests: test_fst_config: convert FstLauncher to context manager Date: Tue, 11 May 2021 21:35:47 +0200 Message-Id: <1620761747-Ib8559f233fe7a1110974ab5855ba8e93fc26b48d@changeid> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210511_123554_145619_523778B4 X-CRM114-Status: GOOD ( 11.58 ) X-Spam-Score: 0.1 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Johannes Berg Using __del__ for any kind of cleanup is not a good idea as it's not guaranteed to be called at any particular time, it's only called whenever the next garbage collect cycle kicks in. Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg Using __del__ for any kind of cleanup is not a good idea as it's not guaranteed to be called at any particular time, it's only called whenever the next garbage collect cycle kicks in. Use a context manager instead, which basically removes the need for the try/finally and fixes the reliance on __del__. Signed-off-by: Johannes Berg --- tests/hwsim/test_fst_config.py | 105 ++++++++++++++++----------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/tests/hwsim/test_fst_config.py b/tests/hwsim/test_fst_config.py index 98134014150f..5dc404282f3c 100644 --- a/tests/hwsim/test_fst_config.py +++ b/tests/hwsim/test_fst_config.py @@ -111,7 +111,10 @@ class FstLauncher: self.reg_ctrl = fst_test_common.HapdRegCtrl() self.test_is_supported() - def __del__(self): + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): self.cleanup() @staticmethod @@ -303,19 +306,19 @@ def run_test_ap_configuration(apdev, test_params, 0 - no errors discovered, an error otherwise. The function is used for simplek "bad configuration" tests.""" logdir = test_params['logdir'] - fst_launcher = FstLauncher(logdir) - ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_goodconf', 'a', - fst_test_common.fst_test_def_chan_a, - fst_test_common.fst_test_def_group, - fst_test_common.fst_test_def_prio_low, - fst_test_common.fst_test_def_llt) - ap2 = FstLauncherConfigAP(apdev[1]['ifname'], 'fst_badconf', 'b', - fst_test_common.fst_test_def_chan_g, fst_group, - fst_pri, fst_llt) - fst_launcher.add_cfg(ap1) - fst_launcher.add_cfg(ap2) - res = fst_launcher.run_hostapd() - return res + with FstLauncher(logdir) as fst_launcher: + ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_goodconf', 'a', + fst_test_common.fst_test_def_chan_a, + fst_test_common.fst_test_def_group, + fst_test_common.fst_test_def_prio_low, + fst_test_common.fst_test_def_llt) + ap2 = FstLauncherConfigAP(apdev[1]['ifname'], 'fst_badconf', 'b', + fst_test_common.fst_test_def_chan_g, fst_group, + fst_pri, fst_llt) + fst_launcher.add_cfg(ap1) + fst_launcher.add_cfg(ap2) + res = fst_launcher.run_hostapd() + return res def run_test_sta_configuration(test_params, fst_group=fst_test_common.fst_test_def_group, @@ -326,16 +329,16 @@ def run_test_sta_configuration(test_params, the run: 0 - no errors discovered, an error otherwise. The function is used for simple "bad configuration" tests.""" logdir = test_params['logdir'] - fst_launcher = FstLauncher(logdir) - sta1 = FstLauncherConfigSTA('wlan5', - fst_test_common.fst_test_def_group, - fst_test_common.fst_test_def_prio_low, - fst_test_common.fst_test_def_llt) - sta2 = FstLauncherConfigSTA('wlan6', fst_group, fst_pri, fst_llt) - fst_launcher.add_cfg(sta1) - fst_launcher.add_cfg(sta2) - res = fst_launcher.run_wpa_supplicant() - return res + with FstLauncher(logdir) as fst_launcher: + sta1 = FstLauncherConfigSTA('wlan5', + fst_test_common.fst_test_def_group, + fst_test_common.fst_test_def_prio_low, + fst_test_common.fst_test_def_llt) + sta2 = FstLauncherConfigSTA('wlan6', fst_group, fst_pri, fst_llt) + fst_launcher.add_cfg(sta1) + fst_launcher.add_cfg(sta2) + res = fst_launcher.run_wpa_supplicant() + return res def test_fst_ap_config_llt_neg(dev, apdev, test_params): """FST AP configuration negative LLT""" @@ -481,21 +484,21 @@ def test_fst_scan_mb(dev, apdev, test_params): logdir = test_params['logdir'] # Test valid MB IE in scan results - fst_launcher = FstLauncher(logdir) - ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_11a', 'a', - fst_test_common.fst_test_def_chan_a, - fst_test_common.fst_test_def_group, - fst_test_common.fst_test_def_prio_high) - ap2 = FstLauncherConfigAP(apdev[1]['ifname'], 'fst_11g', 'b', - fst_test_common.fst_test_def_chan_g, - fst_test_common.fst_test_def_group, - fst_test_common.fst_test_def_prio_low) - fst_launcher.add_cfg(ap1) - fst_launcher.add_cfg(ap2) - res = fst_launcher.run_hostapd() - if res != 0: - raise Exception("hostapd didn't start properly") - try: + with FstLauncher(logdir) as fst_launcher: + ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_11a', 'a', + fst_test_common.fst_test_def_chan_a, + fst_test_common.fst_test_def_group, + fst_test_common.fst_test_def_prio_high) + ap2 = FstLauncherConfigAP(apdev[1]['ifname'], 'fst_11g', 'b', + fst_test_common.fst_test_def_chan_g, + fst_test_common.fst_test_def_group, + fst_test_common.fst_test_def_prio_low) + fst_launcher.add_cfg(ap1) + fst_launcher.add_cfg(ap2) + res = fst_launcher.run_hostapd() + if res != 0: + raise Exception("hostapd didn't start properly") + mbie1 = [] flags1 = '' mbie2 = [] @@ -514,8 +517,6 @@ def test_fst_scan_mb(dev, apdev, test_params): mbie2 = parse_ies(vals2['ie'], 0x9e) if 'flags' in vals2: flags2 = vals2['flags'] - finally: - fst_launcher.cleanup() if len(mbie1) == 0: raise Exception("No MB IE created by 1st AP") @@ -527,16 +528,16 @@ def test_fst_scan_nomb(dev, apdev, test_params): logdir = test_params['logdir'] # Test valid MB IE in scan results - fst_launcher = FstLauncher(logdir) - ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_11a', 'a', - fst_test_common.fst_test_def_chan_a, - fst_test_common.fst_test_def_group, - fst_test_common.fst_test_def_prio_high) - fst_launcher.add_cfg(ap1) - res = fst_launcher.run_hostapd() - if res != 0: - raise Exception("Hostapd didn't start properly") - try: + with FstLauncher(logdir) as fst_launcher: + ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_11a', 'a', + fst_test_common.fst_test_def_chan_a, + fst_test_common.fst_test_def_group, + fst_test_common.fst_test_def_prio_high) + fst_launcher.add_cfg(ap1) + res = fst_launcher.run_hostapd() + if res != 0: + raise Exception("Hostapd didn't start properly") + time.sleep(2) mbie1 = [] flags1 = '' @@ -546,8 +547,6 @@ def test_fst_scan_nomb(dev, apdev, test_params): mbie1 = parse_ies(vals1['ie'], 0x9e) if 'flags' in vals1: flags1 = vals1['flags'] - finally: - fst_launcher.cleanup() if len(mbie1) != 0: raise Exception("MB IE exists with 1 AP")