This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC 2/7] Add unit test to builtin tdesc generated by xml

On 05/18/2017 10:54 AM, Yao Qi wrote:
> Pedro Alves <> writes:
>>> +{
>>> +  std::string feature_dir (ldirname (__FILE__));
>>> +  struct stat st;
>> Ugh.  Obviously this can't work if gdb is installed / copied elsewhere,
>> remote host testing, etc.
> I thought about this, but I can't figure out one better than __FILE__.
> What I want to do is to find srcdir, and open these xml files during
> unit tests.  Since it is a unit test, I expect gdb is executed in either
> builddir/gdb or builddir/gdb/testsuite.  I don't see a case that people
> build gdb in one place, and run unit/self tests somewhere else.

Not sure -- does it work in remote host testing scenarios?
Recall that unit testing is invoked by the normal testsuite, from

An alternative would be to add a specific command to run these tests,
which would take the path as argument, like
"maint check xml-descriptions /path/to/features/", and then run that
from gdb.gdb/unittest.exp.

>>> +
>>> +  /* Look for the features directory.  If the directory of __FILE__ can't
>>> +     be found, __FILE__ is a file name with relative path.  Guess that
>>> +     GDB is executed in testsuite directory like ../gdb, because I don't
>>> +     expect that GDB is invoked somewhere else and run self tests.  */
>>> +  if (stat ( (), &st) < 0)
>>> +    {
>>> +      feature_dir.insert (0, SLASH_STRING);
>>> +      feature_dir.insert (0, "..");
>>> +
>>> +      /* If still can't find the path, something is wrong.  */
>>> +      SELF_CHECK (stat ( (), &st) == 0);
>> Do we want to flag this as an error / unit test failure?
>> Maybe it should be a warning instead?
> We can skip this test if it can't find "features" directory in source, but
> something wrong can be easily ignored if we do so.
>>> --- a/gdb/target-descriptions.h
>>> +++ b/gdb/target-descriptions.h
>>> @@ -162,6 +162,12 @@ enum gdb_osabi tdesc_osabi (const struct target_desc *);
>>>  int tdesc_compatible_p (const struct target_desc *,
>>>  			const struct bfd_arch_info *);
>>> +/* Compare target descriptions TDESC1 and TDESC2, return true if they
>>> +   are identical.  */
>>> +
>>> +bool tdesc_equals (const struct target_desc *tdesc1,
>>> +		   const struct target_desc *tdesc2);
>> Any reason this and the other equals functions aren't operator==
>> implementations?
> tdesc_reg, tdesc_type, tdesc_feature and target_desc should be
> class-fied first, including adding proper ctor, dtor, etc.

There's no such requirement in the language.

> I thought it
> must be a lot of work, so I don't do that.  I can do that if it doesn't
> take me much time.

But you don't need to do that to implement operators.

>> It's not obvious since the comments say "identical", which would maybe
>> suggest that
>> there may be some property that is not being compared and thus this is not
>> strict value equality, but then function name says "equals".
> I think "identical" implies "strict value equality".  

Yeah, I think I got it backwards (been a long time since I used a programming
language that has such a distinction), but the point still stands -- "identical"
and "equals" can mean slightly different things so I'd rather not mix them up
to avoid confusion.

> The information I
> want to deliver is that this function compares all properties, return
> true if they are exactly the same.  Is it this better,
> /* Return true if target description TDESC1 and TDESC2 are equal.  */

Sure, that makes the comment matches the function name, so it's fine.

Say "target descriptions", plural, though.

Pedro Alves

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]