From: Yao Qi Date: Tue, 9 May 2017 11:36:53 +0000 (+0100) Subject: Add current_regcache unit test X-Git-Tag: users/hjl/linux/release/2.28.51.0.1~1^2~34^2~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8248946cc5fd4522de630b9d86627af6e8fe0097;p=thirdparty%2Fbinutils-gdb.git Add current_regcache unit test 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 * 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fec07277954..cec30582ac5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2017-05-09 Yao Qi + + * 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 * mips-tdep.c (mips_o32_return_value): Remove unused buffer. diff --git a/gdb/regcache.c b/gdb/regcache.c index d2c253a9b6d..07b1c97fd30 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -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 }