github.com/ethxdao/go-ethereum@v0.0.0-20221218102228-5ae34a9cc189/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/ethxdao/go-ethereum/cmd/devp2p/internal/v4test" 23 "github.com/ethxdao/go-ethereum/internal/utesting" 24 "github.com/ethxdao/go-ethereum/log" 25 ) 26 27 var ( 28 testPatternFlag = &cli.StringFlag{ 29 Name: "run", 30 Usage: "Pattern of test suite(s) to run", 31 } 32 testTAPFlag = &cli.BoolFlag{ 33 Name: "tap", 34 Usage: "Output TAP", 35 } 36 // These two are specific to the discovery tests. 37 testListen1Flag = &cli.StringFlag{ 38 Name: "listen1", 39 Usage: "IP address of the first tester", 40 Value: v4test.Listen1, 41 } 42 testListen2Flag = &cli.StringFlag{ 43 Name: "listen2", 44 Usage: "IP address of the second tester", 45 Value: v4test.Listen2, 46 } 47 ) 48 49 func runTests(ctx *cli.Context, tests []utesting.Test) error { 50 // Filter test cases. 51 if ctx.IsSet(testPatternFlag.Name) { 52 tests = utesting.MatchTests(tests, ctx.String(testPatternFlag.Name)) 53 } 54 // Disable logging unless explicitly enabled. 55 if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") { 56 log.Root().SetHandler(log.DiscardHandler()) 57 } 58 // Run the tests. 59 var run = utesting.RunTests 60 if ctx.Bool(testTAPFlag.Name) { 61 run = utesting.RunTAP 62 } 63 results := run(tests, os.Stdout) 64 if utesting.CountFailures(results) > 0 { 65 os.Exit(1) 66 } 67 return nil 68 }