Skip to content

Commit

Permalink
oasis-test-runner: Use explicit flagsets for scenario parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed May 22, 2020
1 parent a28a9cd commit cded8f0
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 140 deletions.
44 changes: 26 additions & 18 deletions go/oasis-test-runner/scenario/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
)

var (
// E2eParamsDummy is a dummy instance of e2eImpl used to register e2e-wise parameters.
E2eParamsDummy *e2eImpl = &e2eImpl{name: "e2e"}
// E2eParamsDummy is a dummy instance of e2eImpl used to register e2e/* parameters.
E2eParamsDummy *e2eImpl = newE2eImpl("")

logger = logging.GetLogger("e2e/common")
)
Expand All @@ -27,37 +27,45 @@ type e2eImpl struct {
net *oasis.Network
name string
logger *logging.Logger

// nodeBinary is the path to oasis-node executable.
nodeBinary string
flags *flag.FlagSet
}

func newE2eImpl(name string) *e2eImpl {
return &e2eImpl{
name: "e2e/" + name,
logger: logging.GetLogger("scenario/e2e/" + name),
nodeBinary: "oasis-node",
// Empty scenario name is used for registering global parameters only.
fullName := "e2e"
if name != "" {
fullName += "/" + name
}

sc := &e2eImpl{
name: fullName,
logger: logging.GetLogger("scenario/e2e/" + name),
flags: flag.NewFlagSet(name, flag.ContinueOnError),
}

sc.flags.String(cfgNodeBinary, "oasis-node", "path to the node binary")

return sc
}

func (sc *e2eImpl) Clone() e2eImpl {
return e2eImpl{
net: sc.net,
name: sc.name,
logger: sc.logger,
nodeBinary: sc.nodeBinary,
newSc := &e2eImpl{
net: sc.net,
name: sc.name,
logger: sc.logger,
flags: flag.NewFlagSet(sc.name, flag.ContinueOnError),
}
newSc.flags.AddFlagSet(sc.flags)

return *newSc
}

func (sc *e2eImpl) Name() string {
return sc.name
}

func (sc *e2eImpl) Parameters() *flag.FlagSet {
fs := flag.NewFlagSet(sc.name, flag.ContinueOnError)
fs.StringVar(&sc.nodeBinary, cfgNodeBinary, sc.nodeBinary, "path to the node binary")

return fs
return sc.flags
}

func (sc *e2eImpl) Init(childEnv *env.Env, net *oasis.Network) error {
Expand Down
18 changes: 15 additions & 3 deletions go/oasis-test-runner/scenario/e2e/gas_fees_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ func (sc *gasFeesImpl) Fixture() (*oasis.NetworkFixture, error) {
}

var tee node.TEEHardware
err = tee.FromString(sc.TEEHardware)
teeStr, err := sc.flags.GetString(cfgTEEHardware)
if err != nil {
return nil, err
}
err = tee.FromString(teeStr)
if err != nil {
return nil, err
}
Expand All @@ -78,9 +82,17 @@ func (sc *gasFeesImpl) Fixture() (*oasis.NetworkFixture, error) {
Hardware: tee,
MrSigner: mrSigner,
}
nodeBinary, err := sc.flags.GetString(cfgNodeBinary)
if err != nil {
return nil, err
}
runtimeLoader, err := sc.flags.GetString(cfgRuntimeLoader)
if err != nil {
return nil, err
}
f.Network = oasis.NetworkCfg{
NodeBinary: sc.nodeBinary,
RuntimeSGXLoaderBinary: sc.runtimeLoader,
NodeBinary: nodeBinary,
RuntimeSGXLoaderBinary: runtimeLoader,
EpochtimeMock: true,
StakingGenesis: "tests/fixture-data/gas-fees/staking-genesis.json",
DefaultLogWatcherHandlerFactories: DefaultRuntimeLogWatcherHandlerFactories,
Expand Down
12 changes: 10 additions & 2 deletions go/oasis-test-runner/scenario/e2e/identity_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (ident *identityCLIImpl) Run(childEnv *env.Env) error {
"identity", "init",
"--" + common.CfgDataDir, ident.dataDir,
}
if err := cli.RunSubCommand(childEnv, ident.logger, "identity-init", ident.nodeBinary, args); err != nil {
nodeBinary, err := ident.flags.GetString(cfgNodeBinary)
if err != nil {
return err
}
if err := cli.RunSubCommand(childEnv, ident.logger, "identity-init", nodeBinary, args); err != nil {
return fmt.Errorf("scenario/e2e/identity_cli: failed provision node's identity: %w", err)
}

Expand Down Expand Up @@ -96,7 +100,11 @@ func (ident *identityCLIImpl) tendermintShowAddress(childEnv *env.Env, addrName
"identity", "tendermint", subCmd,
"--" + common.CfgDataDir, ident.dataDir,
}
if out, err := cli.RunSubCommandWithOutput(childEnv, ident.logger, subCmd, ident.nodeBinary, args); err != nil {
nodeBinary, err := ident.flags.GetString(cfgNodeBinary)
if err != nil {
return err
}
if out, err := cli.RunSubCommandWithOutput(childEnv, ident.logger, subCmd, nodeBinary, args); err != nil {
return fmt.Errorf("failed to get %s's tendermint address: error: %w output: %s", addrName, err, out.String())
}
return nil
Expand Down
82 changes: 40 additions & 42 deletions go/oasis-test-runner/scenario/e2e/multiple_runtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"time"

flag "github.com/spf13/pflag"

"github.com/oasislabs/oasis-core/go/common"
"github.com/oasislabs/oasis-core/go/common/logging"
epochtime "github.com/oasislabs/oasis-core/go/epochtime/api"
Expand All @@ -16,59 +14,43 @@ import (
registry "github.com/oasislabs/oasis-core/go/registry/api"
)

const (
cfgNumComputeRuntimes = "num_compute_runtimes"
cfgNumComputeRuntimeTxns = "num_compute_runtime_txns"
cfgNumComputeWorkers = "num_compute_workers"
cfgExecutorGroupSize = "executor_group_size"
)

var (
// MultipleRuntimes is a scenario which tests running multiple runtimes on one node.
MultipleRuntimes scenario.Scenario = &multipleRuntimesImpl{
runtimeImpl: *newRuntimeImpl("multiple-runtimes", "simple-keyvalue-client", nil),
logger: logging.GetLogger("scenario/e2e/multiple_runtimes"),

numComputeRuntimes: 2,
numComputeRuntimeTxns: 2,
numComputeWorkers: 2,
executorGroupSize: 2,
}
MultipleRuntimes scenario.Scenario = func() scenario.Scenario {
sc := &multipleRuntimesImpl{
runtimeImpl: *newRuntimeImpl("multiple-runtimes", "simple-keyvalue-client", nil),
logger: logging.GetLogger("scenario/e2e/multiple_runtimes"),
}

sc.flags.Int(cfgNumComputeRuntimes, 2, "number of compute runtimes per worker")
sc.flags.Int(cfgNumComputeRuntimeTxns, 2, "number of transactions to perform")
sc.flags.Int(cfgNumComputeWorkers, 2, "number of workers to initiate")
sc.flags.Int(cfgExecutorGroupSize, 2, "number of executor workers in committee")

return sc
}()
)

type multipleRuntimesImpl struct {
runtimeImpl

logger *logging.Logger

// numComputeRuntimes is the number of runtimes, all with common runtimeBinary registered.
numComputeRuntimes int

// numComputeRuntimeTxns is the number of insert test transactions sent to each runtime.
numComputeRuntimeTxns int

// numComputeWorkers is the number of compute workers.
numComputeWorkers int

// executorGroupSize is the number of executor nodes.
executorGroupSize int
}

func (mr *multipleRuntimesImpl) Clone() scenario.Scenario {
return &multipleRuntimesImpl{
runtimeImpl: *mr.runtimeImpl.Clone().(*runtimeImpl),
logger: mr.logger,

numComputeRuntimes: mr.numComputeRuntimes,
numComputeRuntimeTxns: mr.numComputeRuntimeTxns,
numComputeWorkers: mr.numComputeWorkers,
executorGroupSize: mr.executorGroupSize,
}
}

func (mr *multipleRuntimesImpl) Parameters() *flag.FlagSet {
fs := mr.runtimeImpl.Parameters()
fs.IntVar(&mr.numComputeRuntimes, "num_compute_runtimes", mr.numComputeRuntimes, "number of compute runtimes per worker")
fs.IntVar(&mr.numComputeRuntimeTxns, "num_compute_runtime_txns", mr.numComputeRuntimeTxns, "number of transactions to perform")
fs.IntVar(&mr.numComputeWorkers, "num_compute_workers", mr.numComputeWorkers, "number of workers to initiate")
fs.IntVar(&mr.executorGroupSize, "executor_group_size", mr.executorGroupSize, "number of executor workers in committee")

return fs
}

func (mr *multipleRuntimesImpl) Fixture() (*oasis.NetworkFixture, error) {
f, err := mr.runtimeImpl.Fixture()
if err != nil {
Expand Down Expand Up @@ -96,7 +78,15 @@ func (mr *multipleRuntimesImpl) Fixture() (*oasis.NetworkFixture, error) {
f.Network.EpochtimeMock = true

// Add some more consecutive runtime IDs with the same binary.
for i := 1; i <= mr.numComputeRuntimes; i++ {
numComputeRuntimes, err := mr.flags.GetInt(cfgNumComputeRuntimes)
if err != nil {
return nil, err
}
executorGroupSize, err := mr.flags.GetInt(cfgExecutorGroupSize)
if err != nil {
return nil, err
}
for i := 1; i <= numComputeRuntimes; i++ {
// Increase LSB by 1.
id[len(id)-1]++

Expand All @@ -107,7 +97,7 @@ func (mr *multipleRuntimesImpl) Fixture() (*oasis.NetworkFixture, error) {
Keymanager: 0,
Binaries: []string{runtimeBinary},
Executor: registry.ExecutorParameters{
GroupSize: uint64(mr.executorGroupSize),
GroupSize: uint64(executorGroupSize),
GroupBackupSize: 0,
RoundTimeout: 10 * time.Second,
},
Expand Down Expand Up @@ -139,8 +129,12 @@ func (mr *multipleRuntimesImpl) Fixture() (*oasis.NetworkFixture, error) {
}

// Use numComputeWorkers compute worker fixtures.
numComputeWorkers, err := mr.flags.GetInt(cfgNumComputeWorkers)
if err != nil {
return nil, err
}
f.ComputeWorkers = []oasis.ComputeWorkerFixture{}
for i := 0; i < mr.numComputeWorkers; i++ {
for i := 0; i < numComputeWorkers; i++ {
f.ComputeWorkers = append(f.ComputeWorkers, oasis.ComputeWorkerFixture{Entity: 1})
}

Expand All @@ -161,10 +155,14 @@ func (mr *multipleRuntimesImpl) Run(childEnv *env.Env) error {

// Submit transactions.
epoch := epochtime.EpochTime(3)
numComputeRuntimeTxns, err := mr.flags.GetInt(cfgNumComputeRuntimeTxns)
if err != nil {
return err
}
for _, r := range mr.net.Runtimes() {
rt := r.ToRuntimeDescriptor()
if rt.Kind == registry.KindCompute {
for i := 0; i < mr.numComputeRuntimeTxns; i++ {
for i := 0; i < numComputeRuntimeTxns; i++ {
mr.logger.Info("submitting transaction to runtime",
"seq", i,
"runtime_id", rt.ID,
Expand Down
6 changes: 5 additions & 1 deletion go/oasis-test-runner/scenario/e2e/restore_previous.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (sc *restorePrevious) Fixture() (*oasis.NetworkFixture, error) {

func (sc *restorePrevious) Run(childEnv *env.Env) error {
// Restore tests use a fixed genesis that only works on non-TEE environments.
if sc.TEEHardware != "" {
teeStr, err := sc.flags.GetString(cfgTEEHardware)
if err != nil {
return err
}
if teeStr != "" {
sc.logger.Info("skipping test due to incompatible TEE hardware")
return nil
}
Expand Down
Loading

0 comments on commit cded8f0

Please sign in to comment.