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 | "fmt" |
| 26 | "os/exec" |
| 27 | "io/ioutil" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 29 | ) |
| 30 | |
sslobodr | d9daabf | 2019-02-05 13:14:21 -0500 | [diff] [blame] | 31 | |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 32 | func main() { |
| 33 | var cmd *exec.Cmd |
| 34 | var cmdStr string |
| 35 | // Setup logging |
| 36 | if _, err := log.SetDefaultLogger(log.JSON, 0, nil); err != nil { |
| 37 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 38 | } |
| 39 | |
| 40 | defer log.CleanUp() |
| 41 | |
sslobodr | 1d1e50b | 2019-03-14 09:17:40 -0400 | [diff] [blame] | 42 | statFn = "stats.json" |
| 43 | |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 44 | log.Info("Running tests") |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 45 | if err:= os.Chdir(os.Args[1]); err != nil { |
| 46 | log.Error("Could not change directory to %s: %v", os.Args[1], err) |
| 47 | } |
sslobodr | 1d1e50b | 2019-03-14 09:17:40 -0400 | [diff] [blame] | 48 | |
| 49 | if err := initStats(statFn); err != nil { |
| 50 | log.Error(err) |
| 51 | return |
| 52 | } |
| 53 | |
sslobodr | d9daabf | 2019-02-05 13:14:21 -0500 | [diff] [blame] | 54 | {{range .}} |
sslobodr | 1318284 | 2019-02-08 14:40:30 -0500 | [diff] [blame] | 55 | cmdStr = "./"+"{{.}}"+".e" |
sslobodr | d9daabf | 2019-02-05 13:14:21 -0500 | [diff] [blame] | 56 | |
| 57 | log.Infof("Running test suite %s",cmdStr) |
sslobodr | 1d1e50b | 2019-03-14 09:17:40 -0400 | [diff] [blame] | 58 | cmd = exec.Command(cmdStr, statFn) |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 59 | cmd.Stdin = os.Stdin |
| 60 | cmd.Stdout = os.Stdout |
| 61 | cmd.Stderr = os.Stderr |
| 62 | if err := cmd.Run(); err != nil { |
| 63 | log.Errorf("Test '%s' failed", cmdStr) |
| 64 | } |
| 65 | {{end}} |
| 66 | // Open the results file and output it. |
sslobodr | 1d1e50b | 2019-03-14 09:17:40 -0400 | [diff] [blame] | 67 | if s,err := readStats(statFn); err != nil { |
| 68 | log.Error(err) |
| 69 | return |
| 70 | } else { |
| 71 | stats = s |
| 72 | } |
| 73 | |
| 74 | //log.Infof("Stats are: %v", stats) |
| 75 | if resFile, err := ioutil.ReadFile(statFn); err == nil { |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 76 | fmt.Println(string(resFile)) |
| 77 | } else { |
sslobodr | 1d1e50b | 2019-03-14 09:17:40 -0400 | [diff] [blame] | 78 | log.Error("Could not load the stats file 'stats.json'") |
| 79 | } |
| 80 | fmt.Println("Test result summary") |
| 81 | for _,v := range stats.TestSuites { |
| 82 | fmt.Printf("Test suite: %s\n", v.Name[2:len(v.Name)-2]) |
| 83 | pass := 0 |
| 84 | fail := 0 |
| 85 | total := 0 |
| 86 | for _,v1 := range v.TestCases { |
| 87 | total++ |
| 88 | if v1.Result == true { |
| 89 | pass++ |
| 90 | } else { |
| 91 | fail++ |
| 92 | } |
| 93 | } |
| 94 | fmt.Printf("\tTotal test cases: %d\n", total) |
| 95 | fmt.Printf("\t\tTotal passed test cases: %d\n", pass) |
| 96 | fmt.Printf("\t\tTotal failed test cases: %d\n", fail) |
sslobodr | d6e07e7 | 2019-01-31 16:07:20 -0500 | [diff] [blame] | 97 | } |
| 98 | log.Info("Tests complete") |
| 99 | } |