Beispiel #1
0
static void
test_feupdateenv (void)
{
#if defined FE_NOMASK_ENV && defined FE_ALL_EXCEPT
  int res;

  fedisableexcept (FE_ALL_EXCEPT);

  res = feupdateenv (FE_NOMASK_ENV);

  if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (res != 0))
    {
      puts ("feupdateenv (FE_NOMASK_ENV)) not supported, cannot test.");
      return;
    }
  else if (res != 0)
    {
      puts ("feupdateenv (FE_NOMASK_ENV) failed");
      count_errors++;
    }

  if (fegetexcept () != FE_ALL_EXCEPT)
    {
      puts ("feupdateenv did not set all exceptions");
      count_errors++;
    }
#endif
}
Beispiel #2
0
/* Test that program aborts with no masked interrupts */
static void
feenv_nomask_test (const char *flag_name, int fe_exc)
{
#if defined FE_NOMASK_ENV
  int status;
  pid_t pid;

  if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT)
      && fesetenv (FE_NOMASK_ENV) != 0)
    {
      printf ("Test: not testing FE_NOMASK_ENV, it isn't implemented.\n");
      return;
    }

  printf ("Test: after fesetenv (FE_NOMASK_ENV) processes will abort\n");
  printf ("      when feraiseexcept (%s) is called.\n", flag_name);
  pid = fork ();
  if (pid == 0)
    {
#ifdef RLIMIT_CORE
      /* Try to avoid dumping core.  */
      struct rlimit core_limit;
      core_limit.rlim_cur = 0;
      core_limit.rlim_max = 0;
      setrlimit (RLIMIT_CORE, &core_limit);
#endif

      fesetenv (FE_NOMASK_ENV);
      feraiseexcept (fe_exc);
      exit (2);
    }
  else if (pid < 0)
    {
      if (errno != ENOSYS)
	{
	  printf ("  Fail: Could not fork.\n");
	  ++count_errors;
	}
      else
	printf ("  `fork' not implemented, test ignored.\n");
    }
  else {
    if (waitpid (pid, &status, 0) != pid)
      {
	printf ("  Fail: waitpid call failed.\n");
	++count_errors;
      }
    else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGFPE)
      printf ("  Pass: Process received SIGFPE.\n");
    else
      {
	printf ("  Fail: Process didn't receive signal and exited with status %d.\n",
		status);
	++count_errors;
      }
  }
#endif
}
Beispiel #3
0
/* Tests for feenableexcept/fedisableexcept/fegetexcept.  */
static void
feenable_test (const char *flag_name, int fe_exc)
{
  int excepts;

  printf ("Tests for feenableexcepts etc. with flag %s\n", flag_name);

  /* First disable all exceptions.  */
  if (fedisableexcept (FE_ALL_EXCEPT) == -1)
    {
      printf ("Test: fedisableexcept (FE_ALL_EXCEPT) failed\n");
      ++count_errors;
      /* If this fails, the other tests don't make sense.  */
      return;
    }
  excepts = fegetexcept ();
  if (excepts != 0)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0, is %d\n",
	      flag_name, excepts);
      ++count_errors;
    }
  excepts = feenableexcept (fe_exc);
  if (!EXCEPTION_ENABLE_SUPPORTED (fe_exc) && excepts == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != 0)
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != fe_exc)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, fe_exc, excepts);
      ++count_errors;
    }

  /* And now disable the exception again.  */
  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != fe_exc)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, fe_exc, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != 0)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0, is 0x%x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  /* Now the other way round: Enable all exceptions and disable just this one.  */
  if (feenableexcept (FE_ALL_EXCEPT) == -1)
    {
      printf ("Test: feenableexcept (FE_ALL_EXCEPT) failed\n");
      ++count_errors;
      /* If this fails, the other tests don't make sense.  */
      return;
    }

  excepts = fegetexcept ();
  if (excepts != FE_ALL_EXCEPT)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, FE_ALL_EXCEPT, excepts);
      ++count_errors;
    }

  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != FE_ALL_EXCEPT)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0, is 0x%x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != (FE_ALL_EXCEPT & ~fe_exc))
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, (FE_ALL_EXCEPT & ~fe_exc), excepts);
      ++count_errors;
    }

  /* And now enable the exception again.  */
  excepts = feenableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != (FE_ALL_EXCEPT & ~fe_exc))
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is 0x%x\n",
	      flag_name, excepts);
      ++count_errors;
    }

  excepts = fegetexcept ();
  if (excepts != FE_ALL_EXCEPT)
    {
      printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
	      flag_name, FE_ALL_EXCEPT, excepts);
      ++count_errors;
    }
  feexcp_nomask_test (flag_name, fe_exc);
  feexcp_mask_test (flag_name, fe_exc);

}
Beispiel #4
0
/* Tests for feenableexcept/fedisableexcept.  */
static void
feenable_test (const char *flag_name, fexcept_t fe_exc)
{
  int fe_exci = fe_exc;
  double fe_excd = fe_exc;
  int excepts;

  /* First disable all exceptions.  */
  if (fedisableexcept (FE_ALL_EXCEPT) == -1)
    {
      printf ("Test: fedisableexcept (FE_ALL_EXCEPT) failed\n");
      ++count_errors;
      /* If this fails, the other tests don't make sense.  */
      return;
    }

  /* Test for inline macros using integer argument.  */
  excepts = feenableexcept (fe_exci);
  if (!EXCEPTION_ENABLE_SUPPORTED (fe_exci) && excepts == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != 0)
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
              flag_name, excepts);
      ++count_errors;
    }

  /* And now disable the exception again.  */
  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != fe_exc)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
              flag_name, (unsigned int)fe_exc, excepts);
      ++count_errors;
    }

  /* Test for inline macros using double argument.  */
  excepts = feenableexcept (fe_excd);
  if (!EXCEPTION_ENABLE_SUPPORTED (fe_excd) && excepts == -1)
    {
      printf ("Test: not testing feenableexcept, it isn't implemented.\n");
      return;
    }
  if (excepts == -1)
    {
      printf ("Test: feenableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != 0)
    {
      printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
              flag_name, excepts);
      ++count_errors;
    }

  /* And now disable the exception again.  */
  excepts = fedisableexcept (fe_exc);
  if (excepts == -1)
    {
      printf ("Test: fedisableexcept (%s) failed\n", flag_name);
      ++count_errors;
      return;
    }
  if (excepts != fe_exc)
    {
      printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
              flag_name, (unsigned int)fe_exc, excepts);
      ++count_errors;
    }
}