Skip to content

Commit a05fcb8

Browse files
Samuka007mistcoversmyeyes
authored andcommitted
feat: add nix build script for lmbench, seperate syscall test script and bin
1 parent 8bb68ef commit a05fcb8

File tree

6 files changed

+227
-47
lines changed

6 files changed

+227
-47
lines changed

user/apps/default.nix

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,71 @@
55
system,
66
target,
77
fenix,
8-
testOpt
8+
testOpt,
99
}:
1010

1111
# Return a list of app derivations to be copied into the rootfs.
1212
let
13-
cross = if system == "x86_64-linux" && target == "x86_64" then pkgs
14-
else if target == "riscv64" then pkgs.pkgsCross.riscv64
15-
else import nixpkgs {
16-
localSystem = system;
17-
crossSystem = if target == "x86_64" then "x86_64-unknown-linux-gnu"
18-
else abort "Unsupported target: ${target}}";
19-
};
13+
cross =
14+
if system == "x86_64-linux" && target == "x86_64" then
15+
pkgs
16+
else if target == "riscv64" then
17+
pkgs.pkgsCross.riscv64
18+
else
19+
import nixpkgs {
20+
localSystem = system;
21+
crossSystem =
22+
if target == "x86_64" then "x86_64-unknown-linux-gnu" else abort "Unsupported target: ${target}}";
23+
};
2024

21-
cross-musl = if system == "x86_64-linux" && target == "x86_64" then pkgs.pkgsMusl
22-
else if target == "riscv64" then pkgs.pkgsCross.riscv64-musl
23-
else import nixpkgs {
24-
localSystem = system;
25-
crossSystem = if target == "x86_64" then "x86_64-unknown-linux-musl"
26-
else abort "Unsupported target: ${target}-musl}";
27-
};
25+
cross-musl =
26+
if system == "x86_64-linux" && target == "x86_64" then
27+
pkgs.pkgsMusl
28+
else if target == "riscv64" then
29+
pkgs.pkgsCross.riscv64-musl
30+
else
31+
import nixpkgs {
32+
localSystem = system;
33+
crossSystem =
34+
if target == "x86_64" then
35+
"x86_64-unknown-linux-musl"
36+
else
37+
abort "Unsupported target: ${target}-musl}";
38+
};
2839

29-
static = if system == "x86_64-linux" && target == "x86_64" then pkgs.pkgsStatic
30-
else if target == "riscv64" then import nixpkgs {
31-
crossSystem = lib.systems.examples.riscv64-musl;
32-
isStatic = true;
33-
} else abort "Unsupported static target: ${target}";
40+
static =
41+
if system == "x86_64-linux" && target == "x86_64" then
42+
pkgs.pkgsStatic
43+
else if target == "riscv64" then
44+
import nixpkgs {
45+
crossSystem = lib.systems.examples.riscv64-musl;
46+
isStatic = true;
47+
}
48+
else
49+
abort "Unsupported static target: ${target}";
3450

35-
gvisor-syscall-tests = (pkgs.callPackage ./tests/syscall/gvisor {
36-
inherit fenix system;
37-
installDir = testOpt.syscall.testDir;
38-
version = testOpt.syscall.version;
39-
});
40-
in [
51+
gvisor-syscall-tests = (
52+
pkgs.callPackage ./tests/syscall/gvisor {
53+
inherit fenix system;
54+
installDir = testOpt.syscall.testDir;
55+
version = testOpt.syscall.version;
56+
}
57+
);
58+
59+
lmbench-benchmark-tests = (pkgs.callPackage ./tests/benchmark/lmbench { });
60+
in
61+
[
4162
static.busybox
4263
static.curl
4364
static.dropbear
4465
cross.glibc
4566

4667
# Simple C utility
47-
(static.callPackage ./about {})
48-
68+
(static.callPackage ./about { })
4969
]
5070
++ lib.optionals (target == "x86_64" && testOpt.syscall.enable) [
5171
# gvisor test case only included on x86_64
5272
gvisor-syscall-tests
73+
lmbench-benchmark-tests
5374
# TODO: Add debian libcxx deps or FHS
5475
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
result
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
lib,
3+
pkgs,
4+
installDir ? "/opt/lmbench",
5+
}:
6+
7+
let
8+
lmbenchBin = pkgs.fetchurl {
9+
url = "https://mirrors.dragonos.org.cn/pub/third_party/lmbench/lmbench-ubuntu2404-202511301014-36c2fb2d084343e098b5e343576d4fc0.tar.xz";
10+
sha256 = "sha256-/iP7oKc2n0CXpA0OgVQX86quNfbtjXBZ83RBl1MEBhE=";
11+
};
12+
13+
testScript = pkgs.stdenv.mkDerivation {
14+
pname = "lmbench-test-script";
15+
version = "3.0-a9";
16+
17+
src = lib.sourceByRegex ./. [
18+
"^test_cases"
19+
"^.*\.sh$"
20+
];
21+
22+
installPhase = ''
23+
mkdir -p $out/${installDir}
24+
25+
install -m755 *.sh $out/${installDir}/
26+
cp -r test_cases $out/${installDir}/
27+
chmod +x $out/${installDir}/test_cases/*.sh
28+
'';
29+
};
30+
31+
lmbench = pkgs.stdenv.mkDerivation {
32+
pname = "lmbench";
33+
version = "3.0-a9";
34+
35+
src = lmbenchBin;
36+
37+
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
38+
39+
buildInputs = [
40+
pkgs.stdenv.cc.cc.lib
41+
pkgs.glibc
42+
pkgs.bzip2
43+
];
44+
45+
sourceRoot = ".";
46+
47+
installPhase = ''
48+
# Keep Ubuntu package's original directory structure, but flatten sysroot
49+
mkdir -p $out
50+
51+
# If there's a sysroot directory, flatten it
52+
if [ -d sysroot ]; then
53+
cp -r sysroot/* $out/
54+
else
55+
cp -r * $out/
56+
fi
57+
58+
# Make all binaries executable
59+
find $out -type f -executable -exec chmod +x {} \;
60+
61+
# Remove broken symlinks (mainly documentation files from sysroot)
62+
find $out -xtype l -delete
63+
'';
64+
65+
# autoPatchelfHook will automatically run after installPhase
66+
# to patch all ELF binaries with correct library paths
67+
};
68+
in
69+
pkgs.symlinkJoin {
70+
name = "lmbench-with-tests";
71+
paths = [
72+
lmbench
73+
testScript
74+
];
75+
}

user/apps/tests/benchmark/lmbench/flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
description = "LMbench benchmark suite packaged for nix (x86_64-linux only)";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
};
7+
8+
outputs =
9+
{ self, nixpkgs }:
10+
let
11+
system = "x86_64-linux";
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
14+
# Default installation directory
15+
defaultInstallDir = "tests/benchmark/lmbench";
16+
17+
# Import the package definition
18+
lmbench = import ./default.nix {
19+
inherit (pkgs) lib pkgs;
20+
installDir = defaultInstallDir;
21+
};
22+
in
23+
{
24+
packages.${system} = {
25+
default = lmbench;
26+
lmbench = lmbench;
27+
};
28+
29+
# Allow overriding installDir
30+
lib.${system}.mkLmbench =
31+
{
32+
installDir ? defaultInstallDir,
33+
}:
34+
import ./default.nix {
35+
inherit (pkgs) lib pkgs;
36+
inherit installDir;
37+
};
38+
39+
apps.${system}.default = {
40+
type = "app";
41+
program = "${lmbench}/${defaultInstallDir}/run_tests.sh";
42+
};
43+
};
44+
}

user/apps/tests/syscall/gvisor/default.nix

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,57 @@ let
3838
'';
3939
};
4040

41-
# 2. Prepare the test data, scripts, and patched binaries
42-
# This derivation handles downloading, extracting, and patching the tests.
43-
tests = pkgs.stdenv.mkDerivation {
44-
pname = "gvisor-tests-data";
41+
# 2. Extract and patch test binaries
42+
# This derivation handles downloading, extracting, and patching the test binaries.
43+
# Separated from scripts so that whitelist/blocklist changes don't trigger repatching.
44+
testBinaries = pkgs.stdenv.mkDerivation {
45+
pname = "gvisor-tests-binaries";
46+
version = "0.1.0";
47+
48+
src = testsArchive;
49+
50+
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
51+
52+
buildInputs = [ pkgs.stdenv.cc.cc.lib ];
53+
54+
sourceRoot = ".";
55+
56+
installPhase = ''
57+
mkdir -p $out/${installDir}/tests
58+
cp -r * $out/${installDir}/tests/
59+
60+
runHook preInstall
61+
find $out/${installDir}/tests -type f -name '*_test' -exec chmod 755 {} \; || true
62+
runHook postInstall
63+
'';
64+
};
65+
66+
# 3. Prepare test scripts and configuration files
67+
# This derivation contains frequently modified files (whitelist, blocklists, scripts).
68+
# Changes here won't trigger binary repatching.
69+
testScripts = pkgs.stdenv.mkDerivation {
70+
pname = "gvisor-tests-scripts";
4571
version = "0.1.0";
4672

47-
# Use sourceByRegex to only depend on relevant files.
48-
# This prevents rebuilds when files in ./runner change.
4973
src = lib.sourceByRegex ./. [
5074
"^whitelist\.txt$"
5175
"^blocklists"
5276
"^blocklists/.*"
5377
"^run_tests\.sh$"
5478
];
5579

56-
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
57-
58-
buildInputs = [ pkgs.stdenv.cc.cc.lib ];
59-
6080
installPhase = ''
6181
mkdir -p $out/${installDir}
6282
6383
install -m644 whitelist.txt $out/${installDir}/
6484
cp -r blocklists $out/${installDir}/
6585
install -m755 run_tests.sh $out/${installDir}/
66-
67-
# Bundle tests archive for offline systems
68-
mkdir -p $out/${installDir}/tests
69-
tar -xf ${testsArchive} -C $out/${installDir}/tests --strip-components=1
70-
71-
runHook preInstall
72-
find $out/${installDir}/tests -type f -name '*_test' -exec install -m755 {} $out/${installDir}/tests \; || true
73-
runHook postInstall
7486
'';
7587
};
7688

7789
in pkgs.symlinkJoin {
7890
name = "gvisor-tests";
79-
paths = [ runner tests ];
91+
paths = [ runner testBinaries testScripts ];
8092
meta = with lib; {
8193
description = "gVisor syscall test runner and scripts";
8294
platforms = platforms.linux;

0 commit comments

Comments
 (0)