github.com/phillinzzz/newBsc@v1.1.6/cmd/devp2p/runtest.go (about) 1 // Copyright 2020 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "os" 21 22 "github.com/phillinzzz/newBsc/cmd/devp2p/internal/v4test" 23 "github.com/phillinzzz/newBsc/internal/utesting" 24 "github.com/phillinzzz/newBsc/log" 25 "gopkg.in/urfave/cli.v1" 26 ) 27 28 var ( 29 testPatternFlag = cli.StringFlag{ 30 Name: "run", 31 Usage: "Pattern of test suite(s) to run", 32 } 33 testTAPFlag = cli.BoolFlag{ 34 Name: "tap", 35 Usage: "Output TAP", 36 } 37 // These two are specific to the discovery tests. 38 testListen1Flag = cli.StringFlag{ 39 Name: "listen1", 40 Usage: "IP address of the first tester", 41 Value: v4test.Listen1, 42 } 43 testListen2Flag = cli.StringFlag{ 44 Name: "listen2", 45 Usage: "IP address of the second tester", 46 Value: v4test.Listen2, 47 } 48 ) 49 50 func runTests(ctx *cli.Context, tests []utesting.Test) error { 51 // Filter test cases. 52 if ctx.IsSet(testPatternFlag.Name) { 53 tests = utesting.MatchTests(tests, ctx.String(testPatternFlag.Name)) 54 } 55 // Disable logging unless explicitly enabled. 56 if !ctx.GlobalIsSet("verbosity") && !ctx.GlobalIsSet("vmodule") { 57 log.Root().SetHandler(log.DiscardHandler()) 58 } 59 // Run the tests. 60 var run = utesting.RunTests 61 if ctx.Bool(testTAPFlag.Name) { 62 run = utesting.RunTAP 63 } 64 results := run(tests, os.Stdout) 65 if utesting.CountFailures(results) > 0 { 66 os.Exit(1) 67 } 68 return nil 69 }