blob: 73f187a9fd7de3971bd54d5d2c09ebaba5822dcf [file] [log] [blame]
Mike Frysingerdd34dfe2019-12-10 16:25:47 -05001# 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 Frysingerdd34dfe2019-12-10 16:25:47 -05007import os
8
9from chromite.lib import cros_test_lib
10from chromite.lib import osutils
11from chromite.scripts import cros_setup_toolchains
12
13
Mike Frysingerdd34dfe2019-12-10 16:25:47 -050014class 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))