Skip to content

gdb/testsuite: Fix runtime-core.exp wave ordering dependency#196

Merged
amd-bfilipov merged 1 commit into
amd-stagingfrom
users/bfilipov/fix-runtime-core-wave-ordering
Jul 8, 2026
Merged

gdb/testsuite: Fix runtime-core.exp wave ordering dependency#196
amd-bfilipov merged 1 commit into
amd-stagingfrom
users/bfilipov/fix-runtime-core-wave-ordering

Conversation

@amd-bfilipov

@amd-bfilipov amd-bfilipov commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

The "identify waves" test was failing when waves appeared in different
order because the patterns were not anchored to line boundaries, causing
expect to match patterns out of order even with -lbl mode.

Problem:
The test uses gdb_test_multiple with -lbl (line-by-line mode) expecting
each pattern to match complete lines in sequence. However, without proper
anchoring, expect could match a later pattern before an earlier one if
the later pattern's text appeared first in the buffer, consuming the
buffer incorrectly.

When aux_kernel wave appeared before pagefault_kernel wave:

  • pagefault_kernel pattern matched its line first (even though it appeared
    later in output)
  • Buffer was consumed up to that match
  • aux_kernel line (which appeared earlier) was already consumed
  • Second pattern failed to match → test FAIL

Solution:
Anchor patterns to line boundaries using:

  • ^\r\n - enforce beginning of line after previous line ending
  • [^\r\n]+ - match line prefix before the wave info
  • (?=\r\n) - lookahead to ensure pattern matches up to line ending

This ensures each pattern matches a complete line from start to finish,
making the test properly order-independent as -lbl mode intended.

The same anchoring is applied to the gdb_prompt pattern for consistency.

@amd-bfilipov amd-bfilipov requested a review from a team as a code owner July 7, 2026 15:37

@lancesix lancesix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am quite surprised that when having

gdb_test_multiple "foo" "foo" -lbl {
  -re "$a" {
    exp_continue
  }
  -re "$b" {
    exp_continue
  }
}

In our case, $b does not cover $a and vice and versa, and expect that the -lbl should make it so we consume line by line, so should not match $b first if $a could have matched a previous line.

@palves any idea?

Anyway, given some comments, the alternative approach from this patch should be OK.

Comment thread gdb/testsuite/gdb.rocm/runtime-core.exp Outdated
-re "($::decimal) *AMDGPU Wave \[^\r\n\]* aux_kernel \[^\\n\]*" {
set aux_wave $expect_out(1,string)
-re "($::decimal) *AMDGPU Wave \[^\r\n\]*($fault_loc|aux_kernel)\[^\\n\]*" {
if {[string match "*$fault_loc*" $expect_out(0,string)]} {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you could probably extract $expect_out(1,string) first, then match it against $fault_loc or aux_kernel.

Comment thread gdb/testsuite/gdb.rocm/runtime-core.exp Outdated
}
-re "($::decimal) *AMDGPU Wave \[^\r\n\]* aux_kernel \[^\\n\]*" {
set aux_wave $expect_out(1,string)
-re "($::decimal) *AMDGPU Wave \[^\r\n\]*($fault_loc|aux_kernel)\[^\\n\]*" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

still has the \[^\\n\], should be \[^\r\n\].

@aktemur

aktemur commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

I am quite surprised that when having

gdb_test_multiple "foo" "foo" -lbl {
  -re "$a" {
    exp_continue
  }
  -re "$b" {
    exp_continue
  }
}

In our case, $b does not cover $a and vice and versa, and expect that the -lbl should make it so we consume line by line, so should not match $b first if $a could have matched a previous line.

@palves any idea?

Anyway, given some comments, the alternative approach from this patch should be OK.

I think the best approach for such cases is to use ^ to enforce the beginning of the buffer and to match up to \r\n. Like this, for instance:

diff --git a/gdb/testsuite/gdb.rocm/runtime-core.exp b/gdb/testsuite/gdb.rocm/runtime-core.exp
index 7a4cf7036f1..4c8d6506744 100644
--- a/gdb/testsuite/gdb.rocm/runtime-core.exp
+++ b/gdb/testsuite/gdb.rocm/runtime-core.exp
@@ -86,15 +86,15 @@ proc do_test { fault core_type output_type } {
     set faulty_wave 0
     set aux_wave 0
     gdb_test_multiple "info thread" "identify waves" -lbl {
-       -re "($::decimal) *AMDGPU Wave \[^\r\n\]*$fault_loc \[^\\n\]*" {
+       -re "^\r\n\[^\r\n\]+($::decimal) *AMDGPU Wave \[^\r\n\]*$fault_loc \[^\r\n\]*(?=\r\n)" {
            set faulty_wave $expect_out(1,string)
            exp_continue
        }
-       -re "($::decimal) *AMDGPU Wave \[^\r\n\]* aux_kernel \[^\\n\]*" {
+       -re "^\r\n\[^\r\n\]+($::decimal) *AMDGPU Wave \[^\r\n\]* aux_kernel \[^\r\n\]*(?=\r\n)" {
            set aux_wave $expect_out(1,string)
            exp_continue
        }
-       -re "$::gdb_prompt $" {
+       -re "^\r\n$::gdb_prompt $" {
            gdb_assert {($faulty_wave != 0) && ($aux_wave != 0)} $gdb_test_name
        }
     }

@lancesix

lancesix commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

indeed @aktemur, I missed to the ^ bit in the match, and that was the important part… Thanks.

@aktemur

aktemur commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@amd-bfilipov, can you confirm the diff I gave above works for you?

The "identify waves" test was failing when waves appeared in different
order because the patterns were not anchored to line boundaries, causing
expect to match patterns out of order even with -lbl mode.

Problem:
The test uses gdb_test_multiple with -lbl (line-by-line mode) expecting
each pattern to match complete lines in sequence. However, without proper
anchoring, expect could match a later pattern before an earlier one if
the later pattern's text appeared first in the buffer, consuming the
buffer incorrectly.

When aux_kernel wave appeared before pagefault_kernel wave:
- pagefault_kernel pattern matched its line first (even though it appeared
  later in output)
- Buffer was consumed up to that match
- aux_kernel line (which appeared earlier) was already consumed
- Second pattern failed to match → test FAIL

Solution:
Anchor patterns to line boundaries using:
- `^\r\n` - enforce beginning of line after previous line ending
- `[^\r\n]+` - match line prefix before the wave info
- `(?=\r\n)` - lookahead to ensure pattern matches up to line ending

This ensures each pattern matches a complete line from start to finish,
making the test properly order-independent as -lbl mode intended.

The same anchoring is applied to the gdb_prompt pattern for consistency.
@amd-bfilipov amd-bfilipov force-pushed the users/bfilipov/fix-runtime-core-wave-ordering branch from 922f75c to 47ef9da Compare July 8, 2026 16:48
@amd-bfilipov

Copy link
Copy Markdown
Contributor Author

@amd-bfilipov, can you confirm the diff I gave above works for you?

Works, I amended the commit to use your diff. Thanks.

@aktemur aktemur assigned amd-bfilipov and unassigned amd-shahab Jul 8, 2026
@amd-bfilipov amd-bfilipov merged commit e5cfc4c into amd-staging Jul 8, 2026
3 checks passed
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.

4 participants