diff options
author | Yao Qi <yao.qi@linaro.org> | 2017-06-06 23:07:19 +0100 |
---|---|---|
committer | Yao Qi <yao.qi@linaro.org> | 2017-06-20 11:34:13 +0100 |
commit | 188e9303d5e8e9e2a7663b9136a7c282458ca78e (patch) | |
tree | 350931345499d02d1005d5fdd4dd41237247f3d0 | |
parent | 809ac8acb172bf2cb05dd8a6b1f72cd38f3e58fa (diff) | |
download | gdb-188e9303d5e8e9e2a7663b9136a7c282458ca78e.zip gdb-188e9303d5e8e9e2a7663b9136a7c282458ca78e.tar.gz gdb-188e9303d5e8e9e2a7663b9136a7c282458ca78e.tar.bz2 |
[RFC] GDBserver unit test to i386_tdesc
This patch adds a unit test in GDBserver to test dynamically created
target descriptions equal to these pre-generated ones.
gdb/gdbserver:
2017-06-06 Yao Qi <yao.qi@linaro.org>
* linux-x86-tdesc.c (i386_tdesc_test): New function.
(initialize_low_tdesc): Call register_self_test.
* tdesc.h: TODO.
-rw-r--r-- | gdb/gdbserver/linux-x86-tdesc.c | 45 | ||||
-rw-r--r-- | gdb/gdbserver/tdesc.h | 42 | ||||
-rw-r--r-- | gdb/regformats/regdef.h | 12 |
3 files changed, 98 insertions, 1 deletions
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c index f247a3c..06e5bf9 100644 --- a/gdb/gdbserver/linux-x86-tdesc.c +++ b/gdb/gdbserver/linux-x86-tdesc.c @@ -61,6 +61,47 @@ extern const struct target_desc *tdesc_i386_mpx_linux; static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { }; +#if defined GDB_SELF_TEST && !defined IN_PROCESS_AGENT +#include "selftest.h" + +namespace selftests { +namespace gdbserver { +static void +i386_tdesc_test () +{ + const struct target_desc *tdesc = i386_get_ipa_tdesc (X86_TDESC_MMX); + + SELF_CHECK (*tdesc == *tdesc_i386_mmx_linux); + delete tdesc; + + tdesc = i386_get_ipa_tdesc (X86_TDESC_SSE); + SELF_CHECK (*tdesc == *tdesc_i386_linux); + delete tdesc; + + tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX); + SELF_CHECK (*tdesc == *tdesc_i386_avx_linux); + delete tdesc; + + tdesc = i386_get_ipa_tdesc (X86_TDESC_MPX); + SELF_CHECK (*tdesc == *tdesc_i386_mpx_linux); + delete tdesc; + + tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX); + SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_linux); + delete tdesc; + + tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512); + SELF_CHECK (*tdesc == *tdesc_i386_avx_avx512_linux); + delete tdesc; + + tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU); + SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux); + delete tdesc; +} +} +} // namespace selftests +#endif /* GDB_SELF_TEST */ + void initialize_low_tdesc () { @@ -72,6 +113,10 @@ initialize_low_tdesc () init_registers_i386_avx_mpx_linux (); init_registers_i386_avx_avx512_linux (); init_registers_i386_avx_mpx_avx512_pku_linux (); + +#if GDB_SELF_TEST + register_self_test (selftests::gdbserver::i386_tdesc_test); +#endif #endif } diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h index 2d4cbfa..e64f0b3 100644 --- a/gdb/gdbserver/tdesc.h +++ b/gdb/gdbserver/tdesc.h @@ -19,7 +19,8 @@ #ifndef TDESC_H #define TDESC_H -struct reg; +#include "regdef.h" +#include <cstring> typedef struct reg *tdesc_reg_p; DEF_VEC_P(tdesc_reg_p); @@ -60,6 +61,45 @@ public: xfree (reg); VEC_free (tdesc_reg_p, reg_defs); } + bool operator!= (const target_desc &other) const + { + if (VEC_length (tdesc_reg_p, reg_defs) + != VEC_length (tdesc_reg_p, other.reg_defs)) + return true; + + struct reg *reg; + + for (int ix = 0; + VEC_iterate (tdesc_reg_p, reg_defs, ix, reg); + ix++) + { + struct reg *reg2 + = VEC_index (tdesc_reg_p, other.reg_defs, ix); + + if (reg != reg2 && *reg != *reg2) + return true; + } + + /* Compare expedite_regs. */ + int i = 0; + for (; expedite_regs[i] != NULL; i++) + { + if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0) + return true; + } + if (other.expedite_regs[i] != NULL) + return true; + + if (strcmp (xmltarget, other.xmltarget) != 0) + return true; + + return false; + } + + bool operator== (const target_desc &other) const + { + return !(*this != other); + } #endif }; diff --git a/gdb/regformats/regdef.h b/gdb/regformats/regdef.h index de7a010..ff1d40b 100644 --- a/gdb/regformats/regdef.h +++ b/gdb/regformats/regdef.h @@ -34,6 +34,18 @@ struct reg /* The size (in bits) of the value of this register, as transmitted. */ int size; + + bool operator== (const reg &other) const + { + return (strcmp (name, other.name) == 0 + && offset == other.offset + && size == other.size); + } + + bool operator!= (const reg &other) const + { + return !(*this == other); + } }; #endif /* REGDEF_H */ |