Changes to the test framework to support templating of
the json test files to enable the creation of very large
stress test suites. Still a work in progress.

Change-Id: I1a35e4143a2feb577c9ad6048a0339c7b9dc0f89
diff --git a/tests/afrouter/templates/main.go b/tests/afrouter/templates/main.go
index f539a02..c2fddb9 100644
--- a/tests/afrouter/templates/main.go
+++ b/tests/afrouter/templates/main.go
@@ -26,9 +26,28 @@
 	"os/exec"
 	"strings"
 	"context"
+	slog "log"
+	"io/ioutil"
+	"encoding/json"
+	"google.golang.org/grpc/grpclog"
 	"github.com/opencord/voltha-go/common/log"
 )
 
+type TestCase struct {
+	Title string `json:"title"`
+	Result bool `json:"result"`
+	Info []string `json:"info"`
+}
+
+type TestSuite struct {
+	Name string `json:"name"`
+	TestCases []TestCase `json:"testCases"`
+}
+
+type TestRun struct {
+	TestSuites []TestSuite
+}
+
 var resFile *tstLog
 type tstLog struct {
 	fp * os.File
@@ -95,6 +114,37 @@
 	//time.Sleep(1 * time.Second)
 }
 
+func readStats(stats * TestRun) () {
+	// Check if the  stats file exists
+	if _,err := os.Stat("stats.json"); err != nil {
+		// Nothing to do, just return
+		return
+	}
+	// The file is there, read it an unmarshal it into the stats struct
+	if statBytes, err := ioutil.ReadFile("stats.json"); err != nil {
+		log.Error(err)
+		return
+	} else if err := json.Unmarshal(statBytes, stats); err != nil {
+		log.Error(err)
+		return
+	}
+}
+
+func writeStats(stats * TestRun) () {
+	// Check if the  stats file exists
+	// The file is there, read it an unmarshal it into the stats struct
+	if statBytes, err := json.MarshalIndent(stats, "","    "); err != nil {
+		log.Error(err)
+		return
+	} else if err := ioutil.WriteFile("stats.json.new", statBytes, 0644); err != nil {
+		log.Error(err)
+		return
+	}
+	os.Rename("stats.json", "stats.json~")
+	os.Rename("stats.json.new", "stats.json")
+}
+var stats TestRun
+
 func main() {
 	var err error
 
@@ -102,9 +152,13 @@
 	if _, err = log.SetDefaultLogger(log.JSON, 0, nil); err != nil {
 		log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
 	}
-
 	defer log.CleanUp()
 
+	readStats(&stats)
+
+
+	grpclog.SetLogger(slog.New(os.Stderr, "grpc: ", slog.LstdFlags))
+
 	resFile = &tstLog{fn:os.Args[1]}
 	defer resFile.close()
 
@@ -133,5 +187,6 @@
 	// Run all the test cases now
 	log.Infof("Executing tests")
 	runTests()
+	writeStats(&stats)
 
 }