kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

unit.mk (4249B)


      1 # test/lib/unit.mk — build rules for the C unit-test binaries.
      2 #
      3 # Included by test/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 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 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 cg_api_test cg_switch_test cg_fp_cmp_test hash_test rv64_jit_test \
     34     aa64_inline_test rv64_inline_test x64_inline_test strength_reduce_test
     35 ar_test_SRC          := test/ar/ar_test.c
     36 hash_test_SRC        := test/api/hash_test.c
     37 cg_api_test_SRC      := test/api/cg_type_test.c
     38 cg_switch_test_SRC   := test/api/cg_switch_test.c
     39 cg_fp_cmp_test_SRC   := test/api/cg_fp_cmp_test.c
     40 strength_reduce_test_SRC := test/cg/strength_reduce_test.c
     41 rv64_jit_test_SRC    := test/link/rv64_jit_test.c
     42 aa64_inline_test_SRC := test/arch/aa64_inline_test.c
     43 rv64_inline_test_SRC := test/arch/rv64_inline_test.c
     44 x64_inline_test_SRC  := test/arch/x64_inline_test.c
     45 
     46 UNIT_TESTS_INTERNAL := \
     47     dwarf_test debug_roundtrip_unit debug_cfi_unit \
     48     aa64_isa_test rv64_decode_test aa64_sweep_gen \
     49     reloc_uleb128_unit emu_rv64_unit_test interp_smoke_test \
     50     rv64_interp_smoke_test abi_classify_test ir_recorder_test \
     51     native_direct_target_test x64_dbg_test cg_ir_lower_test tiny_inline_test
     52 dwarf_test_SRC                := test/dwarf/dwarf_test.c
     53 debug_roundtrip_unit_SRC      := test/debug/roundtrip_unit.c
     54 debug_cfi_unit_SRC            := test/debug/cfi_unit.c
     55 aa64_isa_test_SRC             := test/arch/aa64_isa_test.c
     56 rv64_decode_test_SRC          := test/arch/rv64_decode_test.c
     57 aa64_sweep_gen_SRC            := test/arch/aa64_sweep_gen.c
     58 reloc_uleb128_unit_SRC        := test/link/reloc_uleb128_unit.c
     59 emu_rv64_unit_test_SRC        := test/emu/rv64_vm_unit_test.c
     60 interp_smoke_test_SRC         := test/interp/interp_smoke_test.c
     61 rv64_interp_smoke_test_SRC    := test/emu/rv64_interp_smoke_test.c
     62 abi_classify_test_SRC         := test/api/abi_classify_test.c
     63 ir_recorder_test_SRC          := test/cg/ir_recorder_test.c
     64 native_direct_target_test_SRC := test/cg/native_direct_target_test.c
     65 x64_dbg_test_SRC              := test/arch/x64_dbg_test.c
     66 cg_ir_lower_test_SRC          := test/opt/cg_ir_lower_test.c
     67 tiny_inline_test_SRC          := test/opt/tiny_inline_test.c
     68 
     69 # ---- build rules ------------------------------------------------------------
     70 # Secondary expansion lets a static-pattern prerequisite reference the
     71 # per-stem source via $$($$*_SRC).
     72 .SECONDEXPANSION:
     73 
     74 $(UNIT_TESTS_PUBLIC:%=build/test/%): build/test/%: $$($$*_SRC) $(UNIT_HDR_DEPS) $(LIB_AR)
     75 	@mkdir -p $(dir $@)
     76 	$(CC) $(UNIT_CFLAGS_PUBLIC) $($*_SRC) $(LIB_AR) -o $@
     77 
     78 $(UNIT_TESTS_INTERNAL:%=build/test/%): build/test/%: $$($$*_SRC) $(UNIT_HDR_DEPS) $(LIB_OBJS)
     79 	@mkdir -p $(dir $@)
     80 	$(CC) $(UNIT_CFLAGS_INTERNAL) $($*_SRC) $(LIB_OBJS) -o $@