diff --git a/contrib/fuzz/oss_fuzz_build.sh b/contrib/fuzz/oss_fuzz_build.sh index 6b86dcfc1..a0c2eb253 100755 --- a/contrib/fuzz/oss_fuzz_build.sh +++ b/contrib/fuzz/oss_fuzz_build.sh @@ -90,11 +90,4 @@ sed -i 's/\/run\/containerd-test/\/tmp\/containerd-test/g' $SRC/containerd/integ cd integration/client -# Rename all *_test.go to *_test_fuzz.go to use their declarations: -for i in $( ls *_test.go ); do mv $i ./${i%.*}_fuzz.go; done - -# Remove windows test to avoid double declarations: -rm ./client_windows_test_fuzz.go -rm ./helpers_windows_test_fuzz.go - compile_fuzzers '^func FuzzInteg.*data' compile_go_fuzzer vendor diff --git a/integration/client/client.go b/integration/client/client.go new file mode 100644 index 000000000..4cb51534d --- /dev/null +++ b/integration/client/client.go @@ -0,0 +1,74 @@ +/* + Copyright The containerd 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 client + +import ( + "context" + "flag" + "fmt" + "os" + "testing" + + "github.com/containerd/containerd" + "github.com/containerd/containerd/defaults" + "github.com/containerd/containerd/log/logtest" + "github.com/containerd/containerd/namespaces" +) + +const ( + testNamespace = "testing" +) + +var ( + address string + ctrdStdioFilePath string + testSnapshotter = containerd.DefaultSnapshotter + ctrd = &daemon{} +) + +func init() { + flag.StringVar(&address, "address", defaults.DefaultAddress, "The address to the containerd socket for use in the tests") +} + +func testContext(t testing.TB) (context.Context, context.CancelFunc) { + ctx, cancel := context.WithCancel(context.Background()) + ctx = namespaces.WithNamespace(ctx, testNamespace) + if t != nil { + ctx = logtest.WithT(ctx, t) + } + return ctx, cancel +} + +func createShimDebugConfig() string { + f, err := os.CreateTemp("", "containerd-config-") + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to create config file: %s\n", err) + os.Exit(1) + } + defer f.Close() + if _, err := f.WriteString("version = 2\n"); err != nil { + fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err) + os.Exit(1) + } + + if _, err := f.WriteString("[plugins.\"io.containerd.runtime.v1.linux\"]\n\tshim_debug = true\n"); err != nil { + fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err) + os.Exit(1) + } + + return f.Name() +} diff --git a/integration/client/client_test.go b/integration/client/client_test.go index 35d4278b3..991b9e120 100644 --- a/integration/client/client_test.go +++ b/integration/client/client_test.go @@ -33,7 +33,6 @@ import ( imagelist "github.com/containerd/containerd/integration/images" "github.com/containerd/containerd/leases" "github.com/containerd/containerd/log" - "github.com/containerd/containerd/log/logtest" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/pkg/testutil" "github.com/containerd/containerd/platforms" @@ -45,32 +44,16 @@ import ( ) var ( - address string - noDaemon bool - noCriu bool - supportsCriu bool - testNamespace = "testing" - testSnapshotter = DefaultSnapshotter - ctrdStdioFilePath string - - ctrd = &daemon{} + noDaemon bool + noCriu bool + supportsCriu bool ) func init() { - flag.StringVar(&address, "address", defaultAddress, "The address to the containerd socket for use in the tests") flag.BoolVar(&noDaemon, "no-daemon", false, "Do not start a dedicated daemon for the tests") flag.BoolVar(&noCriu, "no-criu", false, "Do not run the checkpoint tests") } -func testContext(t testing.TB) (context.Context, context.CancelFunc) { - ctx, cancel := context.WithCancel(context.Background()) - ctx = namespaces.WithNamespace(ctx, testNamespace) - if t != nil { - ctx = logtest.WithT(ctx, t) - } - return ctx, cancel -} - func TestMain(m *testing.M) { flag.Parse() if testing.Short() { @@ -507,26 +490,6 @@ func TestClientReconnect(t *testing.T) { } } -func createShimDebugConfig() string { - f, err := os.CreateTemp("", "containerd-config-") - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to create config file: %s\n", err) - os.Exit(1) - } - defer f.Close() - if _, err := f.WriteString("version = 2\n"); err != nil { - fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err) - os.Exit(1) - } - - if _, err := f.WriteString("[plugins.\"io.containerd.runtime.v1.linux\"]\n\tshim_debug = true\n"); err != nil { - fmt.Fprintf(os.Stderr, "Failed to write to config file %s: %s\n", f.Name(), err) - os.Exit(1) - } - - return f.Name() -} - func TestDefaultRuntimeWithNamespaceLabels(t *testing.T) { client, err := newClient(t, address) if err != nil { diff --git a/integration/client/client_unix.go b/integration/client/client_unix.go new file mode 100644 index 000000000..de83ea76b --- /dev/null +++ b/integration/client/client_unix.go @@ -0,0 +1,26 @@ +//go:build !windows +// +build !windows + +/* + Copyright The containerd 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 client + +const ( + defaultRoot = "/var/lib/containerd-test" + defaultState = "/run/containerd-test" + defaultAddress = "/run/containerd-test/containerd.sock" +) diff --git a/integration/client/client_unix_test.go b/integration/client/client_unix_test.go index 621f4e17a..ba24f4ae1 100644 --- a/integration/client/client_unix_test.go +++ b/integration/client/client_unix_test.go @@ -27,12 +27,6 @@ import ( "github.com/containerd/containerd/platforms" ) -const ( - defaultRoot = "/var/lib/containerd-test" - defaultState = "/run/containerd-test" - defaultAddress = "/run/containerd-test/containerd.sock" -) - var ( testImage = images.Get(images.BusyBox) testMultiLayeredImage = images.Get(images.VolumeCopyUp) diff --git a/integration/client/daemon_test.go b/integration/client/daemon.go similarity index 100% rename from integration/client/daemon_test.go rename to integration/client/daemon.go