tree: a18890e5993173d178873faff832eff15bbe1c48 [path history] [tgz]
  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. div-by-zero-imm.data
  14. div-by-zero-reg.data
  15. div64-by-zero-imm.data
  16. early-exit.data
  17. err-write-r10.dst
  18. factorial.data
  19. jmp.data
  20. ldx.data
  21. ldxb-0offset.data
  22. ldxb-large-offset.data
  23. ldxb-small-offset.data
  24. ldxsb-positive.data
  25. ldxsh.data
  26. ldxsw.data
  27. mod-by-zero-imm.data
  28. mod64-by-zero-imm.data
  29. mul-loop-memory-iterations.data
  30. mul-loop.data
  31. README.md
  32. reload.data
  33. rsh-reg.data
  34. sdiv32-by-zero.data
  35. sdiv32-neg.data
  36. sdiv32-overflow.data
  37. sdiv32.data
  38. sdiv64-by-zero.data
  39. sdiv64-neg.data
  40. sdiv64-overflow.data
  41. sdiv64.data
  42. smod32-by-zero.data
  43. smod32-neg.data
  44. smod32-overflow.data
  45. smod32.data
  46. smod64-by-zero.data
  47. smod64-neg.data
  48. smod64-overflow.data
  49. smod64.data
  50. st.data
  51. stack2.data
  52. stack3.data
  53. string-stack.data
  54. stx.data
  55. 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