detect_host_arch_test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env vpython3
  2. # Copyright 2019 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import os
  6. import platform
  7. import sys
  8. import unittest
  9. from unittest import mock
  10. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  11. import detect_host_arch
  12. class DetectHostArchTest(unittest.TestCase):
  13. def setUp(self):
  14. super(DetectHostArchTest, self).setUp()
  15. mock.patch('platform.machine').start()
  16. mock.patch('platform.processor').start()
  17. mock.patch('platform.architecture').start()
  18. self.addCleanup(mock.patch.stopall)
  19. def testHostArch(self):
  20. test_cases = [
  21. ('ia86', '', [''], 'x86'),
  22. ('i86pc', '', [''], 'x86'),
  23. ('x86_64', '', [''], 'x64'),
  24. ('amd64', '', [''], 'x64'),
  25. ('x86_64', '', ['32bit'], 'x86'),
  26. ('amd64', '', ['32bit'], 'x86'),
  27. ('arm', '', [''], 'arm'),
  28. ('aarch64', '', [''], 'arm64'),
  29. ('aarch64', '', ['32bit'], 'arm'),
  30. ('arm64', '', [''], 'arm64'),
  31. ('amd64', 'ARMv8 (64-bit) Family', ['64bit', 'WindowsPE'], 'x64'),
  32. ('arm64', 'ARMv8 (64-bit) Family', ['32bit', 'WindowsPE'], 'x64'),
  33. ('mips64', '', [''], 'mips64'),
  34. ('mips', '', [''], 'mips'),
  35. ('ppc', '', [''], 'ppc'),
  36. ('foo', 'powerpc', [''], 'ppc'),
  37. ('s390', '', [''], 's390'),
  38. ]
  39. for machine, processor, arch, expected in test_cases:
  40. platform.machine.return_value = machine
  41. platform.processor.return_value = processor
  42. platform.architecture.return_value = arch
  43. detect_host_arch.HostArch.cache_clear()
  44. self.assertEqual(expected, detect_host_arch.HostArch())
  45. if __name__ == '__main__':
  46. unittest.main()