summaryrefslogtreecommitdiffstats
path: root/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py')
-rw-r--r--scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py b/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py
index 971e125eab..6f46a1c03d 100644
--- a/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py
+++ b/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py
@@ -4,16 +4,28 @@ import unittest
4 4
5sys.path.insert(0, os.getcwd()) 5sys.path.insert(0, os.getcwd())
6 6
7import parsing 7import pybootchartgui.parsing as parsing
8import process_tree 8import pybootchartgui.process_tree as process_tree
9import pybootchartgui.main as main
10
11if sys.version_info >= (3, 0):
12 long = int
9 13
10class TestProcessTree(unittest.TestCase): 14class TestProcessTree(unittest.TestCase):
11 15
12 def setUp(self): 16 def setUp(self):
13 self.name = "Process tree unittest" 17 self.name = "Process tree unittest"
14 self.rootdir = '../examples/1' 18 self.rootdir = os.path.join(os.path.dirname(sys.argv[0]), '../../examples/1/')
15 self.ps_stats = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_ps.log')).ps_stats 19
16 self.processtree = process_tree.ProcessTree(self.ps_stats, None, False, for_testing = True) 20 parser = main._mk_options_parser()
21 options, args = parser.parse_args(['--q', self.rootdir])
22 writer = main._mk_writer(options)
23 trace = parsing.Trace(writer, args, options)
24
25 parsing.parse_file(writer, trace, self.mk_fname('proc_ps.log'))
26 trace.compile(writer)
27 self.processtree = process_tree.ProcessTree(writer, None, trace.ps_stats, \
28 trace.ps_stats.sample_period, None, options.prune, None, None, False, for_testing = True)
17 29
18 def mk_fname(self,f): 30 def mk_fname(self,f):
19 return os.path.join(self.rootdir, f) 31 return os.path.join(self.rootdir, f)
@@ -26,14 +38,16 @@ class TestProcessTree(unittest.TestCase):
26 return flattened 38 return flattened
27 39
28 def checkAgainstJavaExtract(self, filename, process_tree): 40 def checkAgainstJavaExtract(self, filename, process_tree):
29 for expected, actual in zip(open(filename), self.flatten(process_tree)): 41 test_data = open(filename)
42 for expected, actual in zip(test_data, self.flatten(process_tree)):
30 tokens = expected.split('\t') 43 tokens = expected.split('\t')
31 self.assertEqual(int(tokens[0]), actual.pid) 44 self.assertEqual(int(tokens[0]), actual.pid // 1000)
32 self.assertEqual(tokens[1], actual.cmd) 45 self.assertEqual(tokens[1], actual.cmd)
33 self.assertEqual(long(tokens[2]), 10 * actual.start_time) 46 self.assertEqual(long(tokens[2]), 10 * actual.start_time)
34 self.assert_(long(tokens[3]) - 10 * actual.duration < 5, "duration") 47 self.assert_(long(tokens[3]) - 10 * actual.duration < 5, "duration")
35 self.assertEqual(int(tokens[4]), len(actual.child_list)) 48 self.assertEqual(int(tokens[4]), len(actual.child_list))
36 self.assertEqual(int(tokens[5]), len(actual.samples)) 49 self.assertEqual(int(tokens[5]), len(actual.samples))
50 test_data.close()
37 51
38 def testBuild(self): 52 def testBuild(self):
39 process_tree = self.processtree.process_tree 53 process_tree = self.processtree.process_tree