Re: [PATCH] gdb/testsuite: Add gdb_test_multiple_name variable

Andrew Burgess
2019-10-02T13:03:56Z

* Keith Seitz <keiths@redhat.com> [2019-10-01 10:41:40 -0700]:

> On 10/1/19 10:28 AM, Andrew Burgess wrote:
> > After this patch you can now write this:
> >
> > gdb_test_multiple "print foo" "test foo" {
> > -re "expected output 1" {
> > pass $gdb_test_multiple_name
> > }
> > -re "expected output 2" {
> > fail $gdb_test_multiple_name
> > }
> > }
>
> OMG, why didn't *I* think of that!?!
>
> > The $gdb_test_multiple_name is setup by gdb_test_multiple, and cleaned
> > up once the test has completed. Nested calls to gdb_test_multiple are
> > supported, though $gdb_test_multiple_name will only ever contain the
> > inner most test message (which is probably what you want).
>
> Your patch looks good to me (but I am not a maintainer), but I wanted to
> ask if you considered using a stack to more robustly solve the nesting
> problem? It might be unnecessary today -- even overkill -- but I
> would think it is much easier on the eyes.

Is your suggestion that we maintain a separate global test name stack
and push/pop the latest test name to the stack? This would have the
advantage that a nested action element could access the names of outer
scopes, but this feels to me like something that would be both a
pretty rare requirement, and something that can easily be solved by
the user setting up some global variables as needed.

On the question of robustness, I'd be interested to know if you've
spotted a possible bug. My intention is that the TCL program stack
should serve to backup any existing value of gdb_test_multiple_name,
so there should never be a case where we have the wrong test name in
place.

Thanks,
Andrew

>
> We have such support in the test suite already. See
> testsuite/lib/data-structures.exp. [I am not suggesting any
> changes, just trying to raise awareness for ::Stack et al usage
> in the test suite.]
>
> Keith