test_unit.mk (4949B)
1 # mk/test_unit.mk — build rules for the C unit-test binaries. 2 # 3 # Included by mk/test.mk. Replaces the hand-written per-binary rules (each a 4 # $(CC) ... SRC $(LIB_AR|LIB_OBJS) -o $@ triple) with two static-pattern rules, 5 # one per regime. Registering a unit test is two lines: add its stem to a list 6 # and set <stem>_SRC. Run-targets (test-isa, test-cg-api, ...) stay in mk/test.mk 7 # and invoke build/test/<stem> directly, so per-binary sequencing and skip 8 # semantics (e.g. rv64-jit's exit-77 wrapper) are unchanged. 9 # 10 # Two regimes, by the interface under test. We prefer tests that exercise the 11 # PUBLIC interface — keep a test public unless it genuinely needs internals. 12 # 13 # PUBLIC public headers only (-Iinclude), linked against the public 14 # archive libkit.a. Internal (visibility-hidden) symbols are 15 # unreachable, so these prove the public surface is self-sufficient. 16 # INTERNAL additionally sees src/ internal headers (-Isrc) and links the raw 17 # objects (LIB_OBJS), exposing internal symbols. For units that have 18 # no public API (ISA tables, ABI classifier, IR/opt internals, ...). 19 # 20 # Both add -Itest so `#include "lib/kit_unit.h"` resolves; neither adds -Ilang 21 # (no unit test needs the frontend-private headers). emu_rv64_test is a 22 # deliberate exception kept in mk/test.mk — see the note there. 23 24 UNIT_HDR_DEPS := test/lib/kit_unit.h test/arch/inline_public_test.h 25 26 # Deferred (=) so they pick up HOST_CFLAGS regardless of include order. 27 UNIT_CFLAGS_PUBLIC = $(HOST_CFLAGS) -Iinclude -Itest 28 UNIT_CFLAGS_INTERNAL = $(HOST_CFLAGS) -Iinclude -Isrc -Itest 29 30 # ---- registrations: stem lists + per-stem source --------------------------- 31 32 UNIT_TESTS_PUBLIC := \ 33 ar_test target_test cg_api_test cg_switch_test cg_fp_cmp_test \ 34 cg_control_test hash_test \ 35 panic_recovery_test \ 36 rv64_jit_test rv32_jit_test aa64_inline_test rv64_inline_test x64_inline_test \ 37 strength_reduce_test 38 ar_test_SRC := test/ar/ar_test.c 39 target_test_SRC := test/api/target_test.c 40 hash_test_SRC := test/api/hash_test.c 41 panic_recovery_test_SRC := test/api/panic_recovery_test.c 42 cg_api_test_SRC := test/api/cg_type_test.c 43 cg_switch_test_SRC := test/api/cg_switch_test.c 44 cg_fp_cmp_test_SRC := test/api/cg_fp_cmp_test.c 45 cg_control_test_SRC := test/api/cg_control_test.c 46 strength_reduce_test_SRC := test/cg/strength_reduce_test.c 47 rv64_jit_test_SRC := test/link/rv64_jit_test.c 48 rv32_jit_test_SRC := test/link/rv32_jit_test.c 49 aa64_inline_test_SRC := test/arch/aa64_inline_test.c 50 rv64_inline_test_SRC := test/arch/rv64_inline_test.c 51 x64_inline_test_SRC := test/arch/x64_inline_test.c 52 53 UNIT_TESTS_INTERNAL := \ 54 dwarf_test debug_roundtrip_unit debug_cfi_unit \ 55 aa64_isa_test rv64_decode_test rv32_decode_test aa64_sweep_gen \ 56 reloc_uleb128_unit reloc_desc_test reloc_apply_test emu_rv64_unit_test \ 57 interp_smoke_test jit_tls_relax_test coff_weak_alias_test \ 58 rv64_interp_smoke_test abi_classify_test ir_recorder_test \ 59 native_direct_target_test x64_dbg_test cg_ir_lower_test tiny_inline_test 60 dwarf_test_SRC := test/dwarf/dwarf_test.c 61 debug_roundtrip_unit_SRC := test/debug/roundtrip_unit.c 62 debug_cfi_unit_SRC := test/debug/cfi_unit.c 63 aa64_isa_test_SRC := test/arch/aa64_isa_test.c 64 rv64_decode_test_SRC := test/arch/rv64_decode_test.c 65 rv32_decode_test_SRC := test/arch/rv32_decode_test.c 66 aa64_sweep_gen_SRC := test/arch/aa64_sweep_gen.c 67 reloc_uleb128_unit_SRC := test/link/reloc_uleb128_unit.c 68 reloc_desc_test_SRC := test/link/reloc_desc_test.c 69 reloc_apply_test_SRC := test/link/reloc_apply_test.c 70 jit_tls_relax_test_SRC := test/link/jit_tls_relax_test.c 71 coff_weak_alias_test_SRC := test/link/coff_weak_alias_test.c 72 emu_rv64_unit_test_SRC := test/emu/rv64_vm_unit_test.c 73 interp_smoke_test_SRC := test/interp/interp_smoke_test.c 74 rv64_interp_smoke_test_SRC := test/emu/rv64_interp_smoke_test.c 75 abi_classify_test_SRC := test/api/abi_classify_test.c 76 ir_recorder_test_SRC := test/cg/ir_recorder_test.c 77 native_direct_target_test_SRC := test/cg/native_direct_target_test.c 78 x64_dbg_test_SRC := test/arch/x64_dbg_test.c 79 cg_ir_lower_test_SRC := test/opt/cg_ir_lower_test.c 80 tiny_inline_test_SRC := test/opt/tiny_inline_test.c 81 82 # ---- build rules ------------------------------------------------------------ 83 # Secondary expansion lets a static-pattern prerequisite reference the 84 # per-stem source via $$($$*_SRC). 85 .SECONDEXPANSION: 86 87 $(UNIT_TESTS_PUBLIC:%=build/test/%): build/test/%: $$($$*_SRC) $(UNIT_HDR_DEPS) $(LIB_AR) 88 @mkdir -p $(dir $@) 89 $(CC) $(UNIT_CFLAGS_PUBLIC) $($*_SRC) $(LIB_AR) -o $@ 90 91 $(UNIT_TESTS_INTERNAL:%=build/test/%): build/test/%: $$($$*_SRC) $(UNIT_HDR_DEPS) $(LIB_OBJS) 92 @mkdir -p $(dir $@) 93 $(CC) $(UNIT_CFLAGS_INTERNAL) $($*_SRC) $(LIB_OBJS) -o $@