From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9755 invoked by alias); 28 Aug 2013 04:17:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9529 invoked by uid 89); 28 Aug 2013 04:17:54 -0000 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Aug 2013 04:17:54 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE,SPF_HELO_FAIL autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VEXCY-0006yh-Hh from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Tue, 27 Aug 2013 21:17:50 -0700 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 27 Aug 2013 21:17:49 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Tue, 27 Aug 2013 21:17:49 -0700 From: Yao Qi To: Subject: [RFC 2/3] Perf test framework Date: Wed, 28 Aug 2013 04:17:00 -0000 Message-ID: <1377663394-4975-3-git-send-email-yao@codesourcery.com> In-Reply-To: <1377663394-4975-1-git-send-email-yao@codesourcery.com> References: <520B7F70.6070207@codesourcery.com> <1377663394-4975-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-08/txt/msg00808.txt.bz2 This patch adds a basic framework to do performance testing for GDB. perftest.py is about the test case, testresult.py is about test results, and how are they saved. reporter.py is about how results are reported (in what format). gdb/testsuite/ * gdb.perf/lib/perftest/__init__.py: New. * gdb.perf/lib/perftest/perftest.py: New. * gdb.perf/lib/perftest/reporter.py: New. * gdb.perf/lib/perftest/testresult.py: New. * gdb.perf/lib/perftest/config.py: New. --- gdb/testsuite/gdb.perf/lib/perftest/config.py | 40 +++++++++++++++++ gdb/testsuite/gdb.perf/lib/perftest/perftest.py | 49 +++++++++++++++++++++ gdb/testsuite/gdb.perf/lib/perftest/reporter.py | 38 ++++++++++++++++ gdb/testsuite/gdb.perf/lib/perftest/testresult.py | 42 ++++++++++++++++++ 4 files changed, 169 insertions(+), 0 deletions(-) create mode 100644 gdb/testsuite/gdb.perf/lib/perftest/__init__.py create mode 100644 gdb/testsuite/gdb.perf/lib/perftest/config.py create mode 100644 gdb/testsuite/gdb.perf/lib/perftest/perftest.py create mode 100644 gdb/testsuite/gdb.perf/lib/perftest/reporter.py create mode 100644 gdb/testsuite/gdb.perf/lib/perftest/testresult.py diff --git a/gdb/testsuite/gdb.perf/lib/perftest/__init__.py b/gdb/testsuite/gdb.perf/lib/perftest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gdb/testsuite/gdb.perf/lib/perftest/config.py b/gdb/testsuite/gdb.perf/lib/perftest/config.py new file mode 100644 index 0000000..db24b16 --- /dev/null +++ b/gdb/testsuite/gdb.perf/lib/perftest/config.py @@ -0,0 +1,40 @@ +# Copyright (C) 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import ConfigParser +import reporter + +class PerfTestConfig(object): + """ + Create the right objects according to file perftest.ini. + """ + + def __init__(self): + self.config = ConfigParser.ConfigParser() + self.config.read("perftest.ini") + + def get_reporter(self): + """Create an instance of class Reporter which is determined by + the option 'type' in section '[Reporter]'.""" + if not self.config.has_section('Reporter'): + return reporter.TextReporter() + if not self.config.has_option('Reporter', 'type'): + return reporter.TextReporter() + + name = self.config.get('Reporter', 'type') + cls = getattr(reporter, name) + return cls() + +perftestconfig = PerfTestConfig() diff --git a/gdb/testsuite/gdb.perf/lib/perftest/perftest.py b/gdb/testsuite/gdb.perf/lib/perftest/perftest.py new file mode 100644 index 0000000..b15fd39 --- /dev/null +++ b/gdb/testsuite/gdb.perf/lib/perftest/perftest.py @@ -0,0 +1,49 @@ +# Copyright (C) 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import gdb +import testresult +from config import perftestconfig + +class TestCase(gdb.Function): + """Base class of all performance testing cases. It registers a GDB + convenience function 'perftest'. Invoke this convenience function + in GDB will call method 'invoke'.""" + + def __init__(self, result): + # Each test case registers a convenience function 'perftest'. + super (TestCase, self).__init__ ("perftest") + self.result = result + + def execute_test(self): + """Abstract method to do the actual tests.""" + raise RuntimeError("Abstract Method.") + + def __report(self, reporter): + # Private method to report the testing result by 'reporter'. + self.result.report (reporter) + + def invoke(self): + """Call method 'execute_test' and '__report'.""" + + self.execute_test() + self.__report(perftestconfig.get_reporter()) + return "Done" + +class SingleVariableTestCase(TestCase): + """Test case with a single variable.""" + + def __init__(self, name): + super (SingleVariableTestCase, self).__init__ (testresult.SingleVariableTestResult (name)) diff --git a/gdb/testsuite/gdb.perf/lib/perftest/reporter.py b/gdb/testsuite/gdb.perf/lib/perftest/reporter.py new file mode 100644 index 0000000..e27b2ae --- /dev/null +++ b/gdb/testsuite/gdb.perf/lib/perftest/reporter.py @@ -0,0 +1,38 @@ +# Copyright (C) 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +class Reporter(object): + """Base class of reporter, which is about reporting test results in + different formatss.""" + + def report(self, arg1, arg2, arg3): + raise RuntimeError("Abstract Method.") + + def end(self): + """Invoked when reporting is done. Usually it can be overridden + to do some cleanups, such as closing file descriptors.""" + raise RuntimeError("Abstract Method:end.") + +class TextReporter(Reporter): + """Report results in plain text 'perftest.log'.""" + + def __init__(self): + self.txt_log = open ("perftest.log", 'a+'); + + def report(self, arg1, arg2, arg3): + print >>self.txt_log, '%s %s %s' % (arg1, arg2, arg3) + + def end(self): + self.txt_log.close () diff --git a/gdb/testsuite/gdb.perf/lib/perftest/testresult.py b/gdb/testsuite/gdb.perf/lib/perftest/testresult.py new file mode 100644 index 0000000..9912326 --- /dev/null +++ b/gdb/testsuite/gdb.perf/lib/perftest/testresult.py @@ -0,0 +1,42 @@ +# Copyright (C) 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +class TestResult(object): + """Base class to record or save test results.""" + + def __init__(self, name): + self.name = name + + def record (self, variable, result): + raise RuntimeError("Abstract Method:record.") + + def report (self, reporter): + """Report the test results by reporter.""" + raise RuntimeError("Abstract Method:report.") + +class SingleVariableTestResult(TestResult): + """Test results for the test case with a single variable. """ + + def __init__(self, name): + super (SingleVariableTestResult, self).__init__ (name) + self.results = dict () + + def record(self, variable, result): + self.results[variable] = result + + def report(self, reporter): + for key in sorted(self.results.iterkeys()): + reporter.report (self.name, key, self.results[key]) + reporter.end () -- 1.7.7.6