Skip to content

test: add automated mesh protocol coverage - #46

Open
Sayandevxyz wants to merge 1 commit into
Asmit-Singh-01:mainfrom
Sayandevxyz:feature/add-mesh-protocol-tests
Open

Sayandevxyz wants to merge 1 commit into
Asmit-Singh-01:mainfrom
Sayandevxyz:feature/add-mesh-protocol-tests

Conversation

@Sayandevxyz

Copy link
Copy Markdown

Summary

Adds a comprehensive, hardware-free C++17 test suite (25 deterministic unit tests) covering all core protocol components of the Decentralized Mesh Protocol.

What Was Added

  • ** ests/test_main.cpp** — Zero-dependency test harness with 25 unit tests
  • CMakeLists.txt — New mesh_protocol_tests CMake target with enable_testing() / �dd_test() CTest integration
  • .github/workflows/build.yml — CI now runs mesh_protocol_tests and ctest --output-on-failure automatically on every push/PR
  • src/routing_engine.cpp — Implements missing RoutingEngine::clear_table() declared in header
  • src/swarm_orchestrator.cpp — Implements missing SwarmOrchestrator::clear_tasks() declared in header

Why It Is Useful

The project had no automated regression tests. Any future change to packet serialization, routing logic, security, or task orchestration could silently break behavior with no detection. This PR ensures all core protocol contracts are verified on every commit.

Tests Covered

Component Scenarios Tested
Packet Serialization Roundtrip for all 6 PacketTypes; empty payload; max payload (64 bytes); oversized payload rejection; truncated buffer rejection; invalid magic byte rejection
CRC16 Integrity Deterministic output; null/zero-length edge cases; single-bit corruption detection
Routing Engine Self-beacon ignored; route insertion and lookup; RSSI/hop metric comparison; stale route pruning with 32-bit timer wraparound; clear_table()
Swarm Orchestrator Priority ordering (highest first); task deduplication; incoming payload deserialization; orchestration cycle garbage collection; clear_tasks()
Security Engine Key lifecycle (set/clear/invalid length); symmetric encrypt→decrypt roundtrip; nonce variation produces different ciphertext
Mesh Node Sequence deduplication sliding window (100-entry); peer last-seen tracking; dead peer cleanup timeout

Validation

`�ash

Configure

cmake -B build -S . -DCMAKE_BUILD_TYPE=Release

Build both targets

cmake --build build

Run test suite directly

./build/mesh_protocol_tests

Or via CTest

ctest --test-dir build --output-on-failure
`

Result: 25/25 tests pass. Exit code 0.

Compatibility

  • C++17 standard — no external testing framework required
  • Desktop simulation (MinGW GCC, GCC/Clang on Linux/macOS, MSVC)
  • Does not require ESP32/LoRa hardware, internet access, or proprietary software
  • Existing mesh_node_sim target unchanged; tests compile against core source files only

Add a zero-dependency C++17 test suite (tests/test_main.cpp) with 25
deterministic unit tests covering all core protocol components:

- Packet serialization/deserialization roundtrip for all PacketTypes
- Boundary conditions: empty payload, max payload (64 bytes), oversized rejection
- CRC16 integrity: deterministic output, single-bit corruption detection
- Routing engine: beacon insertion, RSSI/hop metric comparison, stale route
  pruning with 32-bit timer wraparound handling, clear_table
- Swarm orchestrator: priority ordering, deduplication, incoming payload
  processing, orchestration cycle garbage collection, clear_tasks
- Security engine: key lifecycle, symmetric encrypt/decrypt roundtrip,
  nonce variation
- Mesh node: sequence deduplication sliding window, peer tracking, dead
  peer cleanup

Also:
- Implement missing RoutingEngine::clear_table() definition
- Implement missing SwarmOrchestrator::clear_tasks() definition
- Update CMakeLists.txt to build mesh_protocol_tests target separately
  from mesh_node_sim (core sources extracted to CORE_SOURCES list)
- Enable CTest integration via enable_testing() and add_test()
- Update .github/workflows/build.yml to run mesh_protocol_tests and
  ctest --output-on-failure in CI

Tests run without physical hardware, internet access, or proprietary
tools. All 25 tests pass on desktop (MinGW GCC 6.3, C++17).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant