func init() { glog.SetV(0) if os.Getenv("JITVM") == "true" { ForceJit = true EnableJit = true } }
func (self *adminApi) Verbosity(req *shared.Request) (interface{}, error) { args := new(VerbosityArgs) if err := self.coder.Decode(req.Params, &args); err != nil { return nil, shared.NewDecodeParamError(err.Error()) } glog.SetV(args.Level) return true, nil }
func (js *jsre) verbosity(call otto.FunctionCall) otto.Value { v, err := call.Argument(0).ToInteger() if err != nil { fmt.Println(err) return otto.UndefinedValue() } glog.SetV(int(v)) return otto.UndefinedValue() }
func run(ctx *cli.Context) { vm.Debug = ctx.GlobalBool(DebugFlag.Name) vm.ForceJit = ctx.GlobalBool(ForceJitFlag.Name) vm.EnableJit = !ctx.GlobalBool(DisableJitFlag.Name) glog.SetToStderr(true) glog.SetV(ctx.GlobalInt(VerbosityFlag.Name)) db, _ := ethdb.NewMemDatabase() statedb, _ := state.New(common.Hash{}, db) sender := statedb.CreateAccount(common.StringToAddress("sender")) receiver := statedb.CreateAccount(common.StringToAddress("receiver")) receiver.SetCode(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name))) vmenv := NewEnv(statedb, common.StringToAddress("evmuser"), common.Big(ctx.GlobalString(ValueFlag.Name))) tstart := time.Now() ret, e := vmenv.Call( sender, receiver.Address(), common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), common.Big(ctx.GlobalString(GasFlag.Name)), common.Big(ctx.GlobalString(PriceFlag.Name)), common.Big(ctx.GlobalString(ValueFlag.Name)), ) vmdone := time.Since(tstart) if ctx.GlobalBool(DumpFlag.Name) { fmt.Println(string(statedb.Dump())) } vm.StdErrFormat(vmenv.StructLogs()) if ctx.GlobalBool(SysStatFlag.Name) { var mem runtime.MemStats runtime.ReadMemStats(&mem) fmt.Printf("vm took %v\n", vmdone) fmt.Printf(`alloc: %d tot alloc: %d no. malloc: %d heap alloc: %d heap objs: %d num gc: %d `, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC) } fmt.Printf("OUT: 0x%x", ret) if e != nil { fmt.Printf(" error: %v", e) } fmt.Println() }
func main() { flag.Parse() // Enable logging errors, we really do want to see those glog.SetV(2) glog.SetToStderr(true) // Load the test suite to run the RPC against tests, err := tests.LoadBlockTests(*testFile) if err != nil { log.Fatalf("Failed to load test suite: %v", err) } test, found := tests[*testName] if !found { log.Fatalf("Requested test (%s) not found within suite", *testName) } // Create the protocol stack to run the test with keydir, err := ioutil.TempDir("", "") if err != nil { log.Fatalf("Failed to create temporary keystore directory: %v", err) } defer os.RemoveAll(keydir) stack, err := MakeSystemNode(keydir, *testKey, test) if err != nil { log.Fatalf("Failed to assemble test stack: %v", err) } if err := stack.Start(); err != nil { log.Fatalf("Failed to start test node: %v", err) } defer stack.Stop() log.Println("Test node started...") // Make sure the tests contained within the suite pass if err := RunTest(stack, test); err != nil { log.Fatalf("Failed to run the pre-configured test: %v", err) } log.Println("Initial test suite passed...") quit := make(chan os.Signal, 1) signal.Notify(quit, os.Interrupt) <-quit }
func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config { // Set verbosity on glog glog.SetV(ctx.GlobalInt(VerbosityFlag.Name)) // Set the log type //glog.SetToStderr(ctx.GlobalBool(LogToStdErrFlag.Name)) glog.SetToStderr(true) // Set the log dir glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name)) customName := ctx.GlobalString(IdentityFlag.Name) if len(customName) > 0 { clientID += "/" + customName } return ð.Config{ Name: common.MakeName(clientID, version), DataDir: ctx.GlobalString(DataDirFlag.Name), ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name), BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), SkipBcVersionCheck: false, NetworkId: ctx.GlobalInt(NetworkIdFlag.Name), LogFile: ctx.GlobalString(LogFileFlag.Name), Verbosity: ctx.GlobalInt(VerbosityFlag.Name), LogJSON: ctx.GlobalString(LogJSONFlag.Name), Etherbase: ctx.GlobalString(EtherbaseFlag.Name), MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name), AccountManager: GetAccountManager(ctx), VmDebug: ctx.GlobalBool(VMDebugFlag.Name), MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name), MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name), Port: ctx.GlobalString(ListenPortFlag.Name), NAT: GetNAT(ctx), NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name), NodeKey: GetNodeKey(ctx), Shh: ctx.GlobalBool(WhisperEnabledFlag.Name), Dial: true, BootNodes: ctx.GlobalString(BootnodesFlag.Name), GasPrice: common.String2Big(ctx.GlobalString(GasPriceFlag.Name)), } }
// SetupLogger configures glog from the logging-related command line flags. func SetupLogger(ctx *cli.Context) { glog.SetV(ctx.GlobalInt(VerbosityFlag.Name)) glog.CopyStandardLogTo("INFO") glog.SetToStderr(true) glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name)) }
// Verbosity sets the glog verbosity floor. // The verbosity of individual packages and source files // can be raised using Vmodule. func (*HandlerT) Verbosity(level int) { glog.SetV(level) }
func RunVmTest(r io.Reader) (failed int) { tests := make(map[string]VmTest) data, _ := ioutil.ReadAll(r) err := json.Unmarshal(data, &tests) if err != nil { log.Fatalln(err) } vm.Debug = true glog.SetV(4) glog.SetToStderr(true) for name, test := range tests { db, _ := ethdb.NewMemDatabase() statedb := state.New(common.Hash{}, db) for addr, account := range test.Pre { obj := StateObjectFromAccount(db, addr, account) statedb.SetStateObject(obj) } env := make(map[string]string) env["currentCoinbase"] = test.Env.CurrentCoinbase env["currentDifficulty"] = test.Env.CurrentDifficulty env["currentGasLimit"] = test.Env.CurrentGasLimit env["currentNumber"] = test.Env.CurrentNumber env["previousHash"] = test.Env.PreviousHash if n, ok := test.Env.CurrentTimestamp.(float64); ok { env["currentTimestamp"] = strconv.Itoa(int(n)) } else { env["currentTimestamp"] = test.Env.CurrentTimestamp.(string) } ret, logs, _, _ := helper.RunState(statedb, env, test.Transaction) statedb.Sync() rexp := helper.FromHex(test.Out) if bytes.Compare(rexp, ret) != 0 { glog.V(logger.Info).Infof("%s's return failed. Expected %x, got %x\n", name, rexp, ret) failed = 1 } for addr, account := range test.Post { obj := statedb.GetStateObject(common.HexToAddress(addr)) if obj == nil { continue } if len(test.Exec) == 0 { if obj.Balance().Cmp(common.Big(account.Balance)) != 0 { glog.V(logger.Info).Infof("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address().Bytes()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance())) failed = 1 } } for addr, value := range account.Storage { v := obj.GetState(common.HexToHash(addr)).Bytes() vexp := helper.FromHex(value) if bytes.Compare(v, vexp) != 0 { glog.V(logger.Info).Infof("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address().Bytes()[0:4], addr, vexp, v, common.BigD(vexp), common.BigD(v)) failed = 1 } } } statedb.Sync() //if !bytes.Equal(common.Hex2Bytes(test.PostStateRoot), statedb.Root()) { if common.HexToHash(test.PostStateRoot) != statedb.Root() { glog.V(logger.Info).Infof("%s's : Post state root failed. Expected %s, got %x", name, test.PostStateRoot, statedb.Root()) failed = 1 } if len(test.Logs) > 0 { if len(test.Logs) != len(logs) { glog.V(logger.Info).Infof("log length failed. Expected %d, got %d", len(test.Logs), len(logs)) failed = 1 } else { for i, log := range test.Logs { if common.HexToAddress(log.AddressF) != logs[i].Address { glog.V(logger.Info).Infof("'%s' log address failed. Expected %v got %x", name, log.AddressF, logs[i].Address) failed = 1 } if !bytes.Equal(logs[i].Data, helper.FromHex(log.DataF)) { glog.V(logger.Info).Infof("'%s' log data failed. Expected %v got %x", name, log.DataF, logs[i].Data) failed = 1 } if len(log.TopicsF) != len(logs[i].Topics) { glog.V(logger.Info).Infof("'%s' log topics length failed. Expected %d got %d", name, len(log.TopicsF), logs[i].Topics) failed = 1 } else { for j, topic := range log.TopicsF { if common.HexToHash(topic) != logs[i].Topics[j] { glog.V(logger.Info).Infof("'%s' log topic[%d] failed. Expected %v got %x", name, j, topic, logs[i].Topics[j]) failed = 1 } } } genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256) if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) { glog.V(logger.Info).Infof("'%s' bloom failed.", name) failed = 1 } } } } if failed == 1 { glog.V(logger.Info).Infoln(string(statedb.Dump())) } logger.Flush() } return }