enqueue-fill-buffer: improve array formatting
[piglit.git] / unittests / framework / test_monitoring.py
blob9500c7e930706b34d5e60a5b7d3d124eb0b72765
1 # coding=utf-8
2 # Copyright (c) 2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Tests for the monitoring module.
24 This provides tests for the framework.monitoring modules.
25 """
27 import pytest
29 from framework import exceptions
30 from framework import monitoring
31 from . import skip
33 # pylint: disable=no-self-use,attribute-defined-outside-init
36 class TestMonitoring(object):
37 """Tests for Monitoring methods."""
39 def setup(self):
40 """Setup for TestMonitoring.
42 This create a monitoring.Monitoring instance with monitoring disabled
43 to avoid reading the rules in piglit.conf.
44 """
45 self.regex = r'\*ERROR\*|BUG:'
46 self.init_contents = r'foo bar\n'
47 self.no_error_contents = r'foo bar\n'
48 self.error_contents = r'BUG:bar\n'
49 self.monitoring = monitoring.Monitoring(False)
51 @skip.linux
52 def test_delete_rule(self, tmpdir):
53 """monitoring.Monitoring: add and delete rule."""
54 p = tmpdir.join('foo')
55 p.write(self.init_contents)
56 self.monitoring.add_rule('error_file',
57 'file',
58 str(p),
59 self.regex)
60 self.monitoring.update_monitoring()
62 self.monitoring.delete_rule('error_file')
63 p.write(self.error_contents)
64 self.monitoring.check_monitoring()
66 assert self.monitoring.abort_needed is False
68 def test_add_rule_bad_format(self, tmpdir):
69 """monitoring.Monitoring: add non existing type rule."""
70 p = tmpdir.join('foo')
72 with pytest.raises(exceptions.PiglitFatalError):
73 self.monitoring.add_rule('error_file_bad_type',
74 'bad_type',
75 str(p),
76 self.regex)
78 @skip.linux
79 def test_file_error(self, tmpdir):
80 """monitoring.Monitoring: error found on a file."""
81 p = tmpdir.join('foo')
82 p.write(self.init_contents)
83 self.monitoring.add_rule('error_file',
84 'file',
85 str(p),
86 self.regex)
87 self.monitoring.update_monitoring()
89 p.write(self.error_contents)
90 self.monitoring.check_monitoring()
92 assert self.monitoring.abort_needed is True
94 @skip.linux
95 def test_file_no_error(self, tmpdir):
96 """monitoring.Monitoring: no error found on a file."""
97 p = tmpdir.join('foo')
98 p.write(self.init_contents)
99 self.monitoring.add_rule('no_error_file',
100 'file',
101 str(p),
102 self.regex)
103 self.monitoring.update_monitoring()
105 p.write(self.no_error_contents)
106 self.monitoring.check_monitoring()
108 assert self.monitoring.abort_needed is False
110 @skip.linux
111 def test_locked_file_error(self, tmpdir):
112 """monitoring.Monitoring: error found on a locked file."""
113 p = tmpdir.join('foo')
114 p.write(self.init_contents)
115 self.monitoring.add_rule('error_locked_file',
116 'locked_file',
117 str(p),
118 self.regex)
119 self.monitoring.update_monitoring()
121 p.write(self.error_contents)
122 self.monitoring.check_monitoring()
124 assert self.monitoring.abort_needed is True
126 @skip.linux
127 def test_locked_file_no_error(self, tmpdir):
128 """monitoring.Monitoring: no error found on a locked file."""
129 p = tmpdir.join('foo')
130 p.write(self.init_contents)
131 self.monitoring.add_rule('no_error_file',
132 'locked_file',
133 str(p),
134 self.regex)
135 self.monitoring.update_monitoring()
137 p.write(self.no_error_contents)
138 self.monitoring.check_monitoring()
140 assert self.monitoring.abort_needed is False
142 @skip.linux
143 def test_dmesg_error(self, mocker):
144 """monitoring.Monitoring: error found on the dmesg."""
145 mocker.patch('framework.dmesg.subprocess.check_output',
146 mocker.Mock(return_value=b'[1.0]This\n[2.0]is\n[3.0]dmesg'))
147 self.monitoring.add_rule('no_error_file',
148 'dmesg',
149 '--level emerg,alert,crit,err',
150 self.regex)
151 self.monitoring.update_monitoring()
153 mocker.patch('framework.dmesg.subprocess.check_output',
154 mocker.Mock(return_value=b'[4.0]foo\n[5.0]*ERROR* bar'))
155 self.monitoring.check_monitoring()
157 assert self.monitoring.abort_needed is True
159 @skip.linux
160 def test_dmesg_no_error(self, mocker):
161 """monitoring.Monitoring: no error found on the dmesg."""
162 mocker.patch('framework.dmesg.subprocess.check_output',
163 mocker.Mock(return_value=b'[1.0]This\n[2.0]is\n[3.0]dmesg'))
164 self.monitoring.add_rule('no_error_file',
165 'dmesg',
166 '--level emerg,alert,crit,err',
167 self.regex)
168 self.monitoring.update_monitoring()
170 mocker.patch('framework.dmesg.subprocess.check_output',
171 mocker.Mock(return_value=b'[4.0]foo\n[5.0] bar'))
172 self.monitoring.check_monitoring()
174 assert self.monitoring.abort_needed is False