Skip to content
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 support for filtering on musl libc #58

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ jobs:
fail-fast: false
matrix:
container_image:
- docker.io/library/alpine:edge
- docker.io/library/alpine:latest
- registry.fedoraproject.org/fedora:34
- registry.fedoraproject.org/fedora:35
- registry.fedoraproject.org/fedora:36
- registry.fedoraproject.org/fedora:rawhide
- registry.access.redhat.com/ubi8
dotnet_version:
Expand All @@ -25,6 +28,8 @@ jobs:
exclude:
- container_image: registry.fedoraproject.org/fedora:rawhide
dotnet_version: "5.0"
- container_image: registry.fedoraproject.org/fedora:36
dotnet_version: "5.0"

container:
image: ${{ matrix.container_image }}
Expand All @@ -34,13 +39,36 @@ jobs:
- name: Install build dependencies
timeout-minutes: 5
run: |
dnf install -y dotnet-sdk-${{ matrix.dotnet_version }} make
set -euo pipefail
if command -v dnf; then
dnf install -y dotnet-sdk-${{ matrix.dotnet_version }} git make
elif command -v apk; then
apk add bash curl git icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ make zlib
curl -sSLO https://dot.net/v1/dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --channel ${{ matrix.dotnet_version }}
fi

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Sanity check
run: |
set -euo pipefail
PATH=$PATH:$HOME/.dotnet/

git config --global safe.directory "$GITHUB_WORKSPACE"

make
mkdir -p no-reproducers
dotnet turkey/Turkey.dll no-reproducers

- name: Run tests
run: |
set -euo pipefail
PATH=$PATH:$HOME/.dotnet/

make check

reproducers:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check:

run-samples:
rm -rf ~/.nuget.orig && mv ~/.nuget ~/.nuget.orig && mkdir -p ~/.nuget
cd Samples && test -f ../bin/turkey && (../bin/turkey || true)
cd Samples && test -f ../turkey/Turkey.dll && (dotnet ../turkey/Turkey.dll || true)
rm -rf ~/.nuget && mv ~/.nuget.orig ~/.nuget

publish:
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ It produces results in various forms, including a junit-compatible xml file.

# Supported Platforms and Architectures

This is fully usable on GNU libc-based Linux distributions. This is
used by Red Hat to run .NET tests on Fedora and RHEL on multiple
architectures including 64-bit ARM, Intel x86_64 and IBM Z.
This is fully usable on GNU libc-based and musl libc-based Linux distributions.

This is used by Red Hat to run .NET tests on Fedora and RHEL on multiple
architectures including 64-bit ARM (`aarch64`), Intel x86_64 (`x86_64`) and IBM
Z (`s390x`).

It's also being used by other distributions, such as Alpine.

# Building

Expand Down
13 changes: 13 additions & 0 deletions Samples/NonAlpineBashTest/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "NonAlpineBashTest",
"enabled": true,
"requiresSdk": true,
"version": "1.0",
"versionSpecific": false,
"type": "bash",
"cleanup": true,
"ignoredRIDs":[
"alpine"
]
}

5 changes: 5 additions & 0 deletions Samples/NonAlpineBashTest/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "${@}"

true
36 changes: 24 additions & 12 deletions Turkey.Tests/PlatformIdTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ namespace Turkey.Tests
public class PlatformIdTest
{
[Theory]
[InlineData(new string[] { "ID=fedora", "VERSION_ID=9" }, "x64", new string[] { "linux", "linux-x64", "fedora", "fedora-x64", "fedora9", "fedora.9", "fedora.9-x64" })]
[InlineData(new string[] { "ID=fedora", "VERSION_ID=30" }, "x64", new string[] { "linux", "linux-x64", "fedora", "fedora-x64", "fedora30", "fedora.30", "fedora.30-x64" })]
[InlineData(new string[] { "ID=fedora", "VERSION_ID=30" }, "arm64", new string[] { "linux", "linux-arm64", "fedora", "fedora-arm64", "fedora30", "fedora.30", "fedora.30-arm64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=7" }, "x64", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel7", "rhel.7", "rhel.7-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=7.3" }, "x64", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel7", "rhel.7", "rhel.7-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=8" }, "x64", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=8.0" }, "x64", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=8.1" }, "x64", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=\"rhel\"", "VERSION_ID=\"8.1\"" }, "x64", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=centos", "VERSION_ID=8" }, "x64", new string[] { "linux", "linux-x64", "centos", "centos-x64", "centos8", "centos.8", "centos.8-x64" })]
public void BasicPlatformIds(string[] lines, string architecture, string[] expectedIds)
[InlineData(new string[] { "ID=fedora", "VERSION_ID=9" }, "x64", "", new string[] { "linux", "linux-x64", "fedora", "fedora-x64", "fedora9", "fedora.9", "fedora.9-x64" })]
[InlineData(new string[] { "ID=fedora", "VERSION_ID=30" }, "x64", "", new string[] { "linux", "linux-x64", "fedora", "fedora-x64", "fedora30", "fedora.30", "fedora.30-x64" })]
[InlineData(new string[] { "ID=fedora", "VERSION_ID=30" }, "arm64", "", new string[] { "linux", "linux-arm64", "fedora", "fedora-arm64", "fedora30", "fedora.30", "fedora.30-arm64" })]
[InlineData(new string[] { "ID=rocky", "VERSION_ID=8.5" }, "x64", "", new string[] { "linux", "linux-x64", "rocky", "rocky-x64", "rocky8", "rocky.8", "rocky.8-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=7" }, "x64", "", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel7", "rhel.7", "rhel.7-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=7.3" }, "x64", "", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel7", "rhel.7", "rhel.7-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=8" }, "x64", "", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=8.0" }, "x64", "", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=rhel", "VERSION_ID=8.1" }, "x64", "", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=\"rhel\"", "VERSION_ID=\"8.1\"" }, "x64", "", new string[] { "linux", "linux-x64", "rhel", "rhel-x64", "rhel8", "rhel.8", "rhel.8-x64" })]
[InlineData(new string[] { "ID=centos", "VERSION_ID=8" }, "x64", "", new string[] { "linux", "linux-x64", "centos", "centos-x64", "centos8", "centos.8", "centos.8-x64" })]
[InlineData(new string[] { "ID=alpine", "VERSION_ID=3.15.2" }, "x64", "", new string[] { "linux", "linux-x64", "alpine", "alpine-x64", "alpine3.15", "alpine.3.15", "alpine.3.15-x64" })]
[InlineData(new string[] { "ID=alpine", "VERSION_ID=3.15.2" }, "x64", "musl libc", new string[] { "linux", "linux-x64", "alpine", "alpine-x64", "alpine3.15", "alpine.3.15", "alpine.3.15-x64", "linux-musl", "linux-musl-x64" })]
[InlineData(new string[] { "ID=fedora", "VERSION_ID=39" }, "x64", "GNU libc", new string[] { "linux", "linux-x64", "fedora", "fedora-x64", "fedora39", "fedora.39", "fedora.39-x64" })]
public void BasicPlatformIds(string[] osReleaseLines, string architecture, string lddOutput, string[] expectedIds)
{
var result = new PlatformId().GetPlatformIdsFromOsRelease(lines, architecture);
var result = new PlatformId().ComputePlatformIds(osReleaseLines, architecture, lddOutput);
Assert.Equal(expectedIds.ToList(), result);
}

[Fact]
public void LddWorks()
{
string version = new PlatformId().GetLddVersion();
Assert.NotNull(version);
Assert.NotEmpty(version);
}
}
}
3 changes: 3 additions & 0 deletions Turkey/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("Turkey.Tests")]
53 changes: 43 additions & 10 deletions Turkey/PlatformId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace Turkey
{
Expand All @@ -11,37 +13,53 @@ public class PlatformId
public List<string> CurrentIds
{
// TODO make this async?
get => GetPlatformIdsFromOsRelease(File.ReadAllLines("/etc/os-release"));
get => ComputePlatformIds(File.ReadAllLines("/etc/os-release"), GetLddVersion());
}

public List<string> GetPlatformIdsFromOsRelease(string[] lines)
public List<string> ComputePlatformIds(string[] osReleaseLines, string lddVersionOutput)
{
string arch = Enum.GetName(typeof(Architecture), RuntimeInformation.OSArchitecture).ToLowerInvariant();
return GetPlatformIdsFromOsRelease(lines, arch);
return ComputePlatformIds(osReleaseLines, arch, lddVersionOutput);
}

public List<string> GetPlatformIdsFromOsRelease(string[] lines, string architecture)
public List<string> ComputePlatformIds(string[] osReleaseLines, string architecture, string lddVersionOutput)
{
var id = GetValue("ID", lines);
var id = GetValue("ID", osReleaseLines);
id = Unquote(id);
var versionId = GetValue("VERSION_ID", lines);
var versionId = GetValue("VERSION_ID", osReleaseLines);
versionId = Unquote(versionId);
if (id.Equals("rhel", StringComparison.Ordinal))
var needsLastVersionRemoved = new string[] { "almalinux", "alpine", "ol", "rhel", "rocky" }
.Any(os => id.Equals(os, StringComparison.Ordinal));
if (needsLastVersionRemoved)
{
int indexOfDot = versionId.IndexOf(".", StringComparison.Ordinal);
int indexOfDot = versionId.LastIndexOf(".", StringComparison.Ordinal);
if (indexOfDot > 0)
{
versionId = versionId.Substring(0, indexOfDot);
}
}
var platforms = new string[] {
var platforms = new List<string>()
{
"linux",
"linux" + "-" + architecture,
id,
id + "-" + architecture,
id + versionId,
id + "." + versionId,
id + "." + versionId + "-" + architecture };
id + "." + versionId + "-" + architecture
};

bool isMusl = lddVersionOutput.Contains("musl", StringComparison.Ordinal);

if (isMusl)
{
platforms.AddRange(new []
{
"linux-musl",
"linux-musl" + "-" + architecture,
});

}
return platforms.ToList();
}

Expand All @@ -62,5 +80,20 @@ private string Unquote(string text)

return text;
}

internal string GetLddVersion()
{
using (Process p = new Process())
{
p.StartInfo.FileName = "ldd";
p.StartInfo.Arguments = "--version";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();

return string.Concat(p.StandardOutput.ReadToEnd(), p.StandardError.ReadToEnd());
}
}
}
}