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        self.assertCount(result.output, "This is python stdout", 1)
109
110    def test_python_exit_loggingD(self):
111        # logs, verbose
112        self.write_config('BBINCLUDELOGS = "yes"')
113        result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True)
114        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
115        self.assertCount(result.output, "This is python stdout", 1)
116
117    def test_python_exec_func_python_loggingA(self):
118        # no logs, no verbose
119        self.write_config('BBINCLUDELOGS = ""')
120        result = bitbake("logging-test -c pythontest_exec_func_python -f",
121                         ignore_status = True)
122        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
123        self.assertNotIn("This is python stdout", result.output)
124
125    def test_python_exec_func_python_loggingB(self):
126        # logs, no verbose
127        self.write_config('BBINCLUDELOGS = "yes"')
128        result = bitbake("logging-test -c pythontest_exec_func_python -f",
129                         ignore_status = True)
130        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
131        # A sys.exit() should include the output
132        self.assertCount(result.output, "This is python stdout", 1)
133
134    def test_python_exec_func_python_loggingC(self):
135        # no logs, verbose
136        self.write_config('BBINCLUDELOGS = ""')
137        result = bitbake("logging-test -c pythontest_exec_func_python -f -v",
138                         ignore_status = True)
139        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
140        self.assertCount(result.output, "This is python stdout", 1)
141
142    def test_python_exec_func_python_loggingD(self):
143        # logs, verbose
144        self.write_config('BBINCLUDELOGS = "yes"')
145        result = bitbake("logging-test -c pythontest_exec_func_python -f -v",
146                         ignore_status = True)
147        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
148        self.assertCount(result.output, "This is python stdout", 1)
149
150    def test_python_fatal_loggingA(self):
151        # no logs, no verbose
152        self.write_config('BBINCLUDELOGS = ""')
153        result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True)
154        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
155        self.assertNotIn("This is python fatal test stdout", result.output)
156        self.assertCount(result.output, "This is a fatal error", 1)
157
158    def test_python_fatal_loggingB(self):
159        # logs, no verbose
160        self.write_config('BBINCLUDELOGS = "yes"')
161        result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True)
162        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
163        # A bb.fatal() should not include the output
164        self.assertNotIn("This is python fatal test stdout", result.output)
165        self.assertCount(result.output, "This is a fatal error", 1)
166
167    def test_python_fatal_loggingC(self):
168        # no logs, verbose
169        self.write_config('BBINCLUDELOGS = ""')
170        result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True)
171        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
172        self.assertCount(result.output, "This is python fatal test stdout", 1)
173        self.assertCount(result.output, "This is a fatal error", 1)
174
175    def test_python_fatal_loggingD(self):
176        # logs, verbose
177        self.write_config('BBINCLUDELOGS = "yes"')
178        result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True)
179        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
180        self.assertCount(result.output, "This is python fatal test stdout", 1)
181        self.assertCount(result.output, "This is a fatal error", 1)
182
183