1# 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_loggingA(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 def test_shell_loggingB(self): 23 # logs, no verbose 24 self.write_config('BBINCLUDELOGS = "yes"') 25 result = bitbake("logging-test -c shelltest -f", ignore_status = True) 26 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 27 self.assertCount(result.output, "This is shell stdout", 1) 28 self.assertCount(result.output, "This is shell stderr", 1) 29 30 def test_shell_loggingC(self): 31 # no logs, verbose 32 self.write_config('BBINCLUDELOGS = ""') 33 result = bitbake("logging-test -c shelltest -f -v", ignore_status = True) 34 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 35 # two copies due to set +x 36 self.assertCount(result.output, "This is shell stdout", 2) 37 self.assertCount(result.output, "This is shell stderr", 2) 38 39 def test_shell_loggingD(self): 40 # logs, verbose 41 self.write_config('BBINCLUDELOGS = "yes"') 42 result = bitbake("logging-test -c shelltest -f -v", ignore_status = True) 43 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 44 # two copies due to set +x 45 self.assertCount(result.output, "This is shell stdout", 2) 46 self.assertCount(result.output, "This is shell stderr", 2) 47 48 def test_python_exec_func_shell_loggingA(self): 49 # no logs, no verbose 50 self.write_config('BBINCLUDELOGS = ""') 51 result = bitbake("logging-test -c pythontest_exec_func_shell -f", 52 ignore_status = True) 53 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 54 self.assertNotIn("This is shell stdout", result.output) 55 self.assertNotIn("This is shell stderr", result.output) 56 57 def test_python_exec_func_shell_loggingB(self): 58 # logs, no verbose 59 self.write_config('BBINCLUDELOGS = "yes"') 60 result = bitbake("logging-test -c pythontest_exec_func_shell -f", 61 ignore_status = True) 62 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 63 self.assertCount(result.output, "This is shell stdout", 1) 64 self.assertCount(result.output, "This is shell stderr", 1) 65 66 def test_python_exec_func_shell_loggingC(self): 67 # no logs, verbose 68 self.write_config('BBINCLUDELOGS = ""') 69 result = bitbake("logging-test -c pythontest_exec_func_shell -f -v", 70 ignore_status = True) 71 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 72 # two copies due to set +x 73 self.assertCount(result.output, "This is shell stdout", 2) 74 self.assertCount(result.output, "This is shell stderr", 2) 75 76 def test_python_exec_func_shell_loggingD(self): 77 # logs, verbose 78 self.write_config('BBINCLUDELOGS = "yes"') 79 result = bitbake("logging-test -c pythontest_exec_func_shell -f -v", 80 ignore_status = True) 81 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 82 # two copies due to set +x 83 self.assertCount(result.output, "This is shell stdout", 2) 84 self.assertCount(result.output, "This is shell stderr", 2) 85 86 def test_python_exit_loggingA(self): 87 # no logs, no verbose 88 self.write_config('BBINCLUDELOGS = ""') 89 result = bitbake("logging-test -c pythontest_exit -f", ignore_status = True) 90 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 91 self.assertNotIn("This is python stdout", result.output) 92 93 def test_python_exit_loggingB(self): 94 # logs, no verbose 95 self.write_config('BBINCLUDELOGS = "yes"') 96 result = bitbake("logging-test -c pythontest_exit -f", ignore_status = True) 97 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 98 # A sys.exit() should include the output 99 self.assertCount(result.output, "This is python stdout", 1) 100 101 def test_python_exit_loggingC(self): 102 # no logs, verbose 103 self.write_config('BBINCLUDELOGS = ""') 104 result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True) 105 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 106 # python tasks don't log output with -v currently 107 #self.assertCount(result.output, "This is python stdout", 1) 108 109 def test_python_exit_loggingD(self): 110 # logs, verbose 111 self.write_config('BBINCLUDELOGS = "yes"') 112 result = bitbake("logging-test -c pythontest_exit -f -v", ignore_status = True) 113 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 114 # python tasks don't log output with -v currently 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 # python tasks don't log output with -v currently 141 #self.assertCount(result.output, "This is python stdout", 1) 142 143 def test_python_exec_func_python_loggingD(self): 144 # logs, verbose 145 self.write_config('BBINCLUDELOGS = "yes"') 146 result = bitbake("logging-test -c pythontest_exec_func_python -f -v", 147 ignore_status = True) 148 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 149 # python tasks don't log output with -v currently 150 #self.assertCount(result.output, "This is python stdout", 1) 151 152 def test_python_fatal_loggingA(self): 153 # no logs, no verbose 154 self.write_config('BBINCLUDELOGS = ""') 155 result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True) 156 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 157 self.assertNotIn("This is python fatal test stdout", result.output) 158 self.assertCount(result.output, "This is a fatal error", 1) 159 160 def test_python_fatal_loggingB(self): 161 # logs, no verbose 162 self.write_config('BBINCLUDELOGS = "yes"') 163 result = bitbake("logging-test -c pythontest_fatal -f", ignore_status = True) 164 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 165 # A bb.fatal() should not include the output 166 self.assertNotIn("This is python fatal test stdout", result.output) 167 self.assertCount(result.output, "This is a fatal error", 1) 168 169 def test_python_fatal_loggingC(self): 170 # no logs, verbose 171 self.write_config('BBINCLUDELOGS = ""') 172 result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True) 173 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 174 # python tasks don't log output with -v currently 175 #self.assertCount(result.output, "This is python fatal test stdout", 1) 176 self.assertCount(result.output, "This is a fatal error", 1) 177 178 def test_python_fatal_loggingD(self): 179 # logs, verbose 180 self.write_config('BBINCLUDELOGS = "yes"') 181 result = bitbake("logging-test -c pythontest_fatal -f -v", ignore_status = True) 182 self.assertIn("ERROR: Logfile of failure stored in:", result.output) 183 # python tasks don't log output with -v currently 184 #self.assertCount(result.output, "This is python fatal test stdout", 1) 185 self.assertCount(result.output, "This is a fatal error", 1) 186 187