blob: ea6c3c8c77ebf2e95d22080a1d9edc3cd1353443 [file] [log] [blame]
Andrew Geissler5199d832021-09-24 16:47:35 -05001#
2# SPDX-License-Identifier: MIT
3#
4
5
6from oeqa.selftest.case import OESelftestTestCase
7from oeqa.utils.commands import bitbake
8
9class BitBakeLogging(OESelftestTestCase):
10
11 def assertCount(self, item, entry, count):
12 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))
13
14 def test_shell_logging(self):
15 # no logs, no verbose
16 self.write_config('BBINCLUDELOGS = ""')
17 result = bitbake("logging-test -c shelltest -f", ignore_status = True)
18 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
19 self.assertNotIn("This is shell stdout", result.output)
20 self.assertNotIn("This is shell stderr", result.output)
21
22 # logs, no verbose
23 self.write_config('BBINCLUDELOGS = "yes"')
24 result = bitbake("logging-test -c shelltest -f", ignore_status = True)
25 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
26 self.assertCount(result.output, "This is shell stdout", 1)
27 self.assertCount(result.output, "This is shell stderr", 1)
28
29 # no logs, verbose
30 self.write_config('BBINCLUDELOGS = ""')
31 result = bitbake("logging-test -c shelltest -f -v", ignore_status = True)
32 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
33 # two copies due to set +x
34 self.assertCount(result.output, "This is shell stdout", 2)
35 self.assertCount(result.output, "This is shell stderr", 2)
36
37 # logs, verbose
38 self.write_config('BBINCLUDELOGS = "yes"')
39 result = bitbake("logging-test -c shelltest -f -v", ignore_status = True)
40 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
41 # two copies due to set +x
42 self.assertCount(result.output, "This is shell stdout", 2)
43 self.assertCount(result.output, "This is shell stderr", 2)
44
45 def test_python_exit_logging(self):
46 # no logs, no verbose
47 self.write_config('BBINCLUDELOGS = ""')
48 result = bitbake("logging-test -c pythontest_exit -f", ignore_status = True)
49 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
50 self.assertNotIn("This is python stdout", result.output)
51
52 # logs, no verbose
53 self.write_config('BBINCLUDELOGS = "yes"')
54 result = bitbake("logging-test -c pythontest_exit -f", ignore_status = True)
55 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
56 # A sys.exit() should include the output
57 self.assertCount(result.output, "This is python stdout", 1)
58
59 # no logs, verbose
60 self.write_config('BBINCLUDELOGS = ""')
61 result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True)
62 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
63 # python tasks don't log output with -v currently
64 #self.assertCount(result.output, "This is python stdout", 1)
65
66 # logs, verbose
67 self.write_config('BBINCLUDELOGS = "yes"')
68 result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True)
69 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
70 # python tasks don't log output with -v currently
71 #self.assertCount(result.output, "This is python stdout", 1)
72
73 def test_python_fatal_logging(self):
74 # no logs, no verbose
75 self.write_config('BBINCLUDELOGS = ""')
76 result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True)
77 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
78 self.assertNotIn("This is python fatal test stdout", result.output)
79 self.assertCount(result.output, "This is a fatal error", 1)
80
81 # logs, no verbose
82 self.write_config('BBINCLUDELOGS = "yes"')
83 result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True)
84 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
85 # A bb.fatal() should not include the output
86 self.assertNotIn("This is python fatal test stdout", result.output)
87 self.assertCount(result.output, "This is a fatal error", 1)
88
89 # no logs, verbose
90 self.write_config('BBINCLUDELOGS = ""')
91 result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True)
92 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
93 # python tasks don't log output with -v currently
94 #self.assertCount(result.output, "This is python fatal test stdout", 1)
95 self.assertCount(result.output, "This is a fatal error", 1)
96
97 # logs, verbose
98 self.write_config('BBINCLUDELOGS = "yes"')
99 result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True)
100 self.assertIn("ERROR: Logfile of failure stored in:", result.output)
101 # python tasks don't log output with -v currently
102 #self.assertCount(result.output, "This is python fatal test stdout", 1)
103 self.assertCount(result.output, "This is a fatal error", 1)
104