From 17baf1647fab2cea3407f6a5aeaa7a6f7ec80430 Mon Sep 17 00:00:00 2001 From: Siyuan Miao Date: Fri, 16 May 2025 20:30:41 +0200 Subject: [PATCH] chore: append package name to build script --- Makefile | 19 +++++++++++-------- dev_deploy.sh | 18 +++++++++++++++--- resource/dev_test.sh | 8 ++++++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 0c9bdbf..0b0b060 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ GO_LDFLAGS := \ -X $(PROMETHEUS_TAG).Revision=$(REVISION) \ -X $(KVM_PKG_NAME).builtTimestamp=$(BUILDTS) +TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort -u) + hash_resource: @shasum -a 256 resource/jetkvm_native | cut -d ' ' -f 1 > resource/jetkvm_native.sha256 @@ -29,16 +31,17 @@ build_dev_test: build_test2json # collect all directories that contain tests @echo "Building tests for devices ..." @rm -rf bin/tests && mkdir -p bin/tests - GOOS=linux GOARCH=arm GOARM=7 \ - go test -v \ - -ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION_DEV)" \ - -c -o bin/tests ./...; \ @cat resource/dev_test.sh > bin/tests/run_all_tests - @for test in bin/tests/*.test; do \ - chmod +x $$test; \ - base_name=$$(basename $$test); \ - echo "runTest ./$$base_name" >> bin/tests/run_all_tests; \ + @for test in $(TEST_DIRS); do \ + test_pkg_name=$$(echo $$test | sed 's/^.\///g'); \ + test_pkg_full_name=$(KVM_PKG_NAME)/$$(echo $$test | sed 's/^.\///g'); \ + test_filename=$$(echo $$test_pkg_name | sed 's/\//__/g')_test; \ + GOOS=linux GOARCH=arm GOARM=7 \ + go test -v \ + -ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION_DEV)" \ + -c -o bin/tests/$$test_filename $$test; \ + echo "runTest ./$$test_filename $$test_pkg_full_name" >> bin/tests/run_all_tests; \ done; \ chmod +x bin/tests/run_all_tests; \ cp bin/test2json bin/tests/; \ diff --git a/dev_deploy.sh b/dev_deploy.sh index 03e5dd9..466acc7 100755 --- a/dev_deploy.sh +++ b/dev_deploy.sh @@ -41,7 +41,7 @@ SKIP_UI_BUILD=false RESET_USB_HID_DEVICE=false LOG_TRACE_SCOPES="${LOG_TRACE_SCOPES:-jetkvm,cloud,websocket,native,jsonrpc}" RUN_GO_TESTS=false - +RUN_GO_TESTS_JSON=false # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in @@ -65,6 +65,10 @@ while [[ $# -gt 0 ]]; do RUN_GO_TESTS=true shift ;; + --run-go-tests-json) + RUN_GO_TESTS_JSON=true + shift + ;; --help) show_help exit 0 @@ -77,6 +81,10 @@ while [[ $# -gt 0 ]]; do esac done +if [ "$RUN_GO_TESTS_JSON" = true ]; then + RUN_GO_TESTS=true +fi + # Verify required parameters if [ -z "$REMOTE_HOST" ]; then msg_err "Error: Remote IP is a required parameter" @@ -101,11 +109,15 @@ if [ "$RUN_GO_TESTS" = true ]; then ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > ${REMOTE_PATH}/device-tests.tar.gz" < device-tests.tar.gz msg_info "▶ Running go tests" + TEST_ARGS="" + if [ "$RUN_GO_TESTS_JSON" = true ]; then + TEST_ARGS="-json" + fi ssh "${REMOTE_USER}@${REMOTE_HOST}" ash << EOF set -e cd ${REMOTE_PATH} tar zxvf device-tests.tar.gz -./run_all_tests -test.v +./run_all_tests $TEST_ARGS EOF fi @@ -113,7 +125,7 @@ fi ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true" # Copy the binary to the remote host -ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > ${REMOTE_PATH}/jetkvm_app_debug" < jetkvm_app_debug +ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > ${REMOTE_PATH}/jetkvm_app_debug" < bin/jetkvm_app if [ "$RESET_USB_HID_DEVICE" = true ]; then # Remove the old USB gadget configuration diff --git a/resource/dev_test.sh b/resource/dev_test.sh index 151dc16..ce152aa 100644 --- a/resource/dev_test.sh +++ b/resource/dev_test.sh @@ -1,5 +1,6 @@ #!/bin/sh JSON_OUTPUT=false +GET_COMMANDS=false if [ "$1" = "-json" ]; then JSON_OUTPUT=true shift @@ -8,8 +9,12 @@ ADDITIONAL_ARGS=$@ EXIT_CODE=0 runTest() { + PKG_ARGS="" + if [ "$2" != "" ]; then + PKG_ARGS="-p $2" + fi if [ "$JSON_OUTPUT" = true ]; then - ./test2json $1 -test.v $ADDITIONAL_ARGS | tee $1.result.json + ./test2json $PKG_ARGS -t $1 -test.v $ADDITIONAL_ARGS | tee $1.result.json if [ $? -ne 0 ]; then EXIT_CODE=1 fi @@ -21,7 +26,6 @@ runTest() { fi } - function exit_with_code() { if [ $EXIT_CODE -ne 0 ]; then printf "\e[0;31m❌ Test failed\e[0m\n"