tree: 077d26fbfb817fbd50091d1b69cc3001da3c9e7f
  1. elf/
  2. errors/
  3. extensions/
  4. helpers/
  5. tcp-port-80/
  6. tcp-sack/
  7. alu.data
  8. alu64.data
  9. arsh-reg.data
  10. arsh.data
  11. arsh32-high-shift.data
  12. arsh64.data
  13. call-local-tail-jump.data
  14. div-by-zero-imm.data
  15. div-by-zero-reg.data
  16. div64-by-zero-imm.data
  17. early-exit.data
  18. err-write-r10.dst
  19. factorial.data
  20. jmp.data
  21. ldx.data
  22. ldxb-0offset.data
  23. ldxb-large-offset.data
  24. ldxb-small-offset.data
  25. ldxsb-positive.data
  26. ldxsh.data
  27. ldxsw.data
  28. mod-by-zero-imm.data
  29. mod64-by-zero-imm.data
  30. mul-loop-memory-iterations.data
  31. mul-loop.data
  32. README.md
  33. reload.data
  34. rsh-reg.data
  35. sdiv32-by-zero.data
  36. sdiv32-neg.data
  37. sdiv32-overflow.data
  38. sdiv32.data
  39. sdiv64-by-zero.data
  40. sdiv64-neg.data
  41. sdiv64-overflow.data
  42. sdiv64.data
  43. smod32-by-zero.data
  44. smod32-neg.data
  45. smod32-overflow.data
  46. smod32.data
  47. smod64-by-zero.data
  48. smod64-neg.data
  49. smod64-overflow.data
  50. smod64.data
  51. st.data
  52. stack2.data
  53. stack3.data
  54. string-stack.data
  55. stx.data
  56. unload_reload.data
tests/README.md

uBPF Test Organization

This directory contains tests that are specific to the uBPF implementation. General eBPF instruction conformance tests are located in external/bpf_conformance/tests/ and are shared across multiple BPF runtime implementations.

Test Structure

tests/
├── README.md                  # This file
├── *.data                     # Unique uBPF tests (not in conformance)
├── errors/                    # Error handling tests
│   └── err-*.data            # Tests that verify proper error detection
├── helpers/                   # Tests requiring uBPF-specific helpers
│   ├── call-memfrob.data     # Uses memfrob helper
│   ├── call-save.data        # Register preservation test
│   └── call.data             # Custom helper test
├── extensions/                # Tests for uBPF extensions
│   ├── call_local_use_stack.data  # Local call with stack usage
│   └── call_unwind.data      # Unwind extension test
├── elf/                       # ELF loader tests
│   └── *.data                # Tests for ELF file loading
├── tcp-port-80/               # TCP port 80 test data
└── tcp-sack/                  # TCP SACK test data

Test Categories

Error Handling Tests (errors/)

Tests that verify uBPF properly detects and reports various error conditions:

  • Invalid instructions
  • Out-of-bounds memory access
  • Invalid jumps
  • Stack overflow
  • Register validation
  • Instruction format errors

These tests typically expect the VM to fail gracefully with appropriate error messages.

Helper Function Tests (helpers/)

Tests that rely on uBPF-specific helper functions registered with the VM. These cannot be run through the generic conformance framework without the specific helpers being available.

Extension Tests (extensions/)

Tests for uBPF-specific extensions that are not part of the standard eBPF specification:

  • Local function calls
  • Stack unwinding

ELF Loader Tests (elf/)

Tests for the uBPF ELF file loader, verifying correct parsing and error handling of ELF-formatted eBPF programs.

Root-Level Tests

Tests in the root tests/ directory are uBPF-specific tests that don't fit into the above categories but are not present in the bpf_conformance test suite. These may include:

  • Edge cases specific to uBPF's implementation
  • Performance-sensitive tests
  • Tests for specific bug fixes
  • Tests pending contribution to bpf_conformance

Running Tests

All tests (both uBPF-specific and conformance) are automatically discovered and run through the bpf_conformance test framework when building with tests enabled:

cmake -S . -B build -DUBPF_ENABLE_TESTS=true
cmake --build build
cmake --build build --target test

Tests are run in both JIT and interpreter modes. Each .data file generates two test cases:

  • <test-name>.data-JIT - Tests the JIT compiler
  • <test-name>.data-Interpreter - Tests the interpreter

Test Format

Test files use the .data format with sections marked by -- prefixes:

-- asm
mov %r0, 1
exit

-- result
0x1

-- mem (optional)
00 11 22 33

See the bpf_conformance documentation for complete test format specification.

Contributing Tests

When adding new tests:

  1. Instruction conformance tests should be contributed to the bpf_conformance repository
  2. uBPF-specific tests should be added to the appropriate subdirectory in this tests/ directory
  3. Error handling tests should go in errors/ with the err- prefix
  4. Tests requiring helpers should go in helpers/
  5. Tests for extensions should go in extensions/

This organization ensures:

  • No duplicate tests between ubpf and bpf_conformance
  • Clear separation of concerns
  • Easy test discovery and maintenance
  • Maximum test sharing across BPF implementations