From ddac201228685e727d7c84ac0210d2c968e5ff96 Mon Sep 17 00:00:00 2001 From: Daniel Brown <ddb@star.sr.bham.ac.uk> Date: Thu, 1 Aug 2013 02:52:29 +0100 Subject: [PATCH] Adding kat selection and more reporting --- pykat/testing/test.py | 76 ++++++++--------- pykat/testing/web/templates/finesse_test.html | 82 ++++++++++++++++++- pykat/testing/web/web_interface.py | 29 +++++-- 3 files changed, 134 insertions(+), 53 deletions(-) diff --git a/pykat/testing/test.py b/pykat/testing/test.py index 282b1ca..a56f249 100644 --- a/pykat/testing/test.py +++ b/pykat/testing/test.py @@ -56,9 +56,10 @@ class FinesseTestProcess(Thread): errorOccurred = None diffFound = False diffing = False + kats_to_run = [] def __init__(self, TEST_DIR, BASE_DIR, test_commit, - run_fast=False, suites=[], test_id="0", + run_fast=False, kats=[], test_id="0", git_bin="",emails="", nobuild=True,*args, **kqwargs): Thread.__init__(self) @@ -104,12 +105,8 @@ class FinesseTestProcess(Thread): if not os.path.isdir(self.TEST_DIR): raise Exception("TEST_DIR was not a valid directory, should point to a clone of the FINESSE test repository") - if not suites: - self.suites = ["physics","random"] - else: - self.suites = [] - self.suites.extend(suites) - + self.kats_to_run = kats + self.GIT_BIN = git_bin def cancelCheck(self): @@ -127,9 +124,9 @@ class FinesseTestProcess(Thread): def get_progress(self): if self.diffing: - return 'Diffing {0} out of {1} ({2} in {3})'.format(self.done_kats, self.total_kats, self.running_kat, self.running_suite) + return 'Diffing {0} out of {1} ({2} in {3})'.format(self.done_kats, self.total_kats/2, self.running_kat, self.running_suite) if self.built: - return 'Running {0} out of {1} ({2} in {3})'.format(self.done_kats, self.total_kats, self.running_kat, self.running_suite) + return 'Running {0} out of {1} ({2} in {3})'.format(self.done_kats, self.total_kats/2, self.running_kat, self.running_suite) else: return 'Building FINESSE executable' @@ -223,31 +220,23 @@ class FinesseTestProcess(Thread): # create dictionary structures # and count up total number of files to process - for suite in self.suites: + for suite in self.kats_to_run.keys(): kat_run_exceptions[suite] = {} output_differences[suite] = {} run_times[suite] = {} - os.chdir(os.path.join(self.TEST_DIR,"kat_test",suite)) - - for files in os.listdir("."): - if files.endswith(".kat"): - self.total_kats += 1 + self.total_kats += len(self.kats_to_run[suite]) # multiply as we include the diffining in the percentage # done self.total_kats *= 2 - for suite in self.suites: + for suite in self.kats_to_run.keys(): self.cancelCheck() print "Running suite: " + suite + "..." - kats = [] + kats = self.kats_to_run[suite] os.chdir(os.path.join(self.TEST_DIR,"kat_test",suite)) - for files in os.listdir("."): - if files.endswith(".kat"): - kats.append(files) - SUITE_OUTPUT_DIR = os.path.join(OUTPUTS_DIR,suite) os.mkdir(SUITE_OUTPUT_DIR) @@ -277,7 +266,7 @@ class FinesseTestProcess(Thread): self.cancelCheck() - for suite in self.suites: + for suite in self.kats_to_run.keys(): if len(kat_run_exceptions[suite].keys()) > 0: print "Could not run the following kats:\n" + "\n".join(kat_run_exceptions.keys()) + " in " + suite else: @@ -286,7 +275,7 @@ class FinesseTestProcess(Thread): self.diffing = True # Now we have generated the output files compare them to the references - for suite in self.suites: + for suite in self.kats_to_run.keys(): self.cancelCheck() print "Diffing suite: " + suite + "..." @@ -304,6 +293,7 @@ class FinesseTestProcess(Thread): for out in outs: self.cancelCheck() + self.running_kat = out ref_file = os.path.join(REF_DIR,out) @@ -339,11 +329,9 @@ class FinesseTestProcess(Thread): os.mkdir("reports") os.chdir("reports") - today = datetime.datetime.utcnow() + today = datetime.utcnow() reportname = today.strftime('%d%m%y') print "Writing report to " + reportname - - self.cancelCheck() f = open(reportname,'w') f.write("Python Nightly Test\n") @@ -359,7 +347,7 @@ class FinesseTestProcess(Thread): isError = False - for suite in suites: + for suite in self.kats_to_run.keys(): f.write("\n\n" + str(len(output_differences[suite].keys())) + " differences in suite " + suite) for k in output_differences[suite].keys(): isError = True @@ -376,24 +364,24 @@ class FinesseTestProcess(Thread): f.close() - self.cancelCheck() - - if self.emails: + #if self.emails: + # + # if isError: + # subject = "Finesse test ERROR" + # else: + # subject = "Finesse test OK" + # emails = self.emails + + # args = ["mailx", "-s", subject, emails] + # p = sub.Popen(args, stdout=sub.PIPE, stderr=sub.PIPE, stdin=sub.PIPE) + # r = open(reportname,"r") + # out, err = p.communicate(r.read()) + #else: + # print "No emails specified" + + return output_differences + - if isError: - subject = "Finesse test ERROR" - else: - subject = "Finesse test OK" - - emails = self.emails - - args = ["mailx", "-s", subject, emails] - p = sub.Popen(args, stdout=sub.PIPE, stderr=sub.PIPE, stdin=sub.PIPE) - r = open(reportname,"r") - out, err = p.communicate(r.read()) - else: - print "No emails specified" - def run(self): try: diff --git a/pykat/testing/web/templates/finesse_test.html b/pykat/testing/web/templates/finesse_test.html index beb3490..b766a42 100644 --- a/pykat/testing/web/templates/finesse_test.html +++ b/pykat/testing/web/templates/finesse_test.html @@ -3,6 +3,26 @@ <!--<link rel="stylesheet" type="text/css" href="/css/style.css"/>--> <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/> <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"> + + <style type="text/css"> + SELECT, INPUT[type="text"] { + width: 300px; + box-sizing: border-box; + } + SECTION { + width: 700px; + padding: 8px; + overflow: auto; + } + SECTION > DIV { + float: left; + padding: 4px; + } + SECTION > DIV + DIV { + width: 40px; + text-align: center; + } + </style> </head> <body> @@ -49,6 +69,22 @@ <input type="button" value="Refresh" id="btnGetLogs"/> <input type="button" value="Start new FINESSSE test" id="btnStartTest"/> + + <section class="container"> + <div> + <div>Files to run</div> + <select id="leftValues" size="12" multiple></select> + </div> + <div style="padding-top:100px;"> + <input type="button" id="btnLeft" value="<<" /> + <input type="button" id="btnRight" value=">>" /> + </div> + <div> + <div style="width: 100px;">Files available</div> + <select id="rightValues" size="12" multiple> + </select> + </div> + </section> </div> <div class="prev_test"> @@ -67,6 +103,7 @@ $(document).ready(function(){ updateBranches(); getPreviousTests(); + updateKats(); window.setInterval(function(){ updateQueuedTests(); @@ -75,6 +112,16 @@ }); + $("#btnLeft").click(function () { + var selectedItem = $("#rightValues option:selected"); + $("#leftValues").append(selectedItem); + }); + + $("#btnRight").click(function () { + var selectedItem = $("#leftValues option:selected"); + $("#rightValues").append(selectedItem); + }); + $('#btnGetPrevTests').click(function(){ getPreviousTests(); }); @@ -107,6 +154,27 @@ updateProgress(); }); + function updateKats(){ + $.ajax({ + type: "POST", + url: "/finesse/get/kats", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function(data){ + rlist = $('#rightValues') + rlist.empty() + $('#leftValues').empty() + + for(var i=0; i < data.kats.length; i++){ + rlist.append($('<option>', { value: data.kats[i], text: data.values[i]})); + } + }, + error: function(o,a,err){ + alert("Error getting kats : " + err); + } + }); + } + function getPreviousTests() { $.ajax({ type: "POST", @@ -234,9 +302,21 @@ } function startNewTest(){ + opts = $('#leftValues option'); + kats = {}; + + for(var i=0; i<opts.length; i++){ + suite = opts[i].text.split(" - ")[0] + + if(!(suite in kats)){ + kats[suite] = []; + } + + kats[suite].push(opts[i].value); + } list = $("#commit_list"); - data = JSON.stringify({"git_commit": list.val()}); + data = JSON.stringify({"git_commit": list.val(), "kats":kats}); $.ajax({ type: "POST", diff --git a/pykat/testing/web/web_interface.py b/pykat/testing/web/web_interface.py index c697900..9c9db71 100644 --- a/pykat/testing/web/web_interface.py +++ b/pykat/testing/web/web_interface.py @@ -49,8 +49,6 @@ if db.exists(): print "Current test_id: " + str(test_id) - for a in db.all('srccommit'): - print a else: db.create() db.add_index(TestIDIndex(db.path, 'testid')) @@ -227,10 +225,11 @@ def finesse_start_rerun(id): return "ok" @app.route('/finesse/start_test', methods=["POST"]) -def finesse_start_test(git_commit): - return jsonify(__finesse_start_test(request.json["git_commit"])) +def finesse_start_test(): -def __finesse_start_test(git_commit): + return jsonify(__finesse_start_test(request.json["git_commit"], request.json["kats"])) + +def __finesse_start_test(git_commit, kats): global current_test, test_id try: @@ -252,7 +251,7 @@ def __finesse_start_test(git_commit): test = finesse_test.FinesseTestProcess(os.path.join(app.instance_path, "finesse_test"), TEST_RUN_PATH, git_commit, - run_fast=True, suites=[], test_id=test_id, + run_fast=False, kats=kats, test_id=test_id, emails="", nobuild=False) db.insert(dict(t="test", @@ -474,9 +473,22 @@ def finesse_view(view_test_id): # pass +@app.route("/finesse/get/kats", methods=["POST"]) +def finesse_get_kats(): + suites = ["physics","random"] + kats = [] + values = [] + for suite in suites: + suite_path = os.path.join(app.instance_path,"finesse_test","kat_test",suite) + + for file in os.listdir(suite_path): + if file.endswith(".kat"): + kats.append(str(file)) + values.append(suite + " - " + str(file)) + + return jsonify(kats=kats, values=values) - print "Starting commit watch from most recent commit: " + latest_commit_id_tested def setInterval(interval): @@ -495,7 +507,8 @@ def setInterval(interval): return wrapper return decorator -@setInterval(10) + +@setInterval(600) def checkLatestCommits(): global latest_commit_id_tested out = utils.git(["--git-dir",SRC_GIT_PATH,"log",latest_commit_id_tested + "..HEAD",'--pretty=format:"%H"']) -- GitLab