From patchwork Tue Mar 3 22:08:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 445936 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) by ozlabs.org (Postfix) with ESMTP id E129814016A for ; Wed, 4 Mar 2015 09:09:13 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 1B56117C035; Tue, 3 Mar 2015 17:09:06 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0SwrClKmSBvT; Tue, 3 Mar 2015 17:09:05 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 365EC17C041; Tue, 3 Mar 2015 17:08:54 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CDB339C208 for ; Tue, 3 Mar 2015 17:08:51 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1Tcke+Q9fBrD for ; Tue, 3 Mar 2015 17:08:47 -0500 (EST) Received: from sipsolutions.net (s3.sipsolutions.net [5.9.151.49]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id AB0B09C207 for ; Tue, 3 Mar 2015 17:08:47 -0500 (EST) Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84) (envelope-from ) id 1YSuzc-0006a3-3F; Tue, 03 Mar 2015 23:08:44 +0100 From: Johannes Berg To: hostap@lists.shmoo.com Subject: [PATCH 1/2] parallel-vm.py: use argparse module Date: Tue, 3 Mar 2015 23:08:40 +0100 Message-Id: <1425420521-6153-1-git-send-email-johannes@sipsolutions.net> X-Mailer: git-send-email 2.1.4 Cc: Johannes Berg X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Johannes Berg Instead of hand-writing a (positional) parser, use the argparse module. This also gets us nice help output. Signed-off-by: Johannes Berg --- tests/hwsim/vm/parallel-vm.py | 49 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/hwsim/vm/parallel-vm.py b/tests/hwsim/vm/parallel-vm.py index 13205fe8afca..27033791fc0f 100755 --- a/tests/hwsim/vm/parallel-vm.py +++ b/tests/hwsim/vm/parallel-vm.py @@ -240,6 +240,7 @@ def show_progress(scr): time.sleep(0.3) def main(): + import argparse global num_servers global vm global dir @@ -257,26 +258,24 @@ def main(): debug_level = logging.INFO rerun_failures = True - if len(sys.argv) < 2: - sys.exit("Usage: %s [-1] [--debug] [--codecov] [params..]" % sys.argv[0]) - num_servers = int(sys.argv[1]) - if num_servers < 1: - sys.exit("Too small number of VMs") - - timestamp = int(time.time()) - - idx = 2 - - if len(sys.argv) > idx and sys.argv[idx] == "-1": - idx += 1 - rerun_failures = False - - if len(sys.argv) > idx and sys.argv[idx] == "--debug": - idx += 1 + p = argparse.ArgumentParser(description='run multiple testing VMs in parallel') + p.add_argument('num_servers', metavar='number of VMs', type=int, choices=range(1, 100), + help="number of VMs to start") + p.add_argument('-1', dest='no_retry', action='store_const', const=True, default=False, + help="don't retry failed tests automatically") + p.add_argument('--debug', dest='debug', action='store_const', const=True, default=False, + help="enable debug logging") + p.add_argument('--codecov', dest='codecov', action='store_const', const=True, default=False, + help="enable code coverage collection") + p.add_argument('--shuffle-tests', dest='shuffle', action='store_const', const=True, default=False, + help="enable code coverage collection") + p.add_argument('params', nargs='*') + args = p.parse_args() + num_servers = args.num_servers + rerun_failures = not args.no_retry + if args.debug: debug_level = logging.DEBUG - - if len(sys.argv) > idx and sys.argv[idx] == "--codecov": - idx += 1 + if args.codecov: print "Code coverage - build separate binaries" logdir = "/tmp/hwsim-test-logs/" + str(timestamp) os.makedirs(logdir) @@ -287,19 +286,21 @@ def main(): codecov_args = [] codecov = False + timestamp = int(time.time()) + first_run_failures = [] tests = [] - cmd = [ '../run-tests.py', '-L' ] + sys.argv[idx:] + cmd = [ '../run-tests.py', '-L' ] + args.params lst = subprocess.Popen(cmd, stdout=subprocess.PIPE) for l in lst.stdout.readlines(): name = l.split(' ')[0] tests.append(name) if len(tests) == 0: sys.exit("No test cases selected") - if '-f' in sys.argv[idx:]: - extra_args = sys.argv[idx:] + if '-f' in args.params: + extra_args = args.params else: - extra_args = [x for x in sys.argv[idx:] if x not in tests] + extra_args = [x for x in args.params if x not in tests] dir = '/tmp/hwsim-test-logs' try: @@ -307,7 +308,7 @@ def main(): except: pass - if "--shuffle-tests" in extra_args: + if args.shuffle: from random import shuffle shuffle(tests) elif num_servers > 2 and len(tests) > 100: