From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2069.outbound.protection.outlook.com [40.107.220.69]) by sourceware.org (Postfix) with ESMTPS id 893AE3947408 for ; Fri, 1 Apr 2022 13:00:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 893AE3947408 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eaWbGeVkOgSEiHV4c+Q/TSIBC/B1Rso+EB1Bfpnolif8eMPxzo47g0pJQsGDHF3+gcTVoxJ2TUnjRiDoeq5NSoE6xI28r+zvx8GNf4/kpzDQu5vwhmljm6FUwyamNSGgrSTghBhV1j8XgkgL8WqNjXXz8EBivFY+Jjo1SFIi1XuxsR/kFvlshXRFo/L31kxUoMJrKHogttMBAQS4vXpj3CZlsi1oKucXDSB3Z8syMxi6pzcRriaHJMo4TIG3FRemVs4L3xIH0vX6Whh27dTm72OrBmVIJbPEmvZG+sMTyujubWu1PXN5fR7xF1QQ0yOBHOxJETwak4gdrY8e9uYeEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Sy7/YDLKXa16IiYVBGPCpS8AxXgsyMS0XhTkpIccbxs=; b=oOSjaOlIHmodhnWYTAg3OZSqUsaP8E3caauWSA0UCrfyQkxdgShtkwUAi1da2m0Y2QT3uJAtsnaZ5Ds7bRQtiBKwgCMnOhwpaJ1dWD9SpfNV8ESGS0vTzI3teYXY+vhhgTBa6wnK60GcXEWdEFhsUxPryNlBjZQWCj6e7jdH3CSVVDbHjyJCErkZiVfMjp6HkaRJZSNhFib/9fVgkS4BQBH+q37cKb3FJ3IapOI4jvj0vdFV87dIlxhIF57LqB8lm5kF+K9V7j5yaWZQOsEbbm0k3SAk9J4P7Nx3MU/lTldNmpWkom6gyo7wzhXBZRds7tQ4TN+wpgUwiJ87C6Q+NA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from BN9P221CA0009.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::17) by BYAPR12MB3544.namprd12.prod.outlook.com (2603:10b6:a03:131::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.19; Fri, 1 Apr 2022 13:00:35 +0000 Received: from BN8NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::eb) by BN9P221CA0009.outlook.office365.com (2603:10b6:408:10a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.13 via Frontend Transport; Fri, 1 Apr 2022 13:00:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT051.mail.protection.outlook.com (10.13.177.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5123.19 via Frontend Transport; Fri, 1 Apr 2022 13:00:35 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 1 Apr 2022 08:00:34 -0500 Received: from khazad-dum.amd.com (10.180.168.240) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 1 Apr 2022 08:00:33 -0500 From: Lancelot SIX To: CC: , Lancelot SIX Subject: [PATCH 3/3] gdb/selftest-arch: Make register_test_foreach_arch generate arch tests lazily Date: Fri, 1 Apr 2022 14:00:15 +0100 Message-ID: <20220401130015.513187-4-lancelot.six@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220401130015.513187-1-lancelot.six@amd.com> References: <20220401130015.513187-1-lancelot.six@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB06.amd.com (10.181.40.147) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 35f8d8e7-1cce-481f-43df-08da13df9cc0 X-MS-TrafficTypeDiagnostic: BYAPR12MB3544:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3W/WbwqCiwBIHjvCmI8gNbCGA10l8DpDKgT1A54qx5tQ/Y7mJq5NSlbF2r+w3N0M4vHMmi+EnyyyrSQHvpCLAh2XDfJZ2hKZmMeGpCIwFaZoRY9vsHVbaM1YRgc8GrJazCfmUGnvXT3EypgjHN/YMeKBUL5rBVxi2rgAdAesG3pj7i1HdRP+ujYvEfo9WKrE3Sh39O4c5zZKdkFdC7AazEfbpVbzKxtHA0nkvIwBgJNUZYD1oc4DSuIuiH+qD1ppk/9NxRXQMyCUaGrcY5c0EgkHNuxbfNT8FhfRL1TX7I7ENGv+TifjtmS5N+0S4phbwAvQZqF4honBSPxlIOnrphkSgmSbo9GiizYZ57BdqNBURQGvqHayBH+16XkMjeoHHBDeJWAyiHkXQ1A6CCVYcj25LfRE+9MsRaRbDDGJwysJOh50Q8UdTrISAceMobU+RPpFTCi46obOF6rlXscJ98Iv3gfRgaMmM5Sukd3AwJyao4KxV5Uh5r4QAu9NJ0rpT48B+sDXkTfB1E/F6vrjIyhkdpeGO52X5eRnfE9Z1Eu0lyPbFCP3csypITytcriQzM53MtqoYLFYLBPP2+pE2nX7XItr+fNDS2K1ojS//bVRAkeN8sBly9LuouE+np364pFoqC7Yn4qJ+Do/Gywnr+p79ETmGRxn6er1xOTc1pF1KwxOrcTLsd72sBch1m3sU8rYubKPK/oNQniA4pUONA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(356005)(47076005)(81166007)(2616005)(8676002)(86362001)(26005)(6666004)(16526019)(186003)(36756003)(426003)(336012)(1076003)(82310400004)(2906002)(83380400001)(5660300002)(36860700001)(7696005)(508600001)(6916009)(54906003)(70206006)(8936002)(4326008)(316002)(40460700003)(70586007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 13:00:35.4046 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35f8d8e7-1cce-481f-43df-08da13df9cc0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3544 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Apr 2022 13:00:41 -0000 The register_test_foreach_arch is used to instantiate a given selftest for all architectures supported by GDB. It is used in many _initialize_* functions (under initialize_all_files, called by gdb_init). Because the call is done during GDB's initialization, and because there is no guaranty about the order in which all the _initialize_* functions are executed, when register_test_foreach_arch is called, GDB is not fully initialized. Specifically, when a particular initialize function is executed, only the architectures registered at that point are listed by gdbarch_printable_names. As a consequence, the list of selftest effectively executed depends on the order the _initialize_* functions are called. This can be observed with the following: $ ./gdb/gdb \ -data-directory ./gdb/data-directory \ -quiet -batch -ex "maint selftest" 2>&1 \ | grep -E "Ran [0-9]+ unit tests" Ran 145 unit tests, 0 failed $ GDB_REVERSE_INIT_FUNCTIONS=1 ./gdb/gdb \ -data-directory ./gdb/data-directory \ -quiet -batch -ex "maint selftest" 2>&1 \ | grep -E "Ran [0-9]+ unit tests" Ran 82 unit tests, 0 failed To fix this, make register_test_foreach_arch register a lazy selftest generator. This way when the test generator is eventually executed, all architectures are registered and we do not have a dependency on the order the initialize functions are executed in. Tested on x86_64-linux Change-Id: I88eefebf7d372ad672f42d3a103e89354bc8a925 --- gdb/selftest-arch.c | 29 +++++++++++++++++++++-------- gdb/selftest-arch.h | 3 +++ gdb/testsuite/gdb.gdb/unittest.exp | 25 +++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index 1375838b0c2..f434da718d5 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -49,14 +49,15 @@ static bool skip_arch (const char *arch) return false; } -/* Register a kind of selftest that calls the test function once for each - gdbarch known to GDB. */ +/* Generate a selftest for each gdbarch known to GDB. */ -void -register_test_foreach_arch (const std::string &name, - self_test_foreach_arch_function *function) +static std::vector +foreach_arch_test_generator (const std::string &name, + self_test_foreach_arch_function *function) { + std::vector tests; std::vector arches = gdbarch_printable_names (); + tests.reserve (arches.size ()); for (const char *arch : arches) { if (skip_arch (arch)) @@ -73,10 +74,22 @@ register_test_foreach_arch (const std::string &name, reset (); }); - std::string test_name - = name + std::string ("::") + std::string (arch); - register_test (test_name, test_fn); + tests.emplace_back (string_printf ("%s::%s", name.c_str (), arch), + test_fn); } + return tests; +} + +/* See selftest-arch.h. */ + +void +register_test_foreach_arch (const std::string &name, + self_test_foreach_arch_function *function) +{ + add_lazy_generator ([=] () + { + return foreach_arch_test_generator (name, function); + }); } void diff --git a/gdb/selftest-arch.h b/gdb/selftest-arch.h index f359e4a0ed9..6bdef267c44 100644 --- a/gdb/selftest-arch.h +++ b/gdb/selftest-arch.h @@ -23,6 +23,9 @@ typedef void self_test_foreach_arch_function (struct gdbarch *); namespace selftests { + +/* Register a selftest running FUNCTION for each arch supported by GDB. */ + extern void register_test_foreach_arch (const std::string &name, self_test_foreach_arch_function *function); diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp index 46583cd3504..2967b994cc3 100644 --- a/gdb/testsuite/gdb.gdb/unittest.exp +++ b/gdb/testsuite/gdb.gdb/unittest.exp @@ -58,11 +58,12 @@ proc run_selftests { binfile } { } -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" { unsupported $test + set num_ran 0 set enabled 0 } } - return $enabled + return [list $enabled $num_ran] } # Test completion of command "maintenance selftest". @@ -86,7 +87,27 @@ proc_with_prefix test_completion {} { } with_test_prefix "no executable loaded" { - set self_tests_enabled [run_selftests ""] + set res [run_selftests ""] + set self_tests_enabled [lindex $res 0] + set num_ran [lindex $res 1] +} + +if { $self_tests_enabled && ![is_remote host] } { + # Check that we have the same amount of selftests whatever the + # initialization order of GDB. + with_test_prefix "reversed initialization" { + save_vars { env(GDB_REVERSE_INIT_FUNCTIONS) } { + if [info exists env(GDB_REVERSE_INIT_FUNCTIONS)] { + unset env(GDB_REVERSE_INIT_FUNCTIONS) + } else { + set env(GDB_REVERSE_INIT_FUNCTIONS) 1 + } + + set res [run_selftests ""] + gdb_assert "$num_ran == [lindex $res 1]" \ + "selftest not dependent on initialization order" + } + } } with_test_prefix "executable loaded" { -- 2.25.1