dep_tracker: New script to track dependencies between files.
The new dep_tracker script can be used to track dependencies between
files. This patch creates the dep_tracker script with support for
dynamic library dependencies in ELF files.
BUG=chromium:404692
TEST=Unittest added.
TEST=`dep_tracker --json /tmp/stats.json --portage-db /build/link/var/db/pkg/ ../build/images/link/latest/dir_3`
Change-Id: Ibd3753dda4ffca0e12a7aeecadbcfbc73678c486
Reviewed-on: https://chromium-review.googlesource.com/212947
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/scripts/dep_tracker_unittest.py b/scripts/dep_tracker_unittest.py
new file mode 100755
index 0000000..e340b11
--- /dev/null
+++ b/scripts/dep_tracker_unittest.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+# Copyright 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for dep_tracker.py."""
+
+import os
+
+from chromite.lib import cros_test_lib
+from chromite.lib import unittest_lib
+from chromite.scripts import dep_tracker
+
+# Allow access private members for testing:
+# pylint: disable=W0212
+
+
+class MainTest(cros_test_lib.MoxOutputTestCase):
+ """Tests for the main() function."""
+
+ def testHelp(self):
+ """Test that --help is functioning."""
+ argv = [ '--help' ]
+
+ with self.OutputCapturer() as output:
+ # Running with --help should exit with code==0.
+ self.AssertFuncSystemExitZero(dep_tracker.main, argv)
+
+ # Verify that a message beginning with "usage: " was printed.
+ stdout = output.GetStdout()
+ self.assertTrue(stdout.startswith('usage: '))
+
+
+class DepTrackerTest(cros_test_lib.TempDirTestCase):
+ """Tests for the DepTracker() class."""
+
+ def testSimpleDep(self):
+ unittest_lib.BuildELF(os.path.join(self.tempdir, 'libabc.so'),
+ ['func_a', 'func_b', 'func_c'])
+ unittest_lib.BuildELF(os.path.join(self.tempdir, 'abc_main'),
+ undefined_symbols=['func_b'],
+ used_libs=['abc'],
+ executable=True)
+ dt = dep_tracker.DepTracker(self.tempdir)
+ dt.Init()
+ dt.ComputeELFFileDeps()
+
+ self.assertEquals(sorted(dt._files.keys()), ['abc_main', 'libabc.so'])
+
+
+if __name__ == '__main__':
+ cros_test_lib.main()