This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC 2/3] Perf test framework


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 <http://www.gnu.org/licenses/>.
+
+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 <http://www.gnu.org/licenses/>.
+
+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 <http://www.gnu.org/licenses/>.
+
+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 <http://www.gnu.org/licenses/>.
+
+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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]