summaryrefslogtreecommitdiffstats
path: root/scripts/listtestcases1.py
blob: 666633ef46562a496b5439411ecbb0fc0afc1343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from dbaccess import execQuery
from misc import idToText, textToId, benchmarkToComponents, printJSONHeader

class ListTestCases1:

    def __init__(self, host, platform, branch, sha1):
        self.host = host
        self.platform = platform
        self.branch = branch
        self.sha1 = sha1
        self.host_id = textToId("host", host)
        self.platform_id = textToId("platform", platform)
        self.branch_id = textToId("branch", branch)
        self.sha1_id = textToId("sha1", sha1)

    def execute(self):

        # Get all distinct benchmarks matching the context:
        bmark_ids = execQuery(
            "SELECT DISTINCT benchmarkId " +
            "FROM result WHERE hostId = " + str(self.host_id) +
            " AND platformId = " + str(self.platform_id) + " AND branchId = " +
            str(self.branch_id) + " AND sha1Id = " + str(self.sha1_id) + ";")

        # Extract all distinct test case components:
        tc_map = {}
        for item in bmark_ids:
            bmark_id = item[0]
            benchmark = idToText("benchmark", bmark_id)
            test_case, test_function, data_tag = (
                benchmarkToComponents(benchmark))
            tc_map[test_case] = True

        self.test_cases = sorted(tuple(tc_map.keys()))
        self.writeOutput()

    def writeOutputAsJSON(self):
        printJSONHeader()
        print "{ \"testcases\": ["
        first_test_case = True
        for test_case in self.test_cases:
            if not first_test_case:
                print ","
            first_test_case = False

            print "\"" + test_case + "\""
        print "]}"

class ListTestCases1AsJSON(ListTestCases1):
    def writeOutput(self):
        self.writeOutputAsJSON()