예제 #1
0
void TcuExecute(void)
{
    if (TestGetAutomatic()) {
        if (TestGetFilename()) {
            CU_set_output_filename(TestGetFilename());
        }
        CU_automated_run_tests();
    }
    else if (TestGetBasic()) {
        CU_basic_set_mode(CU_BRM_VERBOSE);
        (void) CU_basic_run_tests();
    }
    else if (TestGetConsole()) {
        CU_console_run_tests();
    }
    else if (TestGetList()) {
        if (TestGetFilename()) {
            CU_set_output_filename(TestGetFilename());
        }
        (void) CU_list_tests_to_file();
    }

	if (CU_get_number_of_tests_failed()) {
		return;
	}

    /* Clean up the registry */

    CU_cleanup_registry();
}
예제 #2
0
int main (void)
{

CU_pSuite pSuite = NULL;

   /* initialize the CUnit test registry */
   if (CUE_SUCCESS != CU_initialize_registry())
      return CU_get_error();

   /* add a suite to the registry */
   pSuite = CU_add_suite("Suite1", init_suite1, clean_suite1);
   if (NULL == pSuite) {
      CU_cleanup_registry();
      return CU_get_error();
   }

   /* add the tests to the suite */

   if ((NULL == CU_add_test(pSuite, " 1: Requesting a single record in a compressed warc file", test1)) ||
       (NULL == CU_add_test(pSuite, " 2: Requesting a whole warc file", test2)) ||
       (NULL == CU_add_test(pSuite, " 3: sending a bad request", test3)) ||
       (NULL == CU_add_test(pSuite,"  4: sending a filter request", test4)) ||
       (NULL == CU_add_test(pSuite,"  5: sending a List request with severral output format", test5)))
   {
      CU_cleanup_registry();
      return CU_get_error();
   }

   /* Run all tests using the automated interface*/ 
    switch (menu()) 
  {
        case 1: {CU_console_run_tests(); break;} 
	case 2:  {
                       
                           case 21: {CU_basic_set_mode(CU_BRM_NORMAL); CU_basic_run_tests(); break;}
                            case 22:{CU_basic_set_mode(CU_BRM_VERBOSE ); CU_basic_run_tests(); break;}
                             case 23:{CU_basic_set_mode(CU_BRM_SILENT); CU_basic_run_tests(); break;}  

                              }
        case 3:{
                CU_set_output_filename("./utest/outputs/client");
    		CU_set_output_filename("./utest/outputs/client" );
  		CU_automated_run_tests();
   		CU_list_tests_to_file();
           	break;}
   }

   CU_cleanup_registry();
   return CU_get_error();
}
예제 #3
0
파일: Automated.c 프로젝트: silview/C100A
/** Run CUnit tests using the automated interface.
 *  This function sets appropriate callback functions,
 *  initializes the test output files, and calls the
 *  appropriate functions to list the tests and run them.
 *  If an output file name root has not been specified using
 *  CU_set_output_filename(), a generic root will be applied.
 *  It is an error to call this function before the CUnit
 *  test registry has been initialized (check by assertion).
 */
void CU_automated_run_tests(void)
{
  assert(NULL != CU_get_registry());

  /* Ensure output makes it to screen at the moment of a SIGSEGV. */
  //setvbuf(stdout, NULL, _IONBF, 0);
  // setvbuf(stderr, NULL, _IONBF, 0);

  /* if a filename root hasn't been set, use the default one */
  if (0 == strlen(f_szTestResultFileName)) {
    CU_set_output_filename(f_szDefaultFileRoot);
  }

  if (CUE_SUCCESS != initialize_result_file(f_szTestResultFileName)) {
   __err( "\nERROR - Failed to create/initialize the result file.");
  }
  else {
    /* set up the message handlers for writing xml output */
    CU_set_test_start_handler(automated_test_start_message_handler);
    CU_set_test_complete_handler(automated_test_complete_message_handler);
    CU_set_all_test_complete_handler(automated_all_tests_complete_message_handler);
    CU_set_suite_init_failure_handler(automated_suite_init_failure_message_handler);
    CU_set_suite_cleanup_failure_handler(automated_suite_cleanup_failure_message_handler);

    f_bWriting_CUNIT_RUN_SUITE = CU_FALSE;

    automated_run_all_tests(NULL);

    if (CUE_SUCCESS != uninitialize_result_file()) {
     __err( "\nERROR - Failed to close/uninitialize the result files.");
    }
  }
}
예제 #4
0
int main() {
    CU_pSuite pSuite = NULL;

    /* initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* add a suite to the registry */
    pSuite = CU_add_suite("malELFicus Test Suite", init_suite_success, clean_suite_success);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* add the tests to the suite */
    if (
        (NULL == CU_add_test(pSuite, "testing malelf_init_object()", test_malelf_init_object)) ||
        (NULL == CU_add_test(pSuite, "testing malelf_openr", test_malelf_openr)) ||
        (NULL == CU_add_test(pSuite, "testing malelf_openw", test_malelf_openw)) ||
        (NULL == CU_add_test(pSuite, "testing malelf_check_elf", test_malelf_check_elf))
        ) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    CU_set_output_filename("test_malelf_object");
    /* Run all tests using the automated interface */
    CU_automated_run_tests();
    CU_list_tests_to_file();

    /* Clean up registry and return */
    CU_cleanup_registry();
    return CU_get_error();
}
예제 #5
0
int main (int argc, char** argv) {
	CU_pSuite pSuite = NULL;

	/* initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
	  return CU_get_error();

	/* add a suite to the registry */
	pSuite = CU_add_suite("Suite_1", setup, teardown);
	if (NULL == pSuite) {
	  CU_cleanup_registry();
	  return CU_get_error();
	}

	/* add the tests to the suite */
	if (NULL == CU_add_test(pSuite, "List Creation Test", test_linkedList_create) ||
		NULL == CU_add_test(pSuite, "List Add Test", test_linkedList_add) ||
		NULL == CU_add_test(pSuite, "List Remove Test", test_linkedList_remove))
	{
	  CU_cleanup_registry();
	  return CU_get_error();
	}

	CU_set_output_filename(argv[1]);
	CU_list_tests_to_file();
	CU_automated_run_tests();
	CU_cleanup_registry();
	return CU_get_error();
}
예제 #6
0
int main(int argc, char *argv[])
{
  int basic;
  int console;
  int automated;

  /* parse the command line options */
  while ((c = getopt(argc, argv, "abc")) != -1)
  {
    switch (c)
    {
      case 'a': /* basic mode */
        basic = 1;
        break;
      case 'b': /* basic mode */
        basic = 1;
        break;
      case 'c': /* run from command line */
        console = 1;
        break;
      default: /* error, print usage */
        usage(argv[0]);
        return -1;
    }
  }

  if (CU_initialize_registry())
  {

    fprintf(stderr, "\nInitialization of Test Registry failed.\n");
    exit(EXIT_FAILURE);
  }
  else
  {
    AddTests();

    // set up the run mode and run the tests
    if (automated)
    {
      CU_set_output_filename("TestOutput.xml");
      CU_list_tests_to_file();
      CU_automated_run_tests();
    }
    else if (basic)
    {
      CU_BasicRunMode mode = CU_BRM_VERBOSE;
      CU_ErrorAction error_action = CUEA_IGNORE;
      CU_basic_set_mode(mode);
      CU_set_error_action(error_action);
      CU_basic_run_tests();
    }
    else if (console)
    {
      CU_console_run_tests();
    }
    CU_cleanup_registry();
  }
  return 0;
}
예제 #7
0
파일: testlibs.c 프로젝트: gerv/fossology
int main(int argc, char** argv)
{
  CU_pFailureRecord FailureList;
  CU_RunSummary *pRunSummary;
  int FailRec;

  if(CU_initialize_registry())
  {
    fprintf(stderr, "Initialization of Test Registry failed.'n");
    return -1;
  }

  assert(CU_get_registry());
  assert(!CU_is_test_running());

  if(CU_register_suites(suites) != CUE_SUCCESS)
  {
    fprintf(stderr, "Register suites failed - %s\n", CU_get_error_msg());
    return -1;
  }

  CU_set_output_filename("lib-c");
  CU_list_tests_to_file();
  CU_automated_run_tests();

  pRunSummary = CU_get_run_summary();
  printf("Results:\n");
  printf("  Number of suites run: %d\n", pRunSummary->nSuitesRun);
  printf("  Number of suites failed: %d\n", pRunSummary->nSuitesFailed);
  printf("  Number of tests run: %d\n", pRunSummary->nTestsRun);
  printf("  Number of tests failed: %d\n", pRunSummary->nTestsFailed);
  printf("  Number of asserts: %d\n", pRunSummary->nAsserts);
  printf("  Number of asserts failed: %d\n", pRunSummary->nAssertsFailed);
  printf("  Number of failures: %d\n", pRunSummary->nFailureRecords);

  /* Print any failures */
  if (pRunSummary->nFailureRecords)
  {
    printf("\nFailures:\n");
    FailRec = 1;
    for (FailureList = CU_get_failure_list(); FailureList; FailureList = FailureList->pNext)
    {
      printf("%d. File: %s  Line: %u   Test: %s\n",
             FailRec,
             FailureList->strFileName,
             FailureList->uiLineNumber,
             (FailureList->pTest)->pName);
      printf("  %s\n",
             FailureList->strCondition);
      FailRec++;
    }
    printf("\n");
  }

  CU_cleanup_registry();

  return 0;
}
예제 #8
0
파일: Automated.c 프로젝트: silview/C100A
/** Generate an xml file containing a list of all tests in all
 *  suites in the active registry.
 *  The output file will be named according to the most recent
 *  call to CU_set_output_filename(), or a default if not
 *  previously set.
 *  @return An error code indicating the error status.
 */
CU_ErrorCode CU_list_tests_to_file()
{
  /* if a filename root hasn't been set, use the default one */
  if (0 == strlen(f_szTestListFileName)) {
    CU_set_output_filename(f_szDefaultFileRoot);
  }

  return automated_list_all_tests(CU_get_registry(), f_szTestListFileName);
}
예제 #9
0
/*
 * Main
 */
int
main(void)
{
	CU_pSuite ptr_suite = NULL;
	int nr_of_failed_tests = 0;
	int nr_of_failed_suites = 0;

	/* Initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
		return CU_get_error();

	/* add a suite to the registry */
	ptr_suite = CU_add_suite("ofp port config", init_suite, clean_suite);
	if (NULL == ptr_suite) {
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_sinlge_port_basic)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_two_ports_vlan)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_gre_port)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

#if OFP_TESTMODE_AUTO
	CU_set_output_filename("CUnit-Port-conf");
	CU_automated_run_tests();
#else
	/* Run all tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
#endif

	nr_of_failed_tests = CU_get_number_of_tests_failed();
	nr_of_failed_suites = CU_get_number_of_suites_failed();
	CU_cleanup_registry();

	return (nr_of_failed_suites > 0 ?
		nr_of_failed_suites : nr_of_failed_tests);
}
예제 #10
0
int main( int argc, char *argv[] ) {
	if(CU_initialize_registry()) {
		fprintf(stderr, " Initialization of Test Registry failed. ");
		exit(EXIT_FAILURE);
	}else{
		AddTests();
		CU_set_output_filename("Test single");
		CU_list_tests_to_file();
		CU_automated_run_tests();
		CU_cleanup_registry();
	}
	return 0;
}
예제 #11
0
파일: main.c 프로젝트: kyokuki/whatAmessy
int automatedTest(int argc, char* argv[])
{
  CU_BOOL Run = CU_FALSE ;

  setvbuf(stdout, NULL, _IONBF, 0);

  if (argc > 1) {
    if (!strcmp("-i", argv[1])) {
      Run = CU_TRUE ;
      CU_set_error_action(CUEA_IGNORE);
    }
    else if (!strcmp("-f", argv[1])) {
      Run = CU_TRUE ;
      CU_set_error_action(CUEA_FAIL);
    }
    else if (!strcmp("-A", argv[1])) {
      Run = CU_TRUE ;
      CU_set_error_action(CUEA_ABORT);
    }
//    else if (!strcmp("-e", argv[1])) {
//      print_example_results();
//    }
    else {
      printf("\nUsage:  AutomatedTest [option]\n\n"
               "        Options: -i  Run, ignoring framework errors [default].\n"
               "                 -f  Run, failing on framework error.\n"
               "                 -A  Run, aborting on framework error.\n"
//               "                 -e  Print expected test results and exit.\n"
               "                 -h  Print this message.\n\n");
    }
  }
  else {
    Run = CU_TRUE;
    CU_set_error_action(CUEA_IGNORE);
  }

  if (CU_TRUE == Run) {
    if (CU_initialize_registry()) {
      printf("\nInitialization of Test Registry failed.");
    }
    else {
      AddTests();
      CU_set_output_filename("TestAutomated");
      CU_list_tests_to_file();
      CU_automated_run_tests();
      CU_cleanup_registry();
    }
  }

  return 0;
}
예제 #12
0
int main(int argc, char* argv[])
{
	int a;

	while ((a = getopt(argc, argv, "@iho:")) != EOF)
		switch (a) {
		case 'o':
			if (optarg)
			{
				OutputEscape = 1;
				OutputEscapeAs = *optarg;
			}
			break;
		case 'h':
			parse_html = 1;
			break;
		case '@':
			parse_email = 1;
			break;
		case 'i':
			fromstdin = 1;
			
			break;
		}


	setvbuf(stdout, NULL, _IONBF, 0);

	StartLibCitadel(8);
	CU_BOOL Run = CU_FALSE ;
	
	CU_set_output_filename("TestAutomated");
	if (CU_initialize_registry()) {
		printf("\nInitialize of test Registry failed.");
	}
	
	Run = CU_TRUE ;
	AddStrBufSimlpeTests();
	
	if (CU_TRUE == Run) {
		//CU_console_run_tests();
		printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
    
		///CU_automated_run_tests();
	}
	
	CU_cleanup_registry();

	return 0;
}
예제 #13
0
int bc_tester_start() {
	int ret;
	if( xml_enabled ){
		size_t size = strlen(xml_file) + strlen(".tmp") + 1;
		char * xml_tmp_file = malloc(sizeof(char) * size);
		snprintf(xml_tmp_file, size, "%s.tmp", xml_file);
		CU_set_output_filename(xml_tmp_file);
		free(xml_tmp_file);
	}

	ret = bc_tester_run_tests(suite_name, test_name);

	return ret;
}
        return;
    }
}

void contact_provider_test_run()
{
    if (CU_initialize_registry())
    {
        return;
    }
    else
    {
        contact_provider_add_tests();
        CU_set_output_filename("contact_provider_test_output");
        CU_list_tests_to_file();
예제 #15
0
파일: test.c 프로젝트: wyt0602/data_struct
int main()
{
    if (CU_initialize_registry()) {
	printf("\nInitialization of Test Registry failed.");
    }else{

	LOG_FILE_OPEN("log.txt");

	AddTests();

	/*******Automated Mode(best)*********************
	 * CU_set_output_filename("TestAutomated");
	 * CU_list_tests_to_file();
	 * CU_automated_run_tests();
	 ******************************************/

	 CU_set_output_filename("TestAutomated");
	 CU_list_tests_to_file();
	 CU_automated_run_tests();
	/*******Basic Mode*********************
	 * mode can choose:
	 * typedef enum {
	 *   CU_BRM_NORMAL = 0, Normal mode - failures and run summary are printed [default].
	 *   CU_BRM_SILENT,     Silent mode - no output is printed except framework error messages.
	 *   CU_BRM_VERBOSE     Verbose mode - maximum output of run details.
	 * } CU_BasicRunMode;
	 ****************************************
	 *
	 * CU_basic_set_mode(CU_BRM_NORMAL);
	 * CU_basic_run_tests();
	 ******************************************/

	/*******Console Mode*********************
	 * CU_console_run_tests();
	 ******************************************/

	/*******Curses Mode*********************
	 * CU_curses_run_tests();
	 ******************************************/ 


	CU_cleanup_registry();
    }

    LOG_FILE_CLOSE();
    return 0;
}
예제 #16
0
int main( int argc, char *argv[] )
{
       printf("test start\n");
       if(CU_initialize_registry()){

                fprintf(stderr, "\nInitialization of Test Registry failed.\n");
                exit(EXIT_FAILURE);
        }else{
                AddTests();

                CU_set_output_filename("ununpack");
                CU_list_tests_to_file();
                CU_automated_run_tests();
                CU_cleanup_registry();
        }
        printf("end\n");
        return 0;
}
예제 #17
0
int bc_tester_start(const char* prog_name) {
	int ret;

	detect_res_prefix(prog_name);

	if (max_vm_kb)
		bc_tester_set_max_vm(max_vm_kb);

	if( xml_enabled ){
		char * xml_tmp_file = bc_sprintf("%s.tmp", xml_file);
		CU_set_output_filename(xml_tmp_file);
		free(xml_tmp_file);
	}

	ret = bc_tester_run_tests(suite_name, test_name);

	return ret;
}
예제 #18
0
파일: hash_map_test.c 프로젝트: ecros/celix
int main (int argc, char** argv) {
    CU_pSuite pSuite = NULL;

    /* initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* add a suite to the registry */
    pSuite = CU_add_suite("Suite_1", setup, NULL);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* add the tests to the suite */
    if (NULL == CU_add_test(pSuite, "Map Creation Test", test_hashMap_create)
            || NULL == CU_add_test(pSuite, "Map Size Test", test_hashMap_size)
            || NULL == CU_add_test(pSuite, "Map Is Empty Test", test_hashMap_isEmpty)
            || NULL == CU_add_test(pSuite, "Map Get Test", test_hashMap_get)
            || NULL == CU_add_test(pSuite, "Map Contains Key Test", test_hashMap_containsKey)
            || NULL == CU_add_test(pSuite, "Map Get Entry Test", test_hashMap_getEntry)
            || NULL == CU_add_test(pSuite, "Map Put Test", test_hashMap_put)
            || NULL == CU_add_test(pSuite, "Map Resize Test", test_hashMap_resize)
            || NULL == CU_add_test(pSuite, "Map Remove Test", test_hashMap_remove)
            || NULL == CU_add_test(pSuite, "Map Remove Mapping Test", test_hashMap_removeMapping)
            || NULL == CU_add_test(pSuite, "Map Clear Test", test_hashMap_clear)
            || NULL == CU_add_test(pSuite, "Map Contains Value Test", test_hashMap_containsValue)
            || NULL == CU_add_test(pSuite, "Map To Array Test", test_hashMapValues_toArray)


       )
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    CU_set_output_filename(argv[1]);
    CU_list_tests_to_file();
    CU_automated_run_tests();
    CU_cleanup_registry();
    return CU_get_error();
}
예제 #19
0
int main (int argc, char** argv) {
	CU_pSuite pSuite = NULL;

	/* initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
	  return CU_get_error();

	/* add a suite to the registry */
	pSuite = CU_add_suite("Suite_1", setup, NULL);
	if (NULL == pSuite) {
	  CU_cleanup_registry();
	  return CU_get_error();
	}

	/* add the tests to the suite */
	if (NULL == CU_add_test(pSuite, "Array List Creation Test", test_arrayList_create)
		|| NULL == CU_add_test(pSuite, "Array List Trim Test", test_arrayList_trimToSize)
		|| NULL == CU_add_test(pSuite, "Array List Capacity Test", test_arrayList_ensureCapacity)
		|| NULL == CU_add_test(pSuite, "Array List Size Test", test_arrayList_size)
		|| NULL == CU_add_test(pSuite, "Array List Is Empty Test", test_arrayList_isEmpty)
		|| NULL == CU_add_test(pSuite, "Array List Contains Test", test_arrayList_contains)
		|| NULL == CU_add_test(pSuite, "Array List Index Of Test", test_arrayList_indexOf)
		|| NULL == CU_add_test(pSuite, "Array List Get Test", test_arrayList_get)
		|| NULL == CU_add_test(pSuite, "Array List Set Test", test_arrayList_set)
		|| NULL == CU_add_test(pSuite, "Array List Add Test", test_arrayList_add)
		|| NULL == CU_add_test(pSuite, "Array List Remove Test", test_arrayList_remove)
		|| NULL == CU_add_test(pSuite, "Array List Remove Element Test", test_arrayList_removeElement)
		|| NULL == CU_add_test(pSuite, "Array List Clear Test", test_arrayList_clear)
		|| NULL == CU_add_test(pSuite, "Array List Add All", test_arrayList_addAll)
	)
	{
	  CU_cleanup_registry();
	  return CU_get_error();
	}

	CU_set_output_filename(argv[1]);
	CU_list_tests_to_file();
	CU_automated_run_tests();
	CU_cleanup_registry();
	return CU_get_error();
}
예제 #20
0
int main(void)
{
	CU_pSuite ptr_suite = NULL;
	int nr_of_failed_tests = 0;
	int nr_of_failed_suites = 0;

	/* Initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
		return CU_get_error();

	/* add a suite to the registry */
	ptr_suite = CU_add_suite("ofp errno", init_suite, NULL);
	if (NULL == ptr_suite) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite, test_strerrno)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite, test_tls_errno)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

#if defined(OFP_TESTMODE_AUTO)
	CU_set_output_filename("CUnit-Util");
	CU_automated_run_tests();
#else
	/* Run all tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
#endif

	nr_of_failed_tests = CU_get_number_of_tests_failed();
	nr_of_failed_suites = CU_get_number_of_suites_failed();
	CU_cleanup_registry();

	return (nr_of_failed_suites > 0 ?
		nr_of_failed_suites : nr_of_failed_tests);
}
예제 #21
0
파일: test_main.c 프로젝트: choueric/doc
int main(int argc, char **argv)
{
	/* 初始化CUnit框架 */
	if(CU_initialize_registry()){
		fprintf(stderr, " Initialization of Test Registry failed\n");
		exit(EXIT_FAILURE);
	}

	/* 添加测试suite和test */
    /* ------------------ 需要添加修改 ------------------------ */
	test_maxi_AddSuites();
	test_mini_AddSuites();
    /* -------------------------------------------------------- */
	
	/* 设置输出模式 start */
#if 0  // Automated
	CU_set_output_filename("TestMax");
	CU_list_tests_to_file();
	CU_automated_run_tests();
#endif

#if 1   //basic
	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
#endif

#if 0   //Console
	CU_console_run_tests();
#endif

#if 0 // Curses
	CU_curses_run_tests();
#endif
	/* 设置输出接口 end */


	/* 清理CUnit框架 */
	CU_cleanup_registry();

	return 0;
}
예제 #22
0
파일: main.c 프로젝트: Torvus/pgmanager
int main( int argc, char *argv[] )
{
	int failed = 0;
	gtk_set_locale ();
	gtk_init (&argc, &argv);

	if( CU_initialize_registry() )
	{
		g_critical( "Initialization of Test Registry failed." );
		return EXIT_FAILURE;
	}

	register_all_tests();
	CU_set_output_filename( "TestsResult" );
	CU_list_tests_to_file();
	CU_automated_run_tests();
	/*CU_console_run_tests();*/
	failed = CU_get_number_of_tests_failed();
	CU_cleanup_registry();

	if( failed == 0 )
		return EXIT_SUCCESS;
	return EXIT_FAILURE;
}
예제 #23
0
int main(int argc, char * const *argv)
{
    int ret = 0;
#ifdef HAVE_GETOPT_LONG
    int c;
    struct option long_options[] = {
        {"help", 0, 0, 'h'},
        {"list", 0, 0, 'l'},
        {0, 0, 0, 0}
    };

    while ((c = getopt_long(argc, argv, "hl", long_options, NULL)) != -1) {
        switch (c) {
            case 'h':
                fprintf(stderr, "Usage: %s [test name]\n", argv[0]);
                fputs("\nOptions:\n", stderr);
                fputs("  -h, --help           Show this help message and exit\n", stderr);
                fputs("  -l, --list           List available tests and exit\n", stderr);
                exit(EXIT_SUCCESS);
            case 'l':
                fputs("Available test suites:\n", stdout);;
                printSuites(CU_get_registry()->pSuite, stdout);
                exit(EXIT_SUCCESS);
        }
    }

    if (optind < argc) {
        CU_pTestRegistry old_registry = CU_get_registry();
        CU_set_registry(CU_create_new_registry());

        while (optind < argc) {
            char *suite_name = strdup(argv[optind++]);
            char *test_name = strstr(suite_name, "::");

            if (test_name) {
                *test_name = '\0';
                test_name += 2;
            }

            if (copySuite(old_registry, suite_name, test_name) == 0) {
                fprintf(stderr, "Can't find test suite \"%s", suite_name);
                if (test_name)
                    fprintf(stderr, "::%s\"\n", test_name);
                else
                    fputs("\"\n", stderr);
                exit(EXIT_FAILURE);
            }

            free(suite_name);
        }
        CU_destroy_existing_registry(&old_registry);
    }
#endif

    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_set_output_filename(XML_TEST_REPORT);
    CU_basic_run_tests();
    ret = (CU_get_number_of_tests_failed() == 0) ? 0 : 1;
    CU_cleanup_registry();

    return ret;
}
예제 #24
0
/*
 * Main
 */
int
main(void)
{
    CU_pSuite ptr_suite = NULL;
    int nr_of_failed_tests = 0;
    int nr_of_failed_suites = 0;

    (void)gre_frame;

    /* Initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* add a suite to the registry */
    ptr_suite = CU_add_suite("ofp packet input", init_suite, clean_suite);
    if (NULL == ptr_suite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_init_packet_input_basic)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_init_ifnet)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_local_hook)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_local_IPv4_hook)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_local_UDPv4_hook)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
#ifdef SP
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_to_sp)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
#endif /* SP */
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_send_arp)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_forwarding_to_output)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_gre_processed_inner_pkt_forwarded)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_gre_orig_pkt_to_sp)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    ptr_suite = CU_add_suite("test VRF", NULL , NULL);
    if (NULL == ptr_suite) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_init_packet_input_vrf)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_init_ifnet)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

#ifdef SP
    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_to_sp)) {
        CU_cleanup_registry();
        return CU_get_error();
    }
#endif /* SP */

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_send_arp)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_forwarding_to_output)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_gre_processed_inner_pkt_forwarded)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_ofp_packet_input_gre_orig_pkt_to_sp)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

#if OFP_TESTMODE_AUTO
    CU_set_output_filename("CUnit-PKT-IN");
    CU_automated_run_tests();
#else
    /* Run all tests using the CUnit Basic interface */
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
#endif

    nr_of_failed_tests = CU_get_number_of_tests_failed();
    nr_of_failed_suites = CU_get_number_of_suites_failed();
    CU_cleanup_registry();

    return (nr_of_failed_suites > 0 ?
            nr_of_failed_suites : nr_of_failed_tests);
}
예제 #25
0
int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) {
	int i;
	int ret;
	/* initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
		return CU_get_error();

	for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) {
		run_test_suite(test_suite[i]);
	}

	CU_set_test_start_handler(test_start_message_handler);
	CU_set_test_complete_handler(test_complete_message_handler);
	CU_set_all_test_complete_handler(test_all_tests_complete_message_handler);
	CU_set_suite_init_failure_handler(test_suite_init_failure_message_handler);
	CU_set_suite_cleanup_failure_handler(test_suite_cleanup_failure_message_handler);
	CU_set_suite_start_handler(test_suite_start_message_handler);


	if( liblinphone_tester_xml_file != NULL ){
		CU_set_output_filename(liblinphone_tester_xml_file);
	}
	if( liblinphone_tester_xml_enabled != 0 ){
		CU_automated_run_tests();
	} else {

#if !HAVE_CU_GET_SUITE
		if( suite_name ){
			ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name);
		}
#else
		if (suite_name){
			CU_pSuite suite;
			suite=CU_get_suite(suite_name);
			if (!suite) {
				ms_error("Could not find suite '%s'. Available suites are:", suite_name);
				liblinphone_tester_list_suites();
				return -1;
			} else if (test_name) {
				CU_pTest test=CU_get_test_by_name(test_name, suite);
				if (!test) {
					ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name);
					// do not use suite_name here, since this method is case sensitive
					liblinphone_tester_list_suite_tests(suite->pName);
					return -2;
				} else {
					CU_ErrorCode err= CU_run_test(suite, test);
					if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err);
				}
			} else {
				CU_run_suite(suite);
			}
		}
		else
#endif
		{
#if HAVE_CU_CURSES
			if (curses) {
				/* Run tests using the CUnit curses interface */
				CU_curses_run_tests();
			}
			else
#endif
			{
				/* Run all tests using the CUnit Basic interface */
				CU_run_all_tests();
			}
		}

	}
	ret=CU_get_number_of_tests_failed()!=0;

	/* Redisplay list of failed tests on end */
	if (CU_get_number_of_failure_records()){
		CU_basic_show_failures(CU_get_failure_list());
		liblinphone_tester_fprintf(stdout,"\n");
	}

	CU_cleanup_registry();

	if( liblinphone_tester_keep_accounts_flag == 0){
		liblinphone_tester_clear_accounts();
	}
	return ret;
}
예제 #26
0
파일: check.c 프로젝트: andreydung/EECS468
int main(void)
{
  CU_pSuite util, nfft, nfct, nfst;
  CU_initialize_registry();
  /*CU_set_output_filename("nfft");*/
#ifdef _OPENMP
  CU_set_output_filename("CUnitAutomated_threads");
#endif

#undef X
#define X(name) NFFT(name)
  nfft = CU_add_suite("nfft", 0, 0);
  CU_add_test(nfft, "nfft_1d_direct_file", X(check_1d_direct_file));
  CU_add_test(nfft, "nfft_1d_fast_file", X(check_1d_fast_file));
  CU_add_test(nfft, "nfft_adjoint_1d_direct_file", X(check_adjoint_1d_direct_file));
  CU_add_test(nfft, "nfft_adjoint_1d_fast_file", X(check_adjoint_1d_fast_file));
  CU_add_test(nfft, "nfft_1d_online", X(check_1d_online));
  CU_add_test(nfft, "nfft_adjoint_1d_online", X(check_adjoint_1d_online));

  CU_add_test(nfft, "nfft_2d_direct_file", X(check_2d_direct_file));
  CU_add_test(nfft, "nfft_2d_fast_file", X(check_2d_fast_file));
  CU_add_test(nfft, "nfft_adjoint_2d_direct_file", X(check_adjoint_2d_direct_file));
  CU_add_test(nfft, "nfft_adjoint_2d_fast_file", X(check_adjoint_2d_fast_file));
  CU_add_test(nfft, "nfft_2d_online", X(check_2d_online));
  CU_add_test(nfft, "nfft_adjoint_2d_online", X(check_adjoint_2d_online));

  CU_add_test(nfft, "nfft_3d_direct_file", X(check_3d_direct_file));
  CU_add_test(nfft, "nfft_3d_fast_file", X(check_3d_fast_file));
  CU_add_test(nfft, "nfft_adjoint_3d_direct_file", X(check_adjoint_3d_direct_file));
  CU_add_test(nfft, "nfft_adjoint_3d_fast_file", X(check_adjoint_3d_fast_file));
  CU_add_test(nfft, "nfft_3d_online", X(check_3d_online));
  CU_add_test(nfft, "nfft_adjoint_3d_online", X(check_adjoint_3d_online));

  CU_add_test(nfft, "nfft_4d_online", X(check_4d_online));
  CU_add_test(nfft, "nfft_adjoint_4d_online", X(check_adjoint_4d_online));
#ifdef HAVE_NFCT
#undef X
#define X(name) NFCT(name)
#ifndef _OPENMP
  nfct = CU_add_suite("nfct", 0, 0);
  CU_add_test(nfct, "nfct_1d_direct_file", X(check_1d_direct_file));
  CU_add_test(nfct, "nfct_1d_fast_file", X(check_1d_fast_file));
  CU_add_test(nfct, "nfct_adjoint_1d_direct_file", X(check_adjoint_1d_direct_file));
  CU_add_test(nfct, "nfct_adjoint_1d_fast_file", X(check_adjoint_1d_fast_file));
  CU_add_test(nfct, "nfct_1d_online", X(check_1d_online));
  CU_add_test(nfct, "nfct_adjoint_1d_online", X(check_adjoint_1d_online));

  CU_add_test(nfct, "nfct_2d_direct_file", X(check_2d_direct_file));
  CU_add_test(nfct, "nfct_2d_fast_file", X(check_2d_fast_file));
  CU_add_test(nfct, "nfct_adjoint_2d_direct_file", X(check_adjoint_2d_direct_file));
  CU_add_test(nfct, "nfct_adjoint_2d_fast_file", X(check_adjoint_2d_fast_file));
  CU_add_test(nfct, "nfct_2d_online", X(check_2d_online));
  CU_add_test(nfct, "nfct_adjoint_2d_online", X(check_adjoint_2d_online));

  CU_add_test(nfct, "nfct_3d_direct_file", X(check_3d_direct_file));
  CU_add_test(nfct, "nfct_3d_fast_file", X(check_3d_fast_file));
  CU_add_test(nfct, "nfct_adjoint_3d_direct_file", X(check_adjoint_3d_direct_file));
  CU_add_test(nfct, "nfct_adjoint_3d_fast_file", X(check_adjoint_3d_fast_file));
  CU_add_test(nfct, "nfct_3d_online", X(check_3d_online));
  CU_add_test(nfct, "nfct_adjoint_3d_online", X(check_adjoint_3d_online));

  CU_add_test(nfct, "nfct_4d_online", X(check_4d_online));
  CU_add_test(nfct, "nfct_adjoint_4d_online", X(check_adjoint_4d_online));
#endif
#endif
#ifdef HAVE_NFST
#undef X
#define X(name) NFST(name)
#ifndef _OPENMP
  nfst = CU_add_suite("nfst", 0, 0);
  CU_add_test(nfst, "nfst_1d_direct_file", X(check_1d_direct_file));
  CU_add_test(nfst, "nfst_1d_fast_file", X(check_1d_fast_file));
  CU_add_test(nfst, "nfst_adjoint_1d_direct_file", X(check_adjoint_1d_direct_file));
  CU_add_test(nfst, "nfst_adjoint_1d_fast_file", X(check_adjoint_1d_fast_file));
  CU_add_test(nfst, "nfst_1d_online", X(check_1d_online));
  CU_add_test(nfst, "nfst_adjoint_1d_online", X(check_adjoint_1d_online));

  CU_add_test(nfst, "nfst_2d_direct_file", X(check_2d_direct_file));
  CU_add_test(nfst, "nfst_2d_fast_file", X(check_2d_fast_file));
  CU_add_test(nfst, "nfst_adjoint_2d_direct_file", X(check_adjoint_2d_direct_file));
  CU_add_test(nfst, "nfst_adjoint_2d_fast_file", X(check_adjoint_2d_fast_file));
  CU_add_test(nfst, "nfst_2d_online", X(check_2d_online));
  CU_add_test(nfst, "nfst_adjoint_2d_online", X(check_adjoint_2d_online));

  CU_add_test(nfst, "nfst_3d_direct_file", X(check_3d_direct_file));
  CU_add_test(nfst, "nfst_3d_fast_file", X(check_3d_fast_file));
  CU_add_test(nfst, "nfst_adjoint_3d_direct_file", X(check_adjoint_3d_direct_file));
  CU_add_test(nfst, "nfst_adjoint_3d_fast_file", X(check_adjoint_3d_fast_file));
  CU_add_test(nfst, "nfst_3d_online", X(check_3d_online));
  CU_add_test(nfst, "nfst_adjoint_3d_online", X(check_adjoint_3d_online));

  CU_add_test(nfst, "nfst_4d_online", X(check_4d_online));
  CU_add_test(nfst, "nfst_adjoint_4d_online", X(check_adjoint_4d_online));
#endif
#endif
#undef X
#define X(name) Y(name)
  util = CU_add_suite("util", 0, 0);
  CU_add_test(util, "bspline", X(check_bspline));
  CU_add_test(util, "bessel_i0", X(check_bessel_i0));
  CU_automated_run_tests();
  //CU_basic_run_tests();
  {
    unsigned int ok = (CU_get_number_of_tests_failed() == 0);
    CU_cleanup_registry();
    return IF(ok, EXIT_SUCCESS, EXIT_FAILURE);
  }
}
예제 #27
0
/*
 * Main
 */
int
main(void)
{
	CU_pSuite ptr_suite = NULL;
	int nr_of_failed_tests = 0;
	int nr_of_failed_suites = 0;

	/* Initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
		return CU_get_error();

	/* add a suite to the registry */
	ptr_suite = CU_add_suite("ofp packet out", init_suite, clean_suite);
	if (NULL == ptr_suite) {
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_packet_output_gre)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_packet_output_gre_no_nexthop)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
#ifdef INET6
	if (NULL == CU_ADD_TEST(ptr_suite,
				test_packet_output_ipv6_to_gre)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
#endif

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_send_frame_packet_len_bigger_than_mtu)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite,
				test_send_frame_novlan_to_novlan)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite,
				test_send_frame_novlan_to_vlan)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite,
				test_send_frame_vlan_to_novlan)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite,
				test_send_frame_vlan_to_vlan)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_ADD_TEST(ptr_suite,
				test_hook_out_ipv4)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

#ifdef INET6
	if (NULL == CU_ADD_TEST(ptr_suite,
				test_hook_out_ipv6)) {
		CU_cleanup_registry();
		return CU_get_error();
	}
#endif /*INET6*/

#if OFP_TESTMODE_AUTO
	CU_set_output_filename("CUnit-PKT-OUT");
	CU_automated_run_tests();
#else
	/* Run all tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
#endif

	nr_of_failed_tests = CU_get_number_of_tests_failed();
	nr_of_failed_suites = CU_get_number_of_suites_failed();
	CU_cleanup_registry();

	return (nr_of_failed_suites > 0 ?
		nr_of_failed_suites : nr_of_failed_tests);
}
예제 #28
0
파일: ofp_test_arp.c 프로젝트: babubalu/ofp
void *pp_thread(void *arg)
{
	ALLOW_UNUSED_LOCAL(arg);

#if ODP_VERSION >= 102
	if (odp_init_local(ODP_THREAD_WORKER)) {
#else
	if (odp_init_local()) {
#endif
		OFP_ERR("odp_init_local failed");
		return NULL;
	}
	if (ofp_init_local()) {
		OFP_ERR("ofp_init_local failed");
		return NULL;
	}

	while (odp_atomic_load_u32(&still_running)) {
		odp_event_t event;
		odp_queue_t source_queue;

		event = odp_schedule(&source_queue, ODP_SCHED_WAIT);

		if (odp_event_type(event) != ODP_EVENT_TIMEOUT) {
			OFP_ERR("Unexpected event type %d",
				odp_event_type(event));
			continue;
		}

		ofp_timer_handle(event);
	}
	return NULL;
}

static void test_arp(void)
{
	struct ofp_ifnet mock_ifnet;
	struct in_addr ip;
	uint8_t mac[OFP_ETHER_ADDR_LEN] = { 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, };

	/* The buffer passed into ofp_ipv4_lookup_mac() must be 8 bytes since
	 * a 64-bit operation is currently being used to copy a MAC address.
	 */
	uint8_t mac_result[OFP_ETHER_ADDR_LEN + 2];

	CU_ASSERT(0 == ofp_init_local());

	memset(&mock_ifnet, 0, sizeof(mock_ifnet));
	CU_ASSERT(0 != inet_aton("1.1.1.1", &ip));

	/* Test entry insert, lookup, and remove. */
	CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));

	CU_ASSERT(0 == ofp_arp_ipv4_insert(ip.s_addr, mac, &mock_ifnet));

	memset(mac_result, 0xFF, OFP_ETHER_ADDR_LEN);
	CU_ASSERT(0 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));
	CU_ASSERT(0 == memcmp(mac, mac_result, OFP_ETHER_ADDR_LEN));

	CU_ASSERT(0 == ofp_arp_ipv4_remove(ip.s_addr, &mock_ifnet));
	CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));

	/* Test entry is aged out. */
	CU_ASSERT(0 == ofp_arp_ipv4_insert(ip.s_addr, mac, &mock_ifnet));
	OFP_INFO("Inserted ARP entry");
	sleep(ARP_AGE_INTERVAL + ARP_ENTRY_TIMEOUT);
	CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));

	/* Test entry is aged out after a few hits. */
	CU_ASSERT(0 == ofp_arp_ipv4_insert(ip.s_addr, mac, &mock_ifnet));
	OFP_INFO("Inserted ARP entry");
	sleep(ARP_AGE_INTERVAL);
	CU_ASSERT(0 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));
	sleep(ARP_AGE_INTERVAL);
	CU_ASSERT(0 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));
	sleep(ARP_AGE_INTERVAL + ARP_ENTRY_TIMEOUT);
	CU_ASSERT(-1 == ofp_ipv4_lookup_mac(ip.s_addr, mac_result, &mock_ifnet));
}

int main(void)
{
	CU_pSuite ptr_suite = NULL;
	int nr_of_failed_tests = 0;
	int nr_of_failed_suites = 0;

	/* Initialize the CUnit test registry */
	if (CUE_SUCCESS != CU_initialize_registry())
		return CU_get_error();

	/* add a suite to the registry */
	ptr_suite = CU_add_suite("ofp errno", init_suite, end_suite);
	if (NULL == ptr_suite) {
		CU_cleanup_registry();
		return CU_get_error();
	}
	if (NULL == CU_ADD_TEST(ptr_suite, test_arp)) {
		CU_cleanup_registry();
		return CU_get_error();
	}

#if defined(OFP_TESTMODE_AUTO)
	CU_set_output_filename("CUnit-Util");
	CU_automated_run_tests();
#else
	/* Run all tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
#endif

	nr_of_failed_tests = CU_get_number_of_tests_failed();
	nr_of_failed_suites = CU_get_number_of_suites_failed();
	CU_cleanup_registry();

	return (nr_of_failed_suites > 0 ?
		nr_of_failed_suites : nr_of_failed_tests);
}
예제 #29
0
/*
 * Main
 */
int
main(void)
{
    CU_pSuite ptr_suite = NULL;
    int nr_of_failed_tests = 0;
    int nr_of_failed_suites = 0;

    /* Initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* add a suite to the registry */
    ptr_suite = CU_add_suite("ofp fragmentation", init_suite, clean_suite);
    if (NULL == ptr_suite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_packet_size_is_less_then_mtu)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_dont_fragment_set_pkt_dropped)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_packet_to_two_fragments)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_packet_to_many_fragments)) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if (NULL == CU_ADD_TEST(ptr_suite,
                            test_fragment_fragmented_to_two)) {
        CU_cleanup_registry();
        return CU_get_error();
    }


#if OFP_TESTMODE_AUTO
    CU_set_output_filename("CUnit-fragmentation");
    CU_automated_run_tests();
#else
    /* Run all tests using the CUnit Basic interface */
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
#endif

    nr_of_failed_tests = CU_get_number_of_tests_failed();
    nr_of_failed_suites = CU_get_number_of_suites_failed();
    CU_cleanup_registry();

    return (nr_of_failed_suites > 0 ?
            nr_of_failed_suites : nr_of_failed_tests);
}
예제 #30
0
int main(int argc, char * argv[]) {
  bool list = false, help = false;
  const char * output = "CUnitAutomated";
  const struct option longopts[] = {
    { "list",   no_argument,       (int *)&list, (int)true },
    { "output", required_argument,         NULL,      'o'  },
    { "help",   no_argument,       (int *)&help, (int)true },
    { NULL,     0,                         NULL,      0    }
  };

  opterr = 0;
  int c, longindex;
  while ((c = getopt_long(argc, argv, ":lo:h", longopts, &longindex)) != -1) {
    switch (c) {
      case 'l':
        list = true;
        break;
      case 'o':
        output = optarg;
        break;
      case 'h':
        help = true;
        break;
      case ':':
        fprintf(stderr, "Missing argument for option '%c'\n", optopt);
        return -1;
      case '?':
        fprintf(stderr, "Unknown option '%c'\n", optopt);
        return -1;
    }
  }

  if (help) {
    printf("Usage: %s [-l|--list] [-o|--output=<template>] [-h|--help]\n", argv[0]);
    puts("Where:");
    puts("  -l|--list    lists the tests to a file (default \"CUnitAutomated-Listing.xml\")");
    puts("  -o|--output  sets the filename template to use (tests are listed in "
         "\"<template>-Listing.xml\" while results are placed in \"<template>-Results.xml\")");
    puts("  -h|--help    displays this message");
    return 0;
  }

  CU_ERROR_CHECK(CU_initialize_registry());

  CU_ERROR_CHECK(CU_register_suites((CU_SuiteInfo *)suites));

  CU_set_output_filename(output);

  if (list) {
    CU_ERROR_CHECK(CU_list_tests_to_file());
    return 0;
  }

  CU_automated_run_tests();

  unsigned int failures = CU_get_number_of_failures();

  CU_cleanup_registry();

  return (int)failures;
}