summaryrefslogtreecommitdiffstats
path: root/testing/talos/tests/test_talosconfig.py
blob: 85b6c953f032b15ff05c1e38b694699885069e8b (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from talos import talosconfig
from talos.configuration import YAML
import unittest
import json


# globals
ffox_path = 'test/path/to/firefox'
command_args = [ffox_path,
                '-profile',
                'pathtoprofile',
                '-tp',
                'pathtotpmanifest',
                '-tpchrome',
                '-tpmozafterpaint',
                '-tpnoisy',
                '-rss',
                '-tpcycles',
                '1',
                '-tppagecycles',
                '1']
with open("test_talosconfig_browser_config.json") as json_browser_config:
    browser_config = json.load(json_browser_config)
with open("test_talosconfig_test_config.json") as json_test_config:
    test_config = json.load(json_test_config)


class TestWriteConfig(unittest.TestCase):
    def test_writeConfigFile(self):
        obj = dict(some=123, thing='456', other=789)

        self.assertEquals(
            json.loads(talosconfig.writeConfigFile(obj, ('some', 'thing'))),
            dict(some=123, thing='456')
        )

        # test without keys
        self.assertEquals(
            json.loads(talosconfig.writeConfigFile(obj, None)),
            obj
        )


class TalosConfigUnitTest(unittest.TestCase):
    """
    A class inheriting from unittest.TestCase to test the generateTalosConfig function.
    """

    def validate(self, var1, var2):
        # Function to check whether the output generated is correct or not.
        # If the output generated is not correct then specify the expected output to be generated.
        if var1 == var2:
            return 1
        else:
            print("input '%s' != expected '%s'" % (var1, var2))

    def test_talosconfig(self):
        # This function stimulates a call to generateTalosConfig in talosconfig.py .
        # It is then tested whether the output generated is correct or not.
        # ensure that the output generated in yaml file is as expected or not.
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])
        self.validate(content['command'],
                      "test/path/to/firefox " +
                      "-profile " +
                      "pathtoprofile " +
                      "-tp " +
                      "pathtotpmanifest " +
                      "-tpchrome " +
                      "-tpmozafterpaint " +
                      "-tpnoisy " +
                      "-rss " +
                      "-tpcycles " +
                      "1 " +
                      "-tppagecycles " +
                      "1")
        self.validate(content['child_process'], "plugin-container")
        self.validate(content['process'], "firefox.exe")
        self.validate(content['browser_wait'], 5)
        self.validate(content['test_timeout'], 1200)
        self.validate(content['browser_log'], "browser_output.txt")
        self.validate(content['browser_path'], "test/path/to/firefox")
        self.validate(content['error_filename'], "pathtoerrorfile")
        self.validate(content['xperf_path'],
                      "C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")
        self.validate(content['buildid'], 20131205075310)
        self.validate(content['sourcestamp'], "39faf812aaec")
        self.validate(content['repository'], "http://hg.mozilla.org/releases/mozilla-release")
        self.validate(content['title'], "qm-pxp01")
        self.validate(content['testname'], "tp5n")
        self.validate(content['xperf_providers'], ['PROC_THREAD',
                                                   'LOADER',
                                                   'HARD_FAULTS',
                                                   'FILENAME',
                                                   'FILE_IO',
                                                   'FILE_IO_INIT'])
        self.validate(content['xperf_user_providers'],
                      ['Mozilla Generic Provider', 'Microsoft-Windows-TCPIP'])
        self.validate(content['xperf_stackwalk'],
                      ['FileCreate', 'FileRead', 'FileWrite', 'FileFlush', 'FileClose'])
        self.validate(content['processID'], "None")
        self.validate(content['approot'], "test/path/to")

    def test_errors(self):
        # Tests if errors are correctly raised.

        # Testing that error is correctly raised or not if xperf_path is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del browser_config_copy['xperf_path']
        talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])

        with self.assertRaises(KeyError):
            self.validate(content['xperf_path'],
                          "C:/Program Files/Microsoft Windows Performance Toolkit/xperf.exe")

        # Test to see if keyerror is raised or not for calling testname when xperf_path is missing
        with self.assertRaises(KeyError):
            self.validate(content['testname'], "tp5n")

        # Testing that error is correctly raised or not if xperf_providers is missing
        browser_config_copy = browser_config.copy()
        test_config_copy = test_config.copy()
        del test_config_copy['xperf_providers']
        talosconfig.generateTalosConfig(command_args, browser_config_copy, test_config_copy)
        yaml = YAML()
        content = yaml.read(browser_config['bcontroller_config'])

        # Checking keyerror when calling xperf_providers
        with self.assertRaises(KeyError):
            self.validate(content['xperf_providers'], ['PROC_THREAD', 'LOADER', 'HARD_FAULTS',
                                                       'FILENAME', 'FILE_IO', 'FILE_IO_INIT'])

        # Checking keyerror when calling xperf_user_providers when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['xperf_user_providers'],
                          ['Mozilla Generic Provider', 'Microsoft-Windows-TCPIP'])

        # Checking keyerror when calling xperf_stackwalk when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['xperf_stackwalk'],
                          ['FileCreate', 'FileRead', 'FileWrite', 'FileFlush', 'FileClose'])

        # Checking keyerror when calling processID when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['processID'], "None")

        # Checking keyerror when calling approot when xperf_providers is missing
        with self.assertRaises(KeyError):
            self.validate(content['approot'], "test/path/to")

if __name__ == '__main__':
    unittest.main()