Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Test crows_setup_toolchains.""" |
| 6 | |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 7 | import os |
| 8 | |
| 9 | from chromite.lib import cros_test_lib |
| 10 | from chromite.lib import osutils |
| 11 | from chromite.scripts import cros_setup_toolchains |
| 12 | |
| 13 | |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 14 | class UtilsTest(cros_test_lib.MockTempDirTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 15 | """Tests for various small util funcs.""" |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 16 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 17 | def testFileIsCrosSdkElf(self): |
| 18 | """Verify FileIsCrosSdkElf on x86_64 ELFs.""" |
| 19 | path = os.path.join(self.tempdir, "file") |
| 20 | data = ( |
| 21 | b"\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00" |
| 22 | b">\x00" |
| 23 | ) |
| 24 | osutils.WriteFile(path, data, mode="wb") |
| 25 | self.assertTrue(cros_setup_toolchains.FileIsCrosSdkElf(path)) |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 26 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 27 | def testArmIsNotCrosSdkElf(self): |
| 28 | """Verify FileIsCrosSdkElf on aarch64 ELFs.""" |
| 29 | path = os.path.join(self.tempdir, "file") |
| 30 | data = ( |
| 31 | b"\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00" |
| 32 | b"(\x00" |
| 33 | ) |
| 34 | osutils.WriteFile(path, data, mode="wb") |
| 35 | self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 36 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 37 | def testScriptIsNotCrosSdkElf(self): |
| 38 | """Verify FileIsCrosSdkElf on shell scripts.""" |
| 39 | path = os.path.join(self.tempdir, "file") |
| 40 | data = "#!/bin/sh\necho hi\n" |
| 41 | osutils.WriteFile(path, data) |
| 42 | self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |