blob: 54f3e9e93292c33e6e000cc17d66e270f0932b52 [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Mike Frysingerdd34dfe2019-12-10 16:25:47 -05002# 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):
Alex Klein1699fab2022-09-08 08:46:06 -060015 """Tests for various small util funcs."""
Mike Frysingerdd34dfe2019-12-10 16:25:47 -050016
Alex Klein1699fab2022-09-08 08:46:06 -060017 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 Frysingerdd34dfe2019-12-10 16:25:47 -050026
Alex Klein1699fab2022-09-08 08:46:06 -060027 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 Frysingerdd34dfe2019-12-10 16:25:47 -050036
Alex Klein1699fab2022-09-08 08:46:06 -060037 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))