Alex Deymo | 3cfb9cd | 2014-08-18 15:56:35 -0700 | [diff] [blame^] | 1 | #!/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 | |
| 8 | import os |
| 9 | |
| 10 | from chromite.lib import cros_test_lib |
| 11 | from chromite.lib import unittest_lib |
| 12 | from chromite.scripts import dep_tracker |
| 13 | |
| 14 | # Allow access private members for testing: |
| 15 | # pylint: disable=W0212 |
| 16 | |
| 17 | |
| 18 | class MainTest(cros_test_lib.MoxOutputTestCase): |
| 19 | """Tests for the main() function.""" |
| 20 | |
| 21 | def testHelp(self): |
| 22 | """Test that --help is functioning.""" |
| 23 | argv = [ '--help' ] |
| 24 | |
| 25 | with self.OutputCapturer() as output: |
| 26 | # Running with --help should exit with code==0. |
| 27 | self.AssertFuncSystemExitZero(dep_tracker.main, argv) |
| 28 | |
| 29 | # Verify that a message beginning with "usage: " was printed. |
| 30 | stdout = output.GetStdout() |
| 31 | self.assertTrue(stdout.startswith('usage: ')) |
| 32 | |
| 33 | |
| 34 | class DepTrackerTest(cros_test_lib.TempDirTestCase): |
| 35 | """Tests for the DepTracker() class.""" |
| 36 | |
| 37 | def testSimpleDep(self): |
| 38 | unittest_lib.BuildELF(os.path.join(self.tempdir, 'libabc.so'), |
| 39 | ['func_a', 'func_b', 'func_c']) |
| 40 | unittest_lib.BuildELF(os.path.join(self.tempdir, 'abc_main'), |
| 41 | undefined_symbols=['func_b'], |
| 42 | used_libs=['abc'], |
| 43 | executable=True) |
| 44 | dt = dep_tracker.DepTracker(self.tempdir) |
| 45 | dt.Init() |
| 46 | dt.ComputeELFFileDeps() |
| 47 | |
| 48 | self.assertEquals(sorted(dt._files.keys()), ['abc_main', 'libabc.so']) |
| 49 | |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | cros_test_lib.main() |