blob: 64eadd87fb8dfb0e50cf6dc31b7949f279f43666 [file] [log] [blame]
Alex Deymo3cfb9cd2014-08-18 15:56:35 -07001#!/usr/bin/python
2# Copyright 2014 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"""Unit tests for dep_tracker.py."""
7
8import os
Mike Frysinger16c51062014-09-05 23:34:29 -04009import sys
Alex Deymo3cfb9cd2014-08-18 15:56:35 -070010
Mike Frysinger16c51062014-09-05 23:34:29 -040011sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
12 '..', '..'))
Alex Deymo3cfb9cd2014-08-18 15:56:35 -070013from chromite.lib import cros_test_lib
14from chromite.lib import unittest_lib
15from chromite.scripts import dep_tracker
16
17# Allow access private members for testing:
18# pylint: disable=W0212
19
20
21class MainTest(cros_test_lib.MoxOutputTestCase):
22 """Tests for the main() function."""
23
24 def testHelp(self):
25 """Test that --help is functioning."""
26 argv = [ '--help' ]
27
28 with self.OutputCapturer() as output:
29 # Running with --help should exit with code==0.
30 self.AssertFuncSystemExitZero(dep_tracker.main, argv)
31
32 # Verify that a message beginning with "usage: " was printed.
33 stdout = output.GetStdout()
34 self.assertTrue(stdout.startswith('usage: '))
35
36
37class DepTrackerTest(cros_test_lib.TempDirTestCase):
38 """Tests for the DepTracker() class."""
39
40 def testSimpleDep(self):
41 unittest_lib.BuildELF(os.path.join(self.tempdir, 'libabc.so'),
42 ['func_a', 'func_b', 'func_c'])
43 unittest_lib.BuildELF(os.path.join(self.tempdir, 'abc_main'),
44 undefined_symbols=['func_b'],
45 used_libs=['abc'],
46 executable=True)
47 dt = dep_tracker.DepTracker(self.tempdir)
48 dt.Init()
49 dt.ComputeELFFileDeps()
50
51 self.assertEquals(sorted(dt._files.keys()), ['abc_main', 'libabc.so'])
52
53
54if __name__ == '__main__':
55 cros_test_lib.main()