Example #1
0
void checkDispatchCases(const char *name, void (*testfunc)(int)) {
	int state;

	dispatchCheckpoint("%s without changes:", name);
	testfunc(0);
	flushschedf();
	
	didResched = 0;
	schedf("\n");
	dispatchCheckpoint("%s with short dispatch suspend:", name);
	testfunc(1);
	flushschedf();

	didResched = 0;
	schedf("\n");
	dispatchCheckpoint("%s while dispatch suspended:", name);
	// Starting a thread apparently resumes the dispatch thread.
	++ignoreResched;
	state = sceKernelSuspendDispatchThread();
	dispatchCheckpoint("sceKernelSuspendDispatchThread: %08x", state);
	testfunc(0);
	dispatchCheckpoint("sceKernelResumeDispatchThread: %08x", sceKernelResumeDispatchThread(state));
	--ignoreResched;
	flushschedf();

	didResched = 0;
	schedf("\n");
	dispatchCheckpoint("%s while intr suspended:", name);
	state = sceKernelCpuSuspendIntr();
	dispatchCheckpoint("sceKernelCpuSuspendIntr: %08x", state);
	testfunc(1);
	dispatchCheckpoint("sceKernelCpuResumeIntr: %08x", sceKernelCpuResumeIntr(state));
	flushschedf();
}
Example #2
0
int main(int argc, char **argv)
{
    unsigned n, j, i, sdim;
    static double x[MAXDIM];
    double testint_sobol = 0, testint_rand = 0;
    nlopt_sobol s;
    if (argc < 3) {
        fprintf(stderr, "Usage: %s <sdim> <ngen>\n", argv[0]);
        return 1;
    }
    nlopt_init_genrand(time(NULL));
    sdim = atoi(argv[1]);
    s = nlopt_sobol_create(sdim);
    n = atoi(argv[2]);
    nlopt_sobol_skip(s, n, x);
    for (j = 1; j <= n; ++j) {
        nlopt_sobol_next01(s, x);
        testint_sobol += testfunc(sdim, x);
        if (j < 100) {
            printf("x[%u]: %g", j, x[0]);
            for (i = 1; i < sdim; ++i)
                printf(", %g", x[i]);
            printf("\n");
        }
        for (i = 0; i < sdim; ++i)
            x[i] = nlopt_urand(0., 1.);
        testint_rand += testfunc(sdim, x);
    }
    nlopt_sobol_destroy(s);
    printf("Test integral = %g using Sobol, %g using pseudorandom.\n", testint_sobol / n, testint_rand / n);
    printf("        error = %g using Sobol, %g using pseudorandom.\n", testint_sobol / n - 1, testint_rand / n - 1);
    return 0;
}
Example #3
0
int main(int argc, char **argv)
{
	int t1, t2, t3, t4;
	double r = 0.0;
	t1 = ReadTSC();
	r += testfunc();
	t2 = ReadTSC();
	r += testfunc();
	t3 = ReadTSC();
	r += testfunc();
	t4 = ReadTSC();

	printf ("Times: %i, %i, %i: result %f\n", t2-t1, t3-t2, t4-t3, r);

	t1 = ReadTSC();
	r += testfunc2();
	t2 = ReadTSC();
	r += testfunc2();
	t3 = ReadTSC();
	r += testfunc2();
	t4 = ReadTSC();

	printf ("Times: %i, %i, %i: result %f\n", t2-t1, t3-t2, t4-t3, r);

	getchar();

	return 0;
}
Example #4
0
/* one operand, two results */
static void
test3a (int (*testfunc)(mpfr_ptr, mpfr_ptr, mpfr_srcptr, mp_rnd_t),
        char *foo, mp_prec_t prec, mp_rnd_t rnd)
{
  mpfr_t ref1, ref2, ref3;
  mpfr_t res1, res2;
  int i;

#ifdef DEBUG
  printf ("checking %s\n", foo);
#endif
  mpfr_init2 (ref1, prec);
  mpfr_init2 (ref2, prec);
  mpfr_init2 (ref3, prec);
  mpfr_init2 (res1, prec);
  mpfr_init2 (res2, prec);

  for (i=0; i<SPECIAL_MAX; i++)
    {
      set_special (ref3, i);

      /* reference call: foo(a, b, c) */
      testfunc (ref1, ref2, ref3, rnd);

      /* foo(a, b, a) */
      mpfr_set (res1, ref3, rnd); /* exact operation */
      testfunc (res1, res2, res1, rnd);
      if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2))
        {
          printf ("Error for %s(a, b, a) for rnd=%s, ", foo,
                  mpfr_print_rnd_mode (rnd));
          DISP2("a=",ref3);
          DISP("expected (", ref1); DISP(",",ref2);
          DISP("), got (", res1); DISP(",", res2); printf(")\n");
          exit (1);
        }

      /* foo(a, b, b) */
      mpfr_set (res2, ref3, rnd); /* exact operation */
      testfunc (res1, res2, res2, rnd);
      if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2))
        {
          printf ("Error for %s(a, b, b) for ", foo);
          DISP2("b=",ref3);
          DISP("expected (", ref1); DISP(",",ref2);
          DISP("), got (", res1); DISP(",", res2); printf(")\n");
          exit (1);
        }
    }

  mpfr_clear (ref1);
  mpfr_clear (ref2);
  mpfr_clear (ref3);
  mpfr_clear (res1);
  mpfr_clear (res2);
}
Example #5
0
int main(int argc, const char *argv[])
{

    if (argc < 2)
    {
        fprintf (stderr, "Usage: %s [mode]\n mode: 0 -> FIXED_STACKSIZE_POOL; 1 -> FIXED_STACKSIZE_MALLOC; 2 -> DYNAMIC_STACKSIZE_MALLOC ; \n", argv[0]);
        exit (EXIT_FAILURE);
    }

    if (argv[1][0] == '0')
    {
        mgr.InitCoMgr(sizeof(int), 128*1024, MAX_CO_COUNT, FIXED_STACKSIZE_POOL, NULL, NULL);
    }
    else if (argv[1][0] == '2')
    {
        mgr.InitCoMgr(sizeof(int), 0, MAX_CO_COUNT, DYNAMIC_STACKSIZE_MALLOC, malloc, free);
    }
    else if (argv[1][0] == '1')
    {
        mgr.InitCoMgr(sizeof(int), 128*1024, MAX_CO_COUNT, FIXED_STACKSIZE_MALLOC, malloc, free);
    }
    else
    {
        fprintf (stderr, "Usage: %s [mode]\n mode: 0 -> FIXED_STACKSIZE_POOL; 1 -> FIXED_STACKSIZE_MALLOC; 2 -> DYNAMIC_STACKSIZE_MALLOC ; \n", argv[0]);
        exit (EXIT_FAILURE);
    }
    

    if (argv[1][1] == '0')
    {
        testfunc();
    }
    else if (argv[1][1] == '1')
    {
        testprocessallactive();
    }
    else if (argv[1][1] == '2')
    {
        testtimeout();
    }

    //
    //
    //
    //printf("\n\n\n\n");
    ////case 2
    //
    //

    //printf("\n\n\n\n");
    //// case 3

    //
    //printf("\n\n\n\n");
    
    testperformance();
    
    mgr.Destory();
    return 0;
}
static void run_test(data_t *data, void (*testfunc)(data_t *), int cursor_w, int cursor_h)
{
	igt_display_t *display = &data->display;
	igt_output_t *output;
	enum pipe p;
	int valid_tests = 0;

	igt_require(cursor_w <= data->cursor_max_w &&
		    cursor_h <= data->cursor_max_h);

	for_each_connected_output(display, output) {
		data->output = output;
		for_each_pipe(display, p) {
			data->pipe = p;

			if (!prepare_crtc(data, output, cursor_w, cursor_h))
				continue;

			valid_tests++;

			igt_info("Beginning %s on pipe %s, connector %s\n",
				 igt_subtest_name(),
				 kmstest_pipe_name(data->pipe),
				 igt_output_name(output));

			testfunc(data);

			igt_info("\n%s on pipe %s, connector %s: PASSED\n\n",
				 igt_subtest_name(),
				 kmstest_pipe_name(data->pipe),
				 igt_output_name(output));

			/* cleanup what prepare_crtc() has done */
			cleanup_crtc(data, output);
		}
Example #7
0
main()
{
    int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
    int *p,*q;
    int *t;
    //p=&a[2][2][2]; not initialized
    t=&a[1][1][1];
    //*q=***a;
    //printf("%d\n",*q);
    //printf("%d\n",***a);
   // printf("%d\n",*p);
   int i;
   for(i=0;i<2;i++)
   {
           printf("t=%d\n",*t);
           int j;
           for(j=0;j<2;j++)
           {
                   int k;
                   for(k=0;k<2;k++)
                   {
                    printf("a=%d\n",a[i][j][k]);
                   }
           }
           
   }
   testfunc();
    testfunc2();
     testfunc2();
    system("pause");
}
Example #8
0
void drc_cmn_init(void)
{
  int ret = plat_mem_set_exec(tcache, sizeof(tcache));
  elprintf(EL_STATUS, "drc_cmn_init: %p, %zd bytes: %d",
    tcache, sizeof(tcache), ret);

#ifdef __arm__
  if (PicoOpt & POPT_EN_DRC)
  {
    static int test_done;
    if (!test_done)
    {
      int *test_out = (void *)tcache;
      int (*testfunc)(void) = (void *)tcache;

      elprintf(EL_STATUS, "testing if we can run recompiled code..");
      *test_out++ = 0xe3a000dd; // mov r0, 0xdd
      *test_out++ = 0xe12fff1e; // bx lr
      cache_flush_d_inval_i(tcache, test_out);

      // we'll usually crash on broken platforms or bad ports,
      // but do a value check too just in case
      ret = testfunc();
      elprintf(EL_STATUS, "test %s.", ret == 0xdd ? "passed" : "failed");
      test_done = 1;
    }
  }
#endif
}
Example #9
0
int
main(int argc, char **argv)
{
	size_t rawlen;
	uint8_t *rawdata;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <HEXDATA>\n", argv[0]);
		return (EXIT_FAILURE);
	}

	if (!hex_decode(argv[1], &rawdata, &rawlen)) {
		fprintf(stderr, "Error: unable to decode hex\n");
		return (EXIT_FAILURE);
	}

	if (loadfunc(rawdata, rawlen)) {
		testfunc();
		freefunc();
	} else {
		free(rawdata);
		fprintf(stderr, "Error: load function failed\n");
		return (EXIT_FAILURE);
	}

	free(rawdata);

	return (EXIT_SUCCESS);
}
static int __init example_init(void)
{
#ifdef DYNAMIC
	int ret;

	ret = kfifo_alloc(&test, FIFO_SIZE, GFP_KERNEL);
	if (ret) {
		printk(KERN_ERR "error kfifo_alloc\n");
		return ret;
	}
#else
	INIT_KFIFO(test);
#endif
	if (testfunc() < 0) {
#ifdef DYNAMIC
		kfifo_free(&test);
#endif
		return -EIO;
	}

	if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) {
#ifdef DYNAMIC
		kfifo_free(&test);
#endif
		return -ENOMEM;
	}
	return 0;
}
Example #11
0
int main(void) {
  printf("Calling testfunc with properly aligned stack\n");
  testfunc();
  printf("Calling testfunc with misaligned stack\n");
  call_with_misaligned_stack(testfunc);
  return 0;
}
Example #12
0
/**
 * Test for an alpha-numeric string
 *
 * @param testfunc  test function for individual character
 * @param str       a pointer of string
 *
 * @return true for ok, otherwise returns false
 *
 * @code
 *   if(qstrtest(isalnum, "hello1234") == true) {
 *     printf("It is alpha-numeric string.");
 *   }
 *
 *   if(qstrtest(isdigit, "0123456789") == true) {
 *     printf("It is alpha-numeric string.");
 *   }
 * @endcode
 *
 * @note
 *  Basically you can use below test functios without creating your own version.
 *  Make sure <ctype.h> header should be included before using any of these
 *  functions.
 *    isalnum - checks for an alphanumeric character.
 *    isalpha - checks for an alphabetic character.
 *    isascii - checks  whether  c is a 7-bit unsigned char value that fits into
 *              the ASCII character set.
 *    isblank - checks for a blank character; that is, a space or a tab.
 *    iscntrl - checks for a control character.
 *    isdigit - checks for a digit (0 through 9).
 *    isgraph - checks for any printable character except space.
 *    islower - checks for a lower-case character.
 *    isprint - checks for any printable character including space.
 *    ispunct - checks for any printable character which is not a  space or an
 *              alphanumeric character.
 *    isspace - checks  for  white-space  characters.
 *    isupper - checks for an uppercase letter.
 *    isxdigit -  checks for a hexadecimal digits.
 *  Please refer "man isalnum" for more details about these functions.
 */
bool qstrtest(int (*testfunc)(int), const char *str)
{
    for (; *str; str++) {
        if (testfunc(*str) == 0) return false;
    }
    return true;
}
void main() {

  const ConstantFloatTy FloatConstant0 = 0x3f9f5c29;    /* 1.245 */
  const ConstantDoubleTy FloatConstant1 = 0x432ff973cafa8000;    /* 4.5e+15 */

  __main();
  testfunc(12, (*(float*)&FloatConstant0), 120, 123456677890ll, -10, (*(double*)&FloatConstant1));
  return;
}
Example #14
0
static void
test2ui (int (*testfunc)(mpfr_ptr, mpfr_srcptr, unsigned long int, mp_rnd_t),
         char *foo, mp_prec_t prec, mp_rnd_t rnd)
{
  mpfr_t ref1, ref2;
  unsigned int ref3;
  mpfr_t res1;
  int i;

#ifdef DEBUG
  printf("checking %s\n", foo);
#endif
  mpfr_init2 (ref1, prec);
  mpfr_init2 (ref2, prec);
  mpfr_init2 (res1, prec);

  /* ref2 can be NaN, +Inf, -Inf, +0, -0 or any number
     ref3 can be 0 or any number */
  for (i=0; i<SPECIAL_MAX*2; i++)
    {
      set_special (ref2, i%SPECIAL_MAX);
      ref3 = i/SPECIAL_MAX == 0 ? 0 : randlimb ();

      /* reference call: foo(a, b, c) */
      testfunc (ref1, ref2, ref3, rnd);

      /* foo(a, a, c) */
      mpfr_set (res1, ref2, rnd); /* exact operation */
      testfunc (res1, res1, ref3, rnd);

      if (mpfr_compare (res1, ref1))
        {
          printf ("Error for %s(a, a, c) for c=%u\n", foo, ref3);
          DISP2("a=",ref2);
          printf ("expected "); mpfr_print_binary (ref1); puts ("");
          printf ("got      "); mpfr_print_binary (res1); puts ("");
          exit (1);
        }
    }

  mpfr_clear (ref1);
  mpfr_clear (ref2);
  mpfr_clear (res1);
}
Example #15
0
static void run_test(const char *testname, int count, void (* testfunc)())
{
    PRIntervalTime start, end;
    start = PR_IntervalNow();
    for (; count; --count)
        testfunc();
    end = PR_IntervalNow();
    printf("completed %s test in %u milliseconds\n", testname,
            PR_IntervalToMilliseconds(end - start));
}
Example #16
0
static void
testui2 (int (*testfunc)(mpfr_ptr, unsigned long int, mpfr_srcptr, mpfr_rnd_t),
         const char *foo, mpfr_prec_t prec, mpfr_rnd_t rnd)
{
  mpfr_t ref1, ref3;
  unsigned int ref2;
  mpfr_t res1;
  int i;

#ifdef DEBUG
  printf("checking %s\n", foo);
#endif
  mpfr_init2 (ref1, prec);
  mpfr_init2 (ref3, prec);
  mpfr_init2 (res1, prec);

  for (i=0; i<SPECIAL_MAX*2; i++)
    {
      set_special (ref3, i%SPECIAL_MAX);
      ref2 = i/SPECIAL_MAX==0 ? 0 : randlimb ();

      /* reference call: foo(a, b, c) */
      testfunc (ref1, ref2, ref3, rnd);

      /* foo(a, b, a) */
      mpfr_set (res1, ref3, rnd); /* exact operation */
      testfunc (res1, ref2, res1, rnd);
      if (mpfr_compare (res1, ref1))
        {
          printf ("Error for %s(a, b, a) for b=%u \n", foo, ref2);
          DISP2("a=", ref3);
          DISP("expected", ref1); DISP2(", got ", res1);
          exit (1);
        }
    }

  mpfr_clear (ref1);
  mpfr_clear (ref3);
  mpfr_clear (res1);
}
Example #17
0
/* foo(mpfr_ptr, mpfr_srcptr) */
static void
test2a (int (*testfunc)(mpfr_ptr, mpfr_srcptr),
        char *foo, mp_prec_t prec)
{
  mpfr_t ref1, ref2;
  mpfr_t res1;
  int i;

#ifdef DEBUG
  printf ("checking %s\n", foo);
#endif
  mpfr_init2 (ref1, prec);
  mpfr_init2 (ref2, prec);
  mpfr_init2 (res1, prec);

  for (i=0; i<SPECIAL_MAX; i++)
    {
      set_special (ref2, i);

      /* reference call: foo(a, b) */
      testfunc (ref1, ref2);

      /* foo(a, a) */
      mpfr_set (res1, ref2, GMP_RNDN); /* exact operation */
      testfunc (res1, res1);
      if (mpfr_compare (res1, ref1))
        {
          printf ("Error for %s(a, a) for ", foo);
          DISP2("a=",ref2);
          DISP("expected", ref1); DISP2(", got ", res1);
          exit (1);
        }
    }

  mpfr_clear (ref1);
  mpfr_clear (ref2);
  mpfr_clear (res1);
}
Example #18
0
File: util.c Project: xiph/flac
double
benchmark_function (void (*testfunc) (void), unsigned count)
{	struct timespec start, end;
	unsigned k ;

	clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start) ;

	for (k = 0 ; k < count ; k++)
		testfunc () ;

	clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &end) ;

	return timespec_diff (&start, &end) / count ;
} /* benchmark_function */
Example #19
0
File: util.c Project: xiph/flac
double
benchmark_function (void (*testfunc) (void), unsigned count)
{	struct timeval start, end;
	unsigned k ;

	gettimeofday(&start, NULL);

	for (k = 0 ; k < count ; k++)
		testfunc () ;

	gettimeofday(&end, NULL);

	return timeval_diff (&start, &end) / count ;
} /* benchmark_function */
Example #20
0
File: util.c Project: xiph/flac
double
benchmark_function (void (*testfunc) (void), unsigned count)
{
	uint64_t start, end;
	unsigned k;

	start = mach_absolute_time();

	for (k = 0 ; k < count ; k++)
		testfunc();

	end = mach_absolute_time();

	return counter_diff (&start, &end) / count ;
} /* benchmark_function */
Example #21
0
File: util.c Project: xiph/flac
double
benchmark_function (void (*testfunc) (void), unsigned count)
{
	LARGE_INTEGER start, end;
	unsigned k;

	QueryPerformanceCounter (&start) ;

	for (k = 0 ; k < count ; k++)
		testfunc();

	QueryPerformanceCounter (&end) ;

	return counter_diff (&start, &end) / count ;
} /* benchmark_function */
void run_test(const char* test_name, void (*testfunc)())
{
    try
    {
        fprintf(stderr, "%s\n", test_name);
        testfunc();
    }
    catch(const std::exception& e)
    {
        fprintf(stderr, "%s\n", e.what());
        fprintf(stderr, "FAIL\n");
        exit(EXIT_FAILURE);
    }
    fprintf(stderr, "PASS\n");
}
static int
runtest_(const char *testname, int (*testfunc)(void), void (*setup)(void),
         void (*teardown)(void))
{
    int nf;
    if (setup)
        setup();
    nf = testfunc();
    if (teardown)
        teardown();
    printf("%c", nf>0 ? 'F':'.');
    fflush(stdout);
    if (nf > 0)
        sprintf(failed, "%s ** F: %s failed!\n", failed, testname);
    return nf;
}
Example #24
0
int main()
{
	::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
	::SetProcessPriorityBoost(::GetCurrentProcess(), TRUE);
	::SetProcessAffinityMask(::GetCurrentProcess(), 0x00000005);

	printf("pid:%u\n", ::GetCurrentProcessId());
	getchar();

	for (int i = 0; i < 10; i++)
	{
		testfunc();
	}

//	getchar();
	return 0;
}
Example #25
0
int main () {
  double vnd[10][20];
  int i, j;
  vnd[i][j] = 3.0;
  #pragma omp target device(cuda) copy_in(vnd) copy_out(vnd)
  #pragma omp parallel  shared(vnd) private(i,j)
  {
  #pragma omp for 
  for (i = 1; i < 10; i++) {
    for (j = i; j < 10; j++) 
     vnd[i][j] = -1.0;
    
  }
  }

  testfunc(vnd);

}
Example #26
0
int main(void)
{
char *msg="123456";
long *srcptr=NULL;
long *dstptr=NULL;
int fd;
long p=(long)&testfunc;
f=(void *)p;
//f=&testfunc;
fd=shm_open("/shmdxw2",O_CREAT|O_RDWR,0666);
if(fd==-1)
	printf("open mq error\n");
ftruncate(fd,sizeof(f));

if(fork()==0)
{
	sleep(1);
	//execl("./shm_becall",NULL);
	dstptr=(long *)mmap(NULL,sizeof(f),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
	printf("shm receive");
	f=(long *)*dstptr;
	printf("f is %p\n",f);
	f();
	exit(0);
}
else
{
	testfunc();
	srcptr=(long *)mmap(NULL,sizeof(f),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
	//close(fd);
	memcpy(srcptr,&p,sizeof(f));
	printf("send f=%p\n",p);
	printf("send done\n");
}
return 0;
}
Example #27
0
int main(int argc,char *argv[])
{
    teststruct ts;
    testfunc(1,&ts,a,ts);
}
Example #28
0
main(int argc, char **argv)
{
    testfunc(r);
    r(1,2,3,4,5,6,7,8,9);
    printf("hi");
}
Example #29
0
static void
test4 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr,
                       mp_rnd_t),
       char *foo, mp_prec_t prec, mp_rnd_t rnd)
{
  mpfr_t ref, op1, op2, op3;
  mpfr_t res;
  int i, j, k;

#ifdef DEBUG
  printf("checking %s\n", foo);
#endif
  mpfr_init2 (ref, prec);
  mpfr_init2 (op1, prec);
  mpfr_init2 (op2, prec);
  mpfr_init2 (op3, prec);
  mpfr_init2 (res, prec);

  /* for each variable, consider each of the following 6 possibilities:
     NaN, +Infinity, -Infinity, +0, -0 or a random number */

  for (i=0; i<SPECIAL_MAX; i++)
    {
      set_special (op1, i);
      for (j=0; j<SPECIAL_MAX; j++)
        {
          set_special (op2, j);
          for (k=0; k<SPECIAL_MAX; k++)
            {
              set_special (op3, k);

              /* reference call: foo(s, a, b, c) */
              testfunc (ref, op1, op2, op3, rnd);

              /* foo(a, a, b, c) */
              mpfr_set (res, op1, rnd); /* exact operation */
              testfunc (res, res, op2, op3, rnd);

              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, b, c) for ", foo);
                  DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }

              /* foo(b, a, b, c) */
              mpfr_set (res, op2, rnd);
              testfunc (res, op1, res, op3, rnd);

              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, b, c) for ", foo);
                  DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }

              /* foo(c, a, b, c) */
              mpfr_set (res, op3, rnd);
              testfunc (res, op1, op2, res, rnd);

              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, b, c) for ", foo);
                  DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }

              /* foo(a, a, a,c) */
              testfunc (ref, op1, op1, op3, rnd);
              mpfr_set (res, op1, rnd);
              testfunc (res, res, res, op3, rnd);
              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, b, c) for ", foo);
                  DISP("a=", op1); DISP(", a=", op2); DISP2(", c=", op3);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }

              /* foo(a, a, b,a) */
              testfunc (ref, op1, op2, op1, rnd);
              mpfr_set (res, op1, rnd);
              testfunc (res, res, op2, res, rnd);
              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, b, c) for ", foo);
                  DISP("a=", op1); DISP(", a=", op2); DISP2(", c=", op3);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }

              /* foo(b, a, b, b) */
              testfunc (ref, op1, op2, op2, rnd);
              mpfr_set (res, op2, rnd);
              testfunc (res, op1, res, res, rnd);
              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, b, c) for ", foo);
                  DISP("a=", op1); DISP(", a=", op2); DISP2(", c=", op3);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }

              /* foo (a, a, a, a) */
              testfunc (ref, op1, op1, op1 ,rnd);
              mpfr_set (res, op1, rnd);
              testfunc (res, res, res, res, rnd);
              if (mpfr_compare (res, ref))
                {
                  printf ("Error for %s(a, a, a, a) for ", foo);
                  DISP2("a=", op1);
                  DISP("expected ", ref); DISP2(", got", res);
                  exit (1);
                }
            }
        }
    }

  mpfr_clear (ref);
  mpfr_clear (op1);
  mpfr_clear (op2);
  mpfr_clear (op3);
  mpfr_clear (res);

}
Example #30
0
static void
test3 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t),
       char *foo, mp_prec_t prec, mp_rnd_t rnd)
{
  mpfr_t ref1, ref2, ref3;
  mpfr_t res1;
  int i;

#ifdef DEBUG
  printf("checking %s\n", foo);
#endif
  mpfr_init2 (ref1, prec);
  mpfr_init2 (ref2, prec);
  mpfr_init2 (ref3, prec);
  mpfr_init2 (res1, prec);

  /* for each variable, consider each of the following 6 possibilities:
     NaN, +Infinity, -Infinity, +0, -0 or a random number */
  for (i=0; i < SPECIAL_MAX*SPECIAL_MAX ; i++) {
    set_special (ref2, i%SPECIAL_MAX);
    set_special (ref3, i/SPECIAL_MAX);

    /* reference call: foo(a, b, c) */
    testfunc (ref1, ref2, ref3, rnd);

    /* foo(a, a, c) */
    mpfr_set (res1, ref2, rnd); /* exact operation */
    testfunc (res1, res1, ref3, rnd);

    if (mpfr_compare (res1, ref1))
      {
        printf ("Error for %s(a, a, c) for ", foo);
        DISP("a=",ref2); DISP2(", c=",ref3);
        printf ("expected "); mpfr_print_binary (ref1); puts ("");
        printf ("got      "); mpfr_print_binary (res1); puts ("");
        exit (1);
      }

    /* foo(a, b, a) */
    mpfr_set (res1, ref3, rnd);
    testfunc (res1, ref2, res1, rnd);
    if (mpfr_compare (res1, ref1))
      {
        printf ("Error for %s(a, b, a) for ", foo);
        DISP("b=",ref2); DISP2(", a=", ref3);
        DISP("expected ", ref1); DISP2(", got ",res1);
        exit (1);
      }

    /* foo(a, a, a) */
    mpfr_set (ref3, ref2, rnd);
    testfunc (ref1, ref2, ref3, rnd);
    mpfr_set (res1, ref2, rnd);
    testfunc (res1, res1, res1, rnd);

    if (mpfr_compare (res1, ref1))
      {
        printf ("Error for %s(a, a, a) for ", foo);
        DISP2("a=",ref2);
        DISP("expected ", ref1); DISP2(", got", res1);
        exit (1);
      }
  }

  mpfr_clear (ref1);
  mpfr_clear (ref2);
  mpfr_clear (ref3);
  mpfr_clear (res1);
}