diff options
author | Kenneth Graunke <kenneth@whitecape.org> | 2012-11-25 23:10:45 -0800 |
---|---|---|
committer | Kenneth Graunke <kenneth@whitecape.org> | 2012-11-25 23:10:45 -0800 |
commit | 86621c853b050ed08ed7edc9156b3a774867974c (patch) | |
tree | c1c7a1b754c193c78cad9a1a81f02ada34fe5471 | |
parent | 3b57707e753087c0475396c3f7e483a324c83655 (diff) |
DB SCHEMA CHANGE: use run_name in results table, not the date.
- Having "date" in one table and "run_id" in the other was confusing.
- It turned out to be really irritating for reporting: 'robyn report
<run name 1> <run name 2> ...' would've had to convert each name to
the numerical ID, which meant yet more SELECTS or JOINS.
- Multiple runs had to have unique names in Piglit too (or at least
unique result directories), so it's no big loss.
-rw-r--r-- | framework/database.py | 39 | ||||
-rw-r--r-- | framework/runner.py | 10 | ||||
-rwxr-xr-x | programs/report.py | 9 | ||||
-rwxr-xr-x | programs/run.py | 9 |
4 files changed, 37 insertions, 30 deletions
diff --git a/framework/database.py b/framework/database.py index f73a4a6..90f393f 100644 --- a/framework/database.py +++ b/framework/database.py @@ -38,12 +38,12 @@ class ResultDatabase: cursor = self.connection.cursor() cursor.execute('''CREATE TABLE IF NOT EXISTS runs - (date INTEGER PRIMARY KEY, - name TEXT, + (name TEXT PRIMARY KEY, + date INTEGER, driver TEXT, sysinfo TEXT)''') cursor.execute('''CREATE TABLE IF NOT EXISTS results - (run_id INTEGER, + (run_name TEXT, test_name TEXT, command TEXT, result TEXT, @@ -55,10 +55,14 @@ class ResultDatabase: sys.exit(0) def createRun(self, name, driver, sysinfo): - cursor = self.connection.cursor() + c = self.connection.cursor() date = int(time.time()) - cursor.execute('INSERT INTO runs VALUES(?,?,?,?)', (date, name, driver, sysinfo)) - return date + try: + c.execute('INSERT INTO runs VALUES(?,?,?,?)', + (name, date, driver, sysinfo)) + return True + except: + return False def listRuns(self): cursor = self.connection.cursor() @@ -69,41 +73,42 @@ class ResultDatabase: rows = [(run, test) for test in tests] c = self.connection.cursor() c.execute('BEGIN IMMEDIATE TRANSACTION') - c.executemany('INSERT INTO results(run_id, test_name) VALUES(?,?)', rows) + c.executemany('INSERT INTO results(run_name, test_name) VALUES(?,?)', rows) c.execute('END TRANSACTION') def findPlaceholders(self, run): c = self.connection.cursor() - xs = c.execute('SELECT test_name FROM results WHERE run_id = ? AND result IS NULL', [run]) + xs = c.execute('SELECT test_name FROM results WHERE run_name = ? AND result IS NULL', [run]) return [x[0] for x in xs] def writeResult(self, run, name, command, result): c = self.connection.cursor() - c.execute('UPDATE results SET command = ?, result = ?, return_code = ?, errors = ?, output = ? WHERE run_id = ? AND test_name = ? AND result IS NULL', (' '.join(command), result['status'], result['exitcode'], result['err'], result['out'], run, name)) + c.execute('UPDATE results SET command = ?, result = ?, return_code = ?, errors = ?, output = ? WHERE run_name = ? AND test_name = ? AND result IS NULL', (' '.join(command), result['status'], result['exitcode'], result['err'], result['out'], run, name)) def getResults(self, runs): c = self.connection.cursor() # Build self-join query to get results. This awful code generates: # - # SELECT R1.test_name, R1.result, R2.result, R3.result FROM - # (SELECT test_name, result FROM results WHERE run_id = 1) R1 + # SELECT R0.test_name, R0.result, R1.result, R2.result FROM + # (SELECT test_name, result FROM results WHERE run_name = 'foo') R0 # INNER JOIN - # (SELECT test_name, result FROM results WHERE run_id = 2) R2 + # (SELECT test_name, result FROM results WHERE run_name = 'bar') R1 # USING (test_name) # INNER JOIN - # (SELECT test_name, result FROM results WHERE run_id = 3) R3 + # (SELECT test_name, result FROM results WHERE run_name = 'quux') R2 # USING (test_name) - subselects = ['(SELECT test_name, result FROM results WHERE run_id = %d) R%d' % (r, r) for r in runs] - query = ' '.join(['SELECT R%d.test_name,' % runs[0], - ', '.join('R%d.result' % r for r in runs), + subselects = ['(SELECT test_name, result FROM results WHERE run_name = ?) R%d' % i for i in range(len(runs))] + query = ' '.join(['SELECT R0.test_name,', + ', '.join('R%d.result' % i for i in range(len(runs))), 'FROM', subselects[0], ' '.join([' INNER JOIN ' + s + ' USING (test_name) ' for s in subselects[1:]])]) + xs = c.execute(query, runs) + # Convert (name, s1, s2, s3) to {name: (s1, s2, s3)} results = {} - xs = c.execute(query) for x in xs: results[x[0]] = x[1:] diff --git a/framework/runner.py b/framework/runner.py index ecfc198..8a081b4 100644 --- a/framework/runner.py +++ b/framework/runner.py @@ -25,17 +25,17 @@ from framework.threading import processQueue __all__ = ['resume'] -def resume(db, config, args, tests, runID): - placeholders = db.findPlaceholders(runID) +def resume(db, config, args, tests, run_name): + placeholders = db.findPlaceholders(run_name) timeout = float(config['options']['timeout']) def runTest(data): - name, test = data + test_name, test = data result = test.run(timeout) - db.writeResult(runID, name, test.command, result) - print(name + ':', result['status']) + db.writeResult(run_name, test_name, test.command, result) + print(test_name + ':', result['status']) todo = [(name, tests[name]) for name in placeholders] diff --git a/programs/report.py b/programs/report.py index a542a5c..2b80dc6 100755 --- a/programs/report.py +++ b/programs/report.py @@ -36,7 +36,8 @@ from framework.database import ResultDatabase def parseArguments(argv, config): p = ArgumentParser(prog='robyn report', description='A GPU test runner') - p.add_argument('report', metavar='<directory to write HTML reports to>') + p.add_argument('-o', '--output', default='summary', + metavar='<directory to write HTML reports to>') p.add_argument('runs', nargs='+', metavar='<run name>') # XXX: alternate database (pending refactoring) @@ -47,13 +48,11 @@ def main(argv, config): db = ResultDatabase(config) - reportDir = args.report + reportDir = args.output if not path.exists(reportDir): os.makedirs(reportDir) - # XXX: translate run names into run IDs. - # XXX: for now, we expect runs to be 1353885503 1353885923 1353885927 - results = db.getResults([int(r) for r in args.runs]) + results = db.getResults(list(args.runs)) print(results) #os.link(path.join(templateDir, 'index.css'), diff --git a/programs/run.py b/programs/run.py index 8e762fb..1dbc47c 100755 --- a/programs/run.py +++ b/programs/run.py @@ -87,14 +87,17 @@ def main(argv, config): # Connect to the database db = ResultDatabase(config) + run_name = args.name # Create test run in database - runID = db.createRun(args.name, 'driver', 'system') + if not db.createRun(run_name, 'driver', 'system'): + print("error: `%s' already exists. Please use a different name." % run_name) + sys.exit(0) # Populate results with "not run yet" - db.addPlaceholderResults(runID, tests.keys()) + db.addPlaceholderResults(run_name, tests.keys()) # "Resume" the new test run - resume(db, config, args, tests, runID) + resume(db, config, args, tests, run_name) if __name__ == '__main__': main(sys.argv[1:]) |