public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] command-def-selftests.c: detect missing or wrong prefix cmd in subcommands.
@ 2020-06-09 12:51 gdb-buildbot
  2020-06-09 12:51 ` Failures on Fedora-x86_64-cc-with-index, branch master gdb-buildbot
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gdb-buildbot @ 2020-06-09 12:51 UTC (permalink / raw)
  To: gdb-testers

*** TEST RESULTS FOR COMMIT 89bcba74f89baceba3fa7387622e3d60e1de02e8 ***

commit 89bcba74f89baceba3fa7387622e3d60e1de02e8
Author:     Philippe Waroquiers <philippe.waroquiers@skynet.be>
AuthorDate: Sat May 9 16:17:45 2020 +0200
Commit:     Philippe Waroquiers <philippe.waroquiers@skynet.be>
CommitDate: Fri May 15 22:17:45 2020 +0200

    command-def-selftests.c: detect missing or wrong prefix cmd in subcommands.
    
    This test revealed a number of problems that are fixed in the previous commit.
    
    2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
    
            * unittests/command-def-selftests.c (traverse_command_structure):
            Verify all commands of a list have the same prefix command and
            that only the top cmdlist commands have a null prefix.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bdb1db961a..d6204a297e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* unittests/command-def-selftests.c (traverse_command_structure):
+	Verify all commands of a list have the same prefix command and
+	that only the top cmdlist commands have a null prefix.
+
 2020-05-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
 	* cli/cli-decode.c (lookup_cmd_for_prefix): Return the aliased command
diff --git a/gdb/unittests/command-def-selftests.c b/gdb/unittests/command-def-selftests.c
index db70743b3f..2146f8028d 100644
--- a/gdb/unittests/command-def-selftests.c
+++ b/gdb/unittests/command-def-selftests.c
@@ -106,20 +106,26 @@ help_doc_invariants_tests ()
 
 namespace command_structure_tests {
 
+/* Nr of commands in which a duplicated list is found.  */
 unsigned int nr_duplicates = 0;
+/* Nr of commands in a list having no valid prefix cmd.  */
+unsigned int nr_invalid_prefixcmd = 0;
 
 /* A map associating a list with the prefix leading to it.  */
 
 std::map<cmd_list_element **, const char *> lists;
 
 /* Store each command list in lists, associated with the prefix to reach it.  A
-   list must only be found once.  */
+   list must only be found once.
+
+   Verifies that all elements of the list have the same non-null prefix
+   command.  */
 
 static void
 traverse_command_structure (struct cmd_list_element **list,
 			    const char *prefix)
 {
-  struct cmd_list_element *c;
+  struct cmd_list_element *c, *prefixcmd;
 
   auto dupl = lists.find (list);
   if (dupl != lists.end ())
@@ -137,6 +143,13 @@ traverse_command_structure (struct cmd_list_element **list,
 
   lists.insert ({list, prefix});
 
+  /* All commands of *list must have a prefix command equal to PREFIXCMD,
+     the prefix command of the first command.  */
+  if (*list == nullptr)
+    prefixcmd = nullptr; /* A prefix command with an empty subcommand list.  */
+  else
+    prefixcmd = (*list)->prefix;
+
   /* Walk through the commands.  */
   for (c = *list; c; c = c->next)
     {
@@ -148,6 +161,23 @@ traverse_command_structure (struct cmd_list_element **list,
 	     passing the right prefix in.  */
 	  traverse_command_structure (c->prefixlist, c->prefixname);
 	}
+      if (prefixcmd != c->prefix
+	  || (prefixcmd == nullptr && *list != cmdlist))
+	{
+	  if (c->prefix == nullptr)
+	    fprintf_filtered (gdb_stdout,
+			      "list %p reachable via prefix '%s'."
+			      "  command '%s' has null prefixcmd\n",
+			      list,
+			      prefix, c->name);
+	  else
+	    fprintf_filtered (gdb_stdout,
+			      "list %p reachable via prefix '%s'."
+			      "  command '%s' has a different prefixcmd\n",
+			      list,
+			      prefix, c->name);
+	  nr_invalid_prefixcmd++;
+	}
     }
 }
 
@@ -157,12 +187,15 @@ static void
 command_structure_invariants_tests ()
 {
   nr_duplicates = 0;
+  nr_invalid_prefixcmd = 0;
+
   traverse_command_structure (&cmdlist, "");
 
   /* Release memory, be ready to be re-run.  */
   lists.clear ();
 
   SELF_CHECK (nr_duplicates == 0);
+  SELF_CHECK (nr_invalid_prefixcmd == 0);
 }
 
 }


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-06-09 15:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 12:51 [binutils-gdb] command-def-selftests.c: detect missing or wrong prefix cmd in subcommands gdb-buildbot
2020-06-09 12:51 ` Failures on Fedora-x86_64-cc-with-index, branch master gdb-buildbot
2020-06-09 13:08 ` Failures on Fedora-x86_64-m32, " gdb-buildbot
2020-06-09 13:26 ` Failures on Fedora-x86_64-m64, " gdb-buildbot
2020-06-09 13:51 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " gdb-buildbot
2020-06-09 14:13 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot
2020-06-09 15:30 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).