Skip to content

[rocprofiler-sdk] Add validation and error handling for the extra counter YAML file - #5551

Closed
mcao59 wants to merge 7 commits into
developfrom
users/mcao/warn_invalid_yaml
Closed

[rocprofiler-sdk] Add validation and error handling for the extra counter YAML file#5551
mcao59 wants to merge 7 commits into
developfrom
users/mcao/warn_invalid_yaml

Conversation

@mcao59

@mcao59 mcao59 commented Apr 28, 2026

Copy link
Copy Markdown
Member

Status: blocked by ROCP_FATAL hang issue #6717

Rework of #4760

Motivation

Fix SIGSEGV crash in rocprofv3 when invalid counter YAML files are provided via the -E flag.
With invalid counter definitions, the program should exit with meaningful error messages.
With duplicate counter definitions, print warning message and program continues.

Technical Details

1. Add YAML validation for extra counter files

Created dedicated function validateExtraCounterYAML() which validates YAML and returns optional error msg

2. Replace ROCP_FATAL with ROCP_ERROR + std::exit(EXIT_FAILURE) in counter-related code paths

  • Reason for not using ROCP_FATAL: ROCP_FATAL and the rocprofiler's signal handler together causes hang:
    • ROCP_FATAL uses Abseil's LOG(FATAL) which sends SIGABRT (signal 6) to terminate
    • rocprofv3 has a signal handler (rocprofv3_error_signal_handler) that catches SIGABRT
    • The signal handler tries to clean up, then calls the chained signal handler (Abseil's original handler)
    • This causes SIGABRT to be raised again, triggering the rocprofv3 handler recursively
    • The process hangs in this signal handling loop instead of terminating
  • Instead, use ROCP_ERROR + std::exit(EXIT_FAILURE)
    • ROCP_ERROR - Logs the error message (same format as ROCP_FATAL)
    • std::exit(EXIT_FAILURE) - Exits and returns 1 instead of 134 (SIGABRT)

3. Add 11 unit test for metrics

Location: source/lib/rocprofiler-sdk/counters/tests/metrics_test.cpp
Run: ctest -R "unit.metrics.validate"

Tests the validateExtraCounterYAML() function with various invalid and valid YAML inputs:

  • validate_malformed_yaml - YAML syntax errors (unclosed quotes, invalid structure)
  • validate_missing_top_key - Missing rocprofiler-sdk: top-level key
  • validate_missing_counters - Missing counters: array under rocprofiler-sdk
  • validate_missing_name - Counter definition without name: field
  • validate_empty_architectures - Empty architectures: [] array
  • validate_no_event_or_expr - Missing both event+block AND expression
  • validate_event_needs_block - Has event: but missing required block:
  • validate_block_needs_event - Has block: but missing required event:
  • validate_valid_yaml - Properly formed YAML passes validation
  • validate_duplicate_counter_same_arch - Duplicate counter (same name + architecture) warns but doesn't error
  • validate_duplicate_counter_different_arch - Same counter name with different architectures is valid

4. Add 8 extra counters integration test

Location: tests/rocprofv3/counter-collection/extra_counters/
Run: ctest -R "rocprofv3-test-extra-counters-invalid"

Tests rocprofv3 with invalid YAML files to verify clean error handling:

  • invalid_malformed.yaml - Malformed YAML syntax
  • invalid_missing_root.yaml - Missing rocprofiler-sdk top-level key
  • invalid_missing_counters.yaml - Missing counters array
  • invalid_missing_name.yaml - Counter without name field
  • invalid_empty_arch.yaml - Empty architectures list
  • invalid_no_event_expr.yaml - Missing both event/block and expression
  • invalid_event_no_block.yaml - Event specified without block
  • invalid_block_no_event.yaml - Block specified without event

All tests use WILL_FAIL TRUE to verify rocprofv3 exits with error status (not crash).

Result: ✅ All 8 tests pass - rocprofv3 exits cleanly with exit code 1

JIRA ID

AIPROFSDK-22

Test Plan

All YAML validation tests pass without crashes. Invalid counter definitions now produce appropriate error messages and gracefully exit the program (or skips the duplicate counters).

Test Result

Submission Checklist

@mcao59
mcao59 requested a review from a team as a code owner April 28, 2026 19:02
@mcao59
mcao59 requested a review from a team as a code owner April 28, 2026 19:02
@mcao59
mcao59 force-pushed the users/mcao/warn_invalid_yaml branch from 4650088 to da3bfbb Compare April 28, 2026 19:02
DEPENDS vector-ops COPY invalid_${invalid_yaml}.yaml
TIMEOUT 10
LABELS "integration-tests"
WILL_FAIL TRUE)

@mcao59 mcao59 Apr 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: improvement for tests:
the new integration tests currently verify invalid extra-counter YAML exits with failure (WILL_FAIL TRUE), but they do not assert the emitted error text.
Perhaps I should validate both non-zero exit behavior and user-facing error messages?

@github-actions

github-actions Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report

Code Coverage Report

Tests Only

code coverage tests.png

Samples Only

code coverage samples.png

Tests + Samples

code coverage all.png

@mcao59
mcao59 force-pushed the users/mcao/warn_invalid_yaml branch from 10c0613 to 4a478b9 Compare May 4, 2026 16:52
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label Jun 1, 2026
@mcao59
mcao59 force-pushed the users/mcao/warn_invalid_yaml branch from 4a478b9 to bcc529f Compare June 2, 2026 18:31
@mcao59 mcao59 removed the Stale PR has no activity for 25+ days label Jun 2, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label Jun 28, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed due to inactivity (30 days with no updates).

If you'd like to continue working on this, feel free to reopen the PR or create a new one.

@github-actions github-actions Bot closed this Jul 4, 2026
@mcao59 mcao59 reopened this Jul 8, 2026
@mcao59
mcao59 force-pushed the users/mcao/warn_invalid_yaml branch from 65be9ed to 449e879 Compare July 8, 2026 17:38
@therock-pr-bot

therock-pr-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
🌿 Branch Name ✅ Pass
📝 PR Title/Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ✅ Pass
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled

🎉 All policy checks passed!

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

@therock-pr-bot

therock-pr-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Title/Description

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

@github-actions github-actions Bot removed the Stale PR has no activity for 25+ days label Jul 9, 2026
@mcao59
mcao59 force-pushed the users/mcao/warn_invalid_yaml branch from 449e879 to 75d4c32 Compare July 21, 2026 16:54
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label Aug 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed due to inactivity (30 days with no updates).

If you'd like to continue working on this, feel free to reopen the PR or create a new one.

@github-actions github-actions Bot closed this Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant