detect_host_arch_test.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if sys.version_info.major == 2:
  10. import mock
  11. else:
  12. from unittest import mock
  13. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  14. import detect_host_arch
  15. class DetectHostArchTest(unittest.TestCase):
  16. def setUp(self):
  17. super(DetectHostArchTest, self).setUp()
  18. mock.patch('platform.machine').start()
  19. mock.patch('platform.processor').start()
  20. mock.patch('platform.architecture').start()
  21. self.addCleanup(mock.patch.stopall)
  22. def testHostArch(self):
  23. test_cases = [
  24. ('ia86', '', [''], 'x86'),
  25. ('i86pc', '', [''], 'x86'),
  26. ('x86_64', '', [''], 'x64'),
  27. ('amd64', '', [''], 'x64'),
  28. ('x86_64', '', ['32bit'], 'x86'),
  29. ('amd64', '', ['32bit'], 'x86'),
  30. ('arm', '', [''], 'arm'),
  31. ('aarch64', '', [''], 'arm64'),
  32. ('aarch64', '', ['32bit'], 'arm'),
  33. ('arm64', '', [''], 'arm64'),
  34. ('amd64', 'ARMv8 (64-bit) Family', ['64bit', 'WindowsPE'], 'x64'),
  35. ('arm64', 'ARMv8 (64-bit) Family', ['32bit', 'WindowsPE'], 'x64'),
  36. ('mips64', '', [''], 'mips64'),
  37. ('mips', '', [''], 'mips'),
  38. ('ppc', '', [''], 'ppc'),
  39. ('foo', 'powerpc', [''], 'ppc'),
  40. ('s390', '', [''], 's390'),
  41. ]
  42. for machine, processor, arch, expected in test_cases:
  43. platform.machine.return_value = machine
  44. platform.processor.return_value = processor
  45. platform.architecture.return_value = arch
  46. self.assertEqual(expected, detect_host_arch.HostArch())
  47. if __name__ == '__main__':
  48. unittest.main()