From patchwork Wed Mar 30 10:12:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Po-Hsu Lin X-Patchwork-Id: 1611032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=g/APNi3i; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KT2Lr5MKyz9sFk for ; Wed, 30 Mar 2022 21:13:08 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nZVK2-0005DV-JP; Wed, 30 Mar 2022 10:13:02 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nZVK0-0005Bp-BK for kernel-team@lists.ubuntu.com; Wed, 30 Mar 2022 10:13:00 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id AB0A03FFC8 for ; Wed, 30 Mar 2022 10:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1648635179; bh=KU5qVqgeonw0qljimFlwU4JPMsJhvy9qIeTGkgTjPYU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g/APNi3i6pdy+W+TuhBsKF6Ujp48esVbVYsVv4/OBSWd1T/uIpFJrh2su/RPORqvR ti4T5gZgOAMew2iVDOx/vYQfuucvoKoIi0raR7XqkTcbQlq8B+N6aNPlbWG2uBZUI0 3ZBKsPvDAoADhRnN8yF/1sewhx8xLOGe6S5FaTo7twyyOy+HhP9+U7AKOOeImUBfpP g6LeaEEFDhZRkxkUuqhFVZuznjy30IQZdJs715RmF+KeNfJSSbNwB4PoONj+LEeSZ/ QMiiTEazzcSmkyCwUN+nexFypiNeQ35RLTSuSjViCFAesB+MsNDUKOmLS/otcFH7SM d/Z+GRyKknPcw== Received: by mail-pf1-f200.google.com with SMTP id i2-20020a056a00224200b004fa60c248a1so11783058pfu.13 for ; Wed, 30 Mar 2022 03:12:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KU5qVqgeonw0qljimFlwU4JPMsJhvy9qIeTGkgTjPYU=; b=fUjTU8TyjGg3eH+sFyoZyCaOAdyrqbU1CyWYlzDxHgTn3jO6Wus2nLJDU7x2prMdZd OiDvnCYvXzkwvLW1PRuKMLK+wFlWLx1w3SaLtVEBZ/uQ1Eks6VzeLs0bseDN3ykJb+iT OU3oi89ryaSgvRxK2U0eOutmvstevq9jVr6ujTENQLE9h9MUjbG4z9eJ0FBcXCY6nUAN 9U1VNRRt1eYkJYL1mb6htNgTrzqwq6mFh+sCezffYcCtrCiSN7wia+HonISdu3gL2i+Y wPs64h+O/VqyGDSSf3mniNei3I99pxZlNnR1HRRQj9g2hLvZGFYt5sA0jyAZm0NnbGMc UfpA== X-Gm-Message-State: AOAM5318HsPmux0MpnlS8F80hsvbR8SxFgnjvR2mzUP99SRNWW2ltxG/ LyUda1JkbrmO8BKXT39OAylIph5CyGJ2tFZ+fd0/gHdvvQykh20lSW2smZtXMGpys1Mg/piB0Z6 46hvkxDH6gmoNG5PD0MjldSGxGbw7Ieu3ro3Lfxve X-Received: by 2002:a17:90b:38d2:b0:1c6:fa94:96bb with SMTP id nn18-20020a17090b38d200b001c6fa9496bbmr4159504pjb.206.1648635177729; Wed, 30 Mar 2022 03:12:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA1Bh93IuMoJCH5hAX0EbhGxUf/Ze2I/YNJsAHZVa5SBQe0JJ0fhdXCa4S8A4jrtQbEyfMSw== X-Received: by 2002:a17:90b:38d2:b0:1c6:fa94:96bb with SMTP id nn18-20020a17090b38d200b001c6fa9496bbmr4159460pjb.206.1648635177266; Wed, 30 Mar 2022 03:12:57 -0700 (PDT) Received: from localhost.localdomain (223-137-21-193.emome-ip.hinet.net. [223.137.21.193]) by smtp.gmail.com with ESMTPSA id a17-20020a62e211000000b004faa5233213sm21715961pfi.101.2022.03.30.03.12.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 03:12:56 -0700 (PDT) From: Po-Hsu Lin To: kernel-team@lists.ubuntu.com Subject: [autotest-client-tests][PATCH 2/2] UBUNTU: SAUCE: ubuntu_boot: move report_failures() to main() and code cleanup Date: Wed, 30 Mar 2022 18:12:06 +0800 Message-Id: <20220330101206.124838-3-po-hsu.lin@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220330101206.124838-1-po-hsu.lin@canonical.com> References: <20220330101206.124838-1-po-hsu.lin@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" The report_failures() is now just return whether the test pass or fail move the code piece to main() and update the docstring accordingly. Remove unnecessary parentheses for return Use raise SystemExit() for taint_file not found exeception instead of the out-of-range (0-255) value of -1. Signed-off-by: Po-Hsu Lin --- ubuntu_boot/kernel_taint_test.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/ubuntu_boot/kernel_taint_test.py b/ubuntu_boot/kernel_taint_test.py index 73177089..0e8a7eaa 100755 --- a/ubuntu_boot/kernel_taint_test.py +++ b/ubuntu_boot/kernel_taint_test.py @@ -44,10 +44,10 @@ def find_taints(taint_file): f = open(taint_file, "r") taints = int(f.read()) except OSError: - taints = -1 - print("Kernel taint file ({}) not found!".format(taint_file)) + raise SystemExit( + "Kernel taint file ({}) not found!".format(taint_file)) print("Kernel taint value is {}".format(taints)) - return(taints) + return taints def get_modules(): @@ -57,7 +57,7 @@ def get_modules(): for line in lsmod_output: if line and 'Module' not in line: modules.append(line.split()[0]) - return(modules) + return modules def print_out_of_tree_modules(modules): @@ -79,8 +79,15 @@ def print_GPL_incompatible_modules(modules): print(" %s: %s" % (mod, license)) -def report_failures(taints): - """Report the failure code and its meaning(s).""" +def main(): + """Print out the tainted state code and its meaning(s).""" + parser = ArgumentParser() + parser.add_argument('--taint-file', + default="/proc/sys/kernel/tainted", + help='The file that holds the taint information') + args = parser.parse_args() + taints = find_taints(args.taint_file) + # Below meaning strings are taken from # https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html taint_meanings = ["proprietary module was loaded", @@ -124,18 +131,5 @@ def report_failures(taints): return 1 -def main(): - parser = ArgumentParser() - parser.add_argument('--taint-file', - default="/proc/sys/kernel/tainted", - help='The file that holds the taint information') - args = parser.parse_args() - taints = find_taints(args.taint_file) - if taints < 0: - return taints - - return(report_failures(taints)) - - if __name__ == '__main__': sys.exit(main())