Skip to content
Draft
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
1 change: 1 addition & 0 deletions test
77 changes: 49 additions & 28 deletions user/apps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,71 @@
system,
target,
fenix,
testOpt
testOpt,
}:

# Return a list of app derivations to be copied into the rootfs.
let
cross = if system == "x86_64-linux" && target == "x86_64" then pkgs
else if target == "riscv64" then pkgs.pkgsCross.riscv64
else import nixpkgs {
localSystem = system;
crossSystem = if target == "x86_64" then "x86_64-unknown-linux-gnu"
else abort "Unsupported target: ${target}}";
};
cross =
if system == "x86_64-linux" && target == "x86_64" then
pkgs
else if target == "riscv64" then
pkgs.pkgsCross.riscv64
else
import nixpkgs {
localSystem = system;
crossSystem =
if target == "x86_64" then "x86_64-unknown-linux-gnu" else abort "Unsupported target: ${target}}";
};

cross-musl = if system == "x86_64-linux" && target == "x86_64" then pkgs.pkgsMusl
else if target == "riscv64" then pkgs.pkgsCross.riscv64-musl
else import nixpkgs {
localSystem = system;
crossSystem = if target == "x86_64" then "x86_64-unknown-linux-musl"
else abort "Unsupported target: ${target}-musl}";
};
cross-musl =
if system == "x86_64-linux" && target == "x86_64" then
pkgs.pkgsMusl
else if target == "riscv64" then
pkgs.pkgsCross.riscv64-musl
else
import nixpkgs {
localSystem = system;
crossSystem =
if target == "x86_64" then
"x86_64-unknown-linux-musl"
else
abort "Unsupported target: ${target}-musl}";
};

static = if system == "x86_64-linux" && target == "x86_64" then pkgs.pkgsStatic
else if target == "riscv64" then import nixpkgs {
crossSystem = lib.systems.examples.riscv64-musl;
isStatic = true;
} else abort "Unsupported static target: ${target}";
static =
if system == "x86_64-linux" && target == "x86_64" then
pkgs.pkgsStatic
else if target == "riscv64" then
import nixpkgs {
crossSystem = lib.systems.examples.riscv64-musl;
isStatic = true;
}
else
abort "Unsupported static target: ${target}";

gvisor-syscall-tests = (pkgs.callPackage ./tests/syscall/gvisor {
inherit fenix system;
installDir = testOpt.syscall.testDir;
version = testOpt.syscall.version;
});
in [
gvisor-syscall-tests = (
pkgs.callPackage ./tests/syscall/gvisor {
inherit fenix system;
installDir = testOpt.syscall.testDir;
version = testOpt.syscall.version;
}
);

lmbench-benchmark-tests = (pkgs.callPackage ./tests/benchmark/lmbench { });
in
[
static.busybox
static.curl
static.dropbear
cross.glibc

# Simple C utility
(static.callPackage ./about {})

(static.callPackage ./about { })
]
++ lib.optionals (target == "x86_64" && testOpt.syscall.enable) [
# gvisor test case only included on x86_64
gvisor-syscall-tests
lmbench-benchmark-tests
# TODO: Add debian libcxx deps or FHS
]
5 changes: 5 additions & 0 deletions user/apps/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Test Tookit Overview
=========================

## Brief Introduction
This Directory contains all using test toolkit and source for DragonOS, including **compatible test** and **performance benchmarks**.
Empty file.
1 change: 1 addition & 0 deletions user/apps/tests/benchmark/lmbench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
result
51 changes: 51 additions & 0 deletions user/apps/tests/benchmark/lmbench/clean_up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /bin/bash
# 测试环境清理脚本
# 清理 lmbench 测试环境
# Usage: ./clean_up.sh

# 获取脚本所在目录
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)



# 清理测试文件
remove_test_files(){
if [[ -f "/tmp/zero_file" ]]; then
rm -f /tmp/zero_file
fi
if [[ -f "/tmp/test_file" ]]; then
rm -f /tmp/test_file
fi
}

# 清理 ext4 文件系统和镜像文件
clean_ext4_fs(){
# 清理挂载的 ext4 文件系统和镜像文件
if [[ -d "/ext4" ]]; then
umount /ext4
rm -rf /ext4
fi
if [[ -f "${SCRIPT_DIR}/ext4.img" ]]; then
rm -f ${SCRIPT_DIR}/ext4.img
fi
}

# main execution function
main(){
# 自动请求 root 权限
if [[ $EUID -ne 0 ]]; then
echo "需要root权限正在自动请求"
exec sudo bash "$0" "$@"
exit 1
fi

remove_test_files
clean_ext4_fs
}



# 执行清理
main "$@"

echo "Lmbench 测试环境已清理完成"
75 changes: 75 additions & 0 deletions user/apps/tests/benchmark/lmbench/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
lib,
pkgs,
installDir ? "/opt/lmbench",
}:

let
lmbenchBin = pkgs.fetchurl {
url = "https://mirrors.dragonos.org.cn/pub/third_party/lmbench/lmbench-ubuntu2404-202511301014-36c2fb2d084343e098b5e343576d4fc0.tar.xz";
sha256 = "sha256-/iP7oKc2n0CXpA0OgVQX86quNfbtjXBZ83RBl1MEBhE=";
};

testScript = pkgs.stdenv.mkDerivation {
pname = "lmbench-test-script";
version = "3.0-a9";

src = lib.sourceByRegex ./. [
"^test_cases"
"^.*\.sh$"
];

installPhase = ''
mkdir -p $out/${installDir}

install -m755 *.sh $out/${installDir}/
cp -r test_cases $out/${installDir}/
chmod +x $out/${installDir}/test_cases/*.sh
'';
};

lmbench = pkgs.stdenv.mkDerivation {
pname = "lmbench";
version = "3.0-a9";

src = lmbenchBin;

nativeBuildInputs = [ pkgs.autoPatchelfHook ];

buildInputs = [
pkgs.stdenv.cc.cc.lib
pkgs.glibc
pkgs.bzip2
];

sourceRoot = ".";

installPhase = ''
# Keep Ubuntu package's original directory structure, but flatten sysroot
mkdir -p $out

# If there's a sysroot directory, flatten it
if [ -d sysroot ]; then
cp -r sysroot/* $out/
else
cp -r * $out/
fi

# Make all binaries executable
find $out -type f -executable -exec chmod +x {} \;

# Remove broken symlinks (mainly documentation files from sysroot)
find $out -xtype l -delete
'';

# autoPatchelfHook will automatically run after installPhase
# to patch all ELF binaries with correct library paths
};
in
pkgs.symlinkJoin {
name = "lmbench-with-tests";
paths = [
lmbench
testScript
];
}
9 changes: 9 additions & 0 deletions user/apps/tests/benchmark/lmbench/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# lmbench 二进制文件路径前缀
export LMBENCH_BIN_DIR="/lib/lmbench/bin/x86_64-linux-gnu"
# 挂载的 ext4 文件系统路径
export LMBENCH_EXT4_DIR="/ext4"
# 临时文件存放路径
export LMBENCH_TMP_DIR="/tmp"
# 测试文件名
export LMBENCH_TEST_FILE="test_file"
export LMBENCH_ZERO_FILE="zero_file"
27 changes: 27 additions & 0 deletions user/apps/tests/benchmark/lmbench/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions user/apps/tests/benchmark/lmbench/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
description = "LMbench benchmark suite packaged for nix (x86_64-linux only)";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs =
{ self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};

# Default installation directory
defaultInstallDir = "tests/benchmark/lmbench";

# Import the package definition
lmbench = import ./default.nix {
inherit (pkgs) lib pkgs;
installDir = defaultInstallDir;
};
in
{
packages.${system} = {
default = lmbench;
lmbench = lmbench;
};

# Allow overriding installDir
lib.${system}.mkLmbench =
{
installDir ? defaultInstallDir,
}:
import ./default.nix {
inherit (pkgs) lib pkgs;
inherit installDir;
};

apps.${system}.default = {
type = "app";
program = "${lmbench}/${defaultInstallDir}/run_tests.sh";
};
};
}
Loading
Loading