Blame tests/dwarf_default_lower_bound.c

Packit 032894
/* Test all DW_LANG constants are handled by dwarf_default_lower_bound.
Packit 032894
Packit 032894
   Copyright (C) 2016 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation; either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include <dwarf.h>
Packit 032894
#include ELFUTILS_HEADER(dw)
Packit 032894
#include "../libdw/known-dwarf.h"
Packit 032894
Packit 032894
#include <inttypes.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <stdlib.h>
Packit 032894
Packit 032894
static void
Packit 032894
test_lang (const char *name, int lang)
Packit 032894
{
Packit 032894
  Dwarf_Sword low;
Packit 032894
  int res = dwarf_default_lower_bound (lang, &low);
Packit 032894
Packit 032894
  /* Assembler is special, it doesn't really have arrays.  */
Packit 032894
  if (lang == DW_LANG_Mips_Assembler)
Packit 032894
    {
Packit 032894
      if (res == 0)
Packit 032894
	{
Packit 032894
	  printf ("%s shouldn't have a known lower bound\n", name);
Packit 032894
	  exit (-1);
Packit 032894
	}
Packit 032894
      printf ("%s: <unknown>\n", name);
Packit 032894
      return;
Packit 032894
    }
Packit 032894
Packit 032894
  if (res != 0)
Packit 032894
    {
Packit 032894
      printf ("dwarf_default_lower_bound failed (%d) for %s\n", res, name);
Packit 032894
      exit (-1);
Packit 032894
    }
Packit 032894
Packit 032894
  /* All currently known lower bounds are either zero or one, but
Packit 032894
     they don't have to.  Update test once one is a different value.  */
Packit 032894
  if (low != 0 && low != 1)
Packit 032894
    {
Packit 032894
      printf ("unexpected lower bound %" PRId64 " for %s\n", low, name);
Packit 032894
      exit (-1);
Packit 032894
    }
Packit 032894
Packit 032894
  printf ("%s: %" PRId64 "\n", name, low);
Packit 032894
}
Packit 032894
Packit 032894
int
Packit 032894
main (int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  Dwarf_Sword low;
Packit 032894
  /* Bad language code must fail.  */
Packit 032894
  if (dwarf_default_lower_bound (-1, &low) == 0)
Packit 032894
    {
Packit 032894
      printf ("Bad lang code -1 succeeded (%" PRId64 ")\n", low);
Packit 032894
      exit (-1);
Packit 032894
    }
Packit 032894
Packit 032894
  /* Test all known language codes.  */
Packit 032894
#define DWARF_ONE_KNOWN_DW_LANG(NAME, CODE) test_lang (#NAME, CODE);
Packit 032894
  DWARF_ALL_KNOWN_DW_LANG
Packit 032894
#undef DWARF_ONE_KNOWN_DW_LANG
Packit 032894
Packit 032894
  return 0;
Packit 032894
}