Add current_regcache unit test
authorYao Qi <yao.qi@linaro.org>
Tue, 9 May 2017 11:36:53 +0000 (12:36 +0100)
committerYao Qi <yao.qi@linaro.org>
Tue, 9 May 2017 11:36:53 +0000 (12:36 +0100)
This patch adds a unit test to current_regcache, to make sure it is
correctly updated by get_thread_arch_aspace_regcache and
registers_changed_ptid.

gdb:

2017-05-09  Yao Qi  <yao.qi@linaro.org>

* regcache.c [GDB_SELF_TEST]: Include selftest.h.
(current_regcache_size): New function.
(current_regcache_test): New function.
(_initialize_regcache) [GDB_SELF_TEST]: Register the unit test.

gdb/ChangeLog
gdb/regcache.c

index fec072779541b1e66d3a2011bd02b3245c0290ca..cec30582ac5a9495df4467901f9838afde725460 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-09  Yao Qi  <yao.qi@linaro.org>
+
+       * regcache.c [GDB_SELF_TEST]: Include selftest.h.
+       (current_regcache_size): New function.
+       (current_regcache_test): New function.
+       (_initialize_regcache) [GDB_SELF_TEST]: Register the unit test.
+
 2017-05-08  Alan Hayward  <alan.hayward@arm.com>
 
        * mips-tdep.c (mips_o32_return_value): Remove unused buffer.
index d2c253a9b6df913fe74c7b4f14af9d27dc768465..07b1c97fd3092459d01f962124583a2e7780a880 100644 (file)
@@ -1699,6 +1699,77 @@ maintenance_print_remote_registers (char *args, int from_tty)
   regcache_print (args, regcache_dump_remote);
 }
 
+#if GDB_SELF_TEST
+#include "selftest.h"
+
+namespace selftests {
+
+/* Return the number of elements in current_regcache.  */
+
+static size_t
+current_regcache_size ()
+{
+  size_t i = 0;
+  for (auto list = current_regcache; list; list = list->next)
+    i++;
+
+  return i;
+}
+
+static void
+current_regcache_test (void)
+{
+  /* It is empty at the start.  */
+  SELF_CHECK (current_regcache_size () == 0);
+
+  ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
+
+  /* Get regcache from ptid1, a new regcache is added to
+     current_regcache.  */
+  regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
+                                                       target_gdbarch (),
+                                                       NULL);
+
+  SELF_CHECK (regcache != NULL);
+  SELF_CHECK (regcache->ptid () == ptid1);
+  SELF_CHECK (current_regcache_size () == 1);
+
+  /* Get regcache from ptid2, a new regcache is added to
+     current_regcache.  */
+  regcache = get_thread_arch_aspace_regcache (ptid2,
+                                             target_gdbarch (),
+                                             NULL);
+  SELF_CHECK (regcache != NULL);
+  SELF_CHECK (regcache->ptid () == ptid2);
+  SELF_CHECK (current_regcache_size () == 2);
+
+  /* Get regcache from ptid3, a new regcache is added to
+     current_regcache.  */
+  regcache = get_thread_arch_aspace_regcache (ptid3,
+                                             target_gdbarch (),
+                                             NULL);
+  SELF_CHECK (regcache != NULL);
+  SELF_CHECK (regcache->ptid () == ptid3);
+  SELF_CHECK (current_regcache_size () == 3);
+
+  /* Get regcache from ptid2 again, nothing is added to
+     current_regcache.  */
+  regcache = get_thread_arch_aspace_regcache (ptid2,
+                                             target_gdbarch (),
+                                             NULL);
+  SELF_CHECK (regcache != NULL);
+  SELF_CHECK (regcache->ptid () == ptid2);
+  SELF_CHECK (current_regcache_size () == 3);
+
+  /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
+     current_regcache.  */
+  registers_changed_ptid (ptid2);
+  SELF_CHECK (current_regcache_size () == 2);
+}
+
+} // namespace selftests
+#endif /* GDB_SELF_TEST */
+
 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
 
 void
@@ -1738,5 +1809,7 @@ Print the internal register configuration including each register's\n\
 remote register number and buffer offset in the g/G packets.\n\
 Takes an optional file parameter."),
           &maintenanceprintlist);
-
+#if GDB_SELF_TEST
+  register_self_test (selftests::current_regcache_test);
+#endif
 }
This page took 0.029889 seconds and 4 git commands to generate.