1 # Copyright (C) 2013-2024 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/>.
16 from __future__
import absolute_import
18 import perftest
.testresult
as testresult
19 import perftest
.reporter
as reporter
20 from perftest
.measure
import Measure
21 from perftest
.measure
import MeasurementPerfCounter
22 from perftest
.measure
import MeasurementProcessTime
23 from perftest
.measure
import MeasurementWallTime
24 from perftest
.measure
import MeasurementVmSize
27 class TestCase(object):
28 """Base class of all performance testing cases.
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.
36 def __init__(self
, name
, measure
):
37 """Constructor of TestCase.
39 Construct an instance of TestCase with a name and a measure
40 which is to measure the test by several different measurements.
44 self
.measure
= measure
46 def execute_test(self
):
47 """Abstract method to do the actual tests."""
48 raise NotImplementedError("Abstract Method.")
51 """Do some operations to warm up the environment."""
54 def run(self
, warm_up
=True, append
=True):
55 """Run this test case.
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
67 self
.measure
.report(reporter
.TextReporter(append
), self
.name
)
70 class TestCaseWithBasicMeasurements(TestCase
):
71 """Test case measuring CPU time, wall time and memory usage."""
73 def __init__(self
, name
):
74 result_factory
= testresult
.SingleStatisticResultFactory()
76 MeasurementPerfCounter(result_factory
.create_result()),
77 MeasurementProcessTime(result_factory
.create_result()),
78 MeasurementWallTime(result_factory
.create_result()),
79 MeasurementVmSize(result_factory
.create_result()),
81 super(TestCaseWithBasicMeasurements
, self
).__init
__(name
, Measure(measurements
))