jiri-swift: Update tests for timeout jenkins issue

We previously disabled tests as jenkins wasn't able to correctly run
them in parallel (things got clobbered between unrelated builds). This
CL is an attempt to help debug the issue and see if we can re-enable
our Swift Testing.

We break up the jiri-swift tests in terms of architecture/project to
deal with timeout limits per-test function as well as disable redundent
and unnecessary tests (amd64 in cgo build + universal build, shared
libs).

Note tests are still disabled as Jenkins is still clobbering
unrelated compiles.

This cherry picks from commit d4c18bcda78aaf57e44719dcb57c1f5a4c0f0d29

Change-Id: Id7f800288957fa5c5b88f6aa5b1b2b3fe4552970
diff --git a/jiri-swift/build_test.go b/jiri-swift/build_test.go
index 5b83dbc..2c0121f 100644
--- a/jiri-swift/build_test.go
+++ b/jiri-swift/build_test.go
@@ -191,19 +191,7 @@
 	}
 }
 
-func TestCgoBuildForSimulator64(t *testing.T) {
-	for _, p := range projects {
-		jirix := initForTest(t)
-		if err := testCgoBuildForArch(jirix, p, targetArchAmd64, buildModeArchive); err != nil {
-			t.Error(err)
-		}
-		if err := testCgoBuildForArch(jirix, p, targetArchAmd64, buildModeShared); err != nil {
-			t.Error(err)
-		}
-	}
-}
-
-func TestCgoBuildForArm(t *testing.T) {
+func TestAllCgoBuildForArmFails(t *testing.T) {
 	for _, p := range projects {
 		jirix := initForTest(t)
 		// Expect error for ARM currently as of Go 1.5
@@ -213,25 +201,34 @@
 	}
 }
 
-func TestCgoBuildForArm64(t *testing.T) {
-	for _, p := range projects {
-		jirix := initForTest(t)
-		if err := testCgoBuildForArch(jirix, p, targetArchArm64, buildModeArchive); err != nil {
-			t.Error(err)
-		}
+func TestVanadiumCoreCgoBuildForArm64(t *testing.T) {
+	jirix := initForTest(t)
+	if err := testCgoBuildForArch(jirix, projectVanadiumCore, targetArchArm64, buildModeArchive); err != nil {
+		t.Error(err)
 	}
+	// Currently disabled as we're not using shared libraries and the unit test can take a while.
+	// Turn back on if we move to shared libraries to get around bitcode restrictions.
+	//if err := testCgoBuildForArch(jirix, projectVanadiumCore, targetArchArm64, buildModeShared); err != nil {
+	//	t.Error(err)
+	//}
 }
 
-func TestCgoBuildForAll(t *testing.T) {
-	for _, p := range projects {
-		jirix := initForTest(t)
-		if err := testCgoBuildForArch(jirix, p, targetArchAll, buildModeArchive); err != nil {
-			t.Error(err)
-		}
+// We don't test amd64 as that gets tested in the universal builds below (which also tests the arm64 build but
+// doesn't inspect the results as closely).
+
+func TestSyncbaseCoreCgoBuildForArm64(t *testing.T) {
+	jirix := initForTest(t)
+	if err := testCgoBuildForArch(jirix, projectSyncbaseCore, targetArchArm64, buildModeArchive); err != nil {
+		t.Error(err)
 	}
+	// Currently disabled as we're not using shared libraries and the unit test can take a while.
+	// Turn back on if we move to shared libraries to get around bitcode restrictions.
+	//if err := testCgoBuildForArch(jirix, projectSyncbaseCore, targetArchArm64, buildModeShared); err != nil {
+	//	t.Error(err)
+	//}
 }
 
-func testCgoBuildForArch(jirix *jiri.X, p project, arch string, buildMode string) error {
+func testCgoBuildForArch(jirix *jiri.X, p *project, arch string, buildMode string) error {
 	resetVars()
 	buildCgo = true
 	flagBuildMode = buildMode
@@ -378,42 +375,48 @@
 	return nil
 }
 
-func TestUniversalFrameworkBuilds(t *testing.T) {
-	for _, p := range projects {
-		jirix := initForTest(t)
-		flagTargetArch = targetArchAll
-		flagProject = p.name
-		if err := parseProjectFlag(); err != nil {
-			t.Error(err)
-			return
+func TestVanadiumCoreUniversalFrameworkBuilds(t *testing.T) {
+	testUniversalFrameworkBuild(t, projectVanadiumCore)
+}
+
+func TestSyncbaseCoreUniversalFrameworkBuilds(t *testing.T) {
+	testUniversalFrameworkBuild(t, projectSyncbaseCore)
+}
+
+func testUniversalFrameworkBuild(t *testing.T, p *project) {
+	jirix := initForTest(t)
+	flagTargetArch = targetArchAll
+	flagProject = p.name
+	if err := parseProjectFlag(); err != nil {
+		t.Error(err)
+		return
+	}
+	if err := parseBuildFlags(); err != nil {
+		t.Error(err)
+		return
+	}
+	// Make sure VanadiumCore exports exist
+	if err := runBuildCgo(jirix); err != nil {
+		t.Error(err)
+		return
+	}
+	if err := runBuildFramework(jirix); err != nil {
+		t.Error(err)
+		return
+	}
+	binaryPath := filepath.Join(flagOutDirSwift, selectedProject.frameworkName, selectedProject.frameworkBinaryName)
+	if err := verifyCgoBinaryForIOS(binaryPath); err != nil {
+		t.Error(err)
+		return
+	}
+	for _, targetArch := range targetArchs {
+		appleArch, _ := appleArchFromGoArch(targetArch)
+		sh.Cmd("lipo", binaryPath, "-verify_arch", appleArch).Run()
+		if !pathExists(filepath.Join(flagOutDirSwift, selectedProject.frameworkName, "Modules", selectedProject.frameworkBinaryName+".swiftmodule", appleArch+".swiftdoc")) {
+			t.Errorf("Missing swift moduledoc for architecture %v", targetArch)
 		}
-		if err := parseBuildFlags(); err != nil {
-			t.Error(err)
-			return
-		}
-		// Make sure VanadiumCore exports exist
-		if err := runBuildCgo(jirix); err != nil {
-			t.Error(err)
-			return
-		}
-		if err := runBuildFramework(jirix); err != nil {
-			t.Error(err)
-			return
-		}
-		binaryPath := filepath.Join(flagOutDirSwift, selectedProject.frameworkName, selectedProject.frameworkBinaryName)
-		if err := verifyCgoBinaryForIOS(binaryPath); err != nil {
-			t.Error(err)
-			return
-		}
-		for _, targetArch := range targetArchs {
-			appleArch, _ := appleArchFromGoArch(targetArch)
-			sh.Cmd("lipo", binaryPath, "-verify_arch", appleArch).Run()
-			if !pathExists(filepath.Join(flagOutDirSwift, selectedProject.frameworkName, "Modules", selectedProject.frameworkBinaryName+".swiftmodule", appleArch+".swiftdoc")) {
-				t.Errorf("Missing swift moduledoc for architecture %v", targetArch)
-			}
-			if !pathExists(filepath.Join(flagOutDirSwift, selectedProject.frameworkName, "Modules", selectedProject.frameworkBinaryName+".swiftmodule", appleArch+".swiftmodule")) {
-				t.Errorf("Missing swift module for architecture %v", targetArch)
-			}
+		if !pathExists(filepath.Join(flagOutDirSwift, selectedProject.frameworkName, "Modules", selectedProject.frameworkBinaryName+".swiftmodule", appleArch+".swiftmodule")) {
+			t.Errorf("Missing swift module for architecture %v", targetArch)
 		}
 	}
 }
diff --git a/jiri-swift/swift.go b/jiri-swift/swift.go
index 2a6c916..5fa06bc 100644
--- a/jiri-swift/swift.go
+++ b/jiri-swift/swift.go
@@ -33,36 +33,35 @@
 
 	targetArchs []string
 
-	selectedProject *project
-	projects        = []project{
-		{
-			name:                       "VanadiumCore",
-			commonHeaderPath:           "release/go/src/v.io/x/swift/types.h",
-			description:                "Core bindings from Swift to Vanadium; incompatible with SyncbaseCore",
-			directoryName:              "VanadiumCore",
-			exportedHeadersPackageRoot: "v.io/x",
-			frameworkName:              "VanadiumCore.framework",
-			frameworkBinaryName:        "VanadiumCore",
-			libraryBinaryName:          "v23",
-			mainPackage:                "v.io/x/swift/main",
-			testCheckExportedSymbols:   []string{"swift_io_v_v23_V_nativeInitGlobal", "swift_io_v_v23_context_VContext_nativeWithCancel"},
-			testCheckSharedTypes:       []string{"SwiftByteArray", "SwiftByteArrayArray", "GoContextHandle"},
-		},
-		{
-			name:                       "SyncbaseCore",
-			commonHeaderPath:           "release/go/src/v.io/x/ref/services/syncbase/bridge/cgo/lib.h",
-			description:                "Core bindings from Swift to Syncbase; incompatible with VanadiumCore",
-			directoryName:              "SyncbaseCore",
-			exportedHeadersPackageRoot: "v.io/x",
-			frameworkName:              "SyncbaseCore.framework",
-			frameworkBinaryName:        "SyncbaseCore",
-			jiriProfiles:               []string{"v23:syncbase"},
-			libraryBinaryName:          "sbcore",
-			mainPackage:                "v.io/x/ref/services/syncbase/bridge/cgo",
-			testCheckExportedSymbols:   []string{"v23_syncbase_Init", "v23_syncbase_DbLeaveSyncgroup", "v23_syncbase_RowDelete"},
-			testCheckSharedTypes:       []string{"v23_syncbase_String", "v23_syncbase_Bytes", "v23_syncbase_Strings", "v23_syncbase_VError"},
-		},
+	selectedProject     *project
+	projectSyncbaseCore = &project{
+		name:                       "SyncbaseCore",
+		commonHeaderPath:           "release/go/src/v.io/x/ref/services/syncbase/bridge/cgo/lib.h",
+		description:                "Core bindings from Swift to Syncbase; incompatible with VanadiumCore",
+		directoryName:              "SyncbaseCore",
+		exportedHeadersPackageRoot: "v.io/x",
+		frameworkName:              "SyncbaseCore.framework",
+		frameworkBinaryName:        "SyncbaseCore",
+		libraryBinaryName:          "sbcore",
+		mainPackage:                "v.io/x/ref/services/syncbase/bridge/cgo",
+		jiriProfiles:               []string{"v23:syncbase"},
+		testCheckExportedSymbols:   []string{"v23_syncbase_Init", "v23_syncbase_DbLeaveSyncgroup", "v23_syncbase_RowDelete"},
+		testCheckSharedTypes:       []string{"v23_syncbase_String", "v23_syncbase_Bytes", "v23_syncbase_Strings", "v23_syncbase_VError"},
 	}
+	projectVanadiumCore = &project{
+		name:                       "VanadiumCore",
+		commonHeaderPath:           "release/go/src/v.io/x/swift/types.h",
+		description:                "Core bindings from Swift to Vanadium; incompatible with SyncbaseCore",
+		directoryName:              "VanadiumCore",
+		exportedHeadersPackageRoot: "v.io/x",
+		frameworkName:              "VanadiumCore.framework",
+		frameworkBinaryName:        "VanadiumCore",
+		libraryBinaryName:          "v23",
+		mainPackage:                "v.io/x/swift/main",
+		testCheckExportedSymbols:   []string{"swift_io_v_v23_V_nativeInitGlobal", "swift_io_v_v23_context_VContext_nativeWithCancel"},
+		testCheckSharedTypes:       []string{"SwiftByteArray", "SwiftByteArrayArray", "GoContextHandle"},
+	}
+	projects = []*project{projectVanadiumCore, projectSyncbaseCore}
 )
 
 type project struct {
@@ -155,7 +154,7 @@
 func parseProjectFlag() error {
 	for _, p := range projects {
 		if strings.ToLower(flagProject) == strings.ToLower(p.name) {
-			selectedProject = &p
+			selectedProject = p
 			return nil
 		}
 	}