aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/rpcserver/runner.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-07-01 16:52:41 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-07-04 12:34:14 +0000
commit092c1914a191f5858db674b4e367c6848500429e (patch)
treef48a5a5e2602cb75a3d37463bddb1212829889f3 /pkg/rpcserver/runner.go
parentdc6bbff0c2fe403c39d8a1d057f668088b09069f (diff)
pkg/rpcserver: move handshake functionality to Runner
This allows for a more clean interface between RPCServer and Runner.
Diffstat (limited to 'pkg/rpcserver/runner.go')
-rw-r--r--pkg/rpcserver/runner.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/pkg/rpcserver/runner.go b/pkg/rpcserver/runner.go
index 219ef2c35..ed45e2e31 100644
--- a/pkg/rpcserver/runner.go
+++ b/pkg/rpcserver/runner.go
@@ -25,6 +25,7 @@ type Runner struct {
source queue.Source
procs int
cover bool
+ coverEdges bool
filterSignal bool
debug bool
sysTarget *targets.Target
@@ -52,6 +53,65 @@ type runnerStats struct {
statNoExecDuration *stats.Val
}
+type handshakeConfig struct {
+ VMLess bool
+ Timeouts targets.Timeouts
+ LeakFrames []string
+ RaceFrames []string
+ Files []string
+ Globs []string
+ Features flatrpc.Feature
+
+ // Callback() is called in the middle of the handshake process.
+ // The return arguments are the coverage filter and the (possible) error.
+ Callback func(*flatrpc.InfoRequestRawT) (handshakeResult, error)
+}
+
+type handshakeResult struct {
+ CovFilter []uint64
+ MachineInfo []byte
+ Canonicalizer *cover.CanonicalizerInstance
+}
+
+func (runner *Runner) handshake(conn *flatrpc.Conn, cfg *handshakeConfig) error {
+ connectReply := &flatrpc.ConnectReply{
+ Debug: runner.debug,
+ Cover: runner.cover,
+ CoverEdges: runner.coverEdges,
+ Kernel64Bit: runner.sysTarget.PtrSize == 8,
+ Procs: int32(runner.procs),
+ Slowdown: int32(cfg.Timeouts.Slowdown),
+ SyscallTimeoutMs: int32(cfg.Timeouts.Syscall / time.Millisecond),
+ ProgramTimeoutMs: int32(cfg.Timeouts.Program / time.Millisecond),
+ LeakFrames: cfg.LeakFrames,
+ RaceFrames: cfg.RaceFrames,
+ Files: cfg.Files,
+ Globs: cfg.Globs,
+ Features: cfg.Features,
+ }
+ if err := flatrpc.Send(conn, connectReply); err != nil {
+ return err
+ }
+ infoReq, err := flatrpc.Recv[*flatrpc.InfoRequestRaw](conn)
+ if err != nil {
+ return err
+ }
+ ret, err := cfg.Callback(infoReq)
+ if err != nil {
+ return err
+ }
+ infoReply := &flatrpc.InfoReply{
+ CoverFilter: ret.CovFilter,
+ }
+ if err := flatrpc.Send(conn, infoReply); err != nil {
+ return err
+ }
+ runner.conn = conn
+ runner.machineInfo = ret.MachineInfo
+ runner.canonicalizer = ret.Canonicalizer
+ return nil
+}
+
func (runner *Runner) connectionLoop() error {
var infoc chan []byte
defer func() {