diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2013-11-15 18:08:50 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-11-18 12:44:06 +0000 |
commit | d0e513d4371789d59bcb902497ca7c537a94c1f0 (patch) | |
tree | 1542d41042ac935aaaa9f6735170ffd8f9044c87 /scripts/pybootchartgui/pybootchartgui/tests | |
parent | a52c9b9a76371ac3f29b0355fea08b788eb2dd10 (diff) | |
download | poky-d0e513d4371789d59bcb902497ca7c537a94c1f0.tar.gz |
pybootchartgui: Import pybootchartgui 0.14.5
This update the pybootchartgui code to the latest release from its new
location at "https://github.com/mmeeks/bootchart". This only imports
the relevant parts, and not all of bootchart2.
(From OE-Core rev: 6f1568e54a7808b2ab568618fc5bb244249579f1)
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/pybootchartgui/pybootchartgui/tests')
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/tests/parser_test.py | 82 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py | 30 |
2 files changed, 69 insertions, 43 deletions
diff --git a/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py b/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py index 574c2c7a2b..00fb3bf797 100644 --- a/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py +++ b/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py | |||
@@ -4,90 +4,102 @@ import unittest | |||
4 | 4 | ||
5 | sys.path.insert(0, os.getcwd()) | 5 | sys.path.insert(0, os.getcwd()) |
6 | 6 | ||
7 | import parsing | 7 | import pybootchartgui.parsing as parsing |
8 | import pybootchartgui.main as main | ||
8 | 9 | ||
9 | debug = False | 10 | debug = False |
10 | 11 | ||
11 | def floatEq(f1, f2): | 12 | def floatEq(f1, f2): |
12 | return math.fabs(f1-f2) < 0.00001 | 13 | return math.fabs(f1-f2) < 0.00001 |
13 | 14 | ||
15 | bootchart_dir = os.path.join(os.path.dirname(sys.argv[0]), '../../examples/1/') | ||
16 | parser = main._mk_options_parser() | ||
17 | options, args = parser.parse_args(['--q', bootchart_dir]) | ||
18 | writer = main._mk_writer(options) | ||
19 | |||
14 | class TestBCParser(unittest.TestCase): | 20 | class TestBCParser(unittest.TestCase): |
15 | 21 | ||
16 | def setUp(self): | 22 | def setUp(self): |
17 | self.name = "My first unittest" | 23 | self.name = "My first unittest" |
18 | self.rootdir = '../examples/1' | 24 | self.rootdir = bootchart_dir |
19 | 25 | ||
20 | def mk_fname(self,f): | 26 | def mk_fname(self,f): |
21 | return os.path.join(self.rootdir, f) | 27 | return os.path.join(self.rootdir, f) |
22 | 28 | ||
23 | def testParseHeader(self): | 29 | def testParseHeader(self): |
24 | state = parsing.parse_file(parsing.ParserState(), self.mk_fname('header')) | 30 | trace = parsing.Trace(writer, args, options) |
31 | state = parsing.parse_file(writer, trace, self.mk_fname('header')) | ||
25 | self.assertEqual(6, len(state.headers)) | 32 | self.assertEqual(6, len(state.headers)) |
26 | self.assertEqual(2, parsing.get_num_cpus(state.headers)) | 33 | self.assertEqual(2, parsing.get_num_cpus(state.headers)) |
27 | 34 | ||
28 | def test_parseTimedBlocks(self): | 35 | def test_parseTimedBlocks(self): |
29 | state = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_diskstats.log')) | 36 | trace = parsing.Trace(writer, args, options) |
37 | state = parsing.parse_file(writer, trace, self.mk_fname('proc_diskstats.log')) | ||
30 | self.assertEqual(141, len(state.disk_stats)) | 38 | self.assertEqual(141, len(state.disk_stats)) |
31 | 39 | ||
32 | def testParseProcPsLog(self): | 40 | def testParseProcPsLog(self): |
33 | state = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_ps.log')) | 41 | trace = parsing.Trace(writer, args, options) |
42 | state = parsing.parse_file(writer, trace, self.mk_fname('proc_ps.log')) | ||
34 | samples = state.ps_stats | 43 | samples = state.ps_stats |
35 | processes = samples.process_list | 44 | processes = samples.process_map |
36 | sorted_processes = sorted(processes, key=lambda p: p.pid ) | 45 | sorted_processes = [processes[k] for k in sorted(processes.keys())] |
37 | 46 | ||
38 | for index, line in enumerate(open(self.mk_fname('extract2.proc_ps.log'))): | 47 | ps_data = open(self.mk_fname('extract2.proc_ps.log')) |
48 | for index, line in enumerate(ps_data): | ||
39 | tokens = line.split(); | 49 | tokens = line.split(); |
40 | process = sorted_processes[index] | 50 | process = sorted_processes[index] |
41 | if debug: | 51 | if debug: |
42 | print tokens[0:4] | 52 | print(tokens[0:4]) |
43 | print process.pid, process.cmd, process.ppid, len(process.samples) | 53 | print(process.pid / 1000, process.cmd, process.ppid, len(process.samples)) |
44 | print '-------------------' | 54 | print('-------------------') |
45 | 55 | ||
46 | self.assertEqual(tokens[0], str(process.pid)) | 56 | self.assertEqual(tokens[0], str(process.pid // 1000)) |
47 | self.assertEqual(tokens[1], str(process.cmd)) | 57 | self.assertEqual(tokens[1], str(process.cmd)) |
48 | self.assertEqual(tokens[2], str(process.ppid)) | 58 | self.assertEqual(tokens[2], str(process.ppid // 1000)) |
49 | self.assertEqual(tokens[3], str(len(process.samples))) | 59 | self.assertEqual(tokens[3], str(len(process.samples))) |
50 | 60 | ps_data.close() | |
51 | 61 | ||
52 | def testparseProcDiskStatLog(self): | 62 | def testparseProcDiskStatLog(self): |
53 | state_with_headers = parsing.parse_file(parsing.ParserState(), self.mk_fname('header')) | 63 | trace = parsing.Trace(writer, args, options) |
64 | state_with_headers = parsing.parse_file(writer, trace, self.mk_fname('header')) | ||
54 | state_with_headers.headers['system.cpu'] = 'xxx (2)' | 65 | state_with_headers.headers['system.cpu'] = 'xxx (2)' |
55 | samples = parsing.parse_file(state_with_headers, self.mk_fname('proc_diskstats.log')).disk_stats | 66 | samples = parsing.parse_file(writer, state_with_headers, self.mk_fname('proc_diskstats.log')).disk_stats |
56 | self.assertEqual(141, len(samples)) | 67 | self.assertEqual(141, len(samples)) |
57 | 68 | ||
58 | for index, line in enumerate(open(self.mk_fname('extract.proc_diskstats.log'))): | 69 | diskstats_data = open(self.mk_fname('extract.proc_diskstats.log')) |
70 | for index, line in enumerate(diskstats_data): | ||
59 | tokens = line.split('\t') | 71 | tokens = line.split('\t') |
60 | sample = samples[index] | 72 | sample = samples[index] |
61 | if debug: | 73 | if debug: |
62 | print line.rstrip(), | 74 | print(line.rstrip()) |
63 | print sample | 75 | print(sample) |
64 | print '-------------------' | 76 | print('-------------------') |
65 | 77 | ||
66 | self.assertEqual(tokens[0], str(sample.time)) | 78 | self.assertEqual(tokens[0], str(sample.time)) |
67 | self.assert_(floatEq(float(tokens[1]), sample.read)) | 79 | self.assert_(floatEq(float(tokens[1]), sample.read)) |
68 | self.assert_(floatEq(float(tokens[2]), sample.write)) | 80 | self.assert_(floatEq(float(tokens[2]), sample.write)) |
69 | self.assert_(floatEq(float(tokens[3]), sample.util)) | 81 | self.assert_(floatEq(float(tokens[3]), sample.util)) |
82 | diskstats_data.close() | ||
70 | 83 | ||
71 | def testparseProcStatLog(self): | 84 | def testparseProcStatLog(self): |
72 | samples = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_stat.log')).cpu_stats | 85 | trace = parsing.Trace(writer, args, options) |
86 | samples = parsing.parse_file(writer, trace, self.mk_fname('proc_stat.log')).cpu_stats | ||
73 | self.assertEqual(141, len(samples)) | 87 | self.assertEqual(141, len(samples)) |
74 | 88 | ||
75 | for index, line in enumerate(open(self.mk_fname('extract.proc_stat.log'))): | 89 | stat_data = open(self.mk_fname('extract.proc_stat.log')) |
90 | for index, line in enumerate(stat_data): | ||
76 | tokens = line.split('\t') | 91 | tokens = line.split('\t') |
77 | sample = samples[index] | 92 | sample = samples[index] |
78 | if debug: | 93 | if debug: |
79 | print line.rstrip() | 94 | print(line.rstrip()) |
80 | print sample | 95 | print(sample) |
81 | print '-------------------' | 96 | print('-------------------') |
82 | self.assert_(floatEq(float(tokens[0]), sample.time)) | 97 | self.assert_(floatEq(float(tokens[0]), sample.time)) |
83 | self.assert_(floatEq(float(tokens[1]), sample.user)) | 98 | self.assert_(floatEq(float(tokens[1]), sample.user)) |
84 | self.assert_(floatEq(float(tokens[2]), sample.sys)) | 99 | self.assert_(floatEq(float(tokens[2]), sample.sys)) |
85 | self.assert_(floatEq(float(tokens[3]), sample.io)) | 100 | self.assert_(floatEq(float(tokens[3]), sample.io)) |
86 | 101 | stat_data.close() | |
87 | def testParseLogDir(self): | 102 | |
88 | res = parsing.parse([self.rootdir], False) | ||
89 | self.assertEqual(4, len(res)) | ||
90 | |||
91 | if __name__ == '__main__': | 103 | if __name__ == '__main__': |
92 | unittest.main() | 104 | unittest.main() |
93 | 105 | ||
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 | ||
5 | sys.path.insert(0, os.getcwd()) | 5 | sys.path.insert(0, os.getcwd()) |
6 | 6 | ||
7 | import parsing | 7 | import pybootchartgui.parsing as parsing |
8 | import process_tree | 8 | import pybootchartgui.process_tree as process_tree |
9 | import pybootchartgui.main as main | ||
10 | |||
11 | if sys.version_info >= (3, 0): | ||
12 | long = int | ||
9 | 13 | ||
10 | class TestProcessTree(unittest.TestCase): | 14 | class 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 |