-
Notifications
You must be signed in to change notification settings - Fork 1
TFTP examplesTesting
Once you've built the TFTP parser, the next step is to verify it correctly accepts valid packets and rejects invalid ones.
- Good packets should be accepted (parse succeeds)
- Bad packets should be rejected (parse fails)
Source files:
main.c,tests.c,tests.hHammer concepts:h_parsefailure propagation · structural validation
examples/tftp/
├── Makefile # Build system
├── main.c # Entry point, calls test runners
├── tests.c # Test cases for each packet type
├── tests.h # Test runner function declarations
└── tftp.c # TFTP protocol grammar
Test cases are defined in tests.c as byte arrays representing valid and invalid TFTP packets. Each packet type has its own test runner function (run_rrqwrq_tests, run_data_tests, run_ack_tests, run_error_tests) declared in tests.h and called from main.c.
From the Hammer repository root, build the checkout-local library first:
scons examplesThen build the TFTP example:
cd examples/tftp
makeThis produces the tftp executable. If ../../build/opt/src is not present, the Makefile falls back to pkg-config libhammer.
./tftpThe executable runs each test case and reports the result.
RRQ/WRQ Test 1 (normal write request): PASSED ✓
RRQ/WRQ Test 3 (invalid op code): PASSED ✓ (correctly rejected)
All tests passed!
The test suite exercises each packet type with both valid and invalid inputs:
- RRQ/WRQ - Valid filenames and modes, invalid opcodes, missing terminators
- DATA - Valid block numbers and payloads, invalid opcodes
- ACK - Valid block numbers, invalid opcodes
- ERROR - Valid error codes and messages, invalid error codes, missing terminators
| Task | Command |
|---|---|
| Build | make |
| Run tests | ./tftp |
When everything is correct, all valid packets are accepted and all invalid packets are rejected.
Previous: Assembling the Parser
Back to: Examples Index
Learn Hammer
Protocol Examples
NTP
- NTP Overview
- Parsing the Header
- Parsing Data Fields
- Extension Fields and MAC
- Assembling the Parser
- Hex Input Preprocessing
- Running and Testing
DNS
TFTP
- TFTP Overview
- RRQ/WRQ Packets
- DATA Packets
- ACK Packets
- ERROR Packets
- Assembling the Parser
- Running and Testing
References
- Hammer Quick Reference
- Parsing Backends
- Unit Testing
- Using RTEMS
- Extending Hammer
- Adding a New Example
- Adding a New Binding
Further Reading