runtest.go 1.9 KB

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