Skip to content

Commit

Permalink
test(preload): run tests for both CPU architectures
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
basti1302 committed Jun 24, 2024
1 parent 61b8535 commit 3765925
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
9 changes: 5 additions & 4 deletions images/dash0-instrumentation/preload/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LIB_LINKER_FLAGS ?= -nostdlib -rdynamic -shared -ldl
SRC_DIR := src
OBJ_DIR := obj
LIB_DIR := lib
LIB_NAME := $(LIB_DIR)/libdash0envhook_$(ARCH).so
TEST_DIR := test
TESTBIN_DIR := testbin/$(ARCH)
SRC_EXT := c
Expand All @@ -21,16 +22,16 @@ OBJECTS :=$(patsubst %,$(OBJ_DIR)/%.o,$(NAMES))
TEST_NAMES := $(notdir $(basename $(wildcard $(TEST_DIR)/*.$(SRC_EXT))))
TEST_OBJECTS :=$(patsubst %,$(TESTBIN_DIR)/%.o,$(TEST_NAMES))

all: $(LIB_DIR)/libdash0envhook.so
all: $(LIB_NAME)

$(LIB_DIR)/libdash0envhook.so: $(OBJECTS)
$(CC) $(CFLAGS) $(LIB_LINKER_FLAGS) $(OBJECTS) -o $(LIB_DIR)/libdash0envhook.so
$(LIB_NAME): $(OBJECTS)
$(CC) $(CFLAGS) $(LIB_LINKER_FLAGS) $(OBJECTS) -o $(LIB_NAME)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.$(SRC_EXT)
$(CC) -c -fPIC $^ -o $@ $(DEBUG) $(CFLAGS) $(LIBS)

clean: clean-test
@rm -f $(OBJECTS) $(LIB_DIR)/libdash0envhook.so
@rm -f $(OBJECTS) $(LIB_NAME)

clean-test:
@rm -f $(TEST_OBJECTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ else
fi

dockerfile_name=docker/Dockerfile-build
image_name=dash0-env-hook-builder
image_name=dash0-env-hook-builder-$ARCH
container_name=$image_name

docker_run_extra_arguments=""
Expand All @@ -34,16 +34,18 @@ echo
echo
echo ">>> Building the library on $ARCH <<<"

docker rm -f "$container_name"
docker rm -f "$container_name" 2> /dev/null

# Note: This is not the multi-platform image that we will need eventually. The combination of docker build and docker
# run here basically only builds the library binary for the given CPU architecture and places it in the lib folder. And
# since the lib folder is mounted, the binary is then available in the host file system for further testing (for
# example, via other container images using a specific CPU architecture).
docker build \
--platform "$docker_platform" \
. \
-f "$dockerfile_name" \
-t "$image_name"

# note: building one image for both platforms is not supported by Docker desktop's standard "docker build" command.
# docker build --platform linux/amd64,linux/arm64 . -f $dockerfile_name -t dash0-env-hook-builder-all-$LIBC

docker run \
--platform "$docker_platform" \
--name "$container_name" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ if [ "${INTERACTIVE:-}" = "true" ]; then
fi

echo
echo
echo ">>> Testing the library on $ARCH and $LIBC <<<"
echo ---------------------------------------
echo "testing the library on $ARCH and $LIBC"
echo ---------------------------------------

docker rm -f "$container_name"
docker build \
Expand Down
42 changes: 37 additions & 5 deletions images/dash0-instrumentation/preload/scripts/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,44 @@

set -eu

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

cd "$(dirname "$0")"/..

scripts/build-in-container.sh
ARCH=arm64 scripts/build-in-container.sh
ARCH=x86_64 scripts/build-in-container.sh

exit_code=0
summary=""

run_tests_for_architecture_and_libc_flavor() {
arch=$1
libc=$2
set +e
ARCH=$arch LIBC=$libc scripts/run-tests-in-container.sh
test_exit_code=$?
set -e
echo
echo ---------------------------------------
if [ $test_exit_code != 0 ]; then
printf "${RED}tests for %s/%s failed (see above for details)${NC}\n" "$arch" "$libc"
exit_code=1
summary="$summary\n$arch/$libc:\tfailed"
else
printf "${GREEN}tests for %s/%s were successful${NC}\n" "$arch" "$libc"
summary="$summary\n$arch/$libc:\tok"
fi
echo ---------------------------------------
echo
}

run_tests_for_architecture_and_libc_flavor arm64 glibc
run_tests_for_architecture_and_libc_flavor x86_64 glibc
run_tests_for_architecture_and_libc_flavor arm64 musl
run_tests_for_architecture_and_libc_flavor x86_64 musl

ARCH=arm64 LIBC=glibc scripts/run-tests-in-container.sh
ARCH=x86_64 LIBC=glibc scripts/run-tests-in-container.sh
ARCH=arm64 LIBC=musl scripts/run-tests-in-container.sh
ARCH=x86_64 LIBC=musl scripts/run-tests-in-container.sh
echo "$summary"
exit $exit_code

12 changes: 6 additions & 6 deletions images/dash0-instrumentation/preload/test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ if [ -z "${EXPECTED_CPU_ARCHITECTURE:-}" ]; then
exit 1
fi

arch_output=$(uname -m)
arch=$(uname -m)
arch_exit_code=$?
if [ $arch_exit_code != 0 ]; then
printf "${RED}verifying CPU architecture failed:${NC}\n"
echo "exit code: $arch_exit_code"
echo "output: $arch_output"
echo "output: $arch"
exit 1
elif [ "$arch_output" != "$EXPECTED_CPU_ARCHITECTURE" ]; then
elif [ "$arch" != "$EXPECTED_CPU_ARCHITECTURE" ]; then
printf "${RED}verifying CPU architecture failed:${NC}\n"
echo "expected: $EXPECTED_CPU_ARCHITECTURE"
echo "actual: $arch_output"
echo "actual: $arch"
exit 1
else
printf "${GREEN}verifying CPU architecture %s successful${NC}\n" "$EXPECTED_CPU_ARCHITECTURE"
fi

preload_lib=$directory/lib/libdash0envhook.so
preload_lib=$directory/lib/libdash0envhook_$arch.so
if [ ! -f $preload_lib ]; then
printf "${RED}error: $preload_lib does not exist, not running any tests.${NC}\n"
exit 1
fi

appundertest=testbin/"${arch_output}"/appundertest.o
appundertest=testbin/"${arch}"/appundertest.o
echo appundertest: $appundertest

run_test_case() {
Expand Down

0 comments on commit 3765925

Please sign in to comment.