-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for source-built NativeAOT. (#362)
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
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
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,38 @@ | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.IO.Compression; | ||
|
||
byte[] bytes = Encoding.UTF8.GetBytes("some bytes"); | ||
|
||
#if NO_DEPS | ||
|
||
// No dependencies. | ||
|
||
#elif DEP_CRYPTO | ||
|
||
using (SHA256 mySHA256 = SHA256.Create()) | ||
{ | ||
mySHA256.ComputeHash(bytes); | ||
} | ||
|
||
#elif DEP_ZLIB | ||
|
||
using (var stream = new ZLibStream(new MemoryStream(), CompressionMode.Compress, leaveOpen: false)) | ||
{ | ||
stream.Write(bytes); | ||
} | ||
|
||
#elif DEP_BROTLI | ||
|
||
using (var stream = new BrotliStream(new MemoryStream(), CompressionMode.Compress, leaveOpen: false)) | ||
{ | ||
stream.Write(bytes); | ||
} | ||
|
||
#else | ||
|
||
#error "A preprocessor macro must be set to control the app dependencies." | ||
|
||
#endif | ||
|
||
Console.WriteLine("Success"); |
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(TestTargetFramework)</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<AssemblyName>console</AssemblyName> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,12 @@ | ||
{ | ||
"name": "nativeaot-sb", | ||
"enabled": true, | ||
"requiresSdk": true, | ||
"version": "9.0", | ||
"versionSpecific": false, | ||
"type": "bash", | ||
"cleanup": true, | ||
"skipWhen": [ | ||
"runtime=mono" // nativeaot is not available with mono | ||
] | ||
} |
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,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -x | ||
|
||
RID_ARG="/p:RuntimeIdentifier=$(../runtime-id --sdk)" | ||
|
||
# Depending on the code used by the program, different native libraries are needed. | ||
# We compile different programs to test if those native libraries are found. | ||
# Some native libraries (like libunwind and rapidjson) are always needed. Consequently, each program check those. | ||
|
||
for DEPENDENCY in NO_DEPS DEP_CRYPTO DEP_ZLIB DEP_BROTLI | ||
do | ||
echo "Testing NativeAOT with $DEPENDENCY" | ||
|
||
rm -rf bin obj | ||
|
||
# Publish the app. | ||
if ! dotnet publish $RID_ARG /p:DefineConstants=$DEPENDENCY /p:PublishAot=true; then | ||
echo "FAIL: failed to publish application using NativeAot." | ||
exit 1 | ||
fi | ||
|
||
# Verify the published output contains a single file. | ||
PUBLISHED_FILE_COUNT=$(ls ./bin/*/net*/*/publish | grep -v console.dbg | wc -l) | ||
if [ "$PUBLISHED_FILE_COUNT" != "1" ]; then | ||
echo "FAIL: published NativeAot app contains more than 1 file." | ||
exit 1 | ||
fi | ||
|
||
# Verify the application runs. | ||
APP_OUTPUT="$(./bin/*/net*/*/publish/console 2>&1)" | ||
if [ "$APP_OUTPUT" != "Success" ]; then | ||
echo "FAIL: NativeAot console application did not have expected output." | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "PASS: source-built NativeAot apps build and run." |