Skip to content

Added test for ParseArguments, ValidMatrixInstruction, ValidWorkGroup,TensileClientConfig and Activation#7722

Open
pdhirajkumarprasad wants to merge 1 commit into
developfrom
users/dhirajp/code_coverage_unit_test_PR5
Open

Added test for ParseArguments, ValidMatrixInstruction, ValidWorkGroup,TensileClientConfig and Activation#7722
pdhirajkumarprasad wants to merge 1 commit into
developfrom
users/dhirajp/code_coverage_unit_test_PR5

Conversation

@pdhirajkumarprasad
Copy link
Copy Markdown
Contributor

Motivation

Technical Details

1. Testing Strategy

  • Pure Python Unit Tests: All tests use Python's unittest.mock module to avoid invoking the actual code generator
  • Lazy Import Pattern: Used pytest fixtures with lazy imports to handle circular dependencies gracefully
  • Incremental Coverage: File-by-file approach to systematically improve coverage across the codebase
  • Mock-Heavy Testing: Extensive use of Mock, MagicMock, patch, and PropertyMock to isolate units under test

2. Circular Dependency Handling

Multiple techniques were employed to work around circular import issues:

  • Lazy Import Fixtures: Delays import until test runs
    @pytest.fixture(scope="module")
    def Module():
        import Tensile.Module as mod
        return mod
  • Direct Module Imports: Import specific modules instead of through package __init__.py
  • Module Namespace Wrappers: Custom namespace classes to expose all module attributes including private ones
  • Skip Tests When Necessary: For hard circular dependencies at import time, tests are marked as skipped

3. Key Technical Patterns

A. Mocking External Dependencies

@patch('Tensile.Activation.rocIsa')
def test_function(self, mock_rocisa):
    mock_rocisa.getInstance.return_value.getArchCaps.return_value = {...}
    # Test code

B. Testing Data Type Variations

Comprehensive coverage of all supported data types:

  • Single precision (s), Double precision (d), Half precision (h)
  • BFloat16 (b), Int8 (I8), Int32 (i)
  • Float8 (F8), BFloat8 (B8) with OCP and NANOO variants
  • Float4 (F4), Float6 (F6), BFloat6 (B6)

C. Testing with Real vs Mock Objects

  • Use real DataType objects when possible for integration-style unit tests
  • Mock complex dependencies like rocIsa, writer, kernel objects
  • Balance between pure mocking and semi-integration testing

Coverage increased:

Tensile/TensileLogic/ParseArguments.py from 0 to 100
Tensile/TensileLogic/ValidMatrixInstruction.py from 0 to 100
Tensile/TensileLogic/ValidWorkGroup.py from 0 to 100
Tensile/TensileClientConfig.py from 0 to 46.5
Tensile/Activation.py from 13.49 to 63.7

total coverage: from 24.66% to 26.11%

5ba977b

Test Plan

N.A

Test Result

N.A

Submission Checklist

…,TensileClientConfig and Activation

Signed-off-by: pdhirajkumarprasad <dhirajp@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant