Home | History | Annotate | Line # | Download | only in gdb
selftest-arch.c revision 1.1.1.1
      1 /* GDB self-test for each gdbarch.
      2    Copyright (C) 2017 Free Software Foundation, Inc.
      3 
      4    This file is part of GDB.
      5 
      6    This program is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18 
     19 #include "defs.h"
     20 
     21 #if GDB_SELF_TEST
     22 #include "selftest.h"
     23 #include "selftest-arch.h"
     24 #include "arch-utils.h"
     25 
     26 static std::vector<self_test_foreach_arch_function *> gdbarch_tests;
     27 
     28 void
     29 register_self_test_foreach_arch (self_test_foreach_arch_function *function)
     30 {
     31   gdbarch_tests.push_back (function);
     32 }
     33 
     34 namespace selftests {
     35 
     36 static void
     37 tests_with_arch ()
     38 {
     39   int failed = 0;
     40 
     41   for (const auto &f : gdbarch_tests)
     42     {
     43       const char **arches = gdbarch_printable_names ();
     44 
     45       for (int i = 0; arches[i] != NULL; i++)
     46 	{
     47 	  if (strcmp ("fr300", arches[i]) == 0)
     48 	    {
     49 	      /* PR 20946 */
     50 	      continue;
     51 	    }
     52 	  else if (strcmp ("powerpc:EC603e", arches[i]) == 0
     53 		   || strcmp ("powerpc:e500mc", arches[i]) == 0
     54 		   || strcmp ("powerpc:e500mc64", arches[i]) == 0
     55 		   || strcmp ("powerpc:titan", arches[i]) == 0
     56 		   || strcmp ("powerpc:vle", arches[i]) == 0
     57 		   || strcmp ("powerpc:e5500", arches[i]) == 0
     58 		   || strcmp ("powerpc:e6500", arches[i]) == 0)
     59 	    {
     60 	      /* PR 19797 */
     61 	      continue;
     62 	    }
     63 
     64 	  QUIT;
     65 
     66 	  TRY
     67 	    {
     68 	      struct gdbarch_info info;
     69 
     70 	      gdbarch_info_init (&info);
     71 	      info.bfd_arch_info = bfd_scan_arch (arches[i]);
     72 
     73 	      struct gdbarch *gdbarch = gdbarch_find_by_info (info);
     74 	      SELF_CHECK (gdbarch != NULL);
     75 	      f (gdbarch);
     76 	    }
     77 	  CATCH (ex, RETURN_MASK_ERROR)
     78 	    {
     79 	      ++failed;
     80 	      exception_fprintf (gdb_stderr, ex,
     81 				 _("Self test failed: arch %s: "), arches[i]);
     82 	    }
     83 	  END_CATCH
     84 	}
     85     }
     86 
     87   SELF_CHECK (failed == 0);
     88 }
     89 
     90 } // namespace selftests
     91 #endif /* GDB_SELF_TEST */
     92 
     93 /* Suppress warning from -Wmissing-prototypes.  */
     94 extern initialize_file_ftype _initialize_selftests_foreach_arch;
     95 
     96 void
     97 _initialize_selftests_foreach_arch ()
     98 {
     99 #if GDB_SELF_TEST
    100   register_self_test (selftests::tests_with_arch);
    101 #endif
    102 }
    103