diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-08-30 10:28:13 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-08-30 10:33:28 -0700 |
commit | 84fff3521a8c691c6e3f512a83970f6466606b27 (patch) | |
tree | 4725ec636885b74273d8e734ec2c8a7768223dc0 | |
parent | 42eadd18d6390a6e2a070fe3391dfcd0325d1395 (diff) | |
download | meson-84fff3521a8c691c6e3f512a83970f6466606b27.zip meson-84fff3521a8c691c6e3f512a83970f6466606b27.tar.gz meson-84fff3521a8c691c6e3f512a83970f6466606b27.tar.bz2 |
unittests: Add a test case for detect_cpu_family
This should help prevent regressions.
-rw-r--r-- | unittests/internaltests.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 9115803..bc6bca5 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import contextlib import stat import subprocess import json @@ -1422,3 +1423,58 @@ class InternalTests(unittest.TestCase): self.assertEqual(k.required, v.required) self.assertEqual(k.default, 'foo') self.assertEqual(v.default, 'bar') + + def test_detect_cpu_family(self) -> None: + """Test the various cpu familes that we detect and normalize. + + This is particularly useful as both documentation, and to keep testing + platforms that are less common. + """ + + @contextlib.contextmanager + def mock_trial(value: str) -> T.Iterable[None]: + """Mock all of the ways we could get the trial at once.""" + mocked = mock.Mock(return_value=value) + + with mock.patch('mesonbuild.environment.detect_windows_arch', mocked), \ + mock.patch('mesonbuild.environment.platform.processor', mocked), \ + mock.patch('mesonbuild.environment.platform.machine', mocked): + yield + + cases = [ + ('x86', 'x86'), + ('i386', 'x86'), + ('bepc', 'x86'), # Haiku + ('earm', 'arm'), # NetBSD + ('arm', 'arm'), + ('ppc64', 'ppc64'), + ('powerpc64', 'ppc64'), + ('powerpc', 'ppc'), + ('ppc', 'ppc'), + ('macppc', 'ppc'), + ('power macintosh', 'ppc'), + ('mips64el', 'mips64'), + ('mips64', 'mips64'), + ('mips', 'mips'), + ('mipsel', 'mips'), + ('ip30', 'mips64'), + ('ip35', 'mips64'), + ('parisc64', 'parisc'), + ('sun4u', 'sparc64'), + ('sun4v', 'sparc64'), + ('amd64', 'x86_64'), + ('x64', 'x86_64'), + ('i86pc', 'x86_64'), # Solaris + ] + + with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)): + for test, expected in cases: + with self.subTest(test, has_define=False), mock_trial(test): + actual = mesonbuild.environment.detect_cpu_family({}) + self.assertEqual(actual, expected) + + with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)): + for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64')]: + with self.subTest(test, has_define=True), mock_trial(test): + actual = mesonbuild.environment.detect_cpu_family({}) + self.assertEqual(actual, expected) |