From 53a5b78d4ed126f1f45f021b55cd3abf3a28ac24 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 24 Nov 2012 17:40:26 -0800 Subject: start switching to sqlite; misc stuff. --- framework/database.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ framework/process.py | 4 ++-- programs/run.py | 25 +++++++++-------------- 3 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 framework/database.py diff --git a/framework/database.py b/framework/database.py new file mode 100644 index 0000000..fb7b1e3 --- /dev/null +++ b/framework/database.py @@ -0,0 +1,56 @@ +# +# Copyright © 2012 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +import apsw +import sys +import os.path as path +import xdg.BaseDirectory as xdg + +__all__ = ['load'] + +databaseFile = path.join(xdg.save_data_path('robyn'), 'results.db') + +def load(): + '''Load the results database, creating it if it doesn't exist. + + Will exit the program if it fails.''' + try: + connection = apsw.Connection(databaseFile) + cursor = connection.cursor() + + cursor.execute('''CREATE TABLE IF NOT EXISTS runs + (date INTEGER, + name TEXT, + driver TEXT, + sysinfo TEXT)''') + cursor.execute('''CREATE TABLE IF NOT EXISTS results + (run_id INTEGER, + test_name TEXT, + command TEXT, + result TEXT, + return_code INTEGER, + errors TEXT, + output TEXT)''') + return cursor + except OSError as e: + print('error: could not open results database', str(e), '\n') + sys.exit(0) diff --git a/framework/process.py b/framework/process.py index b1100a6..9bfa836 100644 --- a/framework/process.py +++ b/framework/process.py @@ -28,14 +28,14 @@ import subprocess __all__ = ['runProgram'] def runProgram(cmd, timeout, env = None): - """Run a program with a timeout in case it never terminates. + '''Run a program with a timeout in case it never terminates. cmd -- List of command and arguments. See subprocess.Popen. timeout -- Fractional number of seconds to wait before killing the program. env -- A dictionary containing additional environment variables to set. Returns a 4-tuple: (stdout, stderr, return code, ) - """ + ''' if env: fullEnv = os.environ.copy() diff --git a/programs/run.py b/programs/run.py index 9a39e58..544bb79 100755 --- a/programs/run.py +++ b/programs/run.py @@ -31,10 +31,10 @@ import os import os.path as path import sys +import framework.database import framework.suites -from framework.suites import TestSuite -def main(argv): +def parseArguments(argv): p = ArgumentParser(prog='robyn run', description='A GPU test runner') p.add_argument('-d', '--dry-run', action='store_true', help='Do not actually run tests, but show what would be performed', @@ -52,23 +52,16 @@ def main(argv): p.add_argument('--valgrind', action='store_true', help="Run tests in Valgrind's memcheck tool.", default=False) + p.add_argument('-r', '--results', action='store', + metavar='', + help='Specify an alternate result database (defaults to ~/.local/share/robyn/results.db))') p.add_argument('suites', nargs='+') - p.add_argument('resultDir', metavar='') - options = p.parse_args(argv) - - # Make/reuse the results directory - resultDir = path.abspath(options.resultDir) + return p.parse_args(argv) - if path.isdir(resultDir): - resume = True - else: - resume = False - try: - os.makedirs(resultDir) - except OSError as e: - print('error: could not create results dir:', str(e), '\n') - sys.exit(0) +def main(argv): + options = parseArguments(argv) + framework.database.load() suites = framework.suites.loadSuiteInfo(options.suites, True) for test in sorted(suites['piglit'].tests.keys()): -- cgit v1.2.3