aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cmd/hakurei/print.go8
-rw-r--r--cmd/hakurei/print_test.go50
-rw-r--r--cmd/hpkg/test/test.py2
-rw-r--r--test/configuration.nix4
-rw-r--r--test/test.py2
5 files changed, 55 insertions, 11 deletions
diff --git a/cmd/hakurei/print.go b/cmd/hakurei/print.go
index 6e5c6908..eaa8661a 100644
--- a/cmd/hakurei/print.go
+++ b/cmd/hakurei/print.go
@@ -1,9 +1,11 @@
package main
import (
+ "bytes"
"fmt"
"io"
"log"
+ "maps"
"slices"
"strconv"
"strings"
@@ -177,10 +179,8 @@ func printPs(output io.Writer, now time.Time, s store.Compat, short, flagJSON bo
}
if !short && flagJSON {
- es := make(map[string]*hst.State, len(entries))
- for id, instance := range entries {
- es[id.String()] = instance
- }
+ es := slices.Collect(maps.Values(entries))
+ slices.SortFunc(es, func(a, b *hst.State) int { return bytes.Compare(a.ID[:], b.ID[:]) })
encodeJSON(log.Fatal, output, short, es)
return
}
diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go
index 3db06ec4..5309e376 100644
--- a/cmd/hakurei/print_test.go
+++ b/cmd/hakurei/print_test.go
@@ -1,10 +1,12 @@
package main
import (
+ "bytes"
"strings"
"testing"
"time"
+ "hakurei.app/container/check"
"hakurei.app/hst"
"hakurei.app/internal/store"
)
@@ -530,8 +532,25 @@ func TestPrintPs(t *testing.T) {
4cf073bd 3405691582 9 (org.chromium.Chromium) 1h2m32s
`},
{"valid short", map[hst.ID]*hst.State{testID: testState}, true, false, "4cf073bd\n"},
- {"valid json", map[hst.ID]*hst.State{testID: testState}, false, true, `{
- "8e2c76b066dabe574cf073bdb46eb5c1": {
+ {"valid json", map[hst.ID]*hst.State{testID: testState, (hst.ID)(bytes.Repeat([]byte{0xaa}, len(hst.ID{}))): {
+ ID: (hst.ID)(bytes.Repeat([]byte{0xaa}, len(hst.ID{}))),
+ PID: 0xbeef,
+ ShimPID: 0xcafe,
+ Config: &hst.Config{
+ ID: "uk.gensokyo.cat",
+ Enablements: hst.NewEnablements(hst.EWayland | hst.EPulse),
+ Identity: 1,
+ Container: &hst.ContainerConfig{
+ Shell: check.MustAbs("/bin/sh"),
+ Home: check.MustAbs("/data/data/uk.gensokyo.cat"),
+ Path: check.MustAbs("/usr/bin/cat"),
+ Args: []string{"cat"},
+ Flags: hst.FUserns,
+ },
+ },
+ Time: time.Unix(0, 0xdeadbeef).UTC(),
+ }}, false, true, `[
+ {
"instance": "8e2c76b066dabe574cf073bdb46eb5c1",
"pid": 3405691582,
"shim_pid": 3735928559,
@@ -683,8 +702,33 @@ func TestPrintPs(t *testing.T) {
"share_tmpdir": true
},
"time": "1970-01-01T00:00:00.000000009Z"
+ },
+ {
+ "instance": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "pid": 48879,
+ "shim_pid": 51966,
+ "id": "uk.gensokyo.cat",
+ "enablements": {
+ "wayland": true,
+ "pulse": true
+ },
+ "identity": 1,
+ "groups": null,
+ "container": {
+ "env": null,
+ "filesystem": null,
+ "shell": "/bin/sh",
+ "home": "/data/data/uk.gensokyo.cat",
+ "path": "/usr/bin/cat",
+ "args": [
+ "cat"
+ ],
+ "userns": true,
+ "map_real_uid": false
+ },
+ "time": "1970-01-01T00:00:03.735928559Z"
}
-}
+]
`},
{"valid short json", map[hst.ID]*hst.State{testID: testState}, true, true, `["8e2c76b066dabe574cf073bdb46eb5c1"]
`},
diff --git a/cmd/hpkg/test/test.py b/cmd/hpkg/test/test.py
index 6f16729d..dcfe4e90 100644
--- a/cmd/hpkg/test/test.py
+++ b/cmd/hpkg/test/test.py
@@ -58,7 +58,7 @@ def check_state(name, enablements):
instances = json.loads(machine.succeed("sudo -u alice -i XDG_RUNTIME_DIR=/run/user/1000 hakurei --json ps"))
if len(instances) != 1:
raise Exception(f"unexpected state length {len(instances)}")
- instance = next(iter(instances.values()))
+ instance = instances[0]
if len(instance['container']['args']) != 1 or not (instance['container']['args'][0].startswith("/nix/store/")) or f"hakurei-{name}-" not in (instance['container']['args'][0]):
raise Exception(f"unexpected args {instance['container']['args']}")
diff --git a/test/configuration.nix b/test/configuration.nix
index 39fd166c..4ac8f76a 100644
--- a/test/configuration.nix
+++ b/test/configuration.nix
@@ -84,14 +84,14 @@
virtualisation = {
# Hopefully reduces spurious test failures:
- memorySize = 4096;
+ memorySize = 8192;
qemu.options = [
# Need to switch to a different GPU driver than the default one (-vga std) so that Sway can launch:
"-vga none -device virtio-gpu-pci"
# Increase Go test compiler performance:
- "-smp 8"
+ "-smp 16"
];
};
diff --git a/test/test.py b/test/test.py
index cfc2f843..839a2b4e 100644
--- a/test/test.py
+++ b/test/test.py
@@ -56,7 +56,7 @@ def check_state(name, enablements):
instances = json.loads(machine.succeed("sudo -u alice -i XDG_RUNTIME_DIR=/run/user/1000 hakurei --json ps"))
if len(instances) != 1:
raise Exception(f"unexpected state length {len(instances)}")
- instance = next(iter(instances.values()))
+ instance = instances[0]
command = f"{name}-start"
if not (instance['container']['path'].startswith("/nix/store/")) or not (instance['container']['path'].endswith(command)):