diff --git a/test/examples_test.go b/test/examples_test.go index 24d89ef339e..a15235ff23f 100644 --- a/test/examples_test.go +++ b/test/examples_test.go @@ -21,16 +21,16 @@ package test import ( "errors" "io/ioutil" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + knativetest "knative.dev/pkg/test" "os" "os/exec" "path/filepath" "regexp" + "runtime" "strings" "testing" "time" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - knativetest "knative.dev/pkg/test" ) var ( @@ -114,8 +114,11 @@ func DeleteClusterTask(t *testing.T, c *clients, name string) { type waitFunc func(t *testing.T, c *clients, name string) -func exampleTest(path string, waitValidateFunc waitFunc, kind string) func(t *testing.T) { +func exampleTest(testName string, path string, waitValidateFunc waitFunc, kind string) func(t *testing.T) { return func(t *testing.T) { + if IsExcluded(testName) { + t.Skipf("skip for %s architecture", runtime.GOARCH) + } t.Parallel() // Setup unique namespaces for each test so they can run in complete @@ -216,6 +219,6 @@ func TestExamples(t *testing.T) { kind = "taskrun" } - t.Run(testName, exampleTest(path, waitValidateFunc, kind)) + t.Run(testName, exampleTest(testName, path, waitValidateFunc, kind)) } } diff --git a/test/git_checkout_test.go b/test/git_checkout_test.go index 814b6f4995d..8d6fa735fab 100644 --- a/test/git_checkout_test.go +++ b/test/git_checkout_test.go @@ -19,6 +19,7 @@ limitations under the License. package test import ( + "runtime" "strings" "testing" @@ -41,6 +42,9 @@ const ( // TestGitPipelineRun is an integration test that will verify the source code is either fetched or pulled // successfully under different revision inputs (branch, commitid, tag, ref) func TestGitPipelineRun(t *testing.T) { + if IsExcluded("TestGitPipelineRun") { + t.Skipf("skip for %s architecture", runtime.GOARCH) + } t.Parallel() revisions := []string{"master", "c15aced0e5aaee6456fbe6f7a7e95e0b5b3b2b2f", "release-0.1", "v0.1.0", "refs/pull/347/head"} @@ -82,6 +86,9 @@ func TestGitPipelineRun(t *testing.T) { // Test revision fetching with refspec specified func TestGitPipelineRunWithRefspec(t *testing.T) { + if IsExcluded("TestGitPipelineRunWithRefspec") { + t.Skipf("skip for %s architecture", runtime.GOARCH) + } t.Parallel() for _, tc := range []struct { @@ -303,6 +310,10 @@ func TestGitPipelineRunFail_HTTPS_PROXY(t *testing.T) { // successfully under different revision inputs (default branch, branch) // This test will run on spring-petclinic repository which does not contain a master branch as the default branch func TestGitPipelineRunWithNonMasterBranch(t *testing.T) { + if IsExcluded("TestGitPipelineRunWithNonMasterBranch") { + t.Skipf("skip for %s architecture", runtime.GOARCH) + } + t.Parallel() revisions := []string{"", "main"} diff --git a/test/init_test.go b/test/init_test.go index 7b279b81e9e..a99ad7ed47c 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -24,6 +24,7 @@ import ( "flag" "fmt" "os" + "runtime" "strings" "sync" "testing" @@ -50,7 +51,26 @@ func init() { flag.BoolVar(&skipRootUserTests, "skipRootUserTests", false, "Skip tests that require root user") } +func excludeForArchitecture(callerLevel int) bool { + //get the Caller and the func name after + pc, _, _, _ := runtime.Caller(callerLevel) + funcFullName := runtime.FuncForPC(pc).Name() + lastSlash := strings.LastIndexByte(funcFullName, '/') + if lastSlash < 0 { + lastSlash = 0 + } + lastDot := strings.LastIndexByte(funcFullName[lastSlash:], '.') + lastSlash + funcName := funcFullName[lastDot+1:] + //check if func name, which equal to test name is excluded for special architecture + + return IsExcluded(funcName) +} + func setup(t *testing.T, fn ...func(*testing.T, *clients, string)) (*clients, string) { + if excludeForArchitecture(1) || excludeForArchitecture(2) { + t.Skipf("skip for %s architecture", runtime.GOARCH) + } + t.Helper() namespace := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("arendelle") diff --git a/test/kaniko_task_test.go b/test/kaniko_task_test.go index 4d0f91d9325..3443e3a9661 100644 --- a/test/kaniko_task_test.go +++ b/test/kaniko_task_test.go @@ -168,7 +168,7 @@ func getTask(repo, namespace string) *v1beta1.Task { }}}, Sidecars: []v1beta1.Sidecar{{Container: corev1.Container{ Name: "registry", - Image: "registry", + Image: GetTestImage(Registry), }}}, }, } diff --git a/test/multiarch_utils.go b/test/multiarch_utils.go new file mode 100644 index 00000000000..cb132fb6cf0 --- /dev/null +++ b/test/multiarch_utils.go @@ -0,0 +1,131 @@ +/* +Copyright 2019 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +import "runtime" + +var ( + imageNames = initImageNames() + excludedTests = initExceludedTests() +) + +const ( + // Busybox image with specific sha + BusyboxSha = iota + // Registry image + Registry +) + +func initImageNames() map[int]string { + mapping := make(map[int]string) + + switch arch := runtime.GOARCH; arch { + case "s390x": + mapping[BusyboxSha] = "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977" + mapping[Registry] = "ibmcom/registry:2.6.2.5" + + default: + mapping[BusyboxSha] = "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649" + mapping[Registry] = "registry" + } + return mapping +} + +func initExceludedTests() map[string]bool { + mapping := make(map[string]bool) + tests := []string{} + switch arch := runtime.GOARCH; arch { + case "s390x": + //examples + tests = []string{ + "v1alpha1/taskruns/dind-sidecar", + "v1beta1/taskruns/dind-sidecar", + "v1alpha1/taskruns/build-gcs-targz", + "v1beta1/taskruns/build-gcs-targz", + "v1alpha1/taskruns/build-push-kaniko", + "v1alpha1/taskruns/pull-private-image", + "v1beta1/taskruns/pull-private-image", + "v1alpha1/pipelineruns/pipelinerun", + "v1beta1/pipelineruns/pipelinerun", + "v1beta1/taskruns/build-gcs-zip", + "v1alpha1/taskruns/build-gcs-zip", + "v1alpha1/taskruns/git-volume", + "v1beta1/taskruns/git-volume", + "v1beta1/taskruns/docker-creds", + "v1alpha1/taskruns/docker-creds", + "v1beta1/taskruns/steps-run-in-order", + "v1alpha1/taskruns/steps-run-in-order", + "v1beta1/taskruns/step-by-digest", + "v1alpha1/taskruns/step-by-digest", + "v1alpha1/taskruns/gcs-resource", + "v1beta1/taskruns/gcs-resource", + "v1beta1/taskruns/authenticating-git-commands", + "v1beta1/pipelineruns/pipelinerun-with-final-tasks", + "v1beta1/taskruns/pullrequest_input_copystep_output", + "v1alpha1/taskruns/pullrequest_input_copystep_output", + "v1beta1/taskruns/pullrequest", + "v1alpha1/taskruns/pullrequest", + "v1beta1/taskruns/step-script", + "v1alpha1/taskruns/step-script", + "v1beta1/pipelineruns/conditional-pipelinerun", + "v1alpha1/pipelineruns/pipelinerun-with-resourcespec", + "v1beta1/pipelineruns/pipelinerun-with-resourcespec", + "v1beta1/taskruns/git-ssh-creds-without-known_hosts", + "v1alpha1/taskruns/optional-resources", + "v1beta1/taskruns/optional-resources", + "v1beta1/taskruns/task-output-image", + //e2e + "TestEntrypointRunningStepsInOrder", + "TestWorkingDirIgnoredNonSlashWorkspace", + "TestTaskRun_EmbeddedResource", + "TestTaskRunPipelineRunCancel", + "TestEntrypointRunningStepsInOrder", + "TestGitPipelineRun", + "TestGitPipelineRunFail", + "TestGitPipelineRunWithRefspec", + "TestGitPipelineRun_Disable_SSLVerify", + "TestGitPipelineRunWithNonMasterBranch", + "TestHelmDeployPipelineRun", + "TestKanikoTaskRun", + "TestPipelineRun", + "TestSidecarTaskSupport", + "TestWorstkingDirCreated", + "TestWorkingDirIgnoredNonSlashWorkspace", + "TestWorkingDirCreated", + "service account propagation and pipeline param", + "pipelinerun succeeds with LimitRange minimum in namespace", + } + default: + // do nothing + } + + for _, test := range tests { + mapping[test] = true + } + + return mapping +} + +// get test image based on unique id +func GetTestImage(image int) string { + return imageNames[image] +} + +// check if test name is in the excluded list based on current hardware architecture +func IsExcluded(testName string) bool { + return excludedTests[testName] +} diff --git a/test/multiarch_utils_test.go b/test/multiarch_utils_test.go new file mode 100644 index 00000000000..36c6b286723 --- /dev/null +++ b/test/multiarch_utils_test.go @@ -0,0 +1,94 @@ +// +build !e2e + +/* +Copyright 2019 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +import ( + "runtime" + "testing" +) + +var excludedtests = map[string][]struct { + in string + out bool +}{ + "s390x": { + { + "v1beta1/taskruns/optional-resources", + true, + }, + { + "TestEntrypointRunningStepsInOrder", + true, + }, + { + "TestEntrypointRunningStepsInOrderNotExcluded", + false, + }, + }, + "amd64": { + + { + "v1beta1/taskruns/optional-resources", + false, + }, + { + "TestEntrypointRunningStepsInOrder", + false, + }, + { + "TestEntrypointRunningStepsInOrderNotExcluded", + false, + }, + }, +} + +func TestGetTestImage(t *testing.T) { + var imageName string + + image := GetTestImage(BusyboxSha) + arch := runtime.GOARCH + + switch arch { + case "s390x": + imageName = "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977" + default: + imageName = "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649" + } + + if image != imageName { + t.Errorf("get image failed for %s arch, got %s instead of %s", arch, image, imageName) + } +} + +func TestIsExcluded(t *testing.T) { + arch := runtime.GOARCH + if arch != "s390x" && arch != "amd64" { + t.Skip("not supported architecture") + } + + for _, tt := range excludedtests[arch] { + t.Run(tt.in, func(t *testing.T) { + tt := tt + s := IsExcluded(tt.in) + if s != tt.out { + t.Errorf("got %t result, want %t result", s, tt.out) + } + }) + } +} diff --git a/test/pipelinerun_test.go b/test/pipelinerun_test.go index 6e8e20c097c..4ba049d26e2 100644 --- a/test/pipelinerun_test.go +++ b/test/pipelinerun_test.go @@ -21,6 +21,7 @@ package test import ( "encoding/base64" "fmt" + "runtime" "strings" "testing" "time" @@ -208,6 +209,9 @@ func TestPipelineRun(t *testing.T) { for i, td := range tds { t.Run(td.name, func(t *testing.T) { td := td + if IsExcluded(td.name) { + t.Skipf("skip for %s architecture", runtime.GOARCH) + } t.Parallel() c, namespace := setup(t) diff --git a/test/registry_test.go b/test/registry_test.go index 32654b62c4f..3680cc78bef 100644 --- a/test/registry_test.go +++ b/test/registry_test.go @@ -67,7 +67,7 @@ func getRegistryDeployment(namespace string) *appsv1.Deployment { Spec: corev1.PodSpec{ Containers: []corev1.Container{{ Name: "registry", - Image: "registry", + Image: GetTestImage(Registry), }}, }, }, diff --git a/test/taskrun_test.go b/test/taskrun_test.go index a1d6ad24e2c..fcfcafa0703 100644 --- a/test/taskrun_test.go +++ b/test/taskrun_test.go @@ -19,7 +19,6 @@ limitations under the License. package test import ( - "runtime" "strings" "testing" @@ -126,10 +125,7 @@ func TestTaskRunStatus(t *testing.T) { taskRunName := "status-taskrun" - fqImageName := "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649" - if runtime.GOARCH == "s390x" { - fqImageName = "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977" - } + fqImageName := GetTestImage(BusyboxSha) t.Logf("Creating Task and TaskRun in namespace %s", namespace) task := &v1beta1.Task{