Commit 751ba28
authored
Add unit test for TensileLogic_Run, TensileMergeLibrary , TensileRetuneLibrary and TensileUpdateLibrary (ROCm#7703)
## Motivation
Continuation of the TensileLite Python unit-test coverage uplift: this
PR adds pytest suites for four library-management modules
(`TensileLogic/Run`, `TensileMergeLibrary`, `TensileRetuneLibrary`,
`TensileUpdateLibrary`), all at 0% coverage on `develop`. **In
addition**, this PR makes three product-code changes in
`TensileRetuneLibrary.py` and `TensileUpdateLibrary.py` that were either
prerequisites for unit-testing the modules in isolation (the import
refactor) or bugs/dead code uncovered while writing the tests. All three
are detailed below. Tracker (internal):
https://amd-hub.atlassian.net/browse/AIHPBLAS-3405. Pairs with ROCm#7722 —
see "Cross-PR coupling" below.
## Product code changes
This PR is **not** tests-only. Three product-code changes are bundled:
1. **Granular import refactor** (`TensileRetuneLibrary.py`,
`TensileUpdateLibrary.py`).
Replaced the umbrella `from .Common import …` lines with specific
submodule imports — `from .Common.GlobalParameters import …`, `from
.Common.Utilities import …`, `from .Common.Constants import …`, etc.
**Rationale:** lets the modules be unit-tested without pulling the full
`Common` package and its hardware-side initialization. **Safety:** every
name removed from the umbrella is either reachable via the new granular
imports or still re-exported from `Common/__init__.py` via existing
`from .Constants/.Utilities/.Parallel import *` lines (and ROCm#7722
explicitly re-exports the four `GlobalParameters` names — see Cross-PR
coupling).
2. **Dead-code removal** (`TensileRetuneLibrary.py`).
Removed an exact-duplicate copy of `pushWorkingPath`, `popWorkingPath`,
`ensurePath`, and `setWorkingPath` (defined twice in the file on
`develop`, lines 45–66 and again at 69–90 with identical bodies — the
second copy was unreachable shadowing). **Safety:** the surviving copies
are byte-for-byte identical to the removed ones.
3. **Bug fix** (`TensileRetuneLibrary.py::parseCurrentLibrary`).
`GlobalParameters.globalParameters["PerformanceMetric"] = libYaml[10]` →
`globalParameters["PerformanceMetric"] = libYaml[10]`. The qualified
form referenced a name (`GlobalParameters`) that is never imported in
this module — it would have raised `NameError` if the optional 11th
element of `libYaml` ever appeared in a real config. **Locked by test:**
`Tests/unit/test_TensileRetuneLibrary.py::TestParseCurrentLibrary::test_parses_library_without_size_file`
mocks `LibraryIO.read` to return an 11-element list, forcing the `if
len(libYaml) > 10:` branch.
## Cross-PR coupling
This PR pairs with **ROCm#7722**, which adds `from .GlobalParameters import
globalParameters, assignGlobalParameters,
restoreDefaultGlobalParameters, __version__` to
`Tensile/Common/__init__.py`. That re-export preserves the historical
`from Tensile.Common import globalParameters` path for any other
internal or external caller after this PR's refactor lands. The two PRs
are reviewable independently but ideally land together; if landed in
either order, no caller is broken (existing `*`-imports in
`Common/__init__.py` already cover the other names).
## Technical Details
**Modules covered in this PR:**
| Module | Before | After |
|--------|-------:|------:|
| `Tensile/TensileLogic/Run.py` | 0.00% | **94.86%** |
| `Tensile/TensileMergeLibrary.py` | 0.00% | **96.40%** |
| `Tensile/TensileRetuneLibrary.py` | 0.00% | **94.87%** |
| `Tensile/TensileUpdateLibrary.py` | 0.00% | **95.65%** |
Project-wide TensileLite total: 24.66% → **25.68%**.
**Testing approach:**
- Pure-Python unit tests, no code-generator invocation.
- Extensive mocking with `unittest.mock` for all external dependencies
(file I/O, YAML read/write, `validateToolchain`, `ClientWriter`,
`LibraryLogic`, `ProblemType`, `Solution`, `ProblemSizes`).
- All tests marked `@pytest.mark.unit`.
- Coverage targeted at normal execution paths, error conditions, edge
cases, state changes, and CLI-argument parsing.
Reference commit for the test additions:
ROCm@a62795d
## Test Plan
Pure-Python unit tests, CPU only. Run via the existing tensilelite tox
`unit` env:
```bash
cd projects/hipblaslt/tensilelite
tox -e unit -- \
Tensile/Tests/unit/test_TensileLogic_Run.py \
Tensile/Tests/unit/test_TensileMergeLibrary.py \
Tensile/Tests/unit/test_TensileRetuneLibrary.py \
Tensile/Tests/unit/test_TensileUpdateLibrary.py
```
The bug fix in `parseCurrentLibrary` is exercised specifically by
`test_TensileRetuneLibrary.py::TestParseCurrentLibrary::test_parses_library_without_size_file`.
## Test Result
Tests pass; new modules at the coverage levels listed in Technical
Details.
## Submission Checklist
- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
---------
Signed-off-by: pdhirajkumarprasad <dhirajp@amd.com>1 parent d4ff8fc commit 751ba28
5 files changed
Lines changed: 2027 additions & 3 deletions
File tree
- projects/hipblaslt/tensilelite/Tensile
- Tests/unit
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
0 commit comments