github.com/core-coin/go-core/v2@v2.1.9/cmd/devp2p/runtest.go (about) 1 // Copyright 2020 by the Authors 2 // This file is part of go-core. 3 // 4 // go-core 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-core 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-core. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "os" 21 22 "gopkg.in/urfave/cli.v1" 23 24 "github.com/core-coin/go-core/v2/cmd/devp2p/internal/v4test" 25 "github.com/core-coin/go-core/v2/internal/utesting" 26 "github.com/core-coin/go-core/v2/log" 27 ) 28 29 var ( 30 testPatternFlag = cli.StringFlag{ 31 Name: "run", 32 Usage: "Pattern of test suite(s) to run", 33 } 34 testTAPFlag = cli.BoolFlag{ 35 Name: "tap", 36 Usage: "Output TAP", 37 } 38 // These two are specific to the discovery tests. 39 testListen1Flag = cli.StringFlag{ 40 Name: "listen1", 41 Usage: "IP address of the first tester", 42 Value: v4test.Listen1, 43 } 44 testListen2Flag = cli.StringFlag{ 45 Name: "listen2", 46 Usage: "IP address of the second tester", 47 Value: v4test.Listen2, 48 } 49 ) 50 51 func runTests(ctx *cli.Context, tests []utesting.Test) error { 52 // Filter test cases. 53 if ctx.IsSet(testPatternFlag.Name) { 54 tests = utesting.MatchTests(tests, ctx.String(testPatternFlag.Name)) 55 } 56 // Disable logging unless explicitly enabled. 57 if !ctx.GlobalIsSet("verbosity") && !ctx.GlobalIsSet("vmodule") { 58 log.Root().SetHandler(log.DiscardHandler()) 59 } 60 // Run the tests. 61 var run = utesting.RunTests 62 if ctx.Bool(testTAPFlag.Name) { 63 run = utesting.RunTAP 64 } 65 results := run(tests, os.Stdout) 66 if utesting.CountFailures(results) > 0 { 67 os.Exit(1) 68 } 69 return nil 70 }