chore: append package name to build script

This commit is contained in:
Siyuan Miao 2025-05-16 20:30:41 +02:00
parent 840743fcf7
commit 17baf1647f
3 changed files with 32 additions and 13 deletions

View File

@ -15,6 +15,8 @@ GO_LDFLAGS := \
-X $(PROMETHEUS_TAG).Revision=$(REVISION) \ -X $(PROMETHEUS_TAG).Revision=$(REVISION) \
-X $(KVM_PKG_NAME).builtTimestamp=$(BUILDTS) -X $(KVM_PKG_NAME).builtTimestamp=$(BUILDTS)
TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort -u)
hash_resource: hash_resource:
@shasum -a 256 resource/jetkvm_native | cut -d ' ' -f 1 > resource/jetkvm_native.sha256 @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 # collect all directories that contain tests
@echo "Building tests for devices ..." @echo "Building tests for devices ..."
@rm -rf bin/tests && mkdir -p bin/tests @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 @cat resource/dev_test.sh > bin/tests/run_all_tests
@for test in bin/tests/*.test; do \ @for test in $(TEST_DIRS); do \
chmod +x $$test; \ test_pkg_name=$$(echo $$test | sed 's/^.\///g'); \
base_name=$$(basename $$test); \ test_pkg_full_name=$(KVM_PKG_NAME)/$$(echo $$test | sed 's/^.\///g'); \
echo "runTest ./$$base_name" >> bin/tests/run_all_tests; \ 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; \ done; \
chmod +x bin/tests/run_all_tests; \ chmod +x bin/tests/run_all_tests; \
cp bin/test2json bin/tests/; \ cp bin/test2json bin/tests/; \

View File

@ -41,7 +41,7 @@ SKIP_UI_BUILD=false
RESET_USB_HID_DEVICE=false RESET_USB_HID_DEVICE=false
LOG_TRACE_SCOPES="${LOG_TRACE_SCOPES:-jetkvm,cloud,websocket,native,jsonrpc}" LOG_TRACE_SCOPES="${LOG_TRACE_SCOPES:-jetkvm,cloud,websocket,native,jsonrpc}"
RUN_GO_TESTS=false RUN_GO_TESTS=false
RUN_GO_TESTS_JSON=false
# Parse command line arguments # Parse command line arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
@ -65,6 +65,10 @@ while [[ $# -gt 0 ]]; do
RUN_GO_TESTS=true RUN_GO_TESTS=true
shift shift
;; ;;
--run-go-tests-json)
RUN_GO_TESTS_JSON=true
shift
;;
--help) --help)
show_help show_help
exit 0 exit 0
@ -77,6 +81,10 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
if [ "$RUN_GO_TESTS_JSON" = true ]; then
RUN_GO_TESTS=true
fi
# Verify required parameters # Verify required parameters
if [ -z "$REMOTE_HOST" ]; then if [ -z "$REMOTE_HOST" ]; then
msg_err "Error: Remote IP is a required parameter" 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 ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > ${REMOTE_PATH}/device-tests.tar.gz" < device-tests.tar.gz
msg_info "▶ Running go tests" 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 ssh "${REMOTE_USER}@${REMOTE_HOST}" ash << EOF
set -e set -e
cd ${REMOTE_PATH} cd ${REMOTE_PATH}
tar zxvf device-tests.tar.gz tar zxvf device-tests.tar.gz
./run_all_tests -test.v ./run_all_tests $TEST_ARGS
EOF EOF
fi fi
@ -113,7 +125,7 @@ fi
ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true" ssh "${REMOTE_USER}@${REMOTE_HOST}" "killall jetkvm_app_debug || true"
# Copy the binary to the remote host # 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 if [ "$RESET_USB_HID_DEVICE" = true ]; then
# Remove the old USB gadget configuration # Remove the old USB gadget configuration

View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
JSON_OUTPUT=false JSON_OUTPUT=false
GET_COMMANDS=false
if [ "$1" = "-json" ]; then if [ "$1" = "-json" ]; then
JSON_OUTPUT=true JSON_OUTPUT=true
shift shift
@ -8,8 +9,12 @@ ADDITIONAL_ARGS=$@
EXIT_CODE=0 EXIT_CODE=0
runTest() { runTest() {
PKG_ARGS=""
if [ "$2" != "" ]; then
PKG_ARGS="-p $2"
fi
if [ "$JSON_OUTPUT" = true ]; then 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 if [ $? -ne 0 ]; then
EXIT_CODE=1 EXIT_CODE=1
fi fi
@ -21,7 +26,6 @@ runTest() {
fi fi
} }
function exit_with_code() { function exit_with_code() {
if [ $EXIT_CODE -ne 0 ]; then if [ $EXIT_CODE -ne 0 ]; then
printf "\e[0;31m❌ Test failed\e[0m\n" printf "\e[0;31m❌ Test failed\e[0m\n"