blob: f1bb3edaf18c329549251789248980775e4a293c [file] [log] [blame]
sslobodrd6e07e72019-01-31 16:07:20 -05001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16// The template for the tester.
17// This template is filled in by the
18// test driver based on the configuration.
19
20package main
21
22import (
23 "os"
24 "time"
25 "os/exec"
26 "strings"
27 "context"
sslobodr1d1e50b2019-03-14 09:17:40 -040028 //slog "log"
29 //"google.golang.org/grpc/grpclog"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080030 "github.com/opencord/voltha-lib-go/v3/pkg/log"
sslobodrd6e07e72019-01-31 16:07:20 -050031)
32
sslobodrd9daabf2019-02-05 13:14:21 -050033func startSut(cmdStr string) (*exec.Cmd, context.CancelFunc, error) {
sslobodrd6e07e72019-01-31 16:07:20 -050034 var err error = nil
35
36 cmdAry := strings.Fields(cmdStr)
37 log.Infof("Running the affinity router: %s",cmdStr)
38 //ctx, cncl := context.WithCancel(context.Background())
39 ctx, cncl := context.WithCancel(context.Background())
40 cmd := exec.CommandContext(ctx, cmdAry[0], cmdAry[1:]...)
41 cmd.Stdin = os.Stdin
42 cmd.Stdout = os.Stdout
43 cmd.Stderr = os.Stderr
44 if err = cmd.Start(); err != nil {
45 log.Errorf("Failed to run the affinity router: %s %v", cmdStr,err)
46 }
47 time.Sleep(1 * time.Second) // Give the command time to get started
sslobodrd9daabf2019-02-05 13:14:21 -050048 return cmd, cncl, err
sslobodrd6e07e72019-01-31 16:07:20 -050049}
50
sslobodrd9daabf2019-02-05 13:14:21 -050051func cleanUp(cmd *exec.Cmd, cncl context.CancelFunc) {
sslobodrd6e07e72019-01-31 16:07:20 -050052 cncl()
sslobodr1d1e50b2019-03-14 09:17:40 -040053 cmd.Wait()
sslobodrd6e07e72019-01-31 16:07:20 -050054}
55
56func main() {
57 var err error
58
59 // Setup logging
sslobodr1d1e50b2019-03-14 09:17:40 -040060 if _, err = log.SetDefaultLogger(log.JSON, 1, nil); err != nil {
sslobodrd6e07e72019-01-31 16:07:20 -050061 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
62 }
sslobodrd6e07e72019-01-31 16:07:20 -050063 defer log.CleanUp()
64
sslobodr1d1e50b2019-03-14 09:17:40 -040065 if len(os.Args) < 2 {
66 log.Fatalf("Stat file name parameter missing for %s. Aborting...", os.Args[0])
67 } else {
68 statFn = os.Args[1]
69 }
sslobodr13182842019-02-08 14:40:30 -050070
sslobodr1d1e50b2019-03-14 09:17:40 -040071 if stats,err = readStats(statFn); err != nil {
72 log.Error(err)
73 return
74 }
75 defer writeStats(statFn, stats)
sslobodr13182842019-02-08 14:40:30 -050076
sslobodr1d1e50b2019-03-14 09:17:40 -040077 // Add a stat entry for this run
sslobodr13182842019-02-08 14:40:30 -050078
sslobodr1d1e50b2019-03-14 09:17:40 -040079 stats.appendNew()
80 tsIdx := len(stats.TestSuites) - 1
81 stats.TestSuites[tsIdx].Name = os.Args[0]
sslobodrd6e07e72019-01-31 16:07:20 -050082
sslobodrd6e07e72019-01-31 16:07:20 -050083
84 // Initialize the servers
85 if err := serverInit(); err != nil {
86 log.Errorf("Error initializing server: %v", err)
87 return
88 }
89
90 // Start the sofware under test
sslobodrd9daabf2019-02-05 13:14:21 -050091 cmd, cnclFunc, err := startSut("./{{.Command}}");
92 defer cleanUp(cmd, cnclFunc)
sslobodrd6e07e72019-01-31 16:07:20 -050093 if err != nil {
94 return
95 }
96
97 // Initialize the clients
98 if err := clientInit(); err != nil {
99 log.Errorf("Error initializing client: %v", err)
100 return
101 }
102
103 log.Infof("The servers are: %v",servers)
104
105 // Run all the test cases now
106 log.Infof("Executing tests")
sslobodr1d1e50b2019-03-14 09:17:40 -0400107
108 //log.Infof("Stats struct: %v", stats)
sslobodrd6e07e72019-01-31 16:07:20 -0500109 runTests()
sslobodrd6e07e72019-01-31 16:07:20 -0500110
111}