madb: add tests for madb

Change-Id: I1daeadb93914354a2089966dbdc2fcdc3e5e478b
MultiPart: 1/2
diff --git a/jiri-test/internal/test/go.go b/jiri-test/internal/test/go.go
index c41ff2e..4b739b4 100644
--- a/jiri-test/internal/test/go.go
+++ b/jiri-test/internal/test/go.go
@@ -1162,6 +1162,17 @@
 	return numWorkersOpt(runtime.NumCPU())
 }
 
+// getDefaultPkgsOpt gets the default packages from the given Opt slice
+func getDefaultPkgsOpt(opts []Opt) []string {
+	for _, opt := range opts {
+		switch v := opt.(type) {
+		case DefaultPkgsOpt:
+			return []string(v)
+		}
+	}
+	return []string{"v.io/..."}
+}
+
 // thirdPartyGoBuild runs Go build for third-party projects.
 func thirdPartyGoBuild(jirix *jiri.X, testName string, opts ...Opt) (_ *test.Result, e error) {
 	// Initialize the test.
@@ -1426,7 +1437,7 @@
 }
 
 // vanadiumGoFormat runs Go format check for vanadium projects.
-func vanadiumGoFormat(jirix *jiri.X, testName string, _ ...Opt) (_ *test.Result, e error) {
+func vanadiumGoFormat(jirix *jiri.X, testName string, opts ...Opt) (_ *test.Result, e error) {
 	// Initialize the test.
 	cleanup, err := initTest(jirix, testName, []string{"v23:base"})
 	if err != nil {
@@ -1436,7 +1447,9 @@
 
 	// Run the gofmt tool.
 	var out bytes.Buffer
-	if err := jirix.NewSeq().Capture(&out, &out).Last("jiri", "go", "fmt", "v.io/..."); err != nil {
+	args := []string{"go", "fmt"}
+	args = append(args, getDefaultPkgsOpt(opts)...)
+	if err := jirix.NewSeq().Capture(&out, &out).Last("jiri", args...); err != nil {
 		return nil, fmt.Errorf("unexpected error while running go fmt: %v", err)
 	}
 	// If the output is non-empty, there are format errors.
@@ -1473,7 +1486,8 @@
 
 	s := jirix.NewSeq()
 
-	pkgs, err := validateAgainstDefaultPackages(jirix, opts, []string{"v.io/..."})
+	defaultPkgs := getDefaultPkgsOpt(opts)
+	pkgs, err := validateAgainstDefaultPackages(jirix, opts, defaultPkgs)
 	if err != nil {
 		return nil, err
 	}
@@ -1721,7 +1735,8 @@
 	defer collect.Error(func() error { return cleanup() }, &e)
 
 	// Test the Vanadium Go packages.
-	pkgs, err := validateAgainstDefaultPackages(jirix, opts, []string{"v.io/..."})
+	defaultPkgs := getDefaultPkgsOpt(opts)
+	pkgs, err := validateAgainstDefaultPackages(jirix, opts, defaultPkgs)
 	if err != nil {
 		return nil, err
 	}
diff --git a/jiri-test/internal/test/madb.go b/jiri-test/internal/test/madb.go
new file mode 100644
index 0000000..733b760
--- /dev/null
+++ b/jiri-test/internal/test/madb.go
@@ -0,0 +1,32 @@
+// Copyright 2016 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package test
+
+import (
+	"v.io/jiri"
+	"v.io/x/devtools/internal/test"
+)
+
+// madbGoTest runs Go tests for the madb project.
+func madbGoTest(jirix *jiri.X, testName string, opts ...Opt) (_ *test.Result, e error) {
+	pkgs := []string{"madb/..."}
+	opts = append(opts, DefaultPkgsOpt(pkgs))
+	return vanadiumGoTest(jirix, testName, opts...)
+}
+
+// madbGoFormat runs Go format check for the madb project.
+func madbGoFormat(jirix *jiri.X, testName string, opts ...Opt) (_ *test.Result, e error) {
+	pkgs := []string{"madb/..."}
+	opts = append(opts, DefaultPkgsOpt(pkgs))
+	return vanadiumGoFormat(jirix, testName, opts...)
+}
+
+// madbGoGenerate checks that files created by 'go generate' are
+// up-to-date.
+func madbGoGenerate(jirix *jiri.X, testName string, opts ...Opt) (_ *test.Result, e error) {
+	pkgs := []string{"madb/..."}
+	opts = append(opts, DefaultPkgsOpt(pkgs))
+	return vanadiumGoGenerate(jirix, testName, opts...)
+}
diff --git a/jiri-test/internal/test/run.go b/jiri-test/internal/test/run.go
index a211661..a5ab895 100644
--- a/jiri-test/internal/test/run.go
+++ b/jiri-test/internal/test/run.go
@@ -72,6 +72,9 @@
 	"ignore-this":                             testMock,
 	"baku-android-build":                      bakuAndroidBuild,
 	"baku-java-test":                          bakuJavaTest,
+	"madb-go-format":                          madbGoFormat,
+	"madb-go-generate":                        madbGoGenerate,
+	"madb-go-test":                            madbGoTest,
 	"test-presubmit-test":                     testPresubmitTest,
 	"third_party-go-build":                    thirdPartyGoBuild,
 	"third_party-go-test":                     thirdPartyGoTest,
@@ -220,6 +223,12 @@
 
 func (MergePoliciesOpt) Opt() {}
 
+// DefaultPkgsOpt is an option that specifies which default packages
+// should be used to validate the test packages against.
+type DefaultPkgsOpt []string
+
+func (DefaultPkgsOpt) Opt() {}
+
 // ListTests returns a list of all tests known by the test package.
 func ListTests() ([]string, error) {
 	result := []string{}
diff --git a/tooldata/data/config.v1.xml b/tooldata/data/config.v1.xml
index fadfb4d..c6896df 100644
--- a/tooldata/data/config.v1.xml
+++ b/tooldata/data/config.v1.xml
@@ -24,6 +24,7 @@
     <project>release.projects.browser</project>
     <project>release.projects.chat</project>
     <project>release.projects.croupier</project>
+    <project>release.projects.madb</project>
     <project>release.projects.media-sharing</project>
     <project>release.projects.physical-lock</project>
     <project>release.projects.pipe2browser</project>
@@ -38,6 +39,7 @@
   <goWorkspaces>
     <workspace>infrastructure/go</workspace>
     <workspace>release/go</workspace>
+    <workspace>release/projects/go</workspace>
     <workspace>release/projects/physical-lock/go</workspace>
     <workspace>release/projects/sensorlog/go</workspace>
     <workspace>roadmap/go</workspace>
@@ -135,6 +137,12 @@
       <test>vanadium-copyright</test>
       <test>vanadium-croupier-unit</test>
     </project>
+    <project name="release.projects.madb">
+      <test>madb-go-format</test>
+      <test>madb-go-generate</test>
+      <test>madb-go-test</test>
+      <test>vanadium-copyright</test>
+    </project>
     <project name="release.projects.playground">
       <test>vanadium-copyright</test>
       <test>vanadium-playground-test</test>