예제 #1
0
int main (int argc, char *argv[])
{
  uint64_t starttime, stoptime, elapsedtime;
  double timing_error;
  const double error_threshold = 5.0;    /* Allow a 5% error. */
  int i;

  /* Initialize the run-time library. */
  debug_printf ("\tTesting ncptl_time() ...\n");
  ncptl_init (NCPTL_RUN_TIME_VERSION, argv[0]);

  /* Measure what should be about a million microseconds. */
  for (i=3; i>0; i--) {
    starttime = ncptl_time();
    sleep (1);
    stoptime = ncptl_time();
    elapsedtime = stoptime - starttime;

    /* Complain if we're far off. */
    timing_error = 100.0 * fabs (((double)elapsedtime-1.0e+6) / 1.0e+6);
    debug_printf ("\t   Starting time (usecs):  %25" PRIu64 "\n", starttime);
    debug_printf ("\t   Ending time (usecs):    %25" PRIu64 "\n", stoptime);
    debug_printf ("\t   Elapsed time (usecs):   %25" PRIu64 "\n", elapsedtime);
    debug_printf ("\t   Expected value (usecs): %25llu\n", 1000000ULL);
    debug_printf ("\t   Error:                  %27.1lf%%\n", timing_error);
    if (timing_error <= error_threshold)
      RETURN_SUCCESS();
    if (i > 1)
      debug_printf ("\tTrying again ...\n");
    else
      debug_printf ("\tGiving up.\n");
  }

  /* Return successfully. */
  ncptl_finalize();
  argc = 0;        /* Try to avoid "unused parameter" warnings. */
  RETURN_FAILURE();
}
예제 #2
0
int main (int argc, char *argv[])
{
  char *test_argv[6]; /* Hardwired argv[] for testing. */
  ncptl_int testvar;  /* Variable that ncptl_parse_command_line() should set */
  char *stringvar;    /* A string variable for ncptl_parse_command_line() */
  NCPTL_CMDLINE arglist[] = {    /* Arguments to test. */
    { NCPTL_TYPE_INT,
      NULL,
      "testing",
      't',
      "Test of ncptl_parse_command_line()",
      {0}
    },
    { NCPTL_TYPE_STRING,
      NULL,
      "somestring",
      's',
      "Another test of ncptl_parse_command_line()",
      {0}
    }
  };

  /* Initialize the run-time library and the ARGLIST array. */
  debug_printf ("\tTesting ncptl_parse_command_line() ...\n");
  ncptl_fast_init = 1;    /* We don't need accurate timing for this test. */
  ncptl_init (NCPTL_RUN_TIME_VERSION, argv[0]);
  arglist[0].variable = (CMDLINE_VALUE *) &testvar;
  arglist[0].defaultvalue.intval = 123;
  arglist[1].variable = (CMDLINE_VALUE *) &stringvar;
  arglist[1].defaultvalue.stringval = "abc123";

  /* Ensure that testvar receives its default value when given an
   * empty command line. */
  test_argv[0] = argv[0];
  test_argv[1] = NULL;
  testvar = 999;
  stringvar = "xxx999";
  ncptl_parse_command_line(1, test_argv, arglist, 2);
  debug_printf ("\tExpected 123;      got %" NICS ".\n", testvar);
  debug_printf ("\tExpected \"abc123\"; got \"%s\".\n", stringvar);
  if (testvar != 123)
    RETURN_FAILURE();
  if (strcmp (stringvar, "abc123"))
    RETURN_FAILURE();

  /* Ensure that short arguments work. */
  test_argv[1] = "-t";
  test_argv[2] = "456";
  test_argv[3] = "-s";
  test_argv[4] = "def456";
  test_argv[5] = NULL;
  testvar = 999;
  stringvar = "xxx999";
  ncptl_parse_command_line(5, test_argv, arglist, 2);
  debug_printf ("\tExpected 456;      got %" NICS ".\n", testvar);
  debug_printf ("\tExpected \"def456\"; got \"%s\".\n", stringvar);
  if (testvar != 456)
    RETURN_FAILURE();
  if (strcmp (stringvar, "def456"))
    RETURN_FAILURE();

  /* Ensure that long arguments work. */
#if defined(USE_POPT) || defined(USE_GETOPT_LONG)
  test_argv[1] = "--testing";
  test_argv[2] = "789";
  test_argv[3] = "--somestring";
  test_argv[4] = "ghi789";
  test_argv[5] = NULL;
  testvar = 999;
  stringvar = "xxx999";
  ncptl_parse_command_line(5, test_argv, arglist, 2);
  debug_printf ("\tExpected 789;      got %" NICS ".\n", testvar);
  debug_printf ("\tExpected \"ghi789\"; got \"%s\".\n", stringvar);
  if (testvar != 789)
    RETURN_FAILURE();
  if (strcmp (stringvar, "ghi789"))
    RETURN_FAILURE();
#endif

  /* Ensure that suffixed arguments work. */
  test_argv[1] = "-t";
  test_argv[2] = "1011e+2";
  test_argv[3] = NULL;
  testvar = 999;
  ncptl_parse_command_line(3, test_argv, arglist, 2);
  debug_printf ("\tExpected 101100;      got %" NICS ".\n", testvar);
  if (testvar != 101100)
    RETURN_FAILURE();

  /* Return successfully. */
  ncptl_finalize();
  argc = 0;        /* Try to avoid "unused parameter" warnings. */
  RETURN_SUCCESS();
}