diff --git a/images/dash0-instrumentation/preload/Makefile b/images/dash0-instrumentation/preload/Makefile index 23915430..0617ed5a 100644 --- a/images/dash0-instrumentation/preload/Makefile +++ b/images/dash0-instrumentation/preload/Makefile @@ -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 @@ -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) diff --git a/images/dash0-instrumentation/preload/scripts/build-in-container.sh b/images/dash0-instrumentation/preload/scripts/build-in-container.sh index e03edfdd..a795c149 100755 --- a/images/dash0-instrumentation/preload/scripts/build-in-container.sh +++ b/images/dash0-instrumentation/preload/scripts/build-in-container.sh @@ -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="" @@ -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" \ diff --git a/images/dash0-instrumentation/preload/scripts/run-tests-in-container.sh b/images/dash0-instrumentation/preload/scripts/run-tests-in-container.sh index 8f5419c2..b8ffc215 100755 --- a/images/dash0-instrumentation/preload/scripts/run-tests-in-container.sh +++ b/images/dash0-instrumentation/preload/scripts/run-tests-in-container.sh @@ -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 \ diff --git a/images/dash0-instrumentation/preload/scripts/test-all.sh b/images/dash0-instrumentation/preload/scripts/test-all.sh index af878dcb..80beed77 100755 --- a/images/dash0-instrumentation/preload/scripts/test-all.sh +++ b/images/dash0-instrumentation/preload/scripts/test-all.sh @@ -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 diff --git a/images/dash0-instrumentation/preload/test/run-tests.sh b/images/dash0-instrumentation/preload/test/run-tests.sh index 77200ff2..e575bb82 100755 --- a/images/dash0-instrumentation/preload/test/run-tests.sh +++ b/images/dash0-instrumentation/preload/test/run-tests.sh @@ -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() {