Skip to content

Commit 767b609

Browse files
committed
Add source for binary files and fix tests for new binaries
1 parent 3a85c8e commit 767b609

File tree

6 files changed

+47
-42
lines changed

6 files changed

+47
-42
lines changed
-48.7 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int add(int a, int b)
2+
{
3+
return a + b;
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
printf("Hello world");
6+
}

src/installer/tests/Melanzana.MachO.Tests/ReadTests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,28 @@ public void ReadExecutable()
2424
var segments = objectFile.LoadCommands.OfType<MachSegment>().ToArray();
2525
Assert.Equal("__PAGEZERO", segments[0].Name);
2626
Assert.Equal("__TEXT", segments[1].Name);
27-
Assert.Equal("__LINKEDIT", segments[2].Name);
27+
Assert.Equal("__DATA_CONST", segments[2].Name);
28+
Assert.Equal("__LINKEDIT", segments[3].Name);
2829

2930
var symbolTable = objectFile.LoadCommands.OfType<MachSymbolTable>().FirstOrDefault();
3031
Assert.NotNull(symbolTable);
3132
var symbols = symbolTable!.Symbols.ToArray();
32-
Assert.Equal(2, symbols.Length);
33+
Assert.Equal(3, symbols.Length);
3334
Assert.Equal("__mh_execute_header", symbols[0].Name);
3435
Assert.Equal(0x100000000u, symbols[0].Value);
3536
Assert.Equal("_main", symbols[1].Name);
36-
Assert.Equal(0x100003fa4u, symbols[1].Value);
37+
Assert.Equal(0x100003F70u, symbols[1].Value);
38+
Assert.Equal("_printf", symbols[2].Name);
39+
Assert.Equal(0u, symbols[2].Value);
3740

3841
var buildVersion = objectFile.LoadCommands.OfType<MachBuildVersion>().FirstOrDefault();
3942
Assert.NotNull(buildVersion);
4043
Assert.Equal(MachPlatform.MacOS, buildVersion!.Platform);
41-
Assert.Equal("12.0.0", buildVersion!.MinimumPlatformVersion.ToString());
42-
Assert.Equal("12.0.0", buildVersion!.SdkVersion.ToString());
44+
Assert.Equal("14.0.0", buildVersion!.MinimumPlatformVersion.ToString());
45+
Assert.Equal("15.0.0", buildVersion!.SdkVersion.ToString());
4346
Assert.Equal(1, buildVersion!.ToolVersions.Count);
4447
Assert.Equal(MachBuildTool.Ld, buildVersion!.ToolVersions[0].BuildTool);
45-
Assert.Equal("711.0.0", buildVersion!.ToolVersions[0].Version.ToString());
48+
Assert.Equal("1115.7.3", buildVersion!.ToolVersions[0].Version.ToString());
4649
}
4750

4851
[Fact]
@@ -80,8 +83,8 @@ public void ReadObjectFile()
8083
Assert.Equal(0u, symbols[0].Value);
8184
Assert.Equal("ltmp1", symbols[1].Name);
8285
Assert.Equal(compactUnwindSection, symbols[1].Section);
83-
Assert.Equal(0x18u, symbols[1].Value);
84-
Assert.Equal("_main", symbols[2].Name);
86+
Assert.Equal(0x20u, symbols[1].Value);
87+
Assert.Equal("_add", symbols[2].Name);
8588
Assert.Equal(textSection, symbols[2].Section);
8689
Assert.Equal(0u, symbols[2].Value);
8790
}

src/installer/tests/Melanzana.MachO.Tests/RoundtripTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ public void BasicRoundtrip()
4848
TestRoundtrip(aOutStream);
4949
}
5050

51-
[Fact]
52-
public void FatRoundtrip()
53-
{
54-
var aFatOutStream = typeof(RoundtripTests).Assembly.GetManifestResourceStream("Melanzana.MachO.Tests.Data.a.fat.out")!;
55-
TestFatRoundtrip(aFatOutStream);
56-
}
57-
5851
[Fact]
5952
public void ObjectFileRoundtrip()
6053
{

src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost/CreateAppHost.cs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Buffers.Binary;
65
using System.Diagnostics;
76
using System.IO;
87
using System.Linq;
@@ -263,32 +262,6 @@ public void ExecutableImage()
263262
.Be(expectedPermissions);
264263
}
265264

266-
267-
[Fact]
268-
public void DoesNotCodeSignAppHostByDefault()
269-
{
270-
using (TestArtifact artifact = CreateTestDirectory())
271-
{
272-
string sourceAppHostMock = PrepareMockMachAppHostFile(artifact.Location);
273-
File.SetAttributes(sourceAppHostMock, FileAttributes.ReadOnly);
274-
string destinationFilePath = Path.Combine(artifact.Location, "DestinationAppHost.exe.mock");
275-
string appBinaryFilePath = "Test/App/Binary/Path.dll";
276-
HostWriter.CreateAppHost(
277-
sourceAppHostMock,
278-
destinationFilePath,
279-
appBinaryFilePath,
280-
windowsGraphicalUserInterface: false);
281-
282-
if (!Codesign.IsAvailable())
283-
{
284-
return;
285-
}
286-
287-
var (exitCode, stdErr) = Codesign.Run("-d", destinationFilePath);
288-
stdErr.Should().Contain($"{Path.GetFullPath(destinationFilePath)}: code object is not signed at all");
289-
}
290-
}
291-
292265
[Theory]
293266
[InlineData("")]
294267
[InlineData("dir with spaces")]
@@ -339,6 +312,32 @@ public void CodeSignMachOAppHost(string subdir)
339312
}
340313
}
341314
}
315+
316+
[Fact]
317+
public void DoesNotCodeSignAppHostByDefault()
318+
{
319+
using (TestArtifact artifact = CreateTestDirectory())
320+
{
321+
string sourceAppHostMock = PrepareMockMachAppHostFile(artifact.Location);
322+
File.SetAttributes(sourceAppHostMock, FileAttributes.ReadOnly);
323+
string destinationFilePath = Path.Combine(artifact.Location, "DestinationAppHost.exe.mock");
324+
string appBinaryFilePath = "Test/App/Binary/Path.dll";
325+
HostWriter.CreateAppHost(
326+
sourceAppHostMock,
327+
destinationFilePath,
328+
appBinaryFilePath,
329+
windowsGraphicalUserInterface: false);
330+
331+
if (!Codesign.IsAvailable())
332+
{
333+
return;
334+
}
335+
336+
var (exitCode, stdErr) = Codesign.Run("-d", destinationFilePath);
337+
stdErr.Should().Contain($"{Path.GetFullPath(destinationFilePath)}: code object is not signed at all");
338+
}
339+
}
340+
342341
[Fact]
343342
public void CodeSigningFailuresThrow()
344343
{

0 commit comments

Comments
 (0)