func (ts *TestSystem) runtest(timeoutms int) { lspnet.SetWriteDropPercent(ts.DropPercent) if ts.Description != "" { fmt.Printf("Testing: %s\n", ts.Description) } go ts.runserver() for i := 0; i < ts.NClients; i++ { go ts.runclient(i) } go ts.runtimeout(timeoutms) for i := 0; i < ts.NClients; i++ { v := <-ts.CChan if v < 0 { ts.RunFlag = false ts.Tester.Logf("Test timed out after %f secs\n", float64(timeoutms)/1000.0) ts.Tester.FailNow() } } ts.RunFlag = false lsplog.Vlogf(0, "Passed: %d clients, %d messages/client, %.2f maxsleep, %.2f drop rate\n", ts.NClients, ts.NMessages, float64(ts.MaxSleepMilliseconds)/1000.0, float64(ts.DropPercent)/100.0) lsplog.SetVerbose(DefaultVerbosity) lspnet.SetWriteDropPercent(0) }
func main() { var ihelp *bool = flag.Bool("h", false, "Print help information") var iport *int = flag.Int("p", 6666, "Port number") var iverb *int = flag.Int("v", 1, "Verbosity (0-6)") var idrop *int = flag.Int("r", 0, "Network packet drop percentage") var elim *int = flag.Int("k", 5, "Epoch limit") var ems *int = flag.Int("d", 2000, "Epoch duration (millisecconds)") flag.Parse() if *ihelp { flag.Usage() os.Exit(0) } var port int = *iport if flag.NArg() > 0 { nread, _ := fmt.Sscanf(flag.Arg(0), "%d", &port) if nread != 1 { flag.Usage() os.Exit(0) } } params := &lsp12.LspParams{*elim, *ems} lsplog.SetVerbose(*iverb) lspnet.SetWriteDropPercent(*idrop) fmt.Printf("Establishing server on port %d\n", port) srv, err := lsp12.NewLspServer(port, params) if err != nil { fmt.Printf("... failed. Error message %s\n", err.Error()) } else { runserver(srv) } }
// Turn network off and on func (ts *SynchTestSystem) RunNetwork() { // Network initially on lspnet.SetWriteDropPercent(0) for ts.RunFlag { lsplog.Vlogf(4, "Network running. Waiting for master\n") <-ts.M2NChan lsplog.Vlogf(4, "Turning off network\n") lspnet.SetWriteDropPercent(100) ts.N2MChan <- true lsplog.Vlogf(4, "Network off. Waiting for master\n") <-ts.M2NChan lsplog.Vlogf(4, "Turning network on and delaying\n") lspnet.SetWriteDropPercent(0) ts.N2MChan <- true ts.synchdelay(2.0) } lsplog.Vlogf(4, "Network handler exiting\n") }
func main() { var ihelp *bool = flag.Bool("h", false, "Show help information") var iport *int = flag.Int("p", 6666, "Port number") var ihost *string = flag.String("H", "localhost", "Host address") var iverb *int = flag.Int("v", 1, "Verbosity (0-6)") var irdrop *int = flag.Int("r", 0, "Network read packet drop percentage") var iwdrop *int = flag.Int("w", 0, "Network write packet drop percentage") var elim *int = flag.Int("k", 5, "Epoch limit") var ems *int = flag.Int("d", 2000, "Epoch duration (millisecconds)") flag.Parse() if *ihelp { flag.Usage() os.Exit(0) } if flag.NArg() > 0 { // Look for host:port on command line ok := true fields := strings.Split(flag.Arg(0), ":") ok = ok && len(fields) == 2 if ok { *ihost = fields[0] n, err := fmt.Sscanf(fields[1], "%d", iport) ok = ok && n == 1 && err == nil } if !ok { flag.Usage() os.Exit(0) } } params := &lsp12.LspParams{*elim, *ems} lsplog.SetVerbose(*iverb) lspnet.SetReadDropPercent(*irdrop) lspnet.SetWriteDropPercent(*iwdrop) hostport := fmt.Sprintf("%s:%v", *ihost, *iport) fmt.Printf("Connecting to server at %s\n", hostport) cli, err := lsp12.NewLspClient(hostport, params) if err != nil { fmt.Printf("... failed. Error message %s\n", err.Error()) } if lsplog.CheckReport(1, err) { return } runclient(cli) }
// Test components func NewSynchTestSystem(t *testing.T, nclients int, nmessages int, mode int, maxepochs int, params *LspParams) { fmt.Printf("Testing: Mode %s, %d clients\n", SynchModeName[mode], nclients) ts := new(SynchTestSystem) ts.Mode = mode ts.Params = params ts.C2MChan = make(chan bool) ts.S2MChan = make(chan bool) ts.N2MChan = make(chan bool) ts.TChan = make(chan int) ts.M2CChan = make(chan bool) ts.M2SChan = make(chan bool) ts.M2NChan = make(chan bool) ts.Nclients = nclients ts.Nmessages = nmessages ts.Clients = make([]*LspClient, nclients) ts.ClientMap = make(map[uint16]int, nclients) ts.Data = make([][]int, nclients) ts.Rgen = *rand.New(rand.NewSource(time.Now().Unix())) for i := 0; i < nclients; i++ { ts.Data[i] = genData(nmessages, ts.Rgen) } ts.Nclients = nclients ts.Port = synchrandport(ts.Rgen) ts.RunFlag = true ts.Tester = t go ts.RunNetwork() go ts.RunServer() // Set up clients for i := 0; i < nclients; i++ { go ts.RunClient(i) } go ts.RunTimeout(float64(maxepochs)) ts.Master() ts.RunFlag = false lsplog.SetVerbose(SynchDefaultVerbosity) lspnet.SetWriteDropPercent(0) }