2424import kunit_parser
2525import kunit_kernel
2626import kunit_json
27+ import kunit_junit
2728import kunit
2829from kunit_printer import stdout
2930
@@ -693,6 +694,38 @@ class StrContains(str):
693694 def __eq__ (self , other ):
694695 return self in other
695696
697+ class KUnitJUnitTest (unittest .TestCase ):
698+ def setUp (self ):
699+ self .print_mock = mock .patch ('kunit_printer.Printer.print' ).start ()
700+ self .addCleanup (mock .patch .stopall )
701+
702+ def _junit_string (self , log_file ):
703+ with open (_test_data_path (log_file )) as file :
704+ test_result = kunit_parser .parse_run_tests (file , stdout )
705+ junit_string = kunit_junit .get_junit_result (
706+ test = test_result )
707+ print (junit_string )
708+ return junit_string
709+
710+ def test_failed_test_junit (self ):
711+ result = self ._junit_string ('test_is_test_passed-failure.log' )
712+ self .assertTrue ("<failure>" in result )
713+
714+ def test_skipped_test_junit (self ):
715+ result = self ._junit_string ('test_skip_tests.log' )
716+ self .assertTrue ("<skipped>" in result )
717+ self .assertTrue ("skipped=\" 1\" " in result )
718+
719+ def test_crashed_test_junit (self ):
720+ result = self ._junit_string ('test_kernel_panic_interrupt.log' )
721+ self .assertTrue ("<error>" in result );
722+
723+ def test_no_tests_junit (self ):
724+ result = self ._junit_string ('test_is_test_passed-no_tests_run_with_header.log' )
725+ self .assertTrue ("tests=\" 0\" " in result )
726+ self .assertFalse ("testcase" in result )
727+
728+
696729class KUnitMainTest (unittest .TestCase ):
697730 def setUp (self ):
698731 path = _test_data_path ('test_is_test_passed-all_passed.log' )
@@ -940,7 +973,7 @@ def test_list_tests(self):
940973 self .linux_source_mock .run_kernel .return_value = ['TAP version 14' , 'init: random output' ] + want
941974
942975 got = kunit ._list_tests (self .linux_source_mock ,
943- kunit .KunitExecRequest (None , None , False , False , '.kunit' , 300 , 'suite*' , '' , None , None , 'suite' , False , False , False ))
976+ kunit .KunitExecRequest (None , None , None , False , False , '.kunit' , 300 , 'suite*' , '' , None , None , 'suite' , False , False , False ))
944977 self .assertEqual (got , want )
945978 # Should respect the user's filter glob when listing tests.
946979 self .linux_source_mock .run_kernel .assert_called_once_with (
@@ -953,7 +986,7 @@ def test_run_isolated_by_suite(self, mock_tests):
953986
954987 # Should respect the user's filter glob when listing tests.
955988 mock_tests .assert_called_once_with (mock .ANY ,
956- kunit .KunitExecRequest (None , None , False , False , '.kunit' , 300 , 'suite*.test*' , '' , None , None , 'suite' , False , False , False ))
989+ kunit .KunitExecRequest (None , None , None , False , False , '.kunit' , 300 , 'suite*.test*' , '' , None , None , 'suite' , False , False , False ))
957990 self .linux_source_mock .run_kernel .assert_has_calls ([
958991 mock .call (args = None , build_dir = '.kunit' , filter_glob = 'suite.test*' , filter = '' , filter_action = None , timeout = 300 ),
959992 mock .call (args = None , build_dir = '.kunit' , filter_glob = 'suite2.test*' , filter = '' , filter_action = None , timeout = 300 ),
@@ -966,7 +999,7 @@ def test_run_isolated_by_test(self, mock_tests):
966999
9671000 # Should respect the user's filter glob when listing tests.
9681001 mock_tests .assert_called_once_with (mock .ANY ,
969- kunit .KunitExecRequest (None , None , False , False , '.kunit' , 300 , 'suite*' , '' , None , None , 'test' , False , False , False ))
1002+ kunit .KunitExecRequest (None , None , None , False , False , '.kunit' , 300 , 'suite*' , '' , None , None , 'test' , False , False , False ))
9701003 self .linux_source_mock .run_kernel .assert_has_calls ([
9711004 mock .call (args = None , build_dir = '.kunit' , filter_glob = 'suite.test1' , filter = '' , filter_action = None , timeout = 300 ),
9721005 mock .call (args = None , build_dir = '.kunit' , filter_glob = 'suite.test2' , filter = '' , filter_action = None , timeout = 300 ),
0 commit comments