...

Source file src/internal/trace/testdata/cmd/gotracevalidate/main.go

Documentation: internal/trace/testdata/cmd/gotracevalidate

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"flag"
     9  	"fmt"
    10  	"io"
    11  	"log"
    12  	"os"
    13  
    14  	"internal/trace"
    15  	"internal/trace/testtrace"
    16  )
    17  
    18  func init() {
    19  	flag.Usage = func() {
    20  		fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s\n", os.Args[0])
    21  		fmt.Fprintf(flag.CommandLine.Output(), "\n")
    22  		fmt.Fprintf(flag.CommandLine.Output(), "Accepts a trace at stdin and validates it.\n")
    23  		flag.PrintDefaults()
    24  	}
    25  	log.SetFlags(0)
    26  }
    27  
    28  var logEvents = flag.Bool("log-events", false, "whether to log events")
    29  
    30  func main() {
    31  	flag.Parse()
    32  
    33  	r, err := trace.NewReader(os.Stdin)
    34  	if err != nil {
    35  		log.Fatal(err)
    36  	}
    37  	v := testtrace.NewValidator()
    38  	for {
    39  		ev, err := r.ReadEvent()
    40  		if err == io.EOF {
    41  			break
    42  		}
    43  		if err != nil {
    44  			log.Fatal(err)
    45  		}
    46  		if *logEvents {
    47  			log.Println(ev.String())
    48  		}
    49  		if err := v.Event(ev); err != nil {
    50  			log.Fatal(err)
    51  		}
    52  	}
    53  }
    54  

View as plain text