blob: 9ad835620175dc4ba49c810c4f64aca9b1cd9ac9 [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 "fmt"
26 "os/exec"
27 "io/ioutil"
Scott Bakerec6e61b2019-10-23 10:21:27 -070028 "github.com/opencord/voltha-lib-go/pkg/log"
sslobodrd6e07e72019-01-31 16:07:20 -050029)
30
sslobodrd9daabf2019-02-05 13:14:21 -050031
sslobodrd6e07e72019-01-31 16:07:20 -050032func 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
sslobodr1d1e50b2019-03-14 09:17:40 -040042 statFn = "stats.json"
43
sslobodrd6e07e72019-01-31 16:07:20 -050044 log.Info("Running tests")
sslobodrd6e07e72019-01-31 16:07:20 -050045 if err:= os.Chdir(os.Args[1]); err != nil {
46 log.Error("Could not change directory to %s: %v", os.Args[1], err)
47 }
sslobodr1d1e50b2019-03-14 09:17:40 -040048
49 if err := initStats(statFn); err != nil {
50 log.Error(err)
51 return
52 }
53
sslobodrd9daabf2019-02-05 13:14:21 -050054 {{range .}}
sslobodr13182842019-02-08 14:40:30 -050055 cmdStr = "./"+"{{.}}"+".e"
sslobodrd9daabf2019-02-05 13:14:21 -050056
57 log.Infof("Running test suite %s",cmdStr)
sslobodr1d1e50b2019-03-14 09:17:40 -040058 cmd = exec.Command(cmdStr, statFn)
sslobodrd6e07e72019-01-31 16:07:20 -050059 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.
sslobodr1d1e50b2019-03-14 09:17:40 -040067 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 {
sslobodrd6e07e72019-01-31 16:07:20 -050076 fmt.Println(string(resFile))
77 } else {
sslobodr1d1e50b2019-03-14 09:17:40 -040078 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)
sslobodrd6e07e72019-01-31 16:07:20 -050097 }
98 log.Info("Tests complete")
99}