From 9e597ce905aa2b426e87f590a671b6726c09f075 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Wed, 30 Mar 2022 17:47:02 +0200 Subject: unittests: add underscore prefix tests Tests the two new detection methods for the underscore prefix against what is detected in the binary. Contrary to the in-the-wild failures, we can trust the binary here as we do not get any additional flags that influence the binary contents in this test environment. --- unittests/allplatformstests.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'unittests') diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 8a7fcd7..25d6305 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -1546,6 +1546,43 @@ class AllPlatformTests(BasePlatformTests): self.build() self.run_tests() + def get_convincing_fake_env_and_cc(self) -> None: + ''' + Return a fake env and C compiler with the fake env + machine info properly detected using that compiler. + ''' + env = get_fake_env('', self.builddir, self.prefix) + cc = detect_c_compiler(env, MachineChoice.HOST) + # Detect machine info + env.machines.host = mesonbuild.environment.detect_machine_info({'c':cc}) + return (env, cc) + + def test_underscore_prefix_detection_list(self) -> None: + ''' + Test the underscore detection hardcoded lookup list + against what was detected in the binary. + ''' + env, cc = self.get_convincing_fake_env_and_cc() + expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env) + list_uscore = cc._symbols_have_underscore_prefix_list(env) + if list_uscore is not None: + self.assertEqual(list_uscore, expected_uscore) + else: + raise SkipTest('No match in underscore prefix list for this platform.') + + def test_underscore_prefix_detection_define(self) -> None: + ''' + Test the underscore detection based on compiler-defined preprocessor macro + against what was detected in the binary. + ''' + env, cc = self.get_convincing_fake_env_and_cc() + expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env) + define_uscore = cc._symbols_have_underscore_prefix_define(env) + if define_uscore is not None: + self.assertEqual(define_uscore, expected_uscore) + else: + raise SkipTest('Did not find the underscore prefix define __USER_LABEL_PREFIX__') + @skipIfNoPkgconfig def test_pkgconfig_static(self): ''' -- cgit v1.1 From 34ea8fdf981b5e10c702e9adfcab7f9e316a129b Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Wed, 30 Mar 2022 23:30:39 +0200 Subject: unittests: move get_convincing_fake_env_and_cc to run_tests.py --- unittests/allplatformstests.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'unittests') diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 25d6305..67c50e7 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -60,7 +60,7 @@ from mesonbuild.scripts import destdir_join from mesonbuild.wrap.wrap import PackageDefinition, WrapException from run_tests import ( - Backend, exe_suffix, get_fake_env + Backend, exe_suffix, get_fake_env, get_convincing_fake_env_and_cc ) from .baseplatformtests import BasePlatformTests @@ -1546,23 +1546,12 @@ class AllPlatformTests(BasePlatformTests): self.build() self.run_tests() - def get_convincing_fake_env_and_cc(self) -> None: - ''' - Return a fake env and C compiler with the fake env - machine info properly detected using that compiler. - ''' - env = get_fake_env('', self.builddir, self.prefix) - cc = detect_c_compiler(env, MachineChoice.HOST) - # Detect machine info - env.machines.host = mesonbuild.environment.detect_machine_info({'c':cc}) - return (env, cc) - def test_underscore_prefix_detection_list(self) -> None: ''' Test the underscore detection hardcoded lookup list against what was detected in the binary. ''' - env, cc = self.get_convincing_fake_env_and_cc() + env, cc = get_convincing_fake_env_and_cc(self.builddir, self.prefix) expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env) list_uscore = cc._symbols_have_underscore_prefix_list(env) if list_uscore is not None: @@ -1575,7 +1564,7 @@ class AllPlatformTests(BasePlatformTests): Test the underscore detection based on compiler-defined preprocessor macro against what was detected in the binary. ''' - env, cc = self.get_convincing_fake_env_and_cc() + env, cc = get_convincing_fake_env_and_cc(self.builddir, self.prefix) expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env) define_uscore = cc._symbols_have_underscore_prefix_define(env) if define_uscore is not None: -- cgit v1.1