kit

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

test_unit.mk (6604B)


      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 arm32_target_features_test cg_api_test cg_switch_test \
     34     cg_fp_cmp_test \
     35     cg_control_test cg_const_test hash_test cas_test release_index_test \
     36     panic_recovery_test profile_test build_public_link_test \
     37     link_script_test link_compat_test object_rewrite_test \
     38     rv64_jit_test rv32_jit_test aa64_inline_test rv64_inline_test x64_inline_test \
     39     arm32_inline_test \
     40     strength_reduce_test
     41 ar_test_SRC          := test/ar/ar_test.c
     42 target_test_SRC      := test/api/target_test.c
     43 arm32_target_features_test_SRC := test/api/arm32_target_features_test.c
     44 hash_test_SRC        := test/api/hash_test.c
     45 cas_test_SRC         := test/api/cas_test.c
     46 release_index_test_SRC := test/api/release_index_test.c
     47 panic_recovery_test_SRC := test/api/panic_recovery_test.c
     48 profile_test_SRC     := test/api/profile_test.c
     49 build_public_link_test_SRC := test/build/build_public_link_test.c
     50 link_script_test_SRC := test/link/link_script_test.c
     51 link_compat_test_SRC := test/link/link_compat_test.c
     52 object_rewrite_test_SRC := test/api/object_rewrite_test.c
     53 cg_api_test_SRC      := test/api/cg_type_test.c
     54 cg_switch_test_SRC   := test/api/cg_switch_test.c
     55 cg_fp_cmp_test_SRC   := test/api/cg_fp_cmp_test.c
     56 cg_control_test_SRC  := test/api/cg_control_test.c
     57 cg_const_test_SRC    := test/api/cg_const_test.c
     58 strength_reduce_test_SRC := test/cg/strength_reduce_test.c
     59 rv64_jit_test_SRC    := test/link/rv64_jit_test.c
     60 rv32_jit_test_SRC    := test/link/rv32_jit_test.c
     61 aa64_inline_test_SRC := test/arch/aa64_inline_test.c
     62 rv64_inline_test_SRC := test/arch/rv64_inline_test.c
     63 x64_inline_test_SRC  := test/arch/x64_inline_test.c
     64 arm32_inline_test_SRC := test/arch/arm32_inline_test.c
     65 
     66 UNIT_TESTS_INTERNAL := \
     67     build_pure_test \
     68     dwarf_test debug_roundtrip_unit debug_cfi_unit \
     69     aa64_isa_test rv64_decode_test rv32_decode_test arm32_decode_test \
     70     aa64_sweep_gen \
     71     reloc_uleb128_unit reloc_desc_test reloc_apply_test emu_rv64_unit_test \
     72     interp_smoke_test jit_tls_relax_test coff_weak_alias_test \
     73     coff_archive_fixpoint_test elf_version_import_test \
     74     rv64_interp_smoke_test abi_classify_test ir_recorder_test \
     75     native_direct_target_test x64_dbg_test cg_ir_lower_test tiny_inline_test \
     76     reg_effects_test location_mir_test combine_cse_test \
     77     native_emit_frame_dst_test frame_value_backend_test native_part_chunk_test
     78 dwarf_test_SRC                := test/dwarf/dwarf_test.c
     79 debug_roundtrip_unit_SRC      := test/debug/roundtrip_unit.c
     80 debug_cfi_unit_SRC            := test/debug/cfi_unit.c
     81 aa64_isa_test_SRC             := test/arch/aa64_isa_test.c
     82 rv64_decode_test_SRC          := test/arch/rv64_decode_test.c
     83 rv32_decode_test_SRC          := test/arch/rv32_decode_test.c
     84 arm32_decode_test_SRC         := test/arch/arm32_decode_test.c
     85 aa64_sweep_gen_SRC            := test/arch/aa64_sweep_gen.c
     86 reloc_uleb128_unit_SRC        := test/link/reloc_uleb128_unit.c
     87 reloc_desc_test_SRC           := test/link/reloc_desc_test.c
     88 reloc_apply_test_SRC          := test/link/reloc_apply_test.c
     89 jit_tls_relax_test_SRC        := test/link/jit_tls_relax_test.c
     90 coff_weak_alias_test_SRC      := test/link/coff_weak_alias_test.c
     91 coff_archive_fixpoint_test_SRC := test/link/coff_archive_fixpoint_test.c
     92 elf_version_import_test_SRC   := test/link/elf_version_import_test.c
     93 emu_rv64_unit_test_SRC        := test/emu/rv64_vm_unit_test.c
     94 interp_smoke_test_SRC         := test/interp/interp_smoke_test.c
     95 rv64_interp_smoke_test_SRC    := test/emu/rv64_interp_smoke_test.c
     96 abi_classify_test_SRC         := test/api/abi_classify_test.c
     97 ir_recorder_test_SRC          := test/cg/ir_recorder_test.c
     98 native_direct_target_test_SRC := test/cg/native_direct_target_test.c
     99 x64_dbg_test_SRC              := test/arch/x64_dbg_test.c
    100 cg_ir_lower_test_SRC          := test/opt/cg_ir_lower_test.c
    101 tiny_inline_test_SRC          := test/opt/tiny_inline_test.c
    102 reg_effects_test_SRC           := test/opt/reg_effects_test.c
    103 location_mir_test_SRC          := test/opt/location_mir_test.c
    104 combine_cse_test_SRC           := test/opt/combine_cse_test.c
    105 native_emit_frame_dst_test_SRC := test/opt/native_emit_frame_dst_test.c
    106 frame_value_backend_test_SRC   := test/opt/frame_value_backend_test.c
    107 native_part_chunk_test_SRC      := test/opt/native_part_chunk_test.c
    108 build_pure_test_SRC          := test/build/build_pure_test.c
    109 
    110 # ---- build rules ------------------------------------------------------------
    111 # Secondary expansion lets a static-pattern prerequisite reference the
    112 # per-stem source via $$($$*_SRC).
    113 .SECONDEXPANSION:
    114 
    115 $(UNIT_TESTS_PUBLIC:%=build/test/%): build/test/%: $$($$*_SRC) $(UNIT_HDR_DEPS) $(LIB_AR)
    116 	@mkdir -p $(dir $@)
    117 	$(CC) $(UNIT_CFLAGS_PUBLIC) $($*_SRC) $(LIB_AR) -o $@
    118 
    119 $(UNIT_TESTS_INTERNAL:%=build/test/%): build/test/%: $$($$*_SRC) $(UNIT_HDR_DEPS) $(LIB_OBJS)
    120 	@mkdir -p $(dir $@)
    121 	$(CC) $(UNIT_CFLAGS_INTERNAL) $($*_SRC) $(LIB_OBJS) -o $@