Skip to content

[lldb][test] XcodeSDKModuleTests: remove non-deterministic source mapping checks #129526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Mar 3, 2025

This assertion was added to check that RegisterXcodeSDK will correctly update the source mappings of the module. However, the source mapping will only get updated if the Host::RunShellCommand call to xcrun succeeded. Even if xcrun failed to find an SDK, the source mappings would get an entry. But if the shell invocation itself failed, then the mappings are not updated (see

lldb_private::Status error = Host::RunShellCommand(
args, FileSpec(), &status, &signo, &output_str, timeout, run_in_shell);
// Check that xcrun returned something useful.
if (error.Fail()) {
// Catastrophic error.
LLDB_LOG(log, "xcrun failed to execute: {0}", error);
return error.ToError();
}
if (status != 0) {
// xcrun didn't find a matching SDK. Not an error, we'll try
// different spellings.
LLDB_LOG(log, "xcrun returned exit code {0}", status);
if (!output_str.empty())
LLDB_LOG(log, "xcrun output was:\n{0}", output_str);
return "";
}
if (output_str.empty()) {
LLDB_LOG(log, "xcrun returned no results");
return "";
}
). This means depending on how slow xcrun is on a given host, this test may fail. On my machine this happens consistently in debug and release builds.

This patch removes this flakey assertion. We unfortunately lost some test coverage here but I'm not sure there's great alternatives unless we either:

  1. Mock the xcrun call somehow (we could maybe pass a callable around which defaults to xcrun in non-test code?)
  2. Make a xcrun time-out not an error either?

…ping checks

This assertion was added to check that `RegisterXcodeSDK` will correctly update the source mappings of the module. However, the source mapping will only get updated if the command-line invocation of `xcrun` succeeded. Even if `xcrun` failed to find an SDK, the source mappings would get an entry (see https://github.com/llvm/llvm-project/blob/f6212c1cd3d8b827c7d7e2f6cf54b135c27eacc6/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm#L424-L444). But if the shell invocation itself failed, then the mappings are not updated. This means depending on how slow `xcrun` is on a given host, this test may fail. On my machine this happens consistently in debug and release builds.

This patch removes this flakey assertion. We unfortunately lost some
test coverage here but I'm not sure there's great alternatives unless we
either:
1. Mock the `xcrun` call somehow (we could maybe pass a callable around
   which defaults to `xcrun` in non-test code?)
2. Make a `xcrun` time-out not an error either?
@Michael137 Michael137 requested a review from adrian-prantl March 3, 2025 12:56
@Michael137 Michael137 requested a review from JDevlieghere as a code owner March 3, 2025 12:56
@llvmbot llvmbot added the lldb label Mar 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

This assertion was added to check that RegisterXcodeSDK will correctly update the source mappings of the module. However, the source mapping will only get updated if the command-line invocation of xcrun succeeded. Even if xcrun failed to find an SDK, the source mappings would get an entry (see

lldb_private::Status error = Host::RunShellCommand(
args, FileSpec(), &status, &signo, &output_str, timeout, run_in_shell);
// Check that xcrun returned something useful.
if (error.Fail()) {
// Catastrophic error.
LLDB_LOG(log, "xcrun failed to execute: {0}", error);
return error.ToError();
}
if (status != 0) {
// xcrun didn't find a matching SDK. Not an error, we'll try
// different spellings.
LLDB_LOG(log, "xcrun returned exit code {0}", status);
if (!output_str.empty())
LLDB_LOG(log, "xcrun output was:\n{0}", output_str);
return "";
}
if (output_str.empty()) {
LLDB_LOG(log, "xcrun returned no results");
return "";
}
). But if the shell invocation itself failed, then the mappings are not updated. This means depending on how slow xcrun is on a given host, this test may fail. On my machine this happens consistently in debug and release builds.

This patch removes this flakey assertion. We unfortunately lost some test coverage here but I'm not sure there's great alternatives unless we either:

  1. Mock the xcrun call somehow (we could maybe pass a callable around which defaults to xcrun in non-test code?)
  2. Make a xcrun time-out not an error either?

Full diff: https://github.com/llvm/llvm-project/pull/129526.diff

1 Files Affected:

  • (modified) lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp (-3)
diff --git a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
index fc008ca7011e4..b3bf4d9219d3e 100644
--- a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -116,11 +116,8 @@ TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
   SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
   CompUnitSP comp_unit = sym_file.GetCompileUnitAtIndex(0);
   ASSERT_TRUE(static_cast<bool>(comp_unit.get()));
-  ModuleSP module = t.GetModule();
-  ASSERT_EQ(module->GetSourceMappingList().GetSize(), 0u);
   XcodeSDK sdk = sym_file.ParseXcodeSDK(*comp_unit);
   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
-  ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
 }
 
 TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {

@Michael137 Michael137 merged commit f9338db into llvm:main Mar 3, 2025
12 checks passed
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…ping checks (llvm#129526)

This assertion was added to check that `RegisterXcodeSDK` will correctly
update the source mappings of the module. However, the source mapping
will only get updated if the `Host::RunShellCommand` call to `xcrun`
succeeded. Even if `xcrun` failed to find an SDK, the source mappings
would get an entry. But if the shell invocation itself failed, then the
mappings are not updated (see
https://github.com/llvm/llvm-project/blob/f6212c1cd3d8b827c7d7e2f6cf54b135c27eacc6/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm#L424-L444).
This means depending on how slow `xcrun` is on a given host, this test
may fail. On my machine this happens consistently in debug and release
builds.

This patch removes this flakey assertion. We unfortunately lost some
test coverage here but I'm not sure there's great alternatives unless we
either:
1. Mock the `xcrun` call somehow (we could maybe pass a callable around
which defaults to `xcrun` in non-test code?)
2. Make a `xcrun` time-out not an error either?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants