Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 1 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 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): |
| 15 | """Tests for various small util funcs.""" |
| 16 | |
| 17 | def testFileIsCrosSdkElf(self): |
| 18 | """Verify FileIsCrosSdkElf on x86_64 ELFs.""" |
| 19 | path = os.path.join(self.tempdir, 'file') |
| 20 | data = (b'\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00' |
| 21 | b'>\x00') |
| 22 | osutils.WriteFile(path, data, mode='wb') |
| 23 | self.assertTrue(cros_setup_toolchains.FileIsCrosSdkElf(path)) |
| 24 | |
| 25 | def testArmIsNotCrosSdkElf(self): |
| 26 | """Verify FileIsCrosSdkElf on aarch64 ELFs.""" |
| 27 | path = os.path.join(self.tempdir, 'file') |
| 28 | data = (b'\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00' |
| 29 | b'(\x00') |
| 30 | osutils.WriteFile(path, data, mode='wb') |
| 31 | self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |
| 32 | |
| 33 | def testScriptIsNotCrosSdkElf(self): |
| 34 | """Verify FileIsCrosSdkElf on shell scripts.""" |
| 35 | path = os.path.join(self.tempdir, 'file') |
| 36 | data = '#!/bin/sh\necho hi\n' |
| 37 | osutils.WriteFile(path, data) |
| 38 | self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |