13256aa8fSRaphael Isemannimport lldb 23256aa8fSRaphael Isemannfrom lldbsuite.test.decorators import * 33256aa8fSRaphael Isemannfrom lldbsuite.test.lldbtest import * 43256aa8fSRaphael Isemannfrom lldbsuite.test import lldbutil 53256aa8fSRaphael Isemannfrom lldbsuite.test_event.build_exception import BuildError 63256aa8fSRaphael Isemann 73256aa8fSRaphael Isemann 82238dcc3SJonas Devlieghereclass TestCase(TestBase): 93256aa8fSRaphael Isemann NO_DEBUG_INFO_TESTCASE = True 103256aa8fSRaphael Isemann 113256aa8fSRaphael Isemann def build_and_run(self, test_file): 123256aa8fSRaphael Isemann """ 133256aa8fSRaphael Isemann Tries building the given test source and runs to the first breakpoint. 143256aa8fSRaphael Isemann Returns false if the file fails to build due to an unsupported calling 153256aa8fSRaphael Isemann convention on the current test target. Returns true if building and 163256aa8fSRaphael Isemann running to the breakpoint succeeded. 173256aa8fSRaphael Isemann """ 183256aa8fSRaphael Isemann try: 192238dcc3SJonas Devlieghere self.build( 202238dcc3SJonas Devlieghere dictionary={ 213256aa8fSRaphael Isemann "C_SOURCES": test_file, 222238dcc3SJonas Devlieghere "CFLAGS_EXTRAS": "-Werror=ignored-attributes", 232238dcc3SJonas Devlieghere } 242238dcc3SJonas Devlieghere ) 253256aa8fSRaphael Isemann except BuildError as e: 263256aa8fSRaphael Isemann # Test source failed to build. Check if it failed because the 273256aa8fSRaphael Isemann # calling convention argument is unsupported/unknown in which case 283256aa8fSRaphael Isemann # the test should be skipped. 293256aa8fSRaphael Isemann error_msg = str(e) 303256aa8fSRaphael Isemann # Clang gives an explicit error when a calling convention is 313256aa8fSRaphael Isemann # not supported. 323256aa8fSRaphael Isemann if "calling convention is not supported for this target" in error_msg: 333256aa8fSRaphael Isemann return False 343256aa8fSRaphael Isemann # GCC's has two different generic warnings it can emit. 353256aa8fSRaphael Isemann if "attribute ignored" in error_msg: 363256aa8fSRaphael Isemann return False 373256aa8fSRaphael Isemann if "attribute directive ignored " in error_msg: 383256aa8fSRaphael Isemann return False 393256aa8fSRaphael Isemann # We got a different build error, so raise it again to fail the 403256aa8fSRaphael Isemann # test. 413256aa8fSRaphael Isemann raise 422238dcc3SJonas Devlieghere lldbutil.run_to_source_breakpoint( 432238dcc3SJonas Devlieghere self, "// break here", lldb.SBFileSpec(test_file) 442238dcc3SJonas Devlieghere ) 453256aa8fSRaphael Isemann return True 463256aa8fSRaphael Isemann 472238dcc3SJonas Devlieghere @skipIf(compiler="clang", compiler_version=["<", "9.0"]) 483256aa8fSRaphael Isemann def test_regcall(self): 493256aa8fSRaphael Isemann if not self.build_and_run("regcall.c"): 503256aa8fSRaphael Isemann return 513256aa8fSRaphael Isemann self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10") 523256aa8fSRaphael Isemann 532238dcc3SJonas Devlieghere @skipIf(compiler="clang", compiler_version=["<", "9.0"]) 543256aa8fSRaphael Isemann def test_ms_abi(self): 553256aa8fSRaphael Isemann if not self.build_and_run("ms_abi.c"): 563256aa8fSRaphael Isemann return 573256aa8fSRaphael Isemann self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10") 583256aa8fSRaphael Isemann 592238dcc3SJonas Devlieghere @skipIf(compiler="clang", compiler_version=["<", "9.0"]) 603256aa8fSRaphael Isemann def test_stdcall(self): 613256aa8fSRaphael Isemann if not self.build_and_run("stdcall.c"): 623256aa8fSRaphael Isemann return 633256aa8fSRaphael Isemann self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10") 643256aa8fSRaphael Isemann 65*528b512bSDavid Spickett # Fails on x86, passes elsewhere because clang doesn't support vectorcall on 66*528b512bSDavid Spickett # any other architectures. 672238dcc3SJonas Devlieghere @expectedFailureAll( 68*528b512bSDavid Spickett triple=re.compile("^(x86|i386)"), 692238dcc3SJonas Devlieghere oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56084" 702238dcc3SJonas Devlieghere ) 713256aa8fSRaphael Isemann def test_vectorcall(self): 723256aa8fSRaphael Isemann if not self.build_and_run("vectorcall.c"): 733256aa8fSRaphael Isemann return 743256aa8fSRaphael Isemann self.expect_expr("func(1.0)", result_type="int", result_value="1") 753256aa8fSRaphael Isemann 762238dcc3SJonas Devlieghere @skipIf(compiler="clang", compiler_version=["<", "9.0"]) 773256aa8fSRaphael Isemann def test_fastcall(self): 783256aa8fSRaphael Isemann if not self.build_and_run("fastcall.c"): 793256aa8fSRaphael Isemann return 803256aa8fSRaphael Isemann self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10") 813256aa8fSRaphael Isemann 822238dcc3SJonas Devlieghere @skipIf(compiler="clang", compiler_version=["<", "9.0"]) 833256aa8fSRaphael Isemann def test_pascal(self): 843256aa8fSRaphael Isemann if not self.build_and_run("pascal.c"): 853256aa8fSRaphael Isemann return 863256aa8fSRaphael Isemann self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10") 873256aa8fSRaphael Isemann 883256aa8fSRaphael Isemann def test_sysv_abi(self): 893256aa8fSRaphael Isemann if not self.build_and_run("sysv_abi.c"): 903256aa8fSRaphael Isemann return 913256aa8fSRaphael Isemann self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10") 92