sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package main |
| 21 | |
| 22 | import ( |
| 23 | "os" |
| 24 | "time" |
| 25 | "os/exec" |
| 26 | "strings" |
| 27 | "context" |
| 28 | "github.com/opencord/voltha-go/common/log" |
| 29 | ) |
| 30 | |
| 31 | var resFile *os.File |
| 32 | |
| 33 | func startSut(cmdStr string) (context.CancelFunc, error) { |
| 34 | 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 |
| 48 | return cncl, err |
| 49 | } |
| 50 | |
| 51 | func cleanUp(cncl context.CancelFunc) { |
| 52 | cncl() |
| 53 | // Give the child processes time to terminate |
| 54 | time.Sleep(1 * time.Second) |
| 55 | } |
| 56 | |
| 57 | func main() { |
| 58 | var err error |
| 59 | |
| 60 | // Setup logging |
| 61 | if _, err = log.SetDefaultLogger(log.JSON, 0, nil); err != nil { |
| 62 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 63 | } |
| 64 | |
| 65 | defer log.CleanUp() |
| 66 | |
| 67 | // Open the results file to write the results to |
| 68 | if resFile, err = os.OpenFile(os.Args[1], os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err != nil { |
| 69 | log.Errorf("Could not append to the results file") |
| 70 | } |
| 71 | |
| 72 | defer resFile.Close() |
| 73 | |
| 74 | // Initialize the servers |
| 75 | if err := serverInit(); err != nil { |
| 76 | log.Errorf("Error initializing server: %v", err) |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | // Start the sofware under test |
| 81 | cnclFunc, err := startSut("./{{.Command}}"); |
| 82 | defer cleanUp(cnclFunc) |
| 83 | if err != nil { |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | // Initialize the clients |
| 88 | if err := clientInit(); err != nil { |
| 89 | log.Errorf("Error initializing client: %v", err) |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | log.Infof("The servers are: %v",servers) |
| 94 | |
| 95 | // Run all the test cases now |
| 96 | log.Infof("Executing tests") |
| 97 | resFile.Write([]byte("Executing tests\n")) |
| 98 | runTests() |
| 99 | |
| 100 | } |