@@ -1598,87 +1598,73 @@ TEST_CASE("Test program order", "[native_tests]")
15981598// Test eBPF string and type conversion APIs
15991599TEST_CASE (" ebpf_string_apis" , " [ebpf_api]" )
16001600{
1601- _disable_crt_report_hook disable_hook;
1602-
16031601 // Test ebpf_free_string - can be called with NULL safely
16041602 ebpf_free_string (nullptr );
16051603
16061604 // Test program type name lookup
1607- ebpf_program_type_t sample_program_type = {
1608- 0x608c517c , 0x6c52 , 0x4a26 , {0xb6 , 0x77 , 0xbb , 0x1c , 0x34 , 0x42 , 0x5a , 0xdf }};
1605+ ebpf_program_type_t sample_program_type = EBPF_PROGRAM_TYPE_BIND_GUID;
16091606 const char * type_name = ebpf_get_program_type_name (&sample_program_type);
1610- // Should return a valid name or NULL for unknown types
1611- if (type_name != nullptr ) {
1612- REQUIRE (strlen (type_name) > 0 );
1613- }
1607+ REQUIRE (type_name != nullptr );
1608+ REQUIRE (strlen (type_name) > 0 );
16141609
16151610 // Test attach type name lookup
1616- ebpf_attach_type_t bind_attach_type = {
1617- 0xb9707e04 , 0x8127 , 0x4c72 , {0x83 , 0x3e , 0x05 , 0xb1 , 0xfb , 0x43 , 0x94 , 0x96 }};
1611+ ebpf_attach_type_t bind_attach_type = EBPF_ATTACH_TYPE_BIND_GUID;
16181612 const char * attach_name = ebpf_get_attach_type_name (&bind_attach_type);
1619- if (attach_name != nullptr ) {
1620- REQUIRE (strlen (attach_name) > 0 );
1621- }
1613+ REQUIRE (attach_name != nullptr );
1614+ REQUIRE (strlen (attach_name) > 0 );
16221615}
16231616
16241617// Test eBPF program and attach type conversion APIs
16251618TEST_CASE (" ebpf_type_conversion_apis" , " [ebpf_api]" )
16261619{
1627- _disable_crt_report_hook disable_hook;
1628-
16291620 // Test BPF to eBPF program type conversion
16301621 const ebpf_program_type_t * ebpf_type = ebpf_get_ebpf_program_type (BPF_PROG_TYPE_SAMPLE);
1631- if (ebpf_type != nullptr ) {
1632- // Test reverse conversion
1633- bpf_prog_type_t bpf_type = ebpf_get_bpf_program_type (ebpf_type);
1634- REQUIRE ( bpf_type == BPF_PROG_TYPE_SAMPLE );
1635- }
1622+ REQUIRE (ebpf_type != nullptr );
1623+
1624+ // Test reverse conversion
1625+ bpf_prog_type_t bpf_type = ebpf_get_bpf_program_type (ebpf_type );
1626+ REQUIRE (bpf_type == BPF_PROG_TYPE_SAMPLE);
16361627
16371628 // Test BPF to eBPF attach type conversion
16381629 ebpf_attach_type_t ebpf_attach_type;
16391630 ebpf_result_t result = ebpf_get_ebpf_attach_type (BPF_ATTACH_TYPE_BIND, &ebpf_attach_type);
1640- if (result == EBPF_SUCCESS) {
1641- // Test reverse conversion
1642- bpf_attach_type_t bpf_attach_type = ebpf_get_bpf_attach_type (&ebpf_attach_type);
1643- REQUIRE ( bpf_attach_type == BPF_ATTACH_TYPE_BIND );
1644- }
1631+ REQUIRE (result == EBPF_SUCCESS);
1632+
1633+ // Test reverse conversion
1634+ bpf_attach_type_t bpf_attach_type = ebpf_get_bpf_attach_type (&ebpf_attach_type );
1635+ REQUIRE (bpf_attach_type == BPF_ATTACH_TYPE_BIND);
16451636
16461637 // Test program type lookup by name
16471638 ebpf_program_type_t program_type;
16481639 ebpf_attach_type_t expected_attach_type;
16491640 result = ebpf_get_program_type_by_name (" bind" , &program_type, &expected_attach_type);
1650- if (result == EBPF_SUCCESS) {
1651- // Verify the lookup worked by converting back to name
1652- const char * retrieved_name = ebpf_get_program_type_name (&program_type);
1653- if (retrieved_name != nullptr ) {
1654- // Name might not match exactly due to internal naming conventions
1655- REQUIRE (strlen (retrieved_name) > 0 );
1656- }
1657- }
1641+ REQUIRE (result == EBPF_SUCCESS);
1642+
1643+ // Verify the lookup worked by converting back to name
1644+ const char * retrieved_name = ebpf_get_program_type_name (&program_type);
1645+ REQUIRE (retrieved_name != nullptr );
1646+ REQUIRE (strlen (retrieved_name) > 0 );
16581647}
16591648
16601649// Test path canonicalization API
16611650TEST_CASE (" ebpf_canonicalize_pin_path" , " [ebpf_api]" )
16621651{
1663- _disable_crt_report_hook disable_hook;
1664-
16651652 char output[MAX_PATH];
16661653
16671654 // Test with a simple path
16681655 ebpf_result_t result = ebpf_canonicalize_pin_path (output, sizeof (output), " /some/test/path" );
1669- // The function should either succeed or fail gracefully
1670- REQUIRE ((result == EBPF_SUCCESS || result != EBPF_SUCCESS) );
1656+ REQUIRE (result == EBPF_SUCCESS);
1657+ REQUIRE (std::string (output) == " BPF: \\ some \\ test \\ path " );
16711658
16721659 // Test with empty path
16731660 result = ebpf_canonicalize_pin_path (output, sizeof (output), " " );
1674- REQUIRE ((result == EBPF_SUCCESS || result != EBPF_SUCCESS));
1661+ REQUIRE (result == EBPF_SUCCESS);
1662+ REQUIRE (std::string (output) == " BPF:\\ " );
16751663}
16761664
16771665// Test enumerate programs API
16781666TEST_CASE (" ebpf_enumerate_programs" , " [ebpf_api]" )
16791667{
1680- _disable_crt_report_hook disable_hook;
1681-
16821668 // Test with a known test file path - using sample programs from the project
16831669 const char * test_files[] = {" test_sample_ebpf.o" , " bindmonitor.o" };
16841670
@@ -1719,8 +1705,6 @@ TEST_CASE("ebpf_enumerate_programs", "[ebpf_api]")
17191705// Test eBPF verification APIs
17201706TEST_CASE (" ebpf_verification_apis" , " [ebpf_api]" )
17211707{
1722- _disable_crt_report_hook disable_hook;
1723-
17241708 // Test file verification APIs with known test files
17251709 const char * test_files[] = {" test_sample_ebpf.o" , " bindmonitor.o" };
17261710
@@ -1740,9 +1724,8 @@ TEST_CASE("ebpf_verification_apis", "[ebpf_api]")
17401724 &error_message,
17411725 &stats);
17421726
1743- // Result should be 0 (success) or 1 (verification failed) for valid files
1744- // For non-existent files, this might be different
1745- REQUIRE ((result == 0 || result == 1 || result != 0 ));
1727+ // Result should be 0 (success)
1728+ REQUIRE (result == 0 );
17461729
17471730 // Clean up strings
17481731 if (report != nullptr ) {
@@ -1784,8 +1767,6 @@ TEST_CASE("ebpf_verification_apis", "[ebpf_api]")
17841767// Test eBPF object management APIs
17851768TEST_CASE (" ebpf_object_apis" , " [ebpf_api]" )
17861769{
1787- _disable_crt_report_hook disable_hook;
1788-
17891770 // Test object_unpin with invalid path - should fail gracefully
17901771 ebpf_result_t result = ebpf_object_unpin (" /invalid/path/that/does/not/exist" );
17911772 REQUIRE (result != EBPF_SUCCESS);
@@ -1816,8 +1797,6 @@ TEST_CASE("ebpf_object_apis", "[ebpf_api]")
18161797// Test eBPF pinned object path APIs
18171798TEST_CASE (" ebpf_pinned_path_apis" , " [ebpf_api]" )
18181799{
1819- _disable_crt_report_hook disable_hook;
1820-
18211800 char next_path[EBPF_MAX_PIN_PATH_LENGTH];
18221801 ebpf_object_type_t object_type = EBPF_OBJECT_UNKNOWN;
18231802
@@ -1844,8 +1823,6 @@ TEST_CASE("ebpf_pinned_path_apis", "[ebpf_api]")
18441823// Test eBPF program synchronization API
18451824TEST_CASE (" ebpf_program_synchronize" , " [ebpf_api]" )
18461825{
1847- _disable_crt_report_hook disable_hook;
1848-
18491826 // Test program synchronization - should succeed even if no programs are running
18501827 ebpf_result_t result = ebpf_program_synchronize ();
18511828 REQUIRE (result == EBPF_SUCCESS);
@@ -1854,8 +1831,6 @@ TEST_CASE("ebpf_program_synchronize", "[ebpf_api]")
18541831// Test eBPF object execution type APIs
18551832TEST_CASE (" ebpf_object_execution_type_apis" , " [ebpf_api]" )
18561833{
1857- _disable_crt_report_hook disable_hook;
1858-
18591834 // Load a test object to test execution type APIs
18601835 struct bpf_object * object = bpf_object__open (" test_sample_ebpf.o" );
18611836 if (object != nullptr ) {
@@ -1887,8 +1862,6 @@ TEST_CASE("ebpf_object_execution_type_apis", "[ebpf_api]")
18871862// Test eBPF perf event array API
18881863TEST_CASE (" ebpf_perf_event_array_api" , " [ebpf_api]" )
18891864{
1890- _disable_crt_report_hook disable_hook;
1891-
18921865 // Create a perf event array map for testing
18931866 fd_t map_fd = bpf_map_create (BPF_MAP_TYPE_PERF_EVENT_ARRAY, " test_perf" , 0 , 0 , 4 , nullptr );
18941867 if (map_fd > 0 ) {
@@ -1899,7 +1872,7 @@ TEST_CASE("ebpf_perf_event_array_api", "[ebpf_api]")
18991872 // Should either succeed or fail gracefully (e.g., if no consumers are attached)
19001873 REQUIRE ((result == EBPF_SUCCESS || result != EBPF_SUCCESS));
19011874
1902- ebpf_close_fd (map_fd);
1875+ ( void ) ebpf_close_fd (map_fd);
19031876 }
19041877}
19051878
@@ -1926,7 +1899,7 @@ TEST_CASE("ebpf_object_info_api", "[ebpf_api]")
19261899 REQUIRE (info.id != 0 );
19271900 REQUIRE (std::string (info.name ) == " test_map" );
19281901
1929- ebpf_close_fd (map_fd);
1902+ ( void ) ebpf_close_fd (map_fd);
19301903 }
19311904
19321905 // Test with invalid fd
@@ -1973,8 +1946,6 @@ TEST_CASE("ebpf_program_attach_apis_basic", "[ebpf_api]")
19731946// Test eBPF native object loading API
19741947TEST_CASE (" ebpf_object_load_native_api" , " [ebpf_api]" )
19751948{
1976- _disable_crt_report_hook disable_hook;
1977-
19781949 // Test loading native object with invalid file
19791950 size_t map_count = 1 ;
19801951 size_t program_count = 1 ;
@@ -1996,8 +1967,6 @@ TEST_CASE("ebpf_object_load_native_api", "[ebpf_api]")
19961967// Test eBPF program info from verifier API
19971968TEST_CASE (" ebpf_program_info_from_verifier_api" , " [ebpf_api]" )
19981969{
1999- _disable_crt_report_hook disable_hook;
2000-
20011970 const ebpf_program_info_t * program_info = nullptr ;
20021971 const char * error_message = nullptr ;
20031972 const char * report = nullptr ;
@@ -2026,8 +1995,6 @@ TEST_CASE("ebpf_program_info_from_verifier_api", "[ebpf_api]")
20261995// Test deprecated eBPF section enumeration API for backward compatibility
20271996TEST_CASE (" ebpf_enumerate_sections_deprecated" , " [ebpf_api]" )
20281997{
2029- _disable_crt_report_hook disable_hook;
2030-
20311998 // Test the deprecated ebpf_enumerate_sections API
20321999 const char * test_file = " test_sample_ebpf.o" ;
20332000 ebpf_section_info_t * section_infos = nullptr ;
@@ -2059,8 +2026,6 @@ TEST_CASE("ebpf_enumerate_sections_deprecated", "[ebpf_api]")
20592026// Test deprecated ebpf_get_next_pinned_program_path API
20602027TEST_CASE (" ebpf_get_next_pinned_program_path_deprecated" , " [ebpf_api]" )
20612028{
2062- _disable_crt_report_hook disable_hook;
2063-
20642029 char next_path[EBPF_MAX_PIN_PATH_LENGTH];
20652030
20662031#pragma warning(push)
@@ -2077,40 +2042,9 @@ TEST_CASE("ebpf_get_next_pinned_program_path_deprecated", "[ebpf_api]")
20772042 }
20782043}
20792044
2080- // Test eBPF store APIs (these are internal/advanced APIs)
2081- TEST_CASE (" ebpf_store_apis" , " [ebpf_api]" )
2082- {
2083- _disable_crt_report_hook disable_hook;
2084-
2085- // These APIs are typically used by system components to manage the eBPF store
2086- // We'll test basic error handling with invalid inputs
2087-
2088- // Test store update with null data - should fail gracefully
2089- ebpf_result_t result = ebpf_store_update_program_information_array (nullptr , 0 );
2090- REQUIRE (result != EBPF_SUCCESS);
2091-
2092- // Test store update section with null data - should fail gracefully
2093- result = ebpf_store_update_section_information (nullptr , 0 );
2094- REQUIRE (result != EBPF_SUCCESS);
2095-
2096- // Test store delete with null data - should fail gracefully
2097- result = ebpf_store_delete_program_information (nullptr );
2098- REQUIRE (result != EBPF_SUCCESS);
2099-
2100- // Test store delete section with null data - should fail gracefully
2101- result = ebpf_store_delete_section_information (nullptr );
2102- REQUIRE (result != EBPF_SUCCESS);
2103-
2104- // Note: These APIs modify system state and require careful handling
2105- // Full testing would require setting up valid program/section information
2106- // which is beyond the scope of basic API coverage testing
2107- }
2108-
21092045// Test eBPF memory-based verification APIs
21102046TEST_CASE (" ebpf_verification_memory_apis" , " [ebpf_api]" )
21112047{
2112- _disable_crt_report_hook disable_hook;
2113-
21142048 // Test memory-based verification with minimal data
21152049 const char * test_data = " minimal_test_data" ;
21162050 const char * report = nullptr ;
@@ -2157,8 +2091,6 @@ TEST_CASE("ebpf_verification_memory_apis", "[ebpf_api]")
21572091// Test remaining deprecated eBPF verification APIs for completeness
21582092TEST_CASE (" ebpf_deprecated_verification_apis" , " [ebpf_api]" )
21592093{
2160- _disable_crt_report_hook disable_hook;
2161-
21622094 const char * test_file = " test_sample_ebpf.o" ;
21632095 const char * disassembly = nullptr ;
21642096 const char * error_message = nullptr ;
0 commit comments