diff options
| author | Michele Bertasi <405934+mbrt@users.noreply.github.com> | 2026-03-26 22:19:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-26 14:19:14 -0700 |
| commit | 298ed2a6c44cde90b4262b884169c53b8deda508 (patch) | |
| tree | 1838fd3e8ca9913292562ee854d633288e6dfced /bin/gen-cgroup-testdata | |
| parent | ea916da7fa9844cc3da608e75510f478c7b09f7d (diff) | |
Add support for cgroup limits (#443)
* Add cgroup package
* Refactor procGgroup
* Add testdata generation
* Add v1 testdata generation
* Move scripts around
* Add integration test in CI
* Remove cgroup v1
* Move to cgroup struct
* Remove half-core test as it's redundant
Diffstat (limited to 'bin/gen-cgroup-testdata')
| -rwxr-xr-x | bin/gen-cgroup-testdata | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bin/gen-cgroup-testdata b/bin/gen-cgroup-testdata new file mode 100755 index 0000000..3d9215b --- /dev/null +++ b/bin/gen-cgroup-testdata @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# +# gen-cgroup-testdata - Generate cgroup testdata by running +# bin/snapshot-cgroup inside Docker containers with known resource limits. +# +# Usage: gen-cgroup-testdata +# +# Prerequisites: Docker on a host running cgroup v2. +# +# Each testdata directory contains: +# expected.json - {"cpu_quota": <float>, "memory_limit": <int>} +# proc/ - snapshot of /proc/self/cgroup +# sys/ - snapshot of cgroup control files + +set -euo pipefail + +cd "$(dirname "$0")/.." + +testdata="cgroup/testdata" +snapshot_script="bin/snapshot-cgroup" + +generate() { + local name="$1" cpu_quota="$2" memory_limit="$3" + shift 3 + local outdir="$testdata/$name" + + echo "Generating $name..." + rm -rf "$outdir" + mkdir -p "$outdir" + + docker run --rm \ + --user "$(id -u):$(id -g)" \ + "$@" \ + -v "$PWD/$snapshot_script:/snapshot:ro" \ + -v "$PWD/$outdir:/out" \ + debian:bookworm-slim \ + /snapshot /out + + cat > "$outdir/expected.json" <<EOF +{"cpu_quota": $cpu_quota, "memory_limit": $memory_limit} +EOF +} + +generate "v2-two-cores-256m" 2.0 268435456 --cpus=2 --memory=256m +generate "v2-quarter-core-64m" 0.25 67108864 --cpus=0.25 --memory=64m +generate "v2-no-limit" null null + +echo "v2 testdata generated successfully." |