From fcc8c7aac161eb8950029724d6b948ffee213c4e Mon Sep 17 00:00:00 2001 From: Derek Su Date: Thu, 20 Jun 2024 08:12:53 +0000 Subject: [PATCH] WIP Signed-off-by: Derek Su --- Dockerfile.dapper | 2 +- pkg/spdk_test.go | 37 +++---------------------------------- scripts/test | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index bdd16c5a..208475f7 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -22,7 +22,7 @@ RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/syste zypper --gpg-auto-import-keys ref RUN zypper -n install cmake curl wget git gcc unzip tar xsltproc docbook-xsl-stylesheets python3 meson ninja python3-pip \ - e2fsprogs xfsprogs util-linux-systemd python3-pyelftools libcmocka-devel device-mapper + e2fsprogs xfsprogs util-linux-systemd python3-pyelftools libcmocka-devel device-mapper psmisc # Install Go & tools ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH_s390x=s390x GOLANG_ARCH=GOLANG_ARCH_${ARCH} \ diff --git a/pkg/spdk_test.go b/pkg/spdk_test.go index bc3725c6..407f214e 100644 --- a/pkg/spdk_test.go +++ b/pkg/spdk_test.go @@ -19,8 +19,6 @@ import ( commonNet "github.com/longhorn/go-common-libs/net" commonTypes "github.com/longhorn/go-common-libs/types" - helperclient "github.com/longhorn/go-spdk-helper/pkg/spdk/client" - "github.com/longhorn/go-spdk-helper/pkg/spdk/target" helpertypes "github.com/longhorn/go-spdk-helper/pkg/types" helperutil "github.com/longhorn/go-spdk-helper/pkg/util" "github.com/longhorn/types/pkg/generated/spdkrpc" @@ -64,36 +62,7 @@ func GetSPDKDir() string { return filepath.Join(os.Getenv("GOPATH"), "src/github.com/longhorn/spdk") } -func LaunchTestSPDKTarget(c *C, execute func(envs []string, name string, args []string, timeout time.Duration) (string, error)) { - targetReady := false - if spdkCli, err := helperclient.NewClient(context.Background()); err == nil { - if _, err := spdkCli.BdevGetBdevs("", 0); err == nil { - targetReady = true - } - } - - if !targetReady { - go func() { - err := target.StartTarget(GetSPDKDir(), []string{"--logflag all", "2>&1 | tee /tmp/spdk_tgt.log"}, execute) - c.Assert(err, IsNil) - }() - - for cnt := 0; cnt < 30; cnt++ { - if spdkCli, err := helperclient.NewClient(context.Background()); err == nil { - if _, err := spdkCli.BdevGetBdevs("", 0); err == nil { - targetReady = true - break - } - } - time.Sleep(time.Second) - } - } - - c.Assert(targetReady, Equals, true) -} - -func LaunchTestSPDKGRPCServer(ctx context.Context, c *C, ip string, execute func(envs []string, name string, args []string, timeout time.Duration) (string, error)) { - LaunchTestSPDKTarget(c, execute) +func LaunchTestSPDKGRPCServer(ctx context.Context, c *C, ip string) { srv, err := server.NewServer(ctx, defaultTestStartPort, defaultTestEndPort) c.Assert(err, IsNil) @@ -171,7 +140,7 @@ func (s *TestSuite) TestSPDKMultipleThread(c *C) { ne, err := helperutil.NewExecutor(commonTypes.ProcDirectory) c.Assert(err, IsNil) - LaunchTestSPDKGRPCServer(ctx, c, ip, ne.Execute) + LaunchTestSPDKGRPCServer(ctx, c, ip) loopDevicePath := PrepareDiskFile(c) defer func() { @@ -441,7 +410,7 @@ func (s *TestSuite) TestSPDKMultipleThreadSnapshot(c *C) { ne, err := helperutil.NewExecutor(commonTypes.ProcDirectory) c.Assert(err, IsNil) - LaunchTestSPDKGRPCServer(ctx, c, ip, ne.Execute) + LaunchTestSPDKGRPCServer(ctx, c, ip) loopDevicePath := PrepareDiskFile(c) defer func() { diff --git a/scripts/test b/scripts/test index c418a822..85ac17e4 100755 --- a/scripts/test +++ b/scripts/test @@ -1,6 +1,28 @@ #!/bin/bash set -e +function enable_spdk_tgt() { + echo "Enabling spdk_tgt" + sh -c 'spdk_tgt --logflag all 2>&1 | tee /var/log/spdk_tgt.log' & + + timeout=120 # Timeout in seconds + interval=1 # Interval in seconds + elapsed_time=0 + + while [ $elapsed_time -lt $timeout ]; do + if [ -S "/var/tmp/spdk.sock" ]; then + echo "Socket file '/var/tmp/spdk.sock' found after $elapsed_time seconds." + return 0 # Exit successfully if the file exists + fi + + sleep $interval + elapsed_time=$((elapsed_time + interval)) + done + + echo "Timeout reached. Socket file '/var/tmp/spdk.sock' not found." + return 1 +} + cd "$(dirname $0)"/.. echo Running unit tests @@ -27,4 +49,8 @@ trap "losetup -D" EXIT PACKAGES="$(find . -name '*.go' -print0 | xargs -0 -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')" trap "rm -f /tmp/test-disk" EXIT + +enable_spdk_tgt +trap "pkill -f spdk_tgt" EXIT + go test -v -race -cover ${PACKAGES} -coverprofile=coverage.out -timeout 12m