Skip to content

Commit

Permalink
fixup! go/oasis-test-runner/scenario/e2e/runtime: Add kv test client
Browse files Browse the repository at this point in the history
  • Loading branch information
Yawning committed Jun 24, 2021
1 parent 5b1fd26 commit 0cef729
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 110 deletions.
2 changes: 0 additions & 2 deletions go/oasis-test-runner/scenario/e2e/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

const (
cfgClientBinaryDir = "client.binary_dir"
cfgRuntimeBinaryDirDefault = "runtime.binary_dir.default"
cfgRuntimeBinaryDirIntelSGX = "runtime.binary_dir.intel-sgx"
cfgRuntimeLoader = "runtime.loader"
Expand Down Expand Up @@ -76,7 +75,6 @@ func newRuntimeImpl(name string, testClient TestClient) *runtimeImpl {
E2E: *e2e.NewE2E(fullName),
testClient: testClient,
}
sc.Flags.String(cfgClientBinaryDir, "", "path to the client binaries directory")
sc.Flags.String(cfgRuntimeBinaryDirDefault, "", "(no-TEE) path to the runtime binaries directory")
sc.Flags.String(cfgRuntimeBinaryDirIntelSGX, "", "(Intel SGX) path to the runtime binaries directory")
sc.Flags.String(cfgRuntimeLoader, "oasis-core-runtime-loader", "path to the runtime loader")
Expand Down
108 changes: 0 additions & 108 deletions go/oasis-test-runner/scenario/e2e/runtime/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package runtime

import (
"context"
"fmt"
"os/exec"
"path/filepath"
"strings"

"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
)
Expand All @@ -21,107 +17,3 @@ type TestClient interface {
// that is ready for Init.
Clone() TestClient
}

// BinaryTestClient is a client that exercises an arbitrary runtime
// by fork/exec-ing another binary.
type BinaryTestClient struct {
ctx context.Context
sc *runtimeImpl

binary string
args []string

cmd *exec.Cmd
errCh chan error
}

func (cli *BinaryTestClient) Init(scenario *runtimeImpl) error {
cli.sc = scenario
return nil
}

func (cli *BinaryTestClient) Start(ctx context.Context, childEnv *env.Env) error {
// Setup the client
d, err := childEnv.NewSubDir("client")
if err != nil {
return err
}

w, err := d.NewLogWriter("client.log")
if err != nil {
return err
}

args := []string{
"--node-address", "unix:" + cli.sc.Net.Clients()[0].SocketPath(),
"--runtime-id", runtimeID.String(),
}
args = append(args, cli.args...)

binary := cli.resolveClientBinary()
cmd := exec.Command(binary, args...)
cmd.SysProcAttr = env.CmdAttrs
cmd.Stdout = w
cmd.Stderr = w

cli.sc.Logger.Info("launching client",
"binary", binary,
"args", strings.Join(args, " "),
)

// Start the client
if err = cmd.Start(); err != nil {
return fmt.Errorf("scenario/e2e: failed to start client: %w", err)
}

// Wire up the termination handler
cli.cmd = cmd
cli.errCh = make(chan error)
go func() {
cli.errCh <- cmd.Wait()
}()

cli.ctx = ctx

return nil
}

func (cli *BinaryTestClient) Wait() error {
var err error

// Wait for the network to fail, the context to be canceled, or the
// client to terminate on it's own.
select {
case err = <-cli.sc.Net.Errors():
_ = cli.cmd.Process.Kill()
case <-cli.ctx.Done():
err = cli.ctx.Err()
_ = cli.cmd.Process.Kill()
case err = <-cli.errCh:
}

return err
}

func (cli *BinaryTestClient) Kill() error {
return cli.cmd.Process.Kill()
}

func (cli *BinaryTestClient) Clone() TestClient {
return &BinaryTestClient{
binary: cli.binary,
args: append([]string{}, cli.args...),
}
}

func (cli *BinaryTestClient) resolveClientBinary() string {
cbDir, _ := cli.sc.Flags.GetString(cfgClientBinaryDir)
return filepath.Join(cbDir, cli.binary)
}

func NewBinaryTestClient(binary string, args []string) *BinaryTestClient {
return &BinaryTestClient{
binary: binary,
args: args,
}
}

0 comments on commit 0cef729

Please sign in to comment.