Example #1
0
/* Check that we can process names which fit into the destination
   buffer exactly.  See bug 21359.  */
static void
test_exact_fit (const char *name, size_t length)
{
  unsigned char *buf = xmalloc (length + 1);
  memset (buf, '$', length + 1);
  enum { ptr_count = 5 };
  const unsigned char *dnptrs[ptr_count] = { buf, };
  int ret = ns_name_compress (name, buf, length,
                          dnptrs, dnptrs + ptr_count);
  if (ret < 0)
    {
      support_record_failure ();
      printf ("error: ns_name_compress for %s/%zu failed\n", name, length);
      return;
    }
  if ((size_t) ret != length)
    {
      support_record_failure ();
      printf ("error: ns_name_compress for %s/%zu result mismatch: %d\n",
              name, length, ret);
    }
  if (buf[length] != '$')
    {
      support_record_failure ();
      printf ("error: ns_name_compress for %s/%zu padding write\n",
              name, length);
    }
  free (buf);
}
Example #2
0
static int
do_test (void)
{
  if (signal (SIGUSR1, sigusr1_handler) == SIG_ERR)
    FAIL_EXIT1 ("signal (SIGUSR1): %m\n");

  sigset_t sigs;
  sigemptyset (&sigs);
  sigaddset (&sigs, SIGUSR2);
  if (sigprocmask (SIG_BLOCK, &sigs, NULL) != 0)
    FAIL_EXIT1 ("sigprocmask (SIGBLOCK, SIGUSR2): %m");
  pid_t pid = signal_sender ();
  int signo = 0;
  int ret = sigwait (&sigs, &signo);
  if (ret != 0)
    {
      support_record_failure ();
      errno = ret;
      printf ("error: sigwait failed: %m (%d)\n", ret);
    }
  TEST_VERIFY (signo == SIGUSR2);

  int status;
  xwaitpid (pid, &status, 0);
  TEST_VERIFY (status == 0);

  return 0;
}
Example #3
0
/* Run test case *TEST with FUNC (named FUNCNAME) and report an error
   if the result does not match the result flag at BIT.  */
static void
one_test (const struct test_case *test, const char *funcname,
          int (*func) (const char *), unsigned int bit)
{
  int expected = (test->result & bit) != 0;
  int actual = func (test->dn);
  if (actual != expected)
    {
      support_record_failure ();
      printf ("error: %s (\"%s\"): expected=%d, actual=%d\n",
              funcname, test->dn, expected, actual);
    }
}
Example #4
0
void
check_hostent (const char *query_description, struct hostent *h,
               const char *expected)
{
  char *formatted = support_format_hostent (h);
  if (strcmp (formatted, expected) != 0)
    {
      support_record_failure ();
      printf ("error: hostent comparison failure\n");
      if (query_description != NULL)
        printf ("query: %s\n", query_description);
      support_run_diff ("expected", expected,
                        "actual", formatted);
    }
  free (formatted);
}
Example #5
0
/* Run 255 tests using all the bytes from 1 to 255, surround the byte
   with the strings PREFIX and SUFFIX, and check that FUNC (named
   FUNCNAME) accepts only those bytes listed in ACCEPTED.  */
static void
one_char (const char *prefix, const char *accepted, const char *suffix,
          const char *funcname, int (*func) (const char *))
{
  for (int ch = 1; ch <= 255; ++ch)
    {
      char dn[1024];
      snprintf (dn, sizeof (dn), "%s%c%s", prefix, ch, suffix);
      int expected = strchr (accepted, ch) != NULL;
      int actual = func (dn);
      if (actual != expected)
        {
          support_record_failure ();
          printf ("error: %s (\"%s\"): expected=%d, actual=%d\n",
                  funcname, dn, expected, actual);
        }
    }
}