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