| # Copyright 2019 The ChromiumOS Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| """Test crows_setup_toolchains.""" | |
| import os | |
| from chromite.lib import cros_test_lib | |
| from chromite.lib import osutils | |
| from chromite.scripts import cros_setup_toolchains | |
| class UtilsTest(cros_test_lib.MockTempDirTestCase): | |
| """Tests for various small util funcs.""" | |
| def testFileIsCrosSdkElf(self): | |
| """Verify FileIsCrosSdkElf on x86_64 ELFs.""" | |
| path = os.path.join(self.tempdir, "file") | |
| data = ( | |
| b"\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00" | |
| b">\x00" | |
| ) | |
| osutils.WriteFile(path, data, mode="wb") | |
| self.assertTrue(cros_setup_toolchains.FileIsCrosSdkElf(path)) | |
| def testArmIsNotCrosSdkElf(self): | |
| """Verify FileIsCrosSdkElf on aarch64 ELFs.""" | |
| path = os.path.join(self.tempdir, "file") | |
| data = ( | |
| b"\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00" | |
| b"(\x00" | |
| ) | |
| osutils.WriteFile(path, data, mode="wb") | |
| self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) | |
| def testScriptIsNotCrosSdkElf(self): | |
| """Verify FileIsCrosSdkElf on shell scripts.""" | |
| path = os.path.join(self.tempdir, "file") | |
| data = "#!/bin/sh\necho hi\n" | |
| osutils.WriteFile(path, data) | |
| self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |