blob: 40765a8fea2df5d565166723f216794ee3581c06 [file] [log] [blame]
Mike Frysingerdd34dfe2019-12-10 16:25:47 -05001# -*- 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
8from __future__ import print_function
9
10import os
11
12from chromite.lib import cros_test_lib
13from chromite.lib import osutils
14from chromite.scripts import cros_setup_toolchains
15
16
17class 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))