Skip to content

TestFunction

Description

Function pointer type for test functions.

Success

Function returns true if test passed, false if failed.

Failure

Function cannot fail - always returns boolean result.

Usage example (Cross-references)

Usage examples (Cross-references)
    /// TAGS: Testing, Deadend, Control
    ///
    bool test_deadend(TestFunction test_func, bool expect_failure);
    
    ///
    /// TAGS: Testing, Driver, Simple
    ///
    int simple_test_driver(TestFunction *tests, int count);
    
    ///
    /// TAGS: Testing, Driver, Deadend
    ///
    int deadend_test_driver(TestFunction *tests, int count);
    
    ///
    ///
    int run_test_suite(
        TestFunction *normal_tests,
        int           normal_count,
        TestFunction *deadend_tests,
        TestFunction *normal_tests,
        int           normal_count,
        TestFunction *deadend_tests,
        int           deadend_count,
        Zstr          test_name
    // aborts must unwind back here too, otherwise the abort handler would
    // longjmp to an uninitialised buffer.
    bool test_deadend(TestFunction test_func, bool expect_failure) {
        if (!test_func) {
            WriteFmt("[ERROR] test_deadend: NULL test function provided\n");
    
    /// Run an array of simple tests
    int simple_test_driver(TestFunction *tests, int count) {
        if (!tests) {
            WriteFmt("[ERROR] simple_test_driver: NULL tests array provided\n");
    
    /// Run an array of deadend tests (all expecting failure)
    int deadend_test_driver(TestFunction *tests, int count) {
        if (!tests) {
            WriteFmt("[ERROR] deadend_test_driver: NULL tests array provided\n");
    /// Main test driver - handles everything: normal tests and deadend tests
    int run_test_suite(
        TestFunction *normal_tests,
        int           normal_count,
        TestFunction *deadend_tests,
        TestFunction *normal_tests,
        int           normal_count,
        TestFunction *deadend_tests,
        int           deadend_count,
        Zstr          test_name
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_empty_object_reading,
            test_empty_array_reading,
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_two_level_nesting_writing,
            test_three_level_nesting_writing,
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_simple_string_writing,
            test_simple_numbers_writing,
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_empty_object_writing,
            test_empty_array_writing,
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_basic_iterator_functionality,
            test_simple_json_object,
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_simple_string_parsing,
            test_simple_numbers,
    int main(void) {
        // Array of test functions
        TestFunction tests[] = {
            test_simple_roundtrip,
            test_numeric_roundtrip,
    
    int main(void) {
        TestFunction tests[] = {
            test_kvconfig_basic_parse,
            test_kvconfig_comments_quotes_and_duplicates,
    
        // Array of test functions
        TestFunction tests[] = {
            test_str_pop_back,
            test_str_pop_front,
        WriteFmt("[INFO] Starting Http tests\n\n");
    
        TestFunction tests[] = {
            test_http_request_parse_get_with_headers,
            test_http_response_serialize_html,
    
    int main(void) {
        TestFunction normal[] = {
            // Happy path
            test_basic_alloc_and_free,
            test_alignment_honored,
        };
        TestFunction deadend[] = {
            test_tiny_buffer_rejects,
            test_reject_foreign_pointer,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_insert_and_set,
            test_map_set_first,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_shrink_to_fit,
            test_bitvec_reserve,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_memory_null_failures,
            test_bitvec_swap_null_failures,
        WriteFmt("[INFO] Starting Int.Access tests\n\n");
    
        TestFunction tests[] = {
            test_int_bit_length,
            test_int_byte_length,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_shift_left,
            test_bitvec_shift_right,
    
        // Array of test functions
        TestFunction tests[] = {
            test_str_try_reduce_space,
            test_str_swap_char_at,
    
    int main(void) {
        TestFunction tests[] = {
            test_graph_access_helpers,
            test_graph_has_edge_query,
            test_graph_has_edge_query,
        };
        TestFunction deadend_tests[] = {
            test_graph_cross_graph_node_handle_deadend,
            test_graph_predecessor_access_oob_deadend,
    
    int main(void) {
        TestFunction tests[] = {
            test_graph_type_defaults,
            test_graph_aligned_init_and_id_layout,
    
        // Array of test functions
        TestFunction tests[] = {
            test_str_cmp,
            test_str_cmp_ignore_case,
        WriteFmt("[INFO] Starting Int.Convert tests\n\n");
    
        TestFunction tests[] = {
            test_int_from_unsigned_integer,
            test_int_bytes_le_round_trip,
        // contract rule (programmer errors abort). The deadend driver
        // catches the abort and treats it as PASS.
        TestFunction deadend_tests[] = {
            test_int_from_binary_null,
            test_int_from_decimal_null,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_foreach_invalid_usage,
            test_bitvec_run_lengths_null_bv,
    
    int main(void) {
        TestFunction tests[] = {
            test_list_init_variants,
            test_list_init_optional_allocator,
        WriteFmt("[INFO] Starting PdbCache tests\n\n");
    
        TestFunction tests[] = {
            test_pdb_cache_resolves_via_codeview,
            test_pdb_cache_rejects_unknown_module,
    
    int main(void) {
        TestFunction tests[] = {
            test_list_insert_and_push_aliases,
            test_list_push_arr_l_zeroes_all_items,
        WriteFmt("[INFO] Starting Backtrace tests\n\n");
    
        TestFunction tests[] = {
            test_backtrace_capture_non_empty,
            test_backtrace_format_resolves_helper,
        WriteFmt("[INFO] Starting Int.Type tests\n\n");
    
        TestFunction tests[] = {
            test_int_init,
            test_int_clear,
        WriteFmt("[INFO] Starting SymbolResolver tests\n\n");
    
        TestFunction tests[] = {
            test_symres_resolve_self,
            test_symres_static_symbol_resolves,
    
    int main(void) {
        TestFunction tests[] = {
            test_page_size_query,
            test_basic_alloc_and_free,
    
    int main(void) {
        TestFunction tests[] = {
            test_list_foreach_basic,
            test_list_foreach_ranges,
    
    int main(void) {
        TestFunction tests[] = {
            test_list_clear_and_reuse,
            test_list_sort_and_reverse,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_str_from_u64,
            test_str_from_i64,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_str_conversion_null_failures,
            test_str_conversion_bounds_failures,
    
    int main(void) {
        TestFunction tests[] = {
            test_graph_node_visit_scratch_state,
            test_graph_mark_delete_commit_and_reuse,
            test_graph_external_indexed_state_requires_reset_on_reuse,
        };
        TestFunction deadend_tests[] = {
            test_graph_stale_node_handle_after_commit_deadend,
        };
        WriteFmt("[INFO] Starting Float.Compare tests\n\n");
    
        TestFunction tests[] = {
            test_float_compare_small_small,
            test_float_compare_very_large_large,
    
        // Array of test functions
        TestFunction tests[] = {
            test_str_len_empty,
            test_str_first,
        WriteFmt("[INFO] Starting Socket tests\n\n");
    
        TestFunction tests[] = {
            test_socket_addr_format_round_trip,
            test_socket_loopback_round_trip,
    
        // Array of test functions
        TestFunction tests[] = {test_vec_swap_items, test_vec_reverse, test_vec_sort};
    
        int total_tests = sizeof(tests) / sizeof(tests[0]);
        WriteFmt("[INFO] Starting MachO tests\n\n");
    
        TestFunction tests[] = {
            test_macho_parses_synthetic_blob,
            test_macho_resolves_address,
        WriteFmt("[INFO] Starting Elf tests\n\n");
    
        TestFunction tests[] = {
            test_elf_self_exe_parse,
            test_elf_find_text_section,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_push,
            test_bitvec_insert_single,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_insert_null_failures,
            test_bitvec_insert_invalid_range_failures,
    
    int main(void) {
        TestFunction normal[] = {
            test_basic_alloc_and_free,
            test_free_then_alloc_recycles,
            test_pool_alignment,
        };
        TestFunction deadend[] = {
            test_reject_foreign_pointer,
            test_reject_misaligned_pointer,
        WriteFmt("[INFO] Starting Io.UserTypes tests\n\n");
    
        TestFunction tests[] = {
            test_user_type_write_basic,
            test_user_type_write_mixed_args,
        WriteFmt("[INFO] Starting SysDns tests\n\n");
    
        TestFunction tests[] = {
            test_dns_resolve_localhost_from_hosts,
            test_dns_resolve_hosts_case_insensitive,
        WriteFmt("[INFO] Starting AllocDebug tests\n\n");
    
        TestFunction normal[] = {
            // Happy path
            test_debug_normal_alloc_free,
            test_debug_page_backed_alloc_free,
        };
        TestFunction deadend[] = {
            test_debug_double_free_aborts,
            test_debug_foreign_free_aborts,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_vec_foreach,
            test_vec_foreach_idx,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_foreach_ptr,
            test_map_foreach_multimap_iterators,
    int main(void) {
        WriteFmt("[INFO] Starting Buf tests\n\n");
        TestFunction tests[] = {
            test_buf_init_clear,
            test_buf_write_u_le_be,
    
    int main(void) {
        TestFunction normal[] = {
            // Happy path
            test_basic_alloc_free,
            test_independent_heaps,
        };
        TestFunction deadend[] = {
            test_reject_foreign_pointer,
            test_reject_double_free,
    
        // Array of test functions
        TestFunction tests[] = {test_bitvec_type_basic, test_bitvec_validate};
    
        int total_tests = sizeof(tests) / sizeof(tests[0]);
    
        // Array of test functions
        TestFunction tests[] = {
            test_bitvec_basic_pattern_functions, test_bitvec_find_pattern,           test_bitvec_find_last_pattern,
            test_bitvec_find_all_pattern,        test_bitvec_find_all_pattern_vec,   test_bitvec_pattern_edge_cases,
        WriteFmt("[INFO] Starting format reader tests\n\n");
    
        TestFunction tests[] = {
            test_integer_decimal_reading,
            test_integer_hex_reading,
        WriteFmt("[INFO] Starting Dwarf tests\n\n");
    
        TestFunction tests[] = {
            test_dwarf_lines_load_self,
            test_dwarf_resolves_helper_to_source_file,
        WriteFmt("[INFO] Starting ProcMaps tests\n\n");
    
        TestFunction tests[] = {
            test_procmaps_load,
            test_procmaps_find_self,
    
    int main(void) {
        TestFunction normal[] = {
            test_basic_bump,
            test_grow_last_in_place,
            test_alignment,
        };
        TestFunction deadend[] = {
            test_reject_remap_non_last,
            test_reject_foreign_free,
    
    int main(void) {
        TestFunction deadend_tests[] = {
            test_validate_uninitialized_map_fails,
            test_map_contains_pair_without_value_compare_fails,
    
    int main(void) {
        TestFunction tests[] = {
            test_graph_reserve_clear,
            test_graph_node_deep_copy,
        WriteFmt("[INFO] Starting Float.Type tests\n\n");
    
        TestFunction tests[] = {
            test_float_init,
            test_float_clear,
        WriteFmt("[INFO] Starting Float.Convert tests\n\n");
    
        TestFunction tests[] = {
            test_float_from_unsigned_integer,
            test_float_from_signed_integer,
    
        // NULL-input: strict contract = LOG_FATAL; deadend driver catches.
        TestFunction deadend_tests[] = {
            test_float_from_str_null,
        };
        WriteFmt("[INFO] Starting format writer tests\n\n");
    
        TestFunction tests[] = {
            test_basic_formatting,
            test_string_formatting,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_hamming_distance_basic,
            test_bitvec_hamming_distance_edge_cases,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_hamming_distance_null_bv1,
            test_bitvec_hamming_distance_null_bv2,
        WriteFmt("[INFO] Stripped-binary resolve test against: {}\n\n", stripped_path_arg);
    
        TestFunction tests[] = {
            test_stripped_resolves_marker_alpha,
            test_stripped_resolves_marker_beta,
    
    int main(void) {
        TestFunction tests[] = {
            test_list_len_empty,
            test_list_value_access_and_swap,
    
        // Deadend tests that would cause program termination
        TestFunction deadend_tests[] = {
            test_bitvec_find_deadend_tests,
            test_bitvec_predicate_deadend_tests,
    
        // Array of test functions
        TestFunction tests[] = {
            test_str_insert_char_at,
            test_str_insert_cstr,
        WriteFmt("[INFO] Starting Float.Math tests\n\n");
    
        TestFunction tests[] = {
            test_float_negate_abs,
            test_float_add_small_small,
        };
    
        TestFunction deadend_tests[1] = {0};
    
        int total_tests         = sizeof(tests) / sizeof(tests[0]);
    
        // Array of test functions
        TestFunction tests[] = {
            test_vec_init_basic,
            test_vec_init_aligned,
    
        // Array of test functions
        TestFunction tests[] = {test_vec_try_reduce_space, test_vec_resize, test_vec_reserve, test_vec_clear};
    
        int total_tests = sizeof(tests) / sizeof(tests[0]);
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_bitwise_null_failures,
            test_bitvec_bitwise_ops_null_failures,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_remove_value,
            test_map_remove_pair,
        WriteFmt("[INFO] Starting Int.Compare tests\n\n");
    
        TestFunction tests[] = {
            test_int_compare,
            test_int_compare_wrappers,
    
        // Array of test functions
        TestFunction tests[] = {
            test_bitvec_get,
            test_bitvec_set,
    int main(void) {
        // Array of normal test functions
        TestFunction normal_tests[] = {
            test_vec_pop_back,
            test_vec_pop_front,
    
    int main(void) {
        TestFunction tests[] = {
            test_list_remove_and_pop,
            test_list_remove_range_and_delete_aliases,
        WriteFmt("[INFO] Starting Float.Access tests\n\n");
    
        TestFunction tests[] = {
            test_float_is_zero,
            test_float_is_negative,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_init,
            test_bitvec_deinit,
    
        // Array of deadend test functions (expected failure scenarios)
        TestFunction deadend_tests[] = {
            test_bitvec_null_pointer_failures,
            test_bitvec_invalid_operations,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_foreach_idx,
            test_bitvec_foreach,
        WriteFmt("[INFO] Starting Int.Math tests\n\n");
    
        TestFunction tests[] = {
            test_int_shift_left_grows,
            test_int_shift_right_shrinks,
        };
    
        TestFunction deadend_tests[] = {
            test_int_add_null_result,
            test_int_shift_left_null,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_contains_and_find,
            test_map_get_ptr,
        WriteFmt("[INFO] Starting File tests\n\n");
    
        TestFunction tests[] = {
            test_file_read_into_str,
            test_file_read_grows_str,
    
        // Array of normal test functions
        TestFunction tests[] = {test_str_type, test_strs_type, test_validate_str, test_validate_strs};
    
        // Array of deadend test functions (tests that should crash/abort)
    
        // Array of deadend test functions (tests that should crash/abort)
        TestFunction deadend_tests[] = {test_validate_invalid_str, test_validate_invalid_strs};
    
        int total_tests   = sizeof(tests) / sizeof(tests[0]);
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_pop,
            test_bitvec_remove_single,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_remove_null_failures,
            test_bitvec_remove_range_null_failures,
    
    int main(void) {
        TestFunction tests[] = {
            test_graph_add_node_semantics,
            test_graph_add_edge_dedup,
    int main(void) {
        WriteFmt("[INFO] Starting Iter.Deadend tests\n\n");
        TestFunction tests[] = {
            deadend_must_read_eof,
            deadend_must_peek_out_of_range,
    
        // Array of test functions
        TestFunction tests[] = {
            test_complex_vec_init,
            test_complex_vec_push,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_shift_left,
            test_bitvec_shift_right,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_bitwise_null_failures,
            test_bitvec_bitwise_ops_null_failures,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_to_string,
            test_bitvec_from_string,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_convert_null_failures,
            test_bitvec_from_string_null_failures,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_foreach_idx,
            test_bitvec_foreach,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_foreach_invalid_usage,
            test_bitvec_run_lengths_null_bv,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_reserve_and_clear,
            test_map_rehash_policy_switch,
    
    int main(void) {
        TestFunction tests[] = {
            test_graph_city_reachability,
            test_graph_foreach_with_external_map_counts,
            test_graph_foreach_predecessors,
        };
        TestFunction deadend_tests[] = {
            test_graph_node_iteration_rejects_structural_mutation_deadend,
            test_graph_neighbor_iteration_rejects_structural_mutation_deadend,
    
        // Array of test functions
        TestFunction tests[] = {
            test_vec_at,
            test_vec_ptr_at,
        WriteFmt("[INFO] Starting Pdb tests\n\n");
    
        TestFunction tests[] = {
            test_pdb_parses_minimal_msf,
            test_pdb_rejects_bad_magic,
    int main(void) {
        WriteFmt("[INFO] Starting Iter tests\n\n");
        TestFunction tests[] = {
            test_iter_remaining_forward,
            test_iter_remaining_reverse,
    
    int main(void) {
        TestFunction deadend_tests[] = {
            test_validate_corrupt_empty_list_fails,
            test_validate_null_list_fails,
    
        // Array of test functions
        TestFunction tests[] = {test_vec_type_basic, test_vec_validate};
    
        int total_tests = sizeof(tests) / sizeof(tests[0]);
    
        // Array of test functions
        TestFunction tests[] = {
            test_vec_push_back,
            test_vec_push_front,
        WriteFmt("[INFO] Starting MachoCache tests\n\n");
    
        TestFunction tests[] = {
            test_macho_cache_resolves_via_main_symtab,
            test_macho_cache_falls_through_to_dsym,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_bitvec_equals,
            test_bitvec_compare,
    
        // Array of deadend test functions
        TestFunction deadend_tests[] = {
            test_bitvec_compare_null_failures,
            test_bitvec_subset_null_failures,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_deep_copy_zstrs,
            test_map_policy_switch_preserves_entries,
        WriteFmt("[INFO] Starting PageProtect tests\n\n");
    
        TestFunction tests[] = {
            test_page_protect_roundtrip,
        };
    
    int main(void) {
        TestFunction tests[] = {
            test_list_type_defaults,
            test_list_node_type_layout,
        WriteFmt("[INFO] Starting Dns tests\n\n");
    
        TestFunction tests[] = {
            test_dns_build_query_basic,
            test_dns_build_query_trailing_dot,
    
        // Array of test functions
        TestFunction tests[] = {
            test_str_init,
            test_str_init_from_cstr,
    
    int main(void) {
        TestFunction tests[] = {
            test_map_type_defaults,
            test_map_type_with_value_compare,
    
        // Array of normal test functions
        TestFunction tests[] = {
            test_str_foreach_idx,
            test_str_foreach_reverse_idx,
        WriteFmt("[INFO] Starting ArgParse tests\n\n");
    
        TestFunction tests[] = {
            test_required_long_space,
            test_required_long_equals,
    
        // Array of test functions (adding new tests to existing ones)
        TestFunction tests[] = {
            test_bitvec_get,
            test_bitvec_set,
    
        // Deadend tests that would cause program termination
        TestFunction deadend_tests[] = {
            test_bitvec_find_deadend_tests,
            test_bitvec_predicate_deadend_tests,
    
        // Deadend tests that would cause program termination
        TestFunction deadend_tests[] = {
            test_bitvec_find_pattern_null_source,      test_bitvec_find_pattern_null_pattern,
            test_bitvec_find_last_pattern_null_source, test_bitvec_find_last_pattern_null_pattern,
        WriteFmt("[INFO] Starting Pe tests\n\n");
    
        TestFunction tests[] = {
            test_pe_parses_synthetic_blob,
            test_pe_rva_to_offset_round_trips,
Last updated on