FIX: Adding init for SPIDEV_0 (#14134)
[betaflight.git] / src / test / Makefile
blobc4d12bf92910aabaf6cf1175af853a1cc3eed6dd
1 # A sample Makefile for building Google Test and using it in user
2 # A sample Makefile for building Google Test and using it in user
3 # tests. Please tweak it to suit your environment and project. You
4 # may want to move it to your project's root directory.
6 # SYNOPSIS:
8 # make [all] - makes everything.
9 # make TARGET - makes the given target.
10 # make clean - removes all files generated by make.
13 # Where to find user code.
14 USER_DIR = ../main
15 TEST_DIR = unit
16 ROOT = ../..
17 OBJECT_DIR = $(ROOT)/obj/test
18 TARGET_DIR = $(USER_DIR)/target
19 MAKE_SCRIPT_DIR := $(ROOT)/mk
21 include $(MAKE_SCRIPT_DIR)/system-id.mk
23 VPATH := $(VPATH):$(USER_DIR):$(TEST_DIR)
25 # specify which files that are included in the test in addition to the unittest file.
26 # variables available:
27 # <test_name>_SRC
28 # <test_name>_DEFINES
29 # <test_name>_INCLUDE_DIRS
30 # <test_name>_EXPAND (run for each target, call the above with target as $1)
31 # <test_name>_BLACKLIST (targets to exclude from an expanded test's run)
33 alignsensor_unittest_SRC := \
34 $(USER_DIR)/sensors/boardalignment.c \
35 $(USER_DIR)/common/sensor_alignment.c \
36 $(USER_DIR)/common/maths.c \
37 $(USER_DIR)/common/vector.c
39 althold_unittest_SRC := \
40 $(USER_DIR)/flight/alt_hold_multirotor.c \
41 $(USER_DIR)/flight/autopilot_multirotor.c \
42 $(USER_DIR)/common/maths.c \
43 $(USER_DIR)/common/vector.c \
44 $(USER_DIR)/common/filter.c \
45 $(USER_DIR)/pg/rx.c
47 althold_unittest_DEFINES := \
48 USE_ALTITUDE_HOLD= \
50 arming_prevention_unittest_SRC := \
51 $(USER_DIR)/common/bitarray.c \
52 $(USER_DIR)/common/filter.c \
53 $(USER_DIR)/common/vector.c \
54 $(USER_DIR)/fc/core.c \
55 $(USER_DIR)/fc/dispatch.c \
56 $(USER_DIR)/fc/rc_controls.c \
57 $(USER_DIR)/fc/rc_modes.c \
58 $(USER_DIR)/fc/runtime_config.c \
59 $(USER_DIR)/flight/autopilot_multirotor.c \
60 $(USER_DIR)/flight/gps_rescue_multirotor.c
62 arming_prevention_unittest_DEFINES := \
63 USE_GPS_RESCUE=
65 atomic_unittest_SRC := \
66 $(USER_DIR)/build/atomic.c \
67 $(TEST_DIR)/atomic_unittest_c.c
69 baro_bmp085_unittest_SRC := \
70 $(USER_DIR)/drivers/barometer/barometer_bmp085.c
72 baro_bmp085_unittest_DEFINES := \
73 USE_BARO_BMP085=
75 baro_bmp280_unittest_SRC := \
76 $(USER_DIR)/drivers/barometer/barometer_bmp280.c
78 baro_bmp280_unittest_DEFINES := \
79 USE_BARO_BMP280= \
80 USE_BARO_SPI_BMP280=
82 baro_bmp388_unittest_SRC := \
83 $(USER_DIR)/common/maths.c \
84 $(USER_DIR)/drivers/barometer/barometer_bmp388.c
86 baro_bmp388_unittest_DEFINES := \
87 USE_EXTI= \
88 USE_BARO_BMP388= \
89 USE_BARO_SPI_BMP388=
91 baro_ms5611_unittest_SRC := \
92 $(USER_DIR)/drivers/barometer/barometer_ms5611.c
94 baro_ms5611_unittest_DEFINES := \
95 USE_BARO_MS5611= \
96 USE_BARO_SPI_MS5611=
98 # This test is disabled due to build errors.
99 # Its source code is archived in unit/battery_unittest.cc.txt
101 #battery_unittest_SRC := \
102 # $(USER_DIR)/sensors/battery.c \
103 # $(USER_DIR)/common/maths.c
106 blackbox_unittest_SRC := \
107 $(USER_DIR)/blackbox/blackbox.c \
108 $(USER_DIR)/blackbox/blackbox_encoding.c \
109 $(USER_DIR)/blackbox/blackbox_io.c \
110 $(USER_DIR)/common/encoding.c \
111 $(USER_DIR)/common/printf.c \
112 $(USER_DIR)/common/maths.c \
113 $(USER_DIR)/common/typeconversion.c \
114 $(USER_DIR)/drivers/accgyro/gyro_sync.c \
115 $(USER_DIR)/pg/gps.c
117 blackbox_encoding_unittest_SRC := \
118 $(USER_DIR)/blackbox/blackbox_encoding.c \
119 $(USER_DIR)/common/encoding.c \
120 $(USER_DIR)/common/printf.c \
121 $(USER_DIR)/common/typeconversion.c
123 cli_unittest_SRC := \
124 $(USER_DIR)/cli/cli.c \
125 $(USER_DIR)/common/crc.c \
126 $(USER_DIR)/common/printf.c \
127 $(USER_DIR)/common/streambuf.c \
128 $(USER_DIR)/common/maths.c \
129 $(USER_DIR)/common/gps_conversion.c \
130 $(USER_DIR)/config/feature.c \
131 $(USER_DIR)/io/gps.c \
132 $(USER_DIR)/io/serial_resource.c \
133 $(USER_DIR)/pg/pg.c \
134 $(USER_DIR)/fc/runtime_config.c \
135 $(USER_DIR)/drivers/serial.c \
136 $(USER_DIR)/drivers/serial_impl.c \
137 $(USER_DIR)/common/typeconversion.c
139 cli_unittest_DEFINES := \
140 USE_OSD= \
141 USE_CLI= \
142 SystemCoreClock=1000000
144 cms_unittest_SRC := \
145 $(USER_DIR)/cms/cms.c \
146 $(USER_DIR)/cms/cms_menu_saveexit.c \
147 $(USER_DIR)/common/typeconversion.c \
148 $(USER_DIR)/drivers/display.c
151 common_filter_unittest_SRC := \
152 $(USER_DIR)/common/filter.c \
153 $(USER_DIR)/common/maths.c
156 encoding_unittest_SRC := \
157 $(USER_DIR)/common/encoding.c
160 flight_failsafe_unittest_SRC := \
161 $(USER_DIR)/common/bitarray.c \
162 $(USER_DIR)/fc/rc_modes.c \
163 $(USER_DIR)/fc/runtime_config.c \
164 $(USER_DIR)/flight/failsafe.c
166 flight_failsafe_unittest_DEFINES := \
167 USE_GPS_RESCUE=
170 flight_imu_unittest_SRC := \
171 $(USER_DIR)/common/bitarray.c \
172 $(USER_DIR)/common/maths.c \
173 $(USER_DIR)/common/vector.c \
174 $(USER_DIR)/common/filter.c \
175 $(USER_DIR)/config/feature.c \
176 $(USER_DIR)/fc/rc_modes.c \
177 $(USER_DIR)/flight/position.c \
178 $(USER_DIR)/flight/imu.c
181 flight_mixer_unittest := \
182 $(USER_DIR)/flight/mixer.c \
183 $(USER_DIR)/flight/servos.c \
184 $(USER_DIR)/common/maths.c
187 gps_conversion_unittest_SRC := \
188 $(USER_DIR)/common/gps_conversion.c
191 io_serial_unittest_SRC := \
192 $(USER_DIR)/io/serial.c \
193 $(USER_DIR)/io/serial_resource.c
196 ledstrip_unittest_SRC := \
197 $(USER_DIR)/common/bitarray.c \
198 $(USER_DIR)/fc/rc_modes.c \
199 $(USER_DIR)/io/ledstrip.c
201 ledstrip_unittest_DEFINES := \
202 USE_LED_STRIP=
205 maths_unittest_SRC := \
206 $(USER_DIR)/common/maths.c \
207 $(USER_DIR)/common/vector.c
210 motor_output_unittest_SRC := \
211 $(USER_DIR)/build/atomic.c \
212 $(USER_DIR)/drivers/dshot.c
214 motor_output_unittest_DEFINES := \
215 USE_DSHOT=
217 osd_unittest_SRC := \
218 $(USER_DIR)/osd/osd.c \
219 $(USER_DIR)/osd/osd_elements.c \
220 $(USER_DIR)/osd/osd_warnings.c \
221 $(USER_DIR)/common/filter.c \
222 $(USER_DIR)/common/maths.c \
223 $(USER_DIR)/common/printf.c \
224 $(USER_DIR)/common/time.c \
225 $(USER_DIR)/common/typeconversion.c \
226 $(USER_DIR)/common/vector.c \
227 $(USER_DIR)/drivers/display.c \
228 $(USER_DIR)/fc/runtime_config.c
230 osd_unittest_DEFINES := \
231 USE_OSD= \
232 USE_GPS= \
233 USE_RTC_TIME= \
234 USE_ADC_INTERNAL=
236 link_quality_unittest_SRC := \
237 $(USER_DIR)/osd/osd.c \
238 $(USER_DIR)/osd/osd_elements.c \
239 $(USER_DIR)/osd/osd_warnings.c \
240 $(USER_DIR)/common/bitarray.c \
241 $(USER_DIR)/common/crc.c \
242 $(USER_DIR)/common/maths.c \
243 $(USER_DIR)/common/printf.c \
244 $(USER_DIR)/common/streambuf.c \
245 $(USER_DIR)/common/time.c \
246 $(USER_DIR)/common/typeconversion.c \
247 $(USER_DIR)/common/vector.c \
248 $(USER_DIR)/drivers/display.c \
249 $(USER_DIR)/drivers/serial.c \
250 $(USER_DIR)/drivers/serial_impl.c \
251 $(USER_DIR)/fc/rc_modes.c \
252 $(USER_DIR)/fc/runtime_config.c \
253 $(USER_DIR)/pg/pg.c \
254 $(USER_DIR)/pg/rx.c \
255 $(USER_DIR)/rx/rx.c \
256 $(USER_DIR)/rx/crsf.c
258 link_quality_unittest_DEFINES := \
259 USE_OSD= \
260 USE_CRSF_LINK_STATISTICS= \
261 USE_RX_LINK_QUALITY_INFO=
263 pg_unittest_SRC := \
264 $(USER_DIR)/common/crc.c \
265 $(USER_DIR)/common/streambuf.c \
266 $(USER_DIR)/pg/pg.c
269 rc_controls_unittest_SRC := \
270 $(USER_DIR)/fc/rc_controls.c \
271 $(USER_DIR)/pg/pg.c \
272 $(USER_DIR)/common/bitarray.c \
273 $(USER_DIR)/common/crc.c \
274 $(USER_DIR)/common/maths.c \
275 $(USER_DIR)/common/streambuf.c \
276 $(USER_DIR)/fc/rc_adjustments.c \
277 $(USER_DIR)/fc/rc_modes.c
280 rx_crsf_unittest_SRC := \
281 $(USER_DIR)/rx/crsf.c \
282 $(USER_DIR)/common/crc.c \
283 $(USER_DIR)/common/printf.c \
284 $(USER_DIR)/common/typeconversion.c \
285 $(USER_DIR)/common/streambuf.c \
286 $(USER_DIR)/drivers/serial.c \
287 $(USER_DIR)/drivers/serial_impl.c
290 rx_ibus_unittest_SRC := \
291 $(USER_DIR)/rx/ibus.c
294 rx_ranges_unittest_SRC := \
295 $(USER_DIR)/common/bitarray.c \
296 $(USER_DIR)/common/crc.c \
297 $(USER_DIR)/common/maths.c \
298 $(USER_DIR)/common/streambuf.c \
299 $(USER_DIR)/fc/rc_modes.c \
300 $(USER_DIR)/rx/rx.c \
301 $(USER_DIR)/pg/pg.c \
302 $(USER_DIR)/pg/rx.c
305 rx_rx_unittest_SRC := \
306 $(USER_DIR)/rx/rx.c \
307 $(USER_DIR)/fc/rc_modes.c \
308 $(USER_DIR)/common/bitarray.c \
309 $(USER_DIR)/common/maths.c \
310 $(USER_DIR)/config/feature.c \
311 $(USER_DIR)/pg/rx.c
313 rx_sumd_unittest_SRC := \
314 $(USER_DIR)/common/crc.c \
315 $(USER_DIR)/common/streambuf.c \
316 $(USER_DIR)/rx/sumd.c
318 scheduler_unittest_SRC := \
319 $(USER_DIR)/scheduler/scheduler.c \
320 $(USER_DIR)/common/crc.c \
321 $(USER_DIR)/common/streambuf.c \
322 $(TEST_DIR)/scheduler_stubs.c
324 scheduler_unittest_DEFINES := \
325 USE_OSD=
327 sensor_gyro_unittest_SRC := \
328 $(USER_DIR)/sensors/gyro.c \
329 $(USER_DIR)/sensors/gyro_init.c \
330 $(USER_DIR)/sensors/boardalignment.c \
331 $(USER_DIR)/common/crc.c \
332 $(USER_DIR)/common/filter.c \
333 $(USER_DIR)/common/maths.c \
334 $(USER_DIR)/common/streambuf.c \
335 $(USER_DIR)/common/sensor_alignment.c \
336 $(USER_DIR)/common/vector.c \
337 $(USER_DIR)/drivers/accgyro/accgyro_virtual.c \
338 $(USER_DIR)/drivers/accgyro/gyro_sync.c \
339 $(USER_DIR)/pg/pg.c \
340 $(USER_DIR)/pg/gyrodev.c
342 telemetry_crsf_unittest_SRC := \
343 $(USER_DIR)/rx/crsf.c \
344 $(USER_DIR)/telemetry/crsf.c \
345 $(USER_DIR)/common/crc.c \
346 $(USER_DIR)/common/maths.c \
347 $(USER_DIR)/common/streambuf.c \
348 $(USER_DIR)/common/gps_conversion.c \
349 $(USER_DIR)/common/printf.c \
350 $(USER_DIR)/common/typeconversion.c \
351 $(USER_DIR)/fc/runtime_config.c
353 telemetry_crsf_unittest_DEFINES := \
354 FLASH_SIZE=128 \
355 __TARGET__="TEST" \
356 __REVISION__="revision"
359 telemetry_crsf_msp_unittest_SRC := \
360 $(USER_DIR)/rx/crsf.c \
361 $(USER_DIR)/build/atomic.c \
362 $(USER_DIR)/common/crc.c \
363 $(USER_DIR)/common/streambuf.c \
364 $(USER_DIR)/common/printf.c \
365 $(USER_DIR)/common/streambuf.c \
366 $(USER_DIR)/drivers/serial.c \
367 $(USER_DIR)/drivers/serial_impl.c \
368 $(USER_DIR)/common/typeconversion.c \
369 $(USER_DIR)/telemetry/crsf.c \
370 $(USER_DIR)/common/gps_conversion.c \
371 $(USER_DIR)/telemetry/msp_shared.c \
372 $(USER_DIR)/fc/runtime_config.c
374 telemetry_crsf_msp_unittest_DEFINES := \
375 USE_MSP_OVER_TELEMETRY=
378 telemetry_hott_unittest_SRC := \
379 $(USER_DIR)/telemetry/hott.c \
380 $(USER_DIR)/io/serial_resource.c \
381 $(USER_DIR)/common/gps_conversion.c
384 telemetry_ibus_unittest_SRC := \
385 $(USER_DIR)/telemetry/ibus_shared.c \
386 $(USER_DIR)/telemetry/ibus.c
388 transponder_ir_unittest_SRC := \
389 $(USER_DIR)/drivers/transponder_ir_ilap.c \
390 $(USER_DIR)/drivers/transponder_ir_arcitimer.c
392 ws2811_unittest_SRC := \
393 $(USER_DIR)/drivers/light_ws2811strip.c
395 huffman_unittest_SRC := \
396 $(USER_DIR)/common/huffman.c \
397 $(USER_DIR)/common/huffman_table.c
399 huffman_unittest_DEFINES := \
400 USE_HUFFMAN=
402 rcdevice_unittest_SRC := \
403 $(USER_DIR)/common/crc.c \
404 $(USER_DIR)/common/bitarray.c \
405 $(USER_DIR)/fc/rc_modes.c \
406 $(USER_DIR)/io/rcdevice.c \
407 $(USER_DIR)/io/rcdevice_cam.c \
408 $(USER_DIR)/pg/pg.c \
410 pid_unittest_SRC := \
411 $(USER_DIR)/common/crc.c \
412 $(USER_DIR)/common/filter.c \
413 $(USER_DIR)/common/maths.c \
414 $(USER_DIR)/common/pwl.c \
415 $(USER_DIR)/common/streambuf.c \
416 $(USER_DIR)/drivers/accgyro/gyro_sync.c \
417 $(USER_DIR)/fc/controlrate_profile.c \
418 $(USER_DIR)/fc/runtime_config.c \
419 $(USER_DIR)/flight/pid.c \
420 $(USER_DIR)/flight/pid_init.c \
421 $(USER_DIR)/pg/pg.c
423 pid_unittest_DEFINES := \
424 USE_ITERM_RELAX= \
425 USE_RC_SMOOTHING_FILTER= \
426 USE_ABSOLUTE_CONTROL= \
427 USE_LAUNCH_CONTROL= \
428 USE_FEEDFORWARD= \
429 USE_ADVANCED_TPA= \
431 rcdevice_unittest_DEFINES := \
432 USE_RCDEVICE=
434 vtx_unittest_SRC := \
435 $(USER_DIR)/fc/core.c \
436 $(USER_DIR)/fc/dispatch.c \
437 $(USER_DIR)/fc/rc_controls.c \
438 $(USER_DIR)/fc/rc_modes.c \
439 $(USER_DIR)/fc/runtime_config.c \
440 $(USER_DIR)/drivers/vtx_common.c \
441 $(USER_DIR)/drivers/vtx_table.c \
442 $(USER_DIR)/io/vtx_control.c \
443 $(USER_DIR)/io/vtx.c \
444 $(USER_DIR)/common/bitarray.c
446 vtx_unittest_DEFINES := \
447 USE_VTX_COMMON= \
448 USE_VTX_CONTROL= \
449 USE_VTX_SMARTAUDIO=
451 rx_spi_spektrum_unittest_SRC := \
452 $(USER_DIR)/rx/cyrf6936_spektrum.c
454 rx_spi_spektrum_unittest_DEFINES := \
455 USE_RX_SPI= \
456 USE_RX_SPEKTRUM=
458 rx_spi_expresslrs_unittest_SRC := \
459 $(USER_DIR)/pg/rx_spi_expresslrs.c \
460 $(USER_DIR)/rx/expresslrs_common.c \
461 $(USER_DIR)/rx/expresslrs.c \
462 $(USER_DIR)/build/atomic.c \
464 rx_spi_expresslrs_unittest_DEFINES := \
465 USE_RX_SPI= \
466 USE_RX_EXPRESSLRS= \
467 USE_RX_SX1280= \
468 USE_RX_SX127X= \
470 rx_spi_expresslrs_telemetry_unittest_SRC := \
471 $(USER_DIR)/rx/crsf.c \
472 $(USER_DIR)/telemetry/crsf.c \
473 $(USER_DIR)/common/crc.c \
474 $(USER_DIR)/common/maths.c \
475 $(USER_DIR)/common/streambuf.c \
476 $(USER_DIR)/common/gps_conversion.c \
477 $(USER_DIR)/common/printf.c \
478 $(USER_DIR)/common/typeconversion.c \
479 $(USER_DIR)/rx/expresslrs_telemetry.c \
480 $(USER_DIR)/build/atomic.c \
481 $(USER_DIR)/telemetry/msp_shared.c \
483 rx_spi_expresslrs_telemetry_unittest_DEFINES := \
484 USE_RX_EXPRESSLRS= \
485 USE_GPS= \
486 USE_MSP_OVER_TELEMETRY= \
488 vtx_msp_unittest_SRC := \
489 $(USER_DIR)/common/crc.c \
490 $(USER_DIR)/common/streambuf.c \
491 $(USER_DIR)/fc/runtime_config.c \
492 $(USER_DIR)/drivers/vtx_common.c \
493 $(USER_DIR)/drivers/vtx_table.c \
494 $(USER_DIR)/pg/vtx_table.c \
495 $(USER_DIR)/io/vtx_control.c \
496 $(USER_DIR)/io/vtx.c \
497 $(USER_DIR)/io/vtx_msp.c \
499 vtx_msp_unittest_DEFINES := \
500 USE_VTX_COMMON= \
501 USE_VTX_CONTROL= \
502 USE_VTX_TABLE= \
503 USE_VTX_MSP=
505 pwl_unittest_SRC := \
506 $(USER_DIR)/common/pwl.c
508 # Please tweak the following variable definitions as needed by your
509 # project, except GTEST_HEADERS, which you can use in your own targets
510 # but shouldn't modify.
512 # Points to the root of Google Test, relative to where this file is.
513 # Remember to tweak this if you move this file.
514 GTEST_DIR = ../../lib/test/gtest
516 # Use clang/clang++ by default
518 CC := clang-18
519 CXX := clang++-18
520 ifeq ($(and $(shell which $(CC) 2>/dev/null), $(shell which $(CXX) 2>/dev/null)),)
521 $(info Falling back to 'clang')
522 CC := clang
523 CXX := clang++
524 endif
526 OPTIMIZE = -O0
528 COMMON_FLAGS = \
529 -g -ggdb3 \
530 -Wall -Wextra \
531 $(OPTIMIZE) \
532 -DUNIT_TEST \
533 -isystem $(GTEST_DIR)/inc \
534 -MMD -MP \
535 -pipe
537 CC_VERSION = $(shell $(CC) -dumpversion)
538 CXX_VERSION = $(shell $(CXX) -dumpversion)
540 ifeq ($(shell $(CC) -v 2>&1 | grep -q "clang version" && echo "clang"),clang)
542 # Please revisit versions when new clang version arrive. Supported versions: { Linux / OSX: 7 - 18 }
543 CC_VERSION_MAJOR := $(firstword $(subst ., ,$(CC_VERSION)))
544 CC_VERSION_CHECK_MIN := 7
545 CC_VERSION_CHECK_MAX := 18
547 # c99-designator is fine, code is not expected to be clean C++
548 COMMON_FLAGS += -Wno-c99-designator
550 # no warning expected on clang
551 COMMON_FLAGS += -Werror
553 ifeq ($(shell expr $(CC_VERSION_MAJOR) \< $(CC_VERSION_CHECK_MIN) \| $(CC_VERSION_MAJOR) \> $(CC_VERSION_CHECK_MAX)),1)
554 $(error $(CC) $(CC_VERSION) is not supported. The officially supported version of clang is 'clang-18'. If this is not found, 'clang' is used as a fallback. The version of the compiler must be between $(CC_VERSION_CHECK_MIN) and $(CC_VERSION_CHECK_MAX).)
555 endif
557 COMMON_FLAGS += -fblocks
558 ifndef CYGWIN
559 ifneq ($(OSFAMILY), macosx)
560 LDFLAGS += -lBlocksRuntime
561 endif # !macosx
562 endif # !CYGWIN
564 else ifeq ($(shell $(CC) -v 2>&1 | grep -q "gcc version" && echo "gcc"),gcc)
566 $(warning warning: gcc/g++ support is experimental. For normal testing, clang is recommended)
568 # no -Werror, allow warning for gcc now
569 COMMON_FLAGS += -Wno-missing-field-initializers
571 endif # is clang / gcc
573 $(info CC version: $(shell $(CC) --version))
574 $(info CXX version: $(shell $(CXX) --version))
576 USE_PTHREAD = YES
577 USE_COVERAGE = YES
578 ifeq ($(OSFAMILY), macosx)
579 USE_PTHREAD =
580 endif
581 ifdef CYGWIN
582 USE_PTHREAD =
583 USE_COVERAGE =
584 endif
586 ifdef USE_PTHREAD
587 COMMON_FLAGS += -pthread
588 endif
590 # Flags passed to the C compiler.
591 C_FLAGS = $(COMMON_FLAGS) \
592 -std=gnu99
594 # Flags passed to the C++ compiler.
595 CXX_FLAGS = $(COMMON_FLAGS) \
596 -std=gnu++14
598 # Compiler flags for coverage instrumentation
599 ifdef USE_COVERAGE
600 COVERAGE_FLAGS := --coverage
601 endif
603 C_FLAGS += $(COVERAGE_FLAGS)
604 CXX_FLAGS += $(COVERAGE_FLAGS)
606 C_FLAGS += -D_GNU_SOURCE
608 # Set up the parameter group linker flags according to OS
609 ifeq ($(OSFAMILY), macosx)
610 LDFLAGS += -Wl,-map,$(OBJECT_DIR)/$@.map
611 else
612 LDFLAGS += -Wl,-T,$(TEST_DIR)/pg.ld -Wl,-Map,$(OBJECT_DIR)/$@.map
613 endif
615 # Gather up all of the tests.
616 TEST_SRCS = $(sort $(wildcard $(TEST_DIR)/*.cc))
617 TEST_BASENAMES = $(TEST_SRCS:$(TEST_DIR)/%.cc=%)
618 TESTS_TARGET_SPECIFIC = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),$(test)))
620 TESTS = $(foreach test,$(TEST_BASENAMES),$(if $($(test)_EXPAND),,$(test)))
621 TESTS_ALL = $(TESTS)
623 # All Google Test headers. Usually you shouldn't change this
624 # definition.
625 GTEST_HEADERS = $(GTEST_DIR)/inc/gtest/*.h
627 ## V : Set verbosity level based on the V= parameter
628 ## V=0 Low
629 ## V=1 High
630 include $(MAKE_SCRIPT_DIR)/build_verbosity.mk
632 # House-keeping build targets.
634 ## test : Build and run the non target specific Unit Tests (default goal)
635 test: $(TESTS:%=test_%)
637 ## test-all : Build and run all Unit Tests
638 test-all: $(TESTS_ALL:%=test_%)
640 ## test-representative : Build and run a representative subset of the Unit Tests (i.e. run every expanded test only for the first target)
641 test-representative: $(TESTS_REPRESENTATIVE:%=test_%)
643 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
644 junittest: EXEC_OPTS = "--gtest_output=xml:$<_results.xml"
645 junittest: $(TESTS:%=test_%)
649 ## help : print this help message and exit
650 ## what : print this help message and exit
651 ## usage : print this help message and exit
652 help what usage: Makefile
653 @echo ""
654 @echo "Makefile for Unit Tests"
655 @echo ""
656 @echo "Usage:"
657 @echo " make [goal] "
658 @echo ""
659 @echo "Valid goals are:"
660 @echo ""
661 @sed -n 's/^## //p' $<
662 @echo ""
663 @echo "Any of the Unit Test programs can be used as goals to build:"
664 @$(foreach test, $(TESTS), echo " $(OBJECT_DIR)/$(test)/$(test)";)
665 @echo ""
666 @echo "Any of the Unit Test programs (except for target specific unit tests) can be used as goals to build and run:"
667 @$(foreach test, $(TESTS), echo " test_$(test)";)
669 versions:
670 @echo "C compiler: $(CC): $(CC_VERSION)"
671 @echo "C++ compiler: $(CXX): $(CXX_VERSION)"
673 ## clean : Cleanup the UnitTest binaries.
674 clean :
675 rm -rf $(OBJECT_DIR)
678 # Builds gtest.a and gtest_main.a.
680 # Usually you shouldn't tweak such internal variables, indicated by a
681 # trailing _.
682 GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/inc/gtest/*.h $(GTEST_HEADERS)
684 # For simplicity and to avoid depending on Google Test's
685 # implementation details, the dependencies specified below are
686 # conservative and not optimized. This is fine as Google Test
687 # compiles fast and for ordinary users its source rarely changes.
688 $(OBJECT_DIR)/gtest-all.o : $(GTEST_SRCS_)
689 @echo "compiling $@" "$(STDOUT)"
690 @mkdir -p $(dir $@)
691 $(V1) $(CXX) $(CXX_FLAGS) -I$(GTEST_DIR) -Wno-missing-field-initializers -Wno-unused-const-variable -c \
692 $(GTEST_DIR)/src/gtest-all.cc -o $@
694 $(OBJECT_DIR)/gtest_main.o : $(GTEST_SRCS_)
695 @echo "compiling $@" "$(STDOUT)"
696 @mkdir -p $(dir $@)
697 $(V1) $(CXX) $(CXX_FLAGS) -I$(GTEST_DIR) -c \
698 $(GTEST_DIR)/src/gtest_main.cc -o $@
700 $(OBJECT_DIR)/gtest.a : $(OBJECT_DIR)/gtest-all.o
701 @echo "linking $@" "$(STDOUT)"
702 $(V1) $(AR) $(ARFLAGS) $@ $^
704 $(OBJECT_DIR)/gtest_main.a : $(OBJECT_DIR)/gtest-all.o $(OBJECT_DIR)/gtest_main.o
705 @echo "linking $@" "$(STDOUT)"
706 $(V1) $(AR) $(ARFLAGS) $@ $^
708 -include $(OBJECT_DIR)/gtest-all.d \
709 $(OBJECT_DIR)/gtest_main.d
712 # includes in test dir must override includes in user dir, unless the user
713 # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
714 test_include_dirs = $1 $(TEST_DIR) $(USER_DIR)
715 test_cflags = $(addprefix -I,$(call test_include_dirs,$1))
718 # target name extractor
719 # param $1 = expanded test name in the form of test.target
720 target = $(1:$(basename $1).%=%)
722 # canned recipe for all test builds
724 # variable expansion rules of thumb (number of $'s):
725 # * parameters: one $, e.g. $1
726 # * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
727 # * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
728 # * make functions accessing only the above: one $, e.g. $(basename $1)
729 # * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
730 # * make functions accessing dynamically set variables: two $,
731 # e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
733 # param $1 = plain test name for global tests, test.target for per-target tests
734 define test-specific-stuff
736 ifeq ($1,$(basename $1))
737 # standard global test
738 $1_OBJS = $(patsubst \
739 $(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$(patsubst \
740 $(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$($1_SRC:=.o)))
741 else
742 # test executed for each target, $1 has the form of test.target
743 $1_SRC = $(addsuffix .o,$(call $(basename $1)_SRC,$(call target,$1)))
744 $1_OBJS = $$(patsubst \
745 $(TEST_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
746 $(USER_DIR)/%,$(OBJECT_DIR)/$1/%,$$(patsubst \
747 $(TARGET_DIR)/$(TARGET)/%,$(OBJECT_DIR)/$1/%,$$($1_SRC))))
748 $1_DEFINES = $(call $(basename $1)_DEFINES,$(call target,$1))
749 $1_INCLUDE_DIRS = $(call $(basename $1)_INCLUDE_DIRS,$(call target,$1))
750 endif
752 # $$(info $1 -v-v-------)
753 # $$(info $1_SRC: $$($1_SRC))
754 # $$(info $1_OBJS: $$($1_OBJS))
755 # $$(info $1 -^-^-------)
757 # include generated dependencies
758 -include $$($1_OBJS:.o=.d)
759 -include $(OBJECT_DIR)/$1/$(basename $1).d
761 $(OBJECT_DIR)/$1/%.c.o: $(USER_DIR)/%.c
762 @echo "compiling $$<" "$(STDOUT)"
763 $(V1) mkdir -p $$(dir $$@)
764 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
765 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
766 -c $$< -o $$@
768 $(OBJECT_DIR)/$1/%.c.o: $(TEST_DIR)/%.c
769 @echo "compiling test c file: $$<" "$(STDOUT)"
770 $(V1) mkdir -p $$(dir $$@)
771 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
772 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
773 -c $$< -o $$@
775 ifneq ($1,$(basename $1))
776 # per-target tests may compile files from the target directory
777 $(OBJECT_DIR)/$1/%.c.o: $(TARGET_DIR)/$(TARGET)/%.c
778 @echo "compiling target c file: $$<" "$(STDOUT)"
779 $(V1) mkdir -p $$(dir $$@)
780 $(V1) $(CC) $(C_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
781 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
782 -c $$< -o $$@
783 endif
785 $(OBJECT_DIR)/$1/$(basename $1).o: $(TEST_DIR)/$(basename $1).cc
786 @echo "compiling $$<" "$(STDOUT)"
787 $(V1) mkdir -p $$(dir $$@)
788 $(V1) $(CXX) $(CXX_FLAGS) $$(call test_cflags,$$($1_INCLUDE_DIRS)) \
789 $$(foreach def,$$($1_DEFINES),-D $$(def)) \
790 -c $$< -o $$@
792 $(OBJECT_DIR)/$1/$(basename $1): $$($1_OBJS) \
793 $(OBJECT_DIR)/$1/$(basename $1).o \
794 $(OBJECT_DIR)/gtest_main.a
796 @echo "linking $$@" "$(STDOUT)"
797 $(V1) mkdir -p $(dir $$@)
798 $(V1) $(CXX) $(CXX_FLAGS) $(LDFLAGS) $$^ -o $$@
800 test_$1: $(OBJECT_DIR)/$1/$(basename $1)
801 $(V1) $$< $$(EXEC_OPTS) "$(STDOUT)" && echo "running $$@: PASS"
803 endef
806 ifeq ($(MAKECMDGOALS),test-all)
807 $(eval $(foreach test,$(TESTS_ALL),$(call test-specific-stuff,$(test))))
808 else
809 ifeq ($(MAKECMDGOALS),test-representative)
810 $(eval $(foreach test,$(TESTS_REPRESENTATIVE),$(call test-specific-stuff,$(test))))
811 else
812 $(eval $(foreach test,$(TESTS),$(call test-specific-stuff,$(test))))
813 endif
814 endif
816 $(foreach test,$(TESTS_ALL),$(if $($(basename $(test))_SRC),,$(error \
817 Test 'unit/$(basename $(test)).cc' has no '$(basename $(test))_SRC' variable defined)))