summaryrefslogtreecommitdiffstats
path: root/scripts/listtestcases2.py
blob: 9cdcbdad94a0522b99e3737e2b9f5ff05c0df0c7 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
import json
from dbaccess import execQuery
from misc import (
    idToText, textToId, getContext, benchmarkToComponents, printJSONHeader)

class ListTestCases2:

    def __init__(
        self, host1, platform1, branch1, sha11, host2, platform2, branch2,
        sha12):
        self.host1 = host1
        self.platform1 = platform1
        self.branch1 = branch1
        self.sha11 = sha11
        self.host2 = host2
        self.platform2 = platform2
        self.branch2 = branch2
        self.sha12 = sha12
        self.host1_id = textToId("host", host1)
        self.platform1_id = textToId("platform", platform1)
        self.branch1_id = textToId("branch", branch1)
        self.sha11_id = textToId("sha1", sha11)
        self.host2_id = textToId("host", host2)
        self.platform2_id = textToId("platform", platform2)
        self.branch2_id = textToId("branch", branch2)
        self.sha12_id = textToId("sha1", sha12)

    def execute(self):

        # Get all distinct benchmarks matching both contexts:
        bmark_ids = execQuery(
            "SELECT DISTINCT benchmarkId"
            " FROM result WHERE contextId = %d"
            " INTERSECT "
            "SELECT DISTINCT benchmarkId"
            " FROM result WHERE contextId = %d;"
            % (getContext(
                    self.host1_id, self.platform1_id, self.branch1_id,
                    self.sha11_id),
               getContext(
                    self.host2_id, self.platform2_id, self.branch2_id,
                    self.sha12_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()
        json.dump({ 'testcases': self.test_cases }, sys.stdout)

class ListTestCases2AsJSON(ListTestCases2):
    def writeOutput(self):
        self.writeOutputAsJSON()