Skip to content

Conversation

@harp-intel
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for the MergeUncoreGroups function that was recently modified in commit cd5bcf2 to eliminate duplicate uncore events across groups. The duplicate event elimination prevents perf from misreporting event values when the same event appears in multiple groups.

Changes

Added cmd/metrics/loader_perfmon_group_uncore_test.go with 7 test functions covering:

Core Functionality Tests

  • TestMergeUncoreGroups_EliminateDuplicateEvents - Tests duplicate event removal in various scenarios:

    • Duplicate events across 2 groups
    • Duplicate events across 3 groups
    • No duplicate events
    • Empty events don't count as duplicates
    • Duplicates across groups with duplicates in same group
  • TestMergeUncoreGroups_KeepsFirstOccurrence - Verifies that when duplicates are removed, the first occurrence is preserved and subsequent duplicates are eliminated

  • TestMergeUncoreGroups_MergingBehavior - Tests that:

    • Compatible groups still merge after deduplication
    • Incompatible units prevent merging
  • TestMergeUncoreGroups_PreservesMetricNames - Ensures metric names from all groups are preserved during deduplication and merging

Edge Case Tests

  • TestMergeUncoreGroups_EmptyInput - Empty input returns empty result
  • TestMergeUncoreGroups_SingleGroup - Single group remains unchanged
  • TestMergeUncoreGroups_AllEmptyEvents - Groups with only empty events are handled correctly

Test Results

✅ All 7 new test functions pass (21 total sub-tests)
✅ All existing tests continue to pass
✅ Code quality checks pass:

  • make format - Code properly formatted
  • make check_format - No formatting issues
  • make check_vet - No suspicious constructs
  • make check_static - No static analysis issues
  • make check_license - License headers present
  • make check_lint - No linting issues
  • make check_vuln - No vulnerabilities
  • make test - All tests pass

Testing Methodology

Tests follow the project's established patterns:

  • Table-driven tests for comprehensive scenario coverage
  • Uses github.com/stretchr/testify for assertions (consistent with existing tests)
  • Tests both positive and negative cases
  • Validates invariants (e.g., event counts, metric preservation)

Related Issue

Addresses testing for commit cd5bcf2 (#565) which eliminated duplicate uncore events across groups.

🤖 Generated with Claude Code

harp-intel and others added 2 commits November 22, 2025 08:03
This commit adds unit tests for the MergeUncoreGroups function that was
recently modified to eliminate duplicate uncore events across groups
(commit cd5bcf2). The duplicate event elimination prevents perf from
misreporting event values when the same event appears in multiple groups.

Test coverage includes:
- Duplicate event elimination across 2 and 3 groups
- Verification that first occurrence is preserved
- Group merging behavior after deduplication
- Preservation of metric names during merge
- Edge cases: empty input, single group, all empty events
- Validation that empty events don't count as duplicates
- Incompatible unit handling

All tests follow the project's established patterns using table-driven
tests and the testify assertion library.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
The .claude directory contains Claude Code session state and should
not be tracked in version control.

Signed-off-by: Jason Harper <jason.m.harper@intel.com>
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
@harp-intel harp-intel merged commit f7cd45c into main Nov 22, 2025
3 checks passed
@harp-intel harp-intel deleted the add-uncore-merge-tests branch November 22, 2025 16:35
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.

2 participants