Skip to content

Commit b6ce330

Browse files
committed
wip
1 parent 6addf09 commit b6ce330

6 files changed

Lines changed: 163 additions & 26 deletions

File tree

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ LIBCLANG_PATH = { value = "devroot/lib", relative = true, force = false }
88

99
[build]
1010
rustflags = ["--cfg=tokio_unstable"]
11+
12+
[target.x86_64-unknown-linux-gnu]
13+
runner = "scripts/test-runner.sh"

default.nix

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ let
122122
cargo-nextest
123123
direnv
124124
gateway-crd
125+
hwloc.dev
125126
just
126127
kopium
127128
llvmPackages'.clang # you need the host compiler in order to link proc macros
@@ -383,8 +384,8 @@ let
383384
}
384385
) package-list;
385386

386-
dataplane-tar = pkgs.stdenv'.mkDerivation {
387-
pname = "dataplane-tar";
387+
min-tar = pkgs.stdenv'.mkDerivation {
388+
pname = "min-tar";
388389
inherit version;
389390
dontUnpack = true;
390391
src = null;
@@ -394,12 +395,8 @@ let
394395
in
395396
''
396397
tmp="$(mktemp -d)"
397-
mkdir -p "$tmp/"{bin,lib,var,etc,run/dataplane,run/frr/hh,run/netns}
398+
mkdir -p "$tmp/"{bin,lib,var,etc,run/dataplane,run/frr/hh,run/netns,home}
398399
ln -s /run "$tmp/var/run"
399-
cp --dereference "${workspace.dataplane}/bin/dataplane" "$tmp/bin"
400-
cp --dereference "${workspace.cli}/bin/cli" "$tmp/bin"
401-
cp --dereference "${workspace.init}/bin/dataplane-init" "$tmp/bin"
402-
ln -s cli "$tmp/bin/sh"
403400
for f in "${pkgs.pkgsHostHost.dockerTools.fakeNss}/etc/"* ; do
404401
cp --archive "$(readlink -e "$f")" "$tmp/etc/$(basename "$f")"
405402
done
@@ -419,8 +416,8 @@ let
419416
--group=0 \
420417
\
421418
`# anybody editing the files shipped in the container image is up to no good, block all of that.` \
422-
`# More, we expressly forbid setuid / setgid anything. May as well toss in the sticky bit as well.` \
423-
--mode='u-sw,go=' \
419+
`# More, we expressly forbid setuid / setgid anything.` \
420+
--mode='ugo-sw' \
424421
\
425422
`# acls / setcap / selinux isn't going to be reliably copied into the image; skip to make more reproducible` \
426423
--no-acls \
@@ -469,6 +466,70 @@ let
469466

470467
};
471468

469+
dataplane-tar = pkgs.stdenv'.mkDerivation {
470+
pname = "dataplane-tar";
471+
inherit version;
472+
dontUnpack = true;
473+
src = null;
474+
buildPhase =
475+
''
476+
tmp="$(mktemp -d)"
477+
tar xf "${min-tar}" -C "$tmp"
478+
chown -R $(id -u):$(id -g) $tmp
479+
chmod +w $tmp/bin
480+
cp --dereference "${workspace.dataplane}/bin/dataplane" "$tmp/bin"
481+
cp --dereference "${workspace.cli}/bin/cli" "$tmp/bin"
482+
cp --dereference "${workspace.init}/bin/dataplane-init" "$tmp/bin"
483+
ln -s cli "$tmp/bin/sh"
484+
cd "$tmp"
485+
# we take some care to make the tar file reproducible here
486+
tar \
487+
--create \
488+
--file "$out" \
489+
--sort=name \
490+
--clamp-mtime \
491+
--mtime=0 \
492+
--format=posix \
493+
--numeric-owner \
494+
--owner=0 \
495+
--group=0 \
496+
--mode='ugo-sw' \
497+
--no-acls \
498+
--no-xattrs \
499+
--no-selinux \
500+
--verbose \
501+
.
502+
'';
503+
504+
};
505+
506+
containers.libc = pkgs.dockerTools.buildLayeredImage {
507+
name = "dataplane-debugger";
508+
tag = "latest";
509+
contents = pkgs.buildEnv {
510+
name = "dataplane-debugger-env";
511+
pathsToLink = [
512+
"/bin"
513+
"/etc"
514+
"/var"
515+
"/lib"
516+
];
517+
paths = [
518+
pkgs.pkgsBuildHost.gdb
519+
pkgs.pkgsBuildHost.rr
520+
pkgs.pkgsBuildHost.coreutils
521+
pkgs.pkgsBuildHost.bashInteractive
522+
pkgs.pkgsBuildHost.iproute2
523+
pkgs.pkgsBuildHost.ethtool
524+
525+
pkgs.pkgsHostHost.libc.debug
526+
workspace.cli.debug
527+
workspace.dataplane.debug
528+
workspace.init.debug
529+
];
530+
};
531+
};
532+
472533
containers.dataplane-debugger = pkgs.dockerTools.buildLayeredImage {
473534
name = "dataplane-debugger";
474535
tag = "latest";
@@ -500,11 +561,12 @@ in
500561
{
501562
inherit
502563
clippy
503-
dataplane-tar
504564
containers
565+
dataplane-tar
505566
dev-pkgs
506-
devroot
507567
devenv
568+
devroot
569+
min-tar
508570
package-list
509571
pkgs
510572
sources

npins/sources.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/installl-real-nix.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
if [ -L /nix ]; then
6+
echo "fake nix detected, removing"
7+
rm /nix
8+
echo "installing real nix"
9+
sh <(curl --proto '=https' --tlsv1.2 -sSf -L https://nixos.org/nix/install) --no-daemon
10+
elif [ -d /nix ]; then
11+
echo "real nix detected, nothing to do"
12+
elif [ -a /nix ]; then
13+
echo "/nix exists but is neither directory no symlink, unsure what is happening"
14+
exit 99
15+
else
16+
echo "installing real nix"
17+
sh <(curl --proto '=https' --tlsv1.2 -sSf -L https://nixos.org/nix/install) --no-daemon
18+
fi

scripts/test-runner.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# SPDX-License-Identifier: Apache-2.0
44
# Copyright Open Network Fabric Authors
@@ -177,7 +177,7 @@ docker run \
177177
--tmpfs "/run/netns:noexec,nosuid,uid=$(id -u),gid=$(id -g)" \
178178
--tmpfs "/var/run/netns:noexec,nosuid,uid=$(id -u),gid=$(id -g)" \
179179
--tmpfs "/tmp:nodev,noexec,nosuid,uid=$(id -u),gid=$(id -g)" \
180-
--user="$(id -u):$(id -g)" \
180+
--user="0:0" \
181181
--group-add="$(getent group docker | cut -d: -f3)" \
182182
--env LLVM_PROFILE_FILE="${LLVM_PROFILE_FILE:-""}" \
183183
--env CARGO_LLVM_COV="${CARGO_LLVM_COV:-0}" \
@@ -191,5 +191,5 @@ docker run \
191191
--cap-add SYS_ADMIN \
192192
--cap-add SYS_RAWIO \
193193
--read-only \
194-
"ghcr.io/githedgehog/dpdk-sys/libc-env:${DPDK_SYS_COMMIT}.${LIBC_ENV_PROFILE:-release}" \
194+
"min:release" \
195195
"${@}"

scripts/todo.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
# This script must be run from within a nix shell
6+
7+
# Step 1: check npins
8+
9+
npins verify
10+
11+
# Step 2: build dataplane
12+
13+
mkdir -p results
14+
nix build -f default.nix min-tar --out-link results/min.tar
15+
16+
mkdir -p results
17+
nix build -f default.nix dataplane-tar --out-link results/dataplane.tar
18+
19+
# Step 3: import dataplane
20+
21+
docker import results/min.tar min:release
22+
docker import results/dataplane.tar dataplane:debug
23+
24+
# Step 4: cargo build
25+
26+
cargo build
27+
28+
# Step 5: cargo nextest run
29+
30+
# (one test is xfail)
31+
32+
cargo nextest run || true
33+
34+
# Step 6: cargo test run
35+
36+
# (one test is xfail)
37+
38+
cargo test || true
39+
40+
# Step 7: build test archive
41+
42+
nix build -f default.nix tests.all --out-link results/tests.all
43+
# (one test is xfail)
44+
45+
cargo nextest run --archive-file results/tests.all/*.tar.zst --workspace-remap "$(pwd)" || true
46+
47+
# Step 8: build individual tests archive
48+
49+
nix build -f default.nix tests.pkg --out-link results/tests.pkg --max-jobs 4
50+
51+
for pkg in results/tests.pkg/*/*.tar.zst; do
52+
# (one test is xfail)
53+
cargo nextest run --archive-file "${pkg}" --workspace-remap "$(pwd)" || true
54+
done

0 commit comments

Comments
 (0)