github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/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/ethereum/go-ethereum/cmd/devp2p/internal/v4test" 23 "github.com/ethereum/go-ethereum/internal/flags" 24 "github.com/ethereum/go-ethereum/internal/utesting" 25 "github.com/ethereum/go-ethereum/log" 26 "github.com/urfave/cli/v2" 27 ) 28 29 var ( 30 testPatternFlag = &cli.StringFlag{ 31 Name: "run", 32 Usage: "Pattern of test suite(s) to run", 33 Category: flags.TestingCategory, 34 } 35 testTAPFlag = &cli.BoolFlag{ 36 Name: "tap", 37 Usage: "Output test results in TAP format", 38 Category: flags.TestingCategory, 39 } 40 41 // for eth/snap tests 42 testChainDirFlag = &cli.StringFlag{ 43 Name: "chain", 44 Usage: "Test chain directory (required)", 45 Category: flags.TestingCategory, 46 } 47 testNodeFlag = &cli.StringFlag{ 48 Name: "node", 49 Usage: "Peer-to-Peer endpoint (ENR) of the test node (required)", 50 Category: flags.TestingCategory, 51 } 52 testNodeJWTFlag = &cli.StringFlag{ 53 Name: "jwtsecret", 54 Usage: "JWT secret for the engine API of the test node (required)", 55 Category: flags.TestingCategory, 56 Value: "0x7365637265747365637265747365637265747365637265747365637265747365", 57 } 58 testNodeEngineFlag = &cli.StringFlag{ 59 Name: "engineapi", 60 Usage: "Engine API endpoint of the test node (required)", 61 Category: flags.TestingCategory, 62 } 63 64 // These two are specific to the discovery tests. 65 testListen1Flag = &cli.StringFlag{ 66 Name: "listen1", 67 Usage: "IP address of the first tester", 68 Value: v4test.Listen1, 69 Category: flags.TestingCategory, 70 } 71 testListen2Flag = &cli.StringFlag{ 72 Name: "listen2", 73 Usage: "IP address of the second tester", 74 Value: v4test.Listen2, 75 Category: flags.TestingCategory, 76 } 77 ) 78 79 func runTests(ctx *cli.Context, tests []utesting.Test) error { 80 // Filter test cases. 81 if ctx.IsSet(testPatternFlag.Name) { 82 tests = utesting.MatchTests(tests, ctx.String(testPatternFlag.Name)) 83 } 84 // Disable logging unless explicitly enabled. 85 if !ctx.IsSet("verbosity") && !ctx.IsSet("vmodule") { 86 log.SetDefault(log.NewLogger(log.DiscardHandler())) 87 } 88 // Run the tests. 89 var run = utesting.RunTests 90 if ctx.Bool(testTAPFlag.Name) { 91 run = utesting.RunTAP 92 } 93 results := run(tests, os.Stdout) 94 if utesting.CountFailures(results) > 0 { 95 os.Exit(1) 96 } 97 return nil 98 }