Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS 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 | |
| 6 | """Test crows_setup_toolchains.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import cros_test_lib |
| 13 | from chromite.lib import osutils |
| 14 | from chromite.scripts import cros_setup_toolchains |
| 15 | |
| 16 | |
| 17 | class UtilsTest(cros_test_lib.MockTempDirTestCase): |
| 18 | """Tests for various small util funcs.""" |
| 19 | |
| 20 | def testFileIsCrosSdkElf(self): |
| 21 | """Verify FileIsCrosSdkElf on x86_64 ELFs.""" |
| 22 | path = os.path.join(self.tempdir, 'file') |
| 23 | data = (b'\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00' |
| 24 | b'>\x00') |
| 25 | osutils.WriteFile(path, data, mode='wb') |
| 26 | self.assertTrue(cros_setup_toolchains.FileIsCrosSdkElf(path)) |
| 27 | |
| 28 | def testArmIsNotCrosSdkElf(self): |
| 29 | """Verify FileIsCrosSdkElf on aarch64 ELFs.""" |
| 30 | path = os.path.join(self.tempdir, 'file') |
| 31 | data = (b'\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00' |
| 32 | b'(\x00') |
| 33 | osutils.WriteFile(path, data, mode='wb') |
| 34 | self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |
| 35 | |
| 36 | def testScriptIsNotCrosSdkElf(self): |
| 37 | """Verify FileIsCrosSdkElf on shell scripts.""" |
| 38 | path = os.path.join(self.tempdir, 'file') |
| 39 | data = '#!/bin/sh\necho hi\n' |
| 40 | osutils.WriteFile(path, data) |
| 41 | self.assertFalse(cros_setup_toolchains.FileIsCrosSdkElf(path)) |