Skip to content

Commit

Permalink
Refactor host rid tests. (#303)
Browse files Browse the repository at this point in the history
Extend host-probes-rid-assets and add a variant that uses the
legacy graph for probing with .NET 8+.
  • Loading branch information
tmds authored Oct 11, 2023
1 parent 9f80c9a commit b062861
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 77 deletions.
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project>
<PropertyGroup>
<!-- This property will be set by the test runner.
You can change it locally when running without the test runner to match with the .NET SDK under test. -->
<TestTargetFramework Condition="'$(TestTargetFramework)' == ''">net6.0</TestTargetFramework>

<SystemDataOdbcVersion>6.0.0</SystemDataOdbcVersion>
<MicrosoftNetTestSdkVersion>17.4.0</MicrosoftNetTestSdkVersion>
<XunitVersion>2.4.1</XunitVersion>
Expand Down
5 changes: 5 additions & 0 deletions host-probes-rid-assets-legacy/app/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.InteropServices;

// Try load the native libraries packed under the rid folders.
NativeLibrary.Load("mylib-unix", typeof(Program).Assembly, DllImportSearchPath.ApplicationDirectory);
NativeLibrary.Load("mylib-sdkrid", typeof(Program).Assembly, DllImportSearchPath.ApplicationDirectory);
18 changes: 18 additions & 0 deletions host-probes-rid-assets-legacy/app/host-probes-rid-assets.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<RestoreSources>$(MSBuildThisFileDirectory)/../packages</RestoreSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="host-probes-rid-assets-mylib-unix" Version="1.0.0" />
<PackageReference Include="host-probes-rid-assets-mylib-sdkrid" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Runtime.Loader.UseRidGraph" Value="true" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions host-probes-rid-assets-legacy/lib/lib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>host-probes-rid-assets-$(LibName)</PackageId>
<!-- We need a native library for this test. Pick one from the runtime. -->
<NativeLibrary>$(NetCoreRoot)/shared/Microsoft.NETCore.App/$(BundledNETCoreAppPackageVersion)/libSystem.Native.so</NativeLibrary>
</PropertyGroup>

<ItemGroup>
<!-- Place it under the rid specific folder and rename it based on the Rid and LibName properties. -->
<Content Include="$(NativeLibrary)">
<PackagePath>runtimes/$(Rid)/native/$(LibName).so</PackagePath>
<Pack>true</Pack>
</Content>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions host-probes-rid-assets-legacy/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "host-probes-rid-assets-legacy",
"enabled": true,
"requiresSdk": true,
"version": "8.0", // test opts into using the legacy graph.
"versionSpecific": false,
"type": "bash",
"cleanup": true,
"ignoredRIDs":[
]
}
18 changes: 18 additions & 0 deletions host-probes-rid-assets-legacy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -euox pipefail

# This test is testing the same functionality as host-probes-rid-assets
# but when opting in to use the legacy graph (by setting System.Runtime.Loader.UseRidGraph=true).

# The lib project packages a native library in a rid-specific folder.
# Only one rid is considered per nuget package.
# We pack it once for the sdk rid, and once for a base rid ('unix').
mkdir -p packages
dotnet pack lib -o packages /p:Rid=unix /p:LibName=mylib-unix
dotnet pack lib -o packages /p:Rid=$(../runtime-id --sdk) /p:LibName=mylib-sdkrid

# This app reference the 'lib' NuGet packages, and loads the native libraries they contains.
dotnet run --project app

echo "PASS"
5 changes: 3 additions & 2 deletions host-probes-rid-assets/app/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;

// Try load the native library packaged from the 'lib' class.
NativeLibrary.Load("mylib", typeof(Program).Assembly, DllImportSearchPath.ApplicationDirectory);
// Try load the native libraries packed under the rid folders.
NativeLibrary.Load("mylib-unix", typeof(Program).Assembly, DllImportSearchPath.ApplicationDirectory);
NativeLibrary.Load("mylib-sdkrid", typeof(Program).Assembly, DllImportSearchPath.ApplicationDirectory);
10 changes: 6 additions & 4 deletions host-probes-rid-assets/app/host-probes-rid-assets.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RestoreSources>$(MSBuildThisFileDirectory)/../packages</RestoreSources>
<OutputType>Exe</OutputType>
<TargetFramework>$(TestTargetFramework)</TargetFramework>
<RestoreSources>$(MSBuildThisFileDirectory)/../packages</RestoreSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="lib" Version="1.0.0" />
<PackageReference Include="host-probes-rid-assets-mylib-unix" Version="1.0.0" />
<PackageReference Include="host-probes-rid-assets-mylib-sdkrid" Version="1.0.0" />
</ItemGroup>

</Project>
10 changes: 6 additions & 4 deletions host-probes-rid-assets/lib/lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>host-probes-rid-assets-$(LibName)</PackageId>
<!-- We need a native library for this test. Pick one from the runtime. -->
<NativeLibrary>$(NetCoreRoot)/shared/Microsoft.NETCore.App/$(BundledNETCoreAppPackageVersion)/libSystem.Native.so</NativeLibrary>
</PropertyGroup>

<ItemGroup>
<!-- We need a native library for this test. Pick one from the runtime. -->
<Content Include="$(NetCoreRoot)/shared/Microsoft.NETCore.App/$(BundledNETCoreAppPackageVersion)/libSystem.Native.so">
<!-- Place it in the rid specific folder, and name it 'mylib.so'. -->
<PackagePath>runtimes/$(NETCoreSdkRuntimeIdentifier)/native/mylib.so</PackagePath>
<!-- Place it under the rid specific folder and rename it based on the Rid and LibName properties. -->
<Content Include="$(NativeLibrary)">
<PackagePath>runtimes/$(Rid)/native/$(LibName).so</PackagePath>
<Pack>true</Pack>
</Content>
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion host-probes-rid-assets/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"name": "host-probes-rid-assets",
"enabled": true,
"requiresSdk": true,
"version": "8.0", // .NET 8+ host probes a hard-coded list of rids.
"version": "6.0",
"versionSpecific": false,
"type": "bash",
"cleanup": true,
"skipWhen": [
"os=alpine,version=6", // see https://github.com/redhat-developer/dotnet-regular-tests/pull/303#issuecomment-1755727884
"os=alpine,version=7",
],
"ignoredRIDs":[
]
}
16 changes: 10 additions & 6 deletions host-probes-rid-assets/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/usr/bin/env bash

set -euo pipefail

set -x
set -euox pipefail

# The lib project packages a native library in a rid-specific folder.
# Only one rid is considered per nuget package.
# We pack it once for the sdk rid, and once for a base rid ('unix').
mkdir -p packages
# This NuGet package packs a native library in a rid-specific folder.
dotnet pack lib -o packages
# This app reference the 'lib' NuGet package, and loads the native library it contains.
dotnet pack lib -o packages /p:Rid=unix /p:LibName=mylib-unix
dotnet pack lib -o packages /p:Rid=$(../runtime-id --sdk) /p:LibName=mylib-sdkrid

# This app reference the 'lib' NuGet packages, and loads the native libraries they contains.
dotnet run --project app

echo "PASS"
14 changes: 0 additions & 14 deletions runtime-fallback-graph/test.json

This file was deleted.

33 changes: 0 additions & 33 deletions runtime-fallback-graph/test.sh

This file was deleted.

48 changes: 35 additions & 13 deletions runtime-id
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,45 @@

set -euo pipefail

SCRIPT_PATH=$(realpath $0)
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")

function usage() {
echo "usage: $0 [--portable]"
echo "usage: $0 [--portable] [--sdk]"
echo ""
echo "Prints a rid for the current environment"
echo ""
echo "Shows the runtime id of the current OS distribution, or general OS (with the --portable flag)"
echo "$0 prints the non-portable rid for the OS"
echo "$0 --portable prints the portable rid for the OS"
echo "$0 --sdk prints the rid the SDK was built for"
}

portable_rid=0
sdk_rid=0
while [[ $# -gt 0 ]]; do
arg=$1
shift
case "$arg" in
--portable) portable_rid=1 ;;
--sdk) sdk_rid=1 ;;
*) usage; exit 1 ;;
esac
done

if [[ ${sdk_rid} == 1 ]]; then
sdk_dir=$("$SCRIPT_DIR/dotnet-directory" --sdk)
rid_line=$(grep -m 1 "<NETCoreSdkRuntimeIdentifier>" "$sdk_dir/Microsoft.NETCoreSdk.BundledVersions.props")
rid_regex="<NETCoreSdkRuntimeIdentifier>(.*)</NETCoreSdkRuntimeIdentifier>"
if [[ "$rid_line" =~ $rid_regex ]]; then
sdk_rid="${BASH_REMATCH[1]}"
else
echo "failed to parse id from: '$rid_line'"
exit 1
fi
echo $sdk_rid
exit 0
fi

source /etc/os-release

declare -A archmap
Expand All @@ -27,17 +60,6 @@ archmap=(

arch=${archmap["$(uname -m)"]}

portable_rid=0

while [[ $# -gt 0 ]]; do
arg=$1
shift
case "$arg" in
--portable) portable_rid=1 ;;
*) usage; exit 1 ;;
esac
done

if [[ ${portable_rid} == 1 ]]; then
if (ldd --version 2>&1 || true) | grep -q musl ; then
echo "linux-musl-${arch}"
Expand Down

0 comments on commit b062861

Please sign in to comment.