1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7
8from oeqa.selftest.case import OESelftestTestCase
9from oeqa.utils.commands import bitbake
10
11class BitBakeLogging(OESelftestTestCase):
12
13    def assertCount(self, item, entry, count):
14        self.assertEqual(item.count(entry), count, msg="Output:\n'''\n%s\n'''\ndoesn't contain %d copies of:\n'''\n%s\n'''\n" % (item, count, entry))
15
16    def test_shell_loggingA(self):
17        # no logs, no verbose
18        self.write_config('BBINCLUDELOGS = ""')
19        result = bitbake("logging-test -c shelltest -f", ignore_status = True)
20        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
21        self.assertNotIn("This is shell stdout", result.output)
22        self.assertNotIn("This is shell stderr", result.output)
23
24    def test_shell_loggingB(self):
25        # logs, no verbose
26        self.write_config('BBINCLUDELOGS = "yes"')
27        result = bitbake("logging-test -c shelltest -f", ignore_status = True)
28        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
29        self.assertCount(result.output, "This is shell stdout", 1)
30        self.assertCount(result.output, "This is shell stderr", 1)
31
32    def test_shell_loggingC(self):
33        # no logs, verbose
34        self.write_config('BBINCLUDELOGS = ""')
35        result = bitbake("logging-test -c shelltest -f -v", ignore_status = True)
36        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
37        # two copies due to set +x
38        self.assertCount(result.output, "This is shell stdout", 2)
39        self.assertCount(result.output, "This is shell stderr", 2)
40
41    def test_shell_loggingD(self):
42        # logs, verbose
43        self.write_config('BBINCLUDELOGS = "yes"')
44        result = bitbake("logging-test -c shelltest -f -v", ignore_status = True)
45        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
46        # two copies due to set +x
47        self.assertCount(result.output, "This is shell stdout", 2)
48        self.assertCount(result.output, "This is shell stderr", 2)
49
50    def test_python_exec_func_shell_loggingA(self):
51        # no logs, no verbose
52        self.write_config('BBINCLUDELOGS = ""')
53        result = bitbake("logging-test -c pythontest_exec_func_shell -f",
54                         ignore_status = True)
55        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
56        self.assertNotIn("This is shell stdout", result.output)
57        self.assertNotIn("This is shell stderr", result.output)
58
59    def test_python_exec_func_shell_loggingB(self):
60        # logs, no verbose
61        self.write_config('BBINCLUDELOGS = "yes"')
62        result = bitbake("logging-test -c pythontest_exec_func_shell -f",
63                         ignore_status = True)
64        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
65        self.assertCount(result.output, "This is shell stdout", 1)
66        self.assertCount(result.output, "This is shell stderr", 1)
67
68    def test_python_exec_func_shell_loggingC(self):
69        # no logs, verbose
70        self.write_config('BBINCLUDELOGS = ""')
71        result = bitbake("logging-test -c pythontest_exec_func_shell -f -v",
72                         ignore_status = True)
73        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
74        # two copies due to set +x
75        self.assertCount(result.output, "This is shell stdout", 2)
76        self.assertCount(result.output, "This is shell stderr", 2)
77
78    def test_python_exec_func_shell_loggingD(self):
79        # logs, verbose
80        self.write_config('BBINCLUDELOGS = "yes"')
81        result = bitbake("logging-test -c pythontest_exec_func_shell -f -v",
82                         ignore_status = True)
83        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
84        # two copies due to set +x
85        self.assertCount(result.output, "This is shell stdout", 2)
86        self.assertCount(result.output, "This is shell stderr", 2)
87
88    def test_python_exit_loggingA(self):
89        # no logs, no verbose
90        self.write_config('BBINCLUDELOGS = ""')
91        result = bitbake("logging-test -c pythontest_exit -f", ignore_status = True)
92        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
93        self.assertNotIn("This is python stdout", result.output)
94
95    def test_python_exit_loggingB(self):
96        # logs, no verbose
97        self.write_config('BBINCLUDELOGS = "yes"')
98        result = bitbake("logging-test -c pythontest_exit -f", ignore_status = True)
99        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
100        # A sys.exit() should include the output
101        self.assertCount(result.output, "This is python stdout", 1)
102
103    def test_python_exit_loggingC(self):
104        # no logs, verbose
105        self.write_config('BBINCLUDELOGS = ""')
106        result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True)
107        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
108        # python tasks don't log output with -v currently
109        #self.assertCount(result.output, "This is python stdout", 1)
110
111    def test_python_exit_loggingD(self):
112        # logs, verbose
113        self.write_config('BBINCLUDELOGS = "yes"')
114        result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True)
115        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
116        # python tasks don't log output with -v currently
117        #self.assertCount(result.output, "This is python stdout", 1)
118
119    def test_python_exec_func_python_loggingA(self):
120        # no logs, no verbose
121        self.write_config('BBINCLUDELOGS = ""')
122        result = bitbake("logging-test -c pythontest_exec_func_python -f",
123                         ignore_status = True)
124        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
125        self.assertNotIn("This is python stdout", result.output)
126
127    def test_python_exec_func_python_loggingB(self):
128        # logs, no verbose
129        self.write_config('BBINCLUDELOGS = "yes"')
130        result = bitbake("logging-test -c pythontest_exec_func_python -f",
131                         ignore_status = True)
132        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
133        # A sys.exit() should include the output
134        self.assertCount(result.output, "This is python stdout", 1)
135
136    def test_python_exec_func_python_loggingC(self):
137        # no logs, verbose
138        self.write_config('BBINCLUDELOGS = ""')
139        result = bitbake("logging-test -c pythontest_exec_func_python -f -v",
140                         ignore_status = True)
141        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
142        # python tasks don't log output with -v currently
143        #self.assertCount(result.output, "This is python stdout", 1)
144
145    def test_python_exec_func_python_loggingD(self):
146        # logs, verbose
147        self.write_config('BBINCLUDELOGS = "yes"')
148        result = bitbake("logging-test -c pythontest_exec_func_python -f -v",
149                         ignore_status = True)
150        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
151        # python tasks don't log output with -v currently
152        #self.assertCount(result.output, "This is python stdout", 1)
153
154    def test_python_fatal_loggingA(self):
155        # no logs, no verbose
156        self.write_config('BBINCLUDELOGS = ""')
157        result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True)
158        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
159        self.assertNotIn("This is python fatal test stdout", result.output)
160        self.assertCount(result.output, "This is a fatal error", 1)
161
162    def test_python_fatal_loggingB(self):
163        # logs, no verbose
164        self.write_config('BBINCLUDELOGS = "yes"')
165        result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True)
166        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
167        # A bb.fatal() should not include the output
168        self.assertNotIn("This is python fatal test stdout", result.output)
169        self.assertCount(result.output, "This is a fatal error", 1)
170
171    def test_python_fatal_loggingC(self):
172        # no logs, verbose
173        self.write_config('BBINCLUDELOGS = ""')
174        result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True)
175        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
176        # python tasks don't log output with -v currently
177        #self.assertCount(result.output, "This is python fatal test stdout", 1)
178        self.assertCount(result.output, "This is a fatal error", 1)
179
180    def test_python_fatal_loggingD(self):
181        # logs, verbose
182        self.write_config('BBINCLUDELOGS = "yes"')
183        result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True)
184        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
185        # python tasks don't log output with -v currently
186        #self.assertCount(result.output, "This is python fatal test stdout", 1)
187        self.assertCount(result.output, "This is a fatal error", 1)
188
189