-
Notifications
You must be signed in to change notification settings - Fork 447
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
Add a source-build smoke test for native debug symbols #16488
Merged
MichaelSimons
merged 1 commit into
dotnet:main
from
omajid:source-build-smoke-test-debugging
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DebugTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.DotNet.SourceBuild.SmokeTests; | ||
|
||
public class DebugTests : SmokeTests | ||
{ | ||
private record ScanResult(string FileName, bool HasDebugInfo, bool HasDebugAbbrevs, bool HasFileSymbols, bool HasGnuDebugLink); | ||
|
||
public DebugTests(ITestOutputHelper outputHelper) : base(outputHelper) { } | ||
|
||
/// <Summary> | ||
/// Verifies that all generated native files include native debug symbols. | ||
/// </Summary> | ||
[Fact] | ||
public void SourceBuiltSdkContainsNativeDebugSymbols() | ||
{ | ||
|
||
var fileNames = Directory.EnumerateFiles(Config.DotNetDirectory, "*", SearchOption.AllDirectories); | ||
var foundIssue = false; | ||
StringBuilder issueDetails = new(); | ||
foreach (var fileName in fileNames) | ||
{ | ||
if (!IsElfFile(fileName)) | ||
{ | ||
continue; | ||
} | ||
|
||
var result = ScanFile(fileName); | ||
|
||
string newLine = Environment.NewLine; | ||
|
||
if (!result.HasDebugInfo) | ||
{ | ||
foundIssue = true; | ||
issueDetails.Append($"missing .debug_info section in {fileName}{newLine}"); | ||
} | ||
if (!result.HasDebugAbbrevs) | ||
{ | ||
foundIssue = true; | ||
issueDetails.Append($"missing .debug_abbrev section in {fileName}{newLine}"); | ||
} | ||
if (!result.HasFileSymbols) | ||
{ | ||
foundIssue = true; | ||
issueDetails.Append($"missing FILE symbols in {fileName}{newLine}"); | ||
} | ||
if (result.HasGnuDebugLink) | ||
{ | ||
foundIssue = true; | ||
issueDetails.Append($"unexpected .gnu_debuglink section in {fileName}{newLine}"); | ||
} | ||
} | ||
|
||
Assert.False(foundIssue, issueDetails.ToString()); | ||
} | ||
|
||
private bool IsElfFile(string fileName) | ||
{ | ||
string fileStdOut = ExecuteHelper.ExecuteProcessValidateExitCode("file", $"{fileName}", OutputHelper); | ||
return Regex.IsMatch(fileStdOut, @"ELF 64-bit [LM]SB (?:pie )?(?:executable|shared object)"); | ||
} | ||
|
||
private ScanResult ScanFile(string fileName) | ||
{ | ||
string readelfSStdOut = ExecuteHelper.ExecuteProcessValidateExitCode("eu-readelf", $"-S {fileName}", OutputHelper); | ||
|
||
// Test for .debug_* sections in the shared object. This is the main test. | ||
// Stripped objects will not contain these. | ||
|
||
bool hasDebugInfo = readelfSStdOut | ||
.Split("\n") | ||
.Where(line => line.Contains("] .debug_info")) | ||
.Any(); | ||
|
||
bool hasDebugAbbrev = readelfSStdOut.Split("\n") | ||
.Where(line => line.Contains("] .debug_abbrev")) | ||
.Any(); | ||
|
||
string readelfsStdOut = ExecuteHelper.ExecuteProcessValidateExitCode("eu-readelf", $"-s {fileName}", OutputHelper); | ||
|
||
// Test FILE symbols. These will most likely be removed by anyting that | ||
// manipulates symbol tables because it's generally useless. So a nice test | ||
// that nothing has messed with symbols. | ||
bool hasFileSymbols = readelfsStdOut.Split("\n").Where(ContainsFileSymbols).Any(); | ||
|
||
// Test that there are no .gnu_debuglink sections pointing to another | ||
// debuginfo file. There shouldn't be any debuginfo files, so the link makes | ||
// no sense either. | ||
bool hasGnuDebuglink = readelfsStdOut.Split("\n").Where(line => line.Contains("] .gnu_debuglink")).Any(); | ||
|
||
return new ScanResult(fileName, hasDebugInfo, hasDebugAbbrev, hasFileSymbols, hasGnuDebuglink); | ||
} | ||
|
||
private bool ContainsFileSymbols(string line) | ||
{ | ||
// Try matching against output like this: | ||
// 10: 0000000000000000 0 FILE LOCAL DEFAULT ABS coreclr_resolver.cpp | ||
// 779: 0000000000000000 0 FILE LOCAL DEFAULT ABS header.cpp | ||
|
||
var parts = new Regex(@"[ \t\n\r]+").Split(line); | ||
int expectedNumberOfParts = 9; | ||
|
||
if (parts.Length < expectedNumberOfParts) | ||
{ | ||
return false; | ||
} | ||
|
||
var fileNameRegex = new Regex(@"(.*/)?[-_a-zA-Z0-9]+\.(c|cc|cpp|cxx)"); | ||
return (parts[3] == "0") && (parts[4] == "FILE") && (parts[5] == "LOCAL") && (parts[6] == "DEFAULT") && | ||
(parts[7] == "ABS") && (fileNameRegex.IsMatch(parts[8])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see
eu-readelf
andfile
were added utils to the centos stream 8 image in dotnet/dotnet-buildtools-prereqs-docker@b15dff8. This dependency is going to be required for all of the other distros/images we run in CI - https://github.com/dotnet/installer/blob/main/eng/pipelines/templates/stages/vmr-build.yml#L16.This leads me to think we should document these native dependencies in the test's readme - https://github.com/dotnet/installer/blob/main/src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/README.md