github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/testing/config.go (about)

     1  // Copyright 2021 The ChromiumOS Authors
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package testing
     6  
     7  import (
     8  	"context"
     9  
    10  	"go.chromium.org/tast/core/dut"
    11  
    12  	"go.chromium.org/tast/core/framework/protocol"
    13  )
    14  
    15  // RuntimeConfig contains details about how an individual test should be run.
    16  type RuntimeConfig struct {
    17  	// DataDir is the directory in which the test's data files are located.
    18  	DataDir string
    19  	// OutDir is the directory to which the test will write output files.
    20  	OutDir string
    21  	// Vars contains names and values of out-of-band variables passed to tests at runtime.
    22  	// Names must be registered in Test.Vars and values may be accessed using State.Var.
    23  	Vars map[string]string
    24  	// Features contains hardware features for all DUTs used in the test.
    25  	Features map[string]*protocol.DUTFeatures
    26  	// CloudStorage is a client to read files on Google Cloud Storage.
    27  	CloudStorage *CloudStorage
    28  	// RemoteData contains information relevant to remote tests.
    29  	// This is nil for local tests.
    30  	RemoteData *RemoteData
    31  	// FixtValue is a value returned by a parent fixture.
    32  	// It is nil if not available.
    33  	FixtValue interface{}
    34  	// FixtSerializedValue is a serialized value returned by a parent fixture.
    35  	// It is nil if not available.
    36  	FixtSerializedValue func() ([]byte, error)
    37  	// FixtCtx is the context that lives as long as the fixture.
    38  	// It can be accessed only from testing.FixtState.
    39  	FixtCtx context.Context
    40  	// PreCtx is the context that lives as long as the precondition.
    41  	// It can be accessed only from testing.PreState.
    42  	PreCtx context.Context
    43  	// Purgeable is a list of file paths which are not used for now and thus
    44  	// can be deleted if the disk space is low.
    45  	Purgeable []string
    46  	//MaxSysMsgLogSize is a size of flag for truncate log file.
    47  	MaxSysMsgLogSize int64
    48  }
    49  
    50  // RemoteData contains information relevant to remote entities.
    51  type RemoteData struct {
    52  	// Meta contains information about how the tast process was run.
    53  	Meta *Meta
    54  	// RPCHint contains information needed to establish gRPC connections.
    55  	RPCHint *RPCHint
    56  	// DUT is an SSH connection shared among remote entities.
    57  	DUT *dut.DUT
    58  	// CompanionDUTs are other DUTs that can be used in remote test.
    59  	CompanionDUTs map[string]*dut.DUT
    60  }
    61  
    62  // Meta contains information about how the "tast" process used to initiate testing was run.
    63  // It is used by remote tests in the "meta" category that run the tast executable to test Tast's behavior.
    64  type Meta struct {
    65  	// TastPath contains the absolute path to the tast executable.
    66  	TastPath string
    67  	// Target contains information about the DUT as "[<user>@]host[:<port>]".
    68  	// DEPRECATED: Use ConnectionSpec instead.
    69  	Target string
    70  	// Flags contains flags that should be passed to the tast command's "run" subcommands.
    71  	RunFlags []string
    72  	// Flags contains flags that should be passed to the tast command's "list" subcommands.
    73  	ListFlags []string
    74  	// ConnectionSpec contains information about the DUT as "[<user>@]host[:<port>]".
    75  	ConnectionSpec string
    76  }
    77  
    78  // clone returns a deep copy of m.
    79  func (m *Meta) clone() *Meta {
    80  	mc := *m
    81  	mc.RunFlags = append([]string{}, m.RunFlags...)
    82  	mc.ListFlags = append([]string{}, m.ListFlags...)
    83  	return &mc
    84  }
    85  
    86  // RPCHint contains information needed to establish gRPC connections.
    87  type RPCHint struct {
    88  	// localBundleDir is the directory on the DUT where local test bundle executables are located.
    89  	// This path is used by remote entities to invoke gRPC services in local test bundles.
    90  	localBundleDir string
    91  	// testVars holds all test variables and will pass to local bundle services.
    92  	testVars map[string]string
    93  }
    94  
    95  // NewRPCHint create a new RPCHint struct.
    96  func NewRPCHint(localBundleDir string, testVars map[string]string) *RPCHint {
    97  	return &RPCHint{
    98  		localBundleDir: localBundleDir,
    99  		testVars:       testVars,
   100  	}
   101  }
   102  
   103  // clone returns a deep copy of h.
   104  func (h *RPCHint) clone() *RPCHint {
   105  	hc := *h
   106  	return &hc
   107  }
   108  
   109  // ExtractLocalBundleDir extracts localBundleDir from RPCHint.
   110  func ExtractLocalBundleDir(h *RPCHint) string {
   111  	return h.localBundleDir
   112  }
   113  
   114  // ExtractTestVars extracts test vars from RPCHint.
   115  func ExtractTestVars(h *RPCHint) map[string]string {
   116  	return h.testVars
   117  }