xref: /llvm-project/lldb/test/API/lang/objc/modules-hash-mismatch/TestClangModulesHashMismatch.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprechtimport os
299451b44SJordan Rupprechtimport shutil
399451b44SJordan Rupprecht
499451b44SJordan Rupprechtimport lldb
599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
899451b44SJordan Rupprecht
999451b44SJordan Rupprecht
1099451b44SJordan Rupprechtclass TestClangModuleHashMismatch(TestBase):
111c6826e8SMichael Buch    @add_test_categories(["gmodules"])
1299451b44SJordan Rupprecht    def test_expr(self):
1399451b44SJordan Rupprecht        with open(self.getBuildArtifact("module.modulemap"), "w") as f:
14*2238dcc3SJonas Devlieghere            f.write(
15*2238dcc3SJonas Devlieghere                """
1699451b44SJordan Rupprecht                    module Foo { header "f.h" }
17*2238dcc3SJonas Devlieghere                    """
18*2238dcc3SJonas Devlieghere            )
1999451b44SJordan Rupprecht        with open(self.getBuildArtifact("f.h"), "w") as f:
20*2238dcc3SJonas Devlieghere            f.write(
21*2238dcc3SJonas Devlieghere                """
2299451b44SJordan Rupprecht                    typedef int my_int;
2399451b44SJordan Rupprecht                    void f() {}
24*2238dcc3SJonas Devlieghere                    """
25*2238dcc3SJonas Devlieghere            )
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht        mod_cache = self.getBuildArtifact("private-module-cache")
2899451b44SJordan Rupprecht        if os.path.isdir(mod_cache):
2999451b44SJordan Rupprecht            shutil.rmtree(mod_cache)
3099451b44SJordan Rupprecht        self.build()
3199451b44SJordan Rupprecht        self.assertTrue(os.path.isdir(mod_cache), "module cache exists")
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        logfile = self.getBuildArtifact("host.log")
34*2238dcc3SJonas Devlieghere        with open(logfile, "w") as f:
35*2238dcc3SJonas Devlieghere            sbf = lldb.SBFile(f.fileno(), "w", False)
3668793919SJonas Devlieghere            status = self.dbg.SetErrorFile(sbf)
3768793919SJonas Devlieghere            self.assertSuccess(status)
3868793919SJonas Devlieghere
3999451b44SJordan Rupprecht            target, _, _, _ = lldbutil.run_to_source_breakpoint(
40*2238dcc3SJonas Devlieghere                self, "break here", lldb.SBFileSpec("main.m")
41*2238dcc3SJonas Devlieghere            )
42*2238dcc3SJonas Devlieghere            target.GetModuleAtIndex(0).FindTypes("my_int")
4399451b44SJordan Rupprecht
44*2238dcc3SJonas Devlieghere        with open(logfile, "r") as f:
4599451b44SJordan Rupprecht            for line in f:
4699451b44SJordan Rupprecht                if "hash mismatch" in line and "Foo" in line:
4799451b44SJordan Rupprecht                    found = True
4899451b44SJordan Rupprecht        self.assertTrue(found)
49