Skip to content
Snippets Groups Projects

feat: add unit tests and integration tests

Merged matthieu marchal requested to merge mmarchal/aidge_export_tensorrt:unit-tests into main
1 unresolved thread

Context

This MR implements comprehensive unit and integration testing for the aidge_export_tensorrt module. The test suite provides complete coverage of export functionality, file generation, and plugin registry operations to ensure code reliability and maintainability.

Modified files

  • test_export.py (18 tests) - Unit tests for main export functionality
  • test_file_generation.py (9 tests) - Unit tests for file and plugin generation
  • test_plugin_registry.py (6 tests) - Unit tests for plugin registry operations
  • test_integration.py (8 tests) - Integration tests for end-to-end functionality

Total: 41 tests covering all module functionality

Detailed major modifications

Test Architecture & Coverage

Export Functionality (18 tests)

  • Input Validation: GraphView/string type detection, ONNX extension validation with endswith checks
  • File Operations: Directory creation with os.makedirs, file copying via shutil.copy, renaming to model.onnx
  • TensorRT Integration: Version-specific static file copying (default: 10.10) with shutil.copytree
  • PyBind11 Integration: Git cloning with subprocess.run management and error handling
  • Error Handling: Invalid inputs, missing files, CalledProcessError and FileNotFoundError scenarios

File Generation (9 tests)

  • Template Rendering: Jinja2 template processing with variable substitution and nested directory support
  • Directory Structure: Multi-level directory creation for plugins using os.makedirs
  • Plugin Generation: .hpp and .cu file creation in plugins/pluginname/ structure
  • Error Handling: Template validation and file system error simulation

Plugin Registry (6 tests)

  • Registration System: Single/multiple plugin decorators with @plugin_registry.register
  • Key Management: Multiple aliases for same plugin using list-based key registration
  • Functionality Preservation: Decorated function callability maintained after registration

Integration Tests (8 tests)

  • End-to-End Workflow: Complete export with ONNX files and GraphView objects
  • Real-World Scenarios: Concurrent operations with thread safety, large file handling (1MB+)
  • Error Integration: File not found, invalid inputs in full context with proper cleanup
  • Version Handling: Different TensorRT version support (8.6, 10.10) with static file management

Test Environment & Mocking Strategy

Isolation & Cleanup

  • Temporary Directories: tempfile.mkdtemp() for isolated testing environment
  • Automatic Cleanup: shutil.rmtree() in tearDown() methods
  • State Restoration: Original module state restored after each test

Mocking Architecture

Component Mock Target Purpose
External Dependencies aidge_core, aidge_onnx Isolate unit under test from external modules
File Operations shutil.copy, shutil.copytree, os.rename Control file system behavior without actual I/O
System Calls subprocess.run Avoid actual git operations during testing
Error Conditions File not found scenarios Test error handling paths and edge cases

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading