]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2013-2024 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 | ||
582a1b00 SM |
16 | from __future__ import absolute_import |
17 | ||
18 | import perftest.testresult as testresult | |
19 | import perftest.reporter as reporter | |
20 | from perftest.measure import Measure | |
46f2c22e PA |
21 | from perftest.measure import MeasurementPerfCounter |
22 | from perftest.measure import MeasurementProcessTime | |
582a1b00 SM |
23 | from perftest.measure import MeasurementWallTime |
24 | from perftest.measure import MeasurementVmSize | |
25 | ||
f27a1236 YQ |
26 | |
27 | class TestCase(object): | |
28 | """Base class of all performance testing cases. | |
29 | ||
30 | Each sub-class should override methods execute_test, in which | |
31 | several GDB operations are performed and measured by attribute | |
32 | measure. Sub-class can also override method warm_up optionally | |
33 | if the test case needs warm up. | |
34 | """ | |
35 | ||
36 | def __init__(self, name, measure): | |
37 | """Constructor of TestCase. | |
38 | ||
39 | Construct an instance of TestCase with a name and a measure | |
40 | which is to measure the test by several different measurements. | |
41 | """ | |
42 | ||
43 | self.name = name | |
44 | self.measure = measure | |
45 | ||
46 | def execute_test(self): | |
47 | """Abstract method to do the actual tests.""" | |
48 | raise NotImplementedError("Abstract Method.") | |
49 | ||
50 | def warm_up(self): | |
51 | """Do some operations to warm up the environment.""" | |
52 | pass | |
53 | ||
54 | def run(self, warm_up=True, append=True): | |
55 | """Run this test case. | |
56 | ||
57 | It is a template method to invoke method warm_up, | |
58 | execute_test, and finally report the measured results. | |
59 | If parameter warm_up is True, run method warm_up. If parameter | |
60 | append is True, the test result will be appended instead of | |
61 | overwritten. | |
62 | """ | |
63 | if warm_up: | |
64 | self.warm_up() | |
65 | ||
66 | self.execute_test() | |
67 | self.measure.report(reporter.TextReporter(append), self.name) | |
68 | ||
13123da8 | 69 | |
f27a1236 YQ |
70 | class TestCaseWithBasicMeasurements(TestCase): |
71 | """Test case measuring CPU time, wall time and memory usage.""" | |
72 | ||
73 | def __init__(self, name): | |
74 | result_factory = testresult.SingleStatisticResultFactory() | |
13123da8 | 75 | measurements = [ |
46f2c22e PA |
76 | MeasurementPerfCounter(result_factory.create_result()), |
77 | MeasurementProcessTime(result_factory.create_result()), | |
13123da8 SM |
78 | MeasurementWallTime(result_factory.create_result()), |
79 | MeasurementVmSize(result_factory.create_result()), | |
80 | ] | |
81 | super(TestCaseWithBasicMeasurements, self).__init__(name, Measure(measurements)) |