-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antithesis] Add test setup for xsvm
- Loading branch information
Showing
21 changed files
with
1,171 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Directory above this script | ||
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) | ||
# Load the constants | ||
source "$AVALANCHE_PATH"/scripts/constants.sh | ||
|
||
echo "Building Workload..." | ||
go build -o "$AVALANCHE_PATH/build/antithesis-xsvm-workload" "$AVALANCHE_PATH/tests/antithesis/xsvm/"*.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package antithesis | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet" | ||
"github.com/ava-labs/avalanchego/utils/perms" | ||
) | ||
|
||
// Initialize the db volumes for a docker-compose configuration. The returned network will be updated with | ||
// subnet and chain IDs and the target path will be configured with volumes for each node containing the | ||
// initialized db state. | ||
func InitDBVolumes(network *tmpnet.Network, avalancheGoPath string, pluginDir string, targetPath string) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2) | ||
defer cancel() | ||
if err := tmpnet.StartNewNetwork( | ||
ctx, | ||
os.Stdout, | ||
network, | ||
"", | ||
avalancheGoPath, | ||
pluginDir, | ||
0, // nodeCount is 0 because nodes should already be configured for subnets | ||
); err != nil { | ||
return fmt.Errorf("failed to start network: %w", err) | ||
} | ||
// Since the goal is to initialize the DB, we can stop the network after it has been started successfully | ||
if err := network.Stop(ctx); err != nil { | ||
return fmt.Errorf("failed to stop network: %w", err) | ||
} | ||
|
||
absPath, err := filepath.Abs(targetPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to convert target path to absolute path: %w", err) | ||
} | ||
|
||
// Create volumes in the target path and copy the db state from the nodes | ||
for i, node := range network.Nodes { | ||
sourcePath := filepath.Join(node.GetDataDir(), "db") | ||
destPath := filepath.Join(absPath, "volumes", getServiceName(i)) | ||
if err := os.MkdirAll(destPath, perms.ReadWriteExecute); err != nil { | ||
return fmt.Errorf("failed to create volume path %q: %w", destPath, err) | ||
} | ||
cmd := exec.Command("cp", "-r", sourcePath, destPath) | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("failed to copy db state from %q to %q: %w", sourcePath, destPath, err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# The version is supplied as a build argument rather than hard-coded | ||
# to minimize the cost of version changes. | ||
ARG GO_VERSION | ||
|
||
# NODE_IMAGE needs to identify an existing xsvm node image and should include the tag | ||
ARG NODE_IMAGE | ||
|
||
FROM $NODE_IMAGE AS xsvm_node | ||
|
||
# ============= Compilation Stage ================ | ||
FROM golang:$GO_VERSION-bullseye AS builder | ||
|
||
WORKDIR /build | ||
# Copy and download avalanche dependencies using go mod | ||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
|
||
# Copy the code into the container | ||
COPY . . | ||
|
||
# IMAGE_TAG should be set to the tag for the images in the generated docker compose file. | ||
ARG IMAGE_TAG=latest | ||
|
||
# Copy the avalanchego binary and plugin from the node image | ||
RUN mkdir -p ./build/plugins | ||
COPY --from=xsvm_node /avalanchego/build/avalanchego ./build | ||
COPY --from=xsvm_node /root/.avalanchego/plugins/* ./build/plugins/ | ||
|
||
# Generate docker compose configuration | ||
RUN AVALANCHEGO_PATH=./build/avalanchego AVALANCHEGO_PLUGIN_DIR=./build/plugins\ | ||
TARGET_PATH=./build IMAGE_TAG="$IMAGE_TAG" go run ./tests/antithesis/xsvm/gencomposeconfig | ||
|
||
# ============= Cleanup Stage ================ | ||
FROM scratch AS execution | ||
|
||
# Copy the docker compose file and volumes into the container | ||
COPY --from=builder /build/build/docker-compose.yml /docker-compose.yml | ||
COPY --from=builder /build/build/volumes /volumes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# The version is supplied as a build argument rather than hard-coded | ||
# to minimize the cost of version changes. | ||
ARG GO_VERSION | ||
|
||
# AVALANCHEGO_NODE_IMAGE needs to identify an existing avalanchego node image and should include the tag | ||
ARG AVALANCHEGO_NODE_IMAGE | ||
|
||
# Antithesis: Getting the Antithesis golang instrumentation library | ||
FROM docker.io/antithesishq/go-instrumentor AS instrumentor | ||
|
||
# ============= Compilation Stage ================ | ||
FROM golang:$GO_VERSION-bullseye AS builder | ||
|
||
WORKDIR /build | ||
# Copy and download avalanche dependencies using go mod | ||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
|
||
# Copy the code into the container | ||
COPY . . | ||
|
||
# Keep the commit hash to easily verify the exact version that is running | ||
RUN git rev-parse HEAD > ./commit_hash.txt | ||
|
||
# Copy the instrumentor and supporting files to their correct locations | ||
COPY --from=instrumentor /opt/antithesis /opt/antithesis | ||
COPY --from=instrumentor /opt/antithesis/lib /lib | ||
|
||
# Create the destination output directory for the instrumented code | ||
RUN mkdir -p /avalanchego_instrumented | ||
|
||
# Park the .git file in a safe location | ||
RUN mkdir -p /opt/tmp/ | ||
RUN cp -r .git /opt/tmp/ | ||
|
||
# Instrument avalanchego | ||
RUN /opt/antithesis/bin/goinstrumentor \ | ||
-stderrthreshold=INFO \ | ||
-antithesis /opt/antithesis/instrumentation \ | ||
. \ | ||
/avalanchego_instrumented | ||
|
||
WORKDIR /avalanchego_instrumented/customer | ||
RUN go mod download | ||
RUN ln -s /opt/tmp/.git .git | ||
|
||
# Build xsvm VM | ||
RUN ./scripts/build_xsvm.sh | ||
|
||
# ============= Cleanup Stage ================ | ||
FROM $AVALANCHEGO_NODE_IMAGE AS execution | ||
|
||
# The commit hash and antithesis dependencies should be part of the base image. | ||
|
||
# Copy the executable into the container | ||
RUN mkdir -p /root/.avalanchego/plugins | ||
COPY --from=builder /avalanchego_instrumented/customer/build/xsvm \ | ||
/root/.avalanchego/plugins/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH | ||
|
||
# The node image's entrypoint will be reused. |
Oops, something went wrong.