ignore invalid DOF provider sections
[binutils-gdb.git] / gdb / testsuite / gdb.perf / lib / perftest / testresult.py
blobc799d38bb8d9c6d9beab3a4bcc72ced711c32c65
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/>.
16 class TestResult(object):
17 """Base class to record and report test results.
19 Method record is to record the results of test case, and report
20 method is to report the recorded results by a given reporter.
21 """
23 def record(self, parameter, result):
24 raise NotImplementedError("Abstract Method:record.")
26 def report(self, reporter, name):
27 """Report the test results by reporter."""
28 raise NotImplementedError("Abstract Method:report.")
30 class SingleStatisticTestResult(TestResult):
31 """Test results for the test case with a single statistic."""
33 def __init__(self):
34 super (SingleStatisticTestResult, self).__init__ ()
35 self.results = dict ()
37 def record(self, parameter, result):
38 if parameter in self.results:
39 self.results[parameter].append(result)
40 else:
41 self.results[parameter] = [result]
43 def report(self, reporter, name):
44 reporter.start()
45 for key in sorted(self.results.iterkeys()):
46 reporter.report(name, key, self.results[key])
47 reporter.end()
49 class ResultFactory(object):
50 """A factory to create an instance of TestResult."""
52 def create_result(self):
53 """Create an instance of TestResult."""
54 raise NotImplementedError("Abstract Method:create_result.")
56 class SingleStatisticResultFactory(ResultFactory):
57 """A factory to create an instance of SingleStatisticTestResult."""
59 def create_result(self):
60 return SingleStatisticTestResult()