1 # Copyright (C) 2013-2015 Free Software Foundation, Inc.
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.
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.
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/>.
18 from measure
import Measure
19 from measure
import MeasurementCpuTime
20 from measure
import MeasurementWallTime
21 from measure
import MeasurementVmSize
23 class TestCase(object):
24 """Base class of all performance testing cases.
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.
32 def __init__(self
, name
, measure
):
33 """Constructor of TestCase.
35 Construct an instance of TestCase with a name and a measure
36 which is to measure the test by several different measurements.
40 self
.measure
= measure
42 def execute_test(self
):
43 """Abstract method to do the actual tests."""
44 raise NotImplementedError("Abstract Method.")
47 """Do some operations to warm up the environment."""
50 def run(self
, warm_up
=True, append
=True):
51 """Run this test case.
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
63 self
.measure
.report(reporter
.TextReporter(append
), self
.name
)
65 class TestCaseWithBasicMeasurements(TestCase
):
66 """Test case measuring CPU time, wall time and memory usage."""
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
))