@@ -28,7 +28,8 @@ SRC_FILES := $(wildcard src/*.cpp) $(wildcard inc/*.hpp) $(wildcard test/unit/*.
2828 build build-debug build-relwithdebinfo run run-debug profile flamegraph \
2929 test-unit test-unit-coverage test-service clean install-tools install-deps \
3030 run-image run-image-debug format-cpp lint-cpp format-python lint-python install-hooks \
31- lint-dockerfile lint-trivy lint-all coverage-html coverage-xml coverage-report
31+ lint-dockerfile lint-trivy lint-all coverage-html coverage-xml coverage-report \
32+ mqtt-subscribe mqtt-publish broker-start broker-stop generate-certs
3233
3334all : build
3435
@@ -81,6 +82,7 @@ install-hooks:
8182 @echo " Installing git pre-commit hook..."
8283 @mkdir -p ../.git/hooks
8384 @echo ' #!/bin/bash' > ../.git/hooks/pre-commit
85+ @echo ' set -e' >> ../.git/hooks/pre-commit
8486 @echo ' make prettier-check' >> ../.git/hooks/pre-commit
8587 @echo ' cd tracker && make lint-cpp && make lint-python && make lint-dockerfile' >> ../.git/hooks/pre-commit
8688 @chmod +x ../.git/hooks/pre-commit
@@ -173,11 +175,20 @@ build-relwithdebinfo: dependencies-relwithdebinfo
173175# Schema and config paths for local development
174176TRACKER_SCHEMA_PATH ?= $(CURDIR ) /schema/config.schema.json
175177TRACKER_CONFIG_PATH ?= $(CURDIR ) /config/tracker.json
178+
179+ # MQTT broker connection (auto-detect from test broker, fallback to 1883)
180+ export TRACKER_MQTT_HOST ?= localhost
181+ export TRACKER_MQTT_PORT ?= $(shell cd test/service && docker compose port broker 1883 2>/dev/null | cut -d : -f2 || echo 1883)
182+
183+ # Export empty proxy vars - Paho MQTT library fails with proxy env vars,
184+ # tracker code detects empty vars and unsets them (see mqtt_client.cpp)
176185run : build
177- . build/conanrun.sh && ./build/$(NAME ) --config $(TRACKER_CONFIG_PATH ) --schema $(TRACKER_SCHEMA_PATH )
186+ export http_proxy= https_proxy= HTTP_PROXY= HTTPS_PROXY= && \
187+ . build/conanrun.sh && ./build/$(NAME ) --config $(TRACKER_CONFIG_PATH ) --schema $(TRACKER_SCHEMA_PATH )
178188
179189run-debug : build-debug
180- . build-debug/conanrun.sh && ./build-debug/$(NAME ) --config $(TRACKER_CONFIG_PATH ) --schema $(TRACKER_SCHEMA_PATH )
190+ export http_proxy= https_proxy= HTTP_PROXY= HTTPS_PROXY= && \
191+ . build-debug/conanrun.sh && ./build-debug/$(NAME ) --config $(TRACKER_CONFIG_PATH ) --schema $(TRACKER_SCHEMA_PATH )
181192
182193# Profile with perf using optimized build with debug symbols.
183194# Requires perf permissions. If you see "Error: Failure to open event", run:
@@ -238,6 +249,7 @@ coverage-html:
238249 ' */external/*' \
239250 ' */third_party/*' \
240251 ' */src/main.cpp' \
252+ ' */src/mqtt_client.cpp' \
241253 --output-file build-debug/coverage/coverage-filtered.info \
242254 --rc branch_coverage=1 \
243255 --ignore-errors unused \
@@ -267,6 +279,7 @@ coverage-xml:
267279 --exclude ' .*external.*' \
268280 --exclude ' .*third_party.*' \
269281 --exclude ' .*main\.cpp' \
282+ --exclude ' .*mqtt_client\.cpp' \
270283 --xml-pretty \
271284 --xml build-debug/coverage/coverage.xml \
272285 --exclude-unreachable-branches \
@@ -291,6 +304,7 @@ coverage-report:
291304 --exclude ' .*external.*' \
292305 --exclude ' .*third_party.*' \
293306 --exclude ' .*main\.cpp' \
307+ --exclude ' .*mqtt_client\.cpp' \
294308 --exclude-unreachable-branches \
295309 --print-summary \
296310 --fail-under-line 90.0 \
@@ -305,7 +319,8 @@ test-service: build-image
305319 @test/service/.venv/bin/pip install -q --upgrade pip
306320 @test/service/.venv/bin/pip install -q -r test/service/requirements.txt
307321 @echo " Running service tests..."
308- cd test/service && .venv/bin/pytest -v --tb=short
322+ unset TRACKER_MQTT_PORT TRACKER_MQTT_HOST TRACKER_MQTT_INSECURE && \
323+ cd test/service && .venv/bin/pytest -v --tb=short
309324
310325# ####################################################################
311326# Docker build targets
@@ -324,8 +339,11 @@ build-image-debug:
324339build-image-relwithdebinfo :
325340 $(MAKE ) build-image TARGET=runtime BUILD_TYPE=RelWithDebInfo IMAGE=scenescape-tracker-relwithdebinfo
326341
342+ # Use host network to reach broker on localhost; empty proxy vars for Paho workaround
327343run-image : build-image
328- docker run --rm -it $(IMAGE ) :$(VERSION )
344+ docker run --rm -it --network=host \
345+ -e http_proxy= -e https_proxy= -e HTTP_PROXY= -e HTTPS_PROXY= \
346+ $(IMAGE ) :$(VERSION )
329347
330348run-image-debug : build-image-debug
331349 -docker stop tracker-debug 2> /dev/null || true
@@ -339,12 +357,58 @@ stop-image-debug:
339357 -docker stop tracker-debug 2> /dev/null || true
340358 -docker rm tracker-debug 2> /dev/null || true
341359
360+ # ####################################################################
361+ # MQTT Broker Management
362+ # ####################################################################
363+
364+ # Certificate paths for broker TLS
365+ CERTS_DIR := $(CURDIR ) /test/service/.certs
366+ ENV_FILE := $(CURDIR ) /test/service/.env
367+
368+ generate-certs :
369+ @if [ ! -f " $( CERTS_DIR) /ca.crt" ]; then \
370+ echo " Generating TLS certificates..." ; \
371+ python3 -m venv test/service/.venv 2> /dev/null || true ; \
372+ test/service/.venv/bin/pip install -q cryptography; \
373+ cd test/service && .venv/bin/python3 -m utils.generate_certs \
374+ $(CERTS_DIR ) --env-file $(ENV_FILE ) ; \
375+ else \
376+ echo " ✓ Certificates already exist in $( CERTS_DIR) " ; \
377+ fi
378+
379+ broker-start : generate-certs
380+ @cd test/service && docker compose up -d broker
381+ @sleep 1
382+ @echo " ✓ Broker running on port $$ (cd test/service && docker compose port broker 1883 | cut -d: -f2)"
383+
384+ broker-stop :
385+ @cd test/service && docker compose down
386+ @echo " ✓ Broker stopped"
387+
388+ # ####################################################################
389+ # MQTT Manual Testing
390+ # ####################################################################
391+
392+ MQTT_DETECTION_TOPIC := scenescape/data/camera/test-cam
393+ MQTT_TRACK_TOPIC := scenescape/data/scene/\#
394+
395+ mqtt-subscribe :
396+ @echo " Subscribing to tracks on $( TRACKER_MQTT_HOST) :$( TRACKER_MQTT_PORT) ..."
397+ mosquitto_sub -h $(TRACKER_MQTT_HOST ) -p $(TRACKER_MQTT_PORT ) -t ' $(MQTT_TRACK_TOPIC)' -v
398+
399+ mqtt-publish :
400+ @echo " Publishing detection to $( TRACKER_MQTT_HOST) :$( TRACKER_MQTT_PORT) ..."
401+ mosquitto_pub -h $(TRACKER_MQTT_HOST ) -p $(TRACKER_MQTT_PORT ) -t ' $(MQTT_DETECTION_TOPIC)' \
402+ -m ' {"id":"test-cam","timestamp":"$(shell date -u +%Y-%m-%dT%H:%M:%S.000Z)","objects":{"person":[{"bounding_box_px":{"x":100,"y":50,"width":80,"height":200}}]}}'
403+ @echo " ✓ Detection published"
404+
342405# ####################################################################
343406# Clean targets
344407# ####################################################################
345408
346409# Override common.mk clean to also remove local build directories
347410clean :
348- rm -rf build* test/service/.venv .pytest_cache
411+ -@cd test/service && docker compose down 2> /dev/null || true
412+ rm -rf build* test/service/.venv test/service/.certs test/service/.env .pytest_cache
349413 -docker rmi $(IMAGE ) :$(VERSION ) $(IMAGE ) :latest 2> /dev/null || true
350414 -rm -f $(BUILD_DIR ) /$(IMAGE ) -* deps.txt $(LOG_FILE ) 2> /dev/null || true
0 commit comments