aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/dispatcher_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-06 14:25:19 +0900
committerOphestra <cat@gensokyo.uk>2025-09-06 14:25:19 +0900
commit05db06c87b743b2e1eb0e8158476ba2a24962967 (patch)
tree373e6d37f9ed93ec42b0739e1e98ebc18cb02fa2 /system/dispatcher_test.go
parente603b688ca6d023b783e58f3876430ea73dd21a6 (diff)
system/dbus: use syscall dispatcher
This allows dbus op methods and builder to be instrumented. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/dispatcher_test.go')
-rw-r--r--system/dispatcher_test.go81
1 files changed, 80 insertions, 1 deletions
diff --git a/system/dispatcher_test.go b/system/dispatcher_test.go
index 7c7c10c9..c23c6c58 100644
--- a/system/dispatcher_test.go
+++ b/system/dispatcher_test.go
@@ -1,12 +1,15 @@
package system
import (
+ "os"
"reflect"
"slices"
"testing"
+ "unsafe"
"hakurei.app/container/stub"
"hakurei.app/system/acl"
+ "hakurei.app/system/dbus"
)
// call initialises a [stub.Call].
@@ -197,9 +200,85 @@ func (k *kstub) aclUpdate(name string, uid int, perms ...acl.Perm) error {
stub.CheckArgReflect(k.Stub, "perms", perms, 2))
}
+func (k *kstub) dbusAddress() (session, system string) {
+ k.Helper()
+ ret := k.Expects("dbusAddress").Ret.([2]string)
+ return ret[0], ret[1]
+}
+
+func (k *kstub) dbusFinalise(sessionBus, systemBus dbus.ProxyPair, session, system *dbus.Config) (final *dbus.Final, err error) {
+ k.Helper()
+ expect := k.Expects("dbusFinalise")
+
+ final = expect.Ret.(*dbus.Final)
+ err = expect.Error(
+ stub.CheckArg(k.Stub, "sessionBus", sessionBus, 0),
+ stub.CheckArg(k.Stub, "systemBus", systemBus, 1),
+ stub.CheckArgReflect(k.Stub, "session", session, 2),
+ stub.CheckArgReflect(k.Stub, "system", system, 3))
+ if err != nil {
+ final = nil
+ }
+ return
+}
+
+func (k *kstub) dbusProxyStart(proxy *dbus.Proxy) error {
+ k.Helper()
+ return k.dbusProxySCW(k.Expects("dbusProxyStart"), proxy)
+}
+func (k *kstub) dbusProxyClose(proxy *dbus.Proxy) {
+ k.Helper()
+ if k.dbusProxySCW(k.Expects("dbusProxyClose"), proxy) != nil {
+ k.Fail()
+ }
+}
+func (k *kstub) dbusProxyWait(proxy *dbus.Proxy) error {
+ k.Helper()
+ return k.dbusProxySCW(k.Expects("dbusProxyWait"), proxy)
+}
+func (k *kstub) dbusProxySCW(expect *stub.Call, proxy *dbus.Proxy) error {
+ k.Helper()
+ v := reflect.ValueOf(proxy).Elem()
+
+ if ctxV := v.FieldByName("ctx"); ctxV.IsNil() {
+ k.Errorf("proxy: ctx = %s", ctxV.String())
+ return os.ErrInvalid
+ }
+
+ finalV := v.FieldByName("final")
+ if gotFinal := reflect.NewAt(finalV.Type(), unsafe.Pointer(finalV.UnsafeAddr())).Elem().Interface().(*dbus.Final); !reflect.DeepEqual(gotFinal, expect.Args[0]) {
+ k.Errorf("proxy: final = %#v, want %#v", gotFinal, expect.Args[0])
+ return os.ErrInvalid
+ }
+
+ outputV := v.FieldByName("output")
+ if _, ok := reflect.NewAt(outputV.Type(), unsafe.Pointer(outputV.UnsafeAddr())).Elem().Interface().(*linePrefixWriter); !ok {
+ k.Errorf("proxy: output = %s", outputV.String())
+ return os.ErrInvalid
+ }
+
+ return expect.Err
+}
+
+func (k *kstub) isVerbose() bool { k.Helper(); return k.Expects("isVerbose").Ret.(bool) }
+
+// ignoreValue marks a value to be ignored by the test suite.
+type ignoreValue struct{}
+
func (k *kstub) verbose(v ...any) {
k.Helper()
- if k.Expects("verbose").Error(
+ expect := k.Expects("verbose")
+
+ // translate ignores in v
+ if want, ok := expect.Args[0].([]any); ok && len(v) == len(want) {
+ for i, a := range want {
+ if _, ok = a.(ignoreValue); ok {
+ v[i] = ignoreValue{}
+ }
+ }
+ }
+
+ if expect.Error(
stub.CheckArgReflect(k.Stub, "v", v, 0)) != nil {
k.FailNow()
}