github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/kvledger/benchmark/experiments/init_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package experiments
     8  
     9  import (
    10  	"flag"
    11  	"fmt"
    12  	"os"
    13  	"regexp"
    14  	"testing"
    15  
    16  	"github.com/hyperledger/fabric/common/flogging"
    17  )
    18  
    19  const chaincodeName = "testChaincode"
    20  
    21  var conf *configuration
    22  
    23  // TestMain loads the yaml file and parses the test parameters
    24  // the configration constructed from test parameters is stored in
    25  // package level variable and is accessible to an expriment
    26  // The test params should be passed in the following format in the golang benchmark test command
    27  // "-testParams=-DataDir="myDir", -NumChains=10, ..."
    28  // This is necessary to parse in the TestMain function because otherwise, the golang test framework
    29  // parses this and does not recognized this flag (-testParams)
    30  func TestMain(m *testing.M) {
    31  	testParams := parseTestParams()
    32  	conf = confFromTestParams(testParams)
    33  	flogging.ActivateSpec("ledgermgmt,fsblkstorage,common.tools.configtxgen.localconfig,kvledger,statebasedval=error")
    34  	os.Exit(m.Run())
    35  }
    36  
    37  func parseTestParams() []string {
    38  	testParams := flag.String("testParams", "", "Test specific parameters")
    39  	flag.Parse()
    40  	regex, err := regexp.Compile(",(\\s+)?")
    41  	if err != nil {
    42  		panic(fmt.Errorf("Error: %s", err))
    43  	}
    44  	paramsArray := regex.Split(*testParams, -1)
    45  	return paramsArray
    46  }