Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Jun 20, 2024
1 parent df7e848 commit fcc8c7a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
37 changes: 3 additions & 34 deletions pkg/spdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
26 changes: 26 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit fcc8c7a

Please sign in to comment.