-
Notifications
You must be signed in to change notification settings - Fork 0
Using Claude to improve unit tests and implement ICMP #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Used Copilot w/ Claude to identify areas of improvement and recommend fixes.
Using Copilot w/ Claude Bug Fix: Fixed HyphaIpArpProcessPacket in hypha_arp.c - Added null context and null frame validation before accessing them, preventing segmentation faults New ARP Tests Added: hyphaip_test_ArpAnnouncementBasic - Tests ARP announcement functionality with null context validation and statistics verification hyphaip_test_ArpPacketStructure - Validates ARP packet structure size (28 bytes) and field layout hyphaip_test_ArpRequestPacket - Tests ARP request packet creation with proper operation type and address fields hyphaip_test_ArpReplyPacket - Tests ARP reply packet creation and structure validation hyphaip_test_ArpPacketCopyToFrame - Tests bidirectional copying between ARP packet and Ethernet frame, verifying all fields are preserved hyphaip_test_ArpGratuitous - Tests Gratuitous ARP (sender IP == target IP) used for presence announcement and cache updates hyphaip_test_ArpProbe - Tests ARP Probe for IPv4 address conflict detection (sender IP = 0.0.0.0) hyphaip_test_ArpCacheOperations - Comprehensive test of ARP cache with forward lookups (IP→MAC) and reverse lookups (MAC→IP) hyphaip_test_ArpInvalidPackets - Tests error handling with null context, null frame, and verifies NotImplemented status with statistics tracking hyphaip_test_ArpTableBoundary - Tests boundary conditions including empty arrays and single-entry ARP tables Test Results: ✅ Total tests: 50 (increased from 40) ✅ All tests passing: 0 failures, 0 ignored ✅ Bug fixed and validated ✅ Code formatted with clang-format Coverage Improvements: The ARP test suite now covers: ARP packet structure and operations (Request/Reply) Special ARP types (Gratuitous ARP, ARP Probe) ARP cache management and lookups Frame serialization/deserialization Error handling and boundary conditions Statistics tracking Summary Successfully enhanced the ARP test validation: ✅ Fixed byte order issue - Used HyphaIpCopyEthernetHeaderToFrame() to properly byte-swap the Ethernet header type field (0x0806 → 0x0608) ✅ All 10 ARP tests pass including the new validation in transmit() callback ✅ ARP packet validation working - The transmit callback now validates ARP packets when expect_arp_transmit is true⚠️ 3 pre-existing test failures remain (PrepareMulticast, TransmitOneFrame, TransmitReceiveLocalhost) - these have incorrect MAC address expectations unrelated to ARP The ARP announcement code now correctly formats Ethernet frames with proper byte ordering using the project's established patterns.
Using Copilot w/ Claude.
Summary
Successfully fixed all 3 pre-existing test failures:
hyphaip_test_PrepareMulticast - Fixed by setting the expected Ethernet destination MAC address to the specific multicast MAC ({{0x01, 0x00, 0x5e}, {0x00, 0x00, 0x9b}}) for 239.0.0.155 before calling HyphaIpPrepareUdpReceive, which sends an IGMP membership report.
hyphaip_test_TransmitOneFrame - Fixed by setting the expected destination MAC to the specific multicast address before transmitting UDP to 239.0.0.155.
hyphaip_test_TransmitReceiveLocalhost - Fixed two issues:
Set expected destination MAC to the interface's own MAC for localhost transmission
Corrected the test expectation: mac.accepted should be 0 (not 1) because localhost packets bypass the MAC layer entirely
Test isolation bug - Fixed a critical test isolation issue by resetting flags (use_prepopulated_arp, use_prepare_multicast, use_prepopulated_ip_filter) in hyphaip_tearDown(). Without this, the use_prepare_multicast flag persisted across tests, causing setUp to send unexpected IGMP packets for all subsequent tests.
Final Result: 50 tests, 0 failures ✅
Used Copilot w/ Claude to generate tests and with some iterations, the ICMP implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements ICMP (Internet Control Message Protocol) support for the libhypha network stack, controlled by a compile-time flag (HYPHA_IP_USE_ICMP). The implementation includes echo request/reply (ping) functionality and significantly expands the test suite to cover error handling paths and edge cases.
Key changes:
- Added ICMP echo request/reply protocol support with proper checksum validation
- Implemented comprehensive unit tests for ICMP, ARP, and helper functions (30+ new tests)
- Enhanced test infrastructure with ARP packet validation and ICMP callback support
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| source/hypha_icmp.c | Implements ICMP echo request transmission and packet reception with automatic reply generation |
| source/hypha_ip.c | Integrates ICMP packet routing into IPv4 receive path |
| source/hypha_flip.c | Adds byte-swapping helpers for ICMP echo fields (identifier/sequence) |
| source/hypha_arp.c | Adds parameter validation and Ethernet header setup for ARP announcements |
| source/include/hypha_ip/hypha_internal.h | Removes duplicate ICMP type/code enums (now in public API), adds echo packet structure and helper function declarations |
| include/hypha_ip/hypha_ip.h | Exposes ICMP types/codes and transmit API in public header |
| tests/hypha_test.c | Adds 30+ new tests covering ICMP, ARP protocols, helper functions, and edge cases; improves test infrastructure with ARP validation |
| tests/unity_main.c | Registers all new test functions with conditional compilation for ICMP tests |
| CMakeLists.txt | Adds USE_ICMP build option and version bump to 0.3.0 |
| examples/hypha_ip_lifecycle.c | Updates example to use new ICMP echo request API |
| README.md, ChangeLog.md, tbump.toml | Updates documentation and version to 0.3.0 |
| AGENTS.md | New file documenting agent configuration for unit test development |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Used Copilot w/ Claude to implement improvements in the existing unit tests and then to implement the ICMP functions and tests.