]>
Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright (C) 2013-2015 Free Software Foundation, Inc. |
f27a1236 YQ |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | import testresult | |
17 | import reporter | |
18 | from measure import Measure | |
19 | from measure import MeasurementCpuTime | |
20 | from measure import MeasurementWallTime | |
21 | from measure import MeasurementVmSize | |
22 | ||
23 | class TestCase(object): | |
24 | """Base class of all performance testing cases. | |
25 | ||
26 | Each sub-class should override methods execute_test, in which | |
27 | several GDB operations are performed and measured by attribute | |
28 | measure. Sub-class can also override method warm_up optionally | |
29 | if the test case needs warm up. | |
30 | """ | |
31 | ||
32 | def __init__(self, name, measure): | |
33 | """Constructor of TestCase. | |
34 | ||
35 | Construct an instance of TestCase with a name and a measure | |
36 | which is to measure the test by several different measurements. | |
37 | """ | |
38 | ||
39 | self.name = name | |
40 | self.measure = measure | |
41 | ||
42 | def execute_test(self): | |
43 | """Abstract method to do the actual tests.""" | |
44 | raise NotImplementedError("Abstract Method.") | |
45 | ||
46 | def warm_up(self): | |
47 | """Do some operations to warm up the environment.""" | |
48 | pass | |
49 | ||
50 | def run(self, warm_up=True, append=True): | |
51 | """Run this test case. | |
52 | ||
53 | It is a template method to invoke method warm_up, | |
54 | execute_test, and finally report the measured results. | |
55 | If parameter warm_up is True, run method warm_up. If parameter | |
56 | append is True, the test result will be appended instead of | |
57 | overwritten. | |
58 | """ | |
59 | if warm_up: | |
60 | self.warm_up() | |
61 | ||
62 | self.execute_test() | |
63 | self.measure.report(reporter.TextReporter(append), self.name) | |
64 | ||
65 | class TestCaseWithBasicMeasurements(TestCase): | |
66 | """Test case measuring CPU time, wall time and memory usage.""" | |
67 | ||
68 | def __init__(self, name): | |
69 | result_factory = testresult.SingleStatisticResultFactory() | |
70 | measurements = [MeasurementCpuTime(result_factory.create_result()), | |
71 | MeasurementWallTime(result_factory.create_result()), | |
72 | MeasurementVmSize(result_factory.create_result())] | |
73 | super (TestCaseWithBasicMeasurements, self).__init__ (name, Measure(measurements)) |