示例#1
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();
}
示例#2
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();
}
示例#3
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();
}
示例#4
0
int main(int argc, char **argv)
{
    int status;

    if(CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    if(!(status = setup_object_tests())
        || !(status = setup_list_tests()))
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    printf("\n");
    CU_basic_show_failures(CU_get_failure_list());
    printf("\n\n");

    CU_automated_run_tests();
    CU_list_tests_to_file();

    //CU_console_run_tests();


    CU_cleanup_registry();

    return CU_get_error();
}
void gradle_cunit_register() {
    CU_TestInfo unique_check_test_array[] = {
        {"unique check", test_initializer},
        CU_TEST_INFO_NULL,
    };

    CU_TestInfo row_column_validator_test_array[] = {
        {"valid row column test", test_valid_row_column_validate},
		{"invalid row column test", test_invalid_row_column_validate},
        CU_TEST_INFO_NULL,
    };

    CU_TestInfo box_validator_test_array[] = {
    	{"valid box valid puzzle test", test_valid_box_validate_valid_puzzle},
		{"valid box invalid puzzle test", test_valid_box_validate_invalid_puzzle},
		{"invalid box invalid puzzle test", test_invalid_box_validate_invalid_puzzle},
		CU_TEST_INFO_NULL,
    };

    CU_SuiteInfo suites[] = {
        { "unique check tests", unique_check_initializer_setup, unique_check_initializer_teardown, unique_check_test_array },
        { "row column validator tests", row_column_validate_setup, row_column_validate_teardown, row_column_validator_test_array },
		{ "box validator tests", box_validate_setup, box_validate_teardown, box_validator_test_array },
        CU_SUITE_INFO_NULL,
    };

    CU_register_suites(suites);

    CU_basic_run_tests();
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_list_tests_to_file();
}
示例#6
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("Suite_1", init_suite1, clean_suite1);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* add the tests to the suite */
    /* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
    if (
        (NULL == CU_add_test(pSuite, "test of init args", test_init_args))
        || (NULL == CU_add_test(pSuite, "test of term args", test_term_args))
        ) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Run all tests using the CUnit Basic interface */
    CU_list_tests_to_file();
    CU_automated_run_tests();
    CU_cleanup_registry();
    return CU_get_error();
}
示例#7
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;
}
示例#8
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;
}
示例#9
0
void gradle_cunit_register() {
	CU_TestInfo mobile_element_test_array[] = { { "mobile element case 1",
			test_mobile_element_state_1 }, { "mobile element case 2",
			test_mobile_element_state_2 }, { "mobile element case 3",
			test_mobile_element_state_3 }, { "mobile element case 4",
			test_mobile_element_state_4 }, { "mobile element case 5",
			test_mobile_element_state_5 }, { "mobile element case 6",
			test_mobile_element_state_6 }, CU_TEST_INFO_NULL, };

	CU_TestInfo generate_permutation_and_update_index_test_array[] = { {
			"generate permutation and update index case 1",
			test_generate_permutation_and_update_index_state_1 }, {
			"generate permutation and update index case 2",
			test_generate_permutation_and_update_index_state_2 }, {
			"generate permutation and update index case 3",
			test_generate_permutation_and_update_index_state_3 }, {
			"generate permutation and update index case 4",
			test_generate_permutation_and_update_index_state_4 }, {
			"generate permutation and update index case 5",
			test_generate_permutation_and_update_index_state_5 },
			CU_TEST_INFO_NULL, };

	CU_TestInfo initialize_record_test_array[] = { { "initialize_record",
			test_initialize_record }, CU_TEST_INFO_NULL, };

	CU_TestInfo update_direction_test_array[] = { { "update direction case 1",
			test_update_direction_case_1 }, { "update direction case 2",
			test_update_direction_case_2 }, CU_TEST_INFO_NULL, };

	CU_TestInfo save_permutation_test_array[] = { {
			"save permutation in storage", test_save_permutation }, {
			"verify saving permutation in storage does not override older one",
			test_adding_another_permutation_will_retain_older_one },
			CU_TEST_INFO_NULL, };

	CU_SuiteInfo suites[] = { { "mobile element tests",
			mobile_element_setup_suite, mobile_element_teardown_suite,
			mobile_element_test_array }, {
			"generate permutation and update index tests",
			test_generate_permutation_and_update_index_setup,
			test_generate_permutation_and_update_index_teardown,
			generate_permutation_and_update_index_test_array }, {
			"mobile element tests", initialize_record_setup,
			initialize_record_teardown, initialize_record_test_array }, {
			"update direction tests", update_direction_setup,
			update_direction_teardown, update_direction_test_array }, {
			"save permutation tests", save_permutation_setup,
			save_permutation_teardown, save_permutation_test_array },
			CU_SUITE_INFO_NULL, };

	CU_register_suites(suites);

	CU_basic_set_mode (CU_BRM_VERBOSE);
	CU_basic_run_tests();
	CU_list_tests_to_file();
}
示例#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 (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();
}
        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();
示例#14
0
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;
}
示例#15
0
int main(void) {
	CU_initialize_registry();

	suite_Utility();
	suite_CcnClient();
	suite_SeqNum();
	suite_NdnlpPkt();
	suite_MsgSlicer();
	suite_PartialMsg();
	suite_SentPkt();
	suite_Link();

	CU_automated_run_tests();
	CU_list_tests_to_file();
	CU_cleanup_registry();
	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;
}
/*
 * Set up and run tests.
 *
 * @return CUE_SUCCESS if successful, else a CUnit error code if
 * any problems arise.
 */
int main()
{
    if (CUE_SUCCESS != CU_initialize_registry())
    {
        return CU_get_error();
    }

    CU_pSuite suite = 
        CU_add_suite("Fibonacci Suite", initialise_suite, cleanup_suite);
    if (NULL == suite) 
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    if ((NULL == CU_add_test(suite, "test_fibonacci_1", test_fibonacci_1)) ||
        (NULL == CU_add_test(suite, "test_fibonacci_2", test_fibonacci_2)) ||
        (NULL == CU_add_test(suite, "test_fibonacci_3", test_fibonacci_3)) ||
        (NULL == CU_add_test(suite, "test_fibonacci_30", test_fibonacci_30)))
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    // Run all tests using CUnit Basic interface which outputs
    // results to command-line.
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();

    // Run all tests using CUnit Automated interface which outputs
    // results to a file, default name CUnitAutomated-Results.xml.
    // DTD CUnit-Run.dtd and and XSL stylesheet CUnit-Run.xsl in Share/
    // Uncomment this line to override default output file prefix.
    // CU_set_output_filename("Test");
    CU_list_tests_to_file();

    // Output listing of tests in suites to a file, default name
    // CUnitAutomated-Listing.xml
    // DTD CUnit-List.dtd and and XSL stylesheet CUnit-List.xsl in Share/
    CU_automated_run_tests();

    CU_cleanup_registry();
    return CU_get_error();
}
示例#18
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, "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
文件: 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;
}
示例#20
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();
}
示例#21
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;
}
示例#22
0
int main (int argc, char *argv []) {
	CK_SLOT_ID slotlist [2];
	CK_ULONG slotcount = 2;
	CU_pSuite st [4];
	int opt;
	int todo;
	extern char *optarg;

	/*
	 * Test arguments.
	 */
	todo = 1;
	while (todo && (opt = getopt_long (argc, argv, opts, longopts, NULL))) {
		switch (opt) {
		case 'p':	// --pin
			storepin ("user", optarg, ascii_pin_user, sizeof (ascii_pin_user) - 1);
			break;
			
		case 'P':	// --so-pin
			storepin ("SO", optarg, ascii_pin_so, sizeof (ascii_pin_so) - 1);
			break;
		case 'l':	// --pkcs1llib
			if (p11) {
				fprintf (stderr, "You should not open multiple PKCS #11 libraries\n");
				exit (1);
			}
			p11 = dlopen (optarg, RTLD_NOW | RTLD_GLOBAL);
			if (!p11) {
				fprintf (stderr, "%s\n", dlerror ());
				exit (1);
			}
			break;
		case 'X':	// --destructive
			if (destructive) {
				fprintf (stderr, "You should not specify your destructive wishes more than once\n");
				exit (1);
			}
			destructive = 1;
			break;
		case 'f':	// --fast-and-frivolous
			if (thousands < 1000) {
				fprintf (stderr, "You should not specify the fast option more than once\n");
				exit (1);
			}
			thousands = 10;
			hundred = 8;
			couple = 3;
			break;
		case 'v':		// --verbose
			if (optarg) {
				verbosity = atoi (optarg);
				if (verbosity < 0) {
					fprintf (stderr, "You should not specify negative verbosity levels\n");
					exit (1);
				}
			} else {
				verbosity++;
			}
			break;
		case 1:			// --test-initiation
			if (skip_initiation == 0) {
				fprintf (stderr, "You should not specify --test-initiation more than once\n");
				exit (1);
			}
			skip_initiation = 0;
			break;
		case 2:			// --skip-fragmentation
			if (skip_fragmentation) {
				fprintf (stderr, "You should not specify --skip-fragmentation more than once\n");
				exit (1);
			}
			skip_fragmentation = 1;
			break;
		case 3:			// --skip-keysizing
			if (skip_keysizing) {
				fprintf (stderr, "You should not specify --skip-keysizing more than once\n");
				exit (1);
			}
			skip_keysizing = 1;
			break;
		case 4:			// --skip-signing
			if (skip_signing) {
				fprintf (stderr, "You should not specify --skip-signing more than once\n");
				exit (1);
			}
			skip_signing = 1;
			break;
		// case 't':
		// Token?
		case -1:		// Done -- but are we, really?
			if ((*ascii_pin_user) && (*ascii_pin_so) && p11) {
				todo = 0;
				break;
			}
			// else continue...
			fprintf (stderr, "Please set all values required.\n");
		case 'h':
		case ':':
		case '?':
			fprintf (stderr, "Minimal usage: %s --pin 1234 --so-pin 4321 --pkcs11lib /path/to/libpkcs11.so\n", argv [0]);
			exit (opt != 'h');
		}
	}

	/*
 	 * Register test suites and tests.
	 */
	if (CU_initialize_registry () != CUE_SUCCESS) {
		fprintf (stderr, "Failed to initialise test registry -- this is abnormal\n");
		exit (1);
	} else {
		cu_open = 1;
	}
	st [0] = CU_add_suite ("Test if slot initiation works properly", NULL, NULL);
	st [1] = CU_add_suite ("Test if memory does not get fragmented", NULL, NULL);
	st [2] = CU_add_suite ("Test if key sizes work as desired", NULL, NULL);
	st [3] = CU_add_suite ("Test if signatures are made correctly", NULL, NULL);
	if (! (st [0] && st [1] && st [2] && st [3])) {
		fprintf (stderr, "Failed to allocate all test suites -- this is abnormal\n");
		exit (1);
	}
	if (! skip_initiation) {
		if (! CU_add_test (st [0], "Initiation test", testslot_initiation)) {
			fprintf (stderr, "Failed to register test #0 -- this is abnormal\n");
			exit (1);
		}
	}
	if (! skip_fragmentation) {
		if (! CU_add_test (st [1], "Fragmentation test", testslot_fragmentation)) {
			fprintf (stderr, "Failed to register test #1 -- this is abnormal\n");
			exit (1);
		}
	}
	if (! skip_keysizing) {
		if (! CU_add_test (st [2], "Key sizing test", testslot_keysizing)) {
			fprintf (stderr, "Failed to register test #2 -- this is abnormal\n");
			exit (1);
		}
	}
	if (! skip_signing) {
		if (! CU_add_test (st [3], "Signing test", testslot_signing)) {
			fprintf (stderr, "Failed to register test #3 -- this is abnormal\n");
			exit (1);
		}
	}

	/*
	 * Initialise the library and demand only one slot with a token.
	 */
	TESTRV ("Initialising PKCS #11 library",
		 P11("C_Initialize") (NULL_PTR));
	MKFATAL ();
	atexit (bailout);
	TESTRV ("Obtaining list of slots",
		 P11("C_GetSlotList") (TRUE, slotlist, &slotcount));
	if (slotcount != 1) {
		fprintf (stderr, "Number of slots is %d, so not equal to 1 -- unsure which to test\n", (int) slotcount);
		exit (1);
	}
	slotid = slotlist [0];

	/*
	 * Obtain mechanism information from the token.
 	 */
	TESTRV ("Getting number of mechanisms from token",
		 P11("C_GetMechanismInfo") (slotid, CKM_RSA_PKCS_KEY_PAIR_GEN, &mech_rsa_pkcs_key_pair_gen));
	MKFATAL ();
	TESTRV ("Getting number of mechanisms from token",
		 P11("C_GetMechanismInfo") (slotid, CKM_RSA_PKCS, &mech_rsa_pkcs));
	MKFATAL ();
	/*
	TESTRV ("Getting number of mechanisms from token",
		 P11("C_GetMechanismInfo") (slotid, CKM_SHA_1, &mech_sha_1));
	MKFATAL ();
	*/

	/*
	 * Format the token and run a test.
	 * Do we need an "are you sure?" warning here?
	 */
	if (strlen (TOKENLABEL_32CHARS) != 32) {
		CU_FAIL_FATAL ("Token labels must be 32 characters long -- fix TOKENLABEL_32CHARS and recompile");
	}

	/*
	 * Automatically run all the tests that were registered
	 */
	if (verbosity >= 1) {
		printf ("Beginning test sequence\n");
	}
	CU_list_tests_to_file ();
	CU_automated_run_tests ();
	if (verbosity >= 1) {
		printf ("Ended test sequence\n");
	}

	/*
	 * Unload the PKCS #11 library
	 */
	if (p11) {
		dlclose (p11);
		p11 = NULL;
	}

	/*
	 * Terminate without error-reporting return value.
	 */
	if (cu_open) {
		CU_cleanup_registry ();
		cu_open = 0;
	}
	exit (0);
}
示例#23
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;
}
示例#24
0
/* The main() function for setting up and running the tests.
 * Returns a CUE_SUCCESS on successful running, another
 * CUnit error code on failure.
 */
int main(int argc, char *argv[]) {
    int xml = 0;
    int con = 0;
    CU_pFailureRecord fr;
    int i;

    if (argc >= 2 && !strcmp(argv[1], "-xml")) {
        xml = 1;
    } else if (argc >= 2 && !strcmp(argv[1], "-con")) {
        con = 1;
    }
#ifdef HAVE_CUNIT
    int rv;

#ifndef WIN32
    struct sigaction sig_act;
    /*
     * Indicate that the broken pipe signal during writes should be
     * ignored
     */
    memset(&sig_act, 0, sizeof(struct sigaction));
    sig_act.sa_handler = SIG_IGN;
    sigemptyset(&sig_act.sa_mask);
    if (sigaction(SIGPIPE, &sig_act, NULL) == -1) {
        printf("\nCannot set ignore action for SIGPIPE\n");
    }
#endif 

    est_apps_startup();

    /*
     * Install thread locking mechanism for OpenSSL
     */
    mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE));
    if (!mutex_buf) {
        printf("Cannot allocate mutexes");
        exit(1);
    }
    for (i = 0; i < CRYPTO_num_locks(); i++)
    MUTEX_SETUP(mutex_buf[i]);
    CRYPTO_set_id_callback(id_function);
    CRYPTO_set_locking_callback(locking_function);

    /* initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry()) {
        return CU_get_error();
    }
#ifdef ENABLE_ALL_SUITES
    rv = us748_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US748 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us893_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US893 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us894_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US894 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us895_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US895 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us896_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US896 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us897_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US897 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us898_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US898 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us899_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US899 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us900_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US900 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us901_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US901 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us902_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US902 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us903_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US903 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us1005_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1005 (%d)", rv);
        exit(1);
    }
#endif
#if (DISABLE_SUITE != 0)
    rv = us1060_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1060 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us1060c_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1060c (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES 
    rv = us1159_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1159 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us1190_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1190 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us1864_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1864 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us1883_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1883 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us1884_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US1884 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us2174_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US2174 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us3496_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US3496 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us3512_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US3512 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us3612_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US3612 (%d)", rv);
        exit(1);
    }
#endif
#ifdef ENABLE_ALL_SUITES
    rv = us4020_add_suite();
    if (rv != CUE_SUCCESS) {
        printf("\nFailed to add test suite for US4020 (%d)", rv);
        exit(1);
    }
#endif

    if (xml) {
        /* Run all test using automated interface, which
         * generates XML output */
        CU_list_tests_to_file();
        CU_automated_run_tests();
    }
    else if (con) {
        CU_console_run_tests();
    }
    else {
        /* Run all tests using the CUnit Basic interface,
         * which generates text output */
        CU_basic_set_mode(CU_BRM_VERBOSE);
        CU_basic_run_tests();
        fr = CU_get_failure_list();
        if (fr) {
            printf("\n\nHere is a summary of the failed test cases:\n");
            CU_basic_show_failures(fr);
        }
    }

    /*
     * Tear down the mutexes used by OpenSSL
     */
    if (!mutex_buf)
    return 0;
    CRYPTO_set_id_callback(NULL);
    CRYPTO_set_locking_callback(NULL);
    for (i = 0; i < CRYPTO_num_locks(); i++)
    MUTEX_CLEANUP(mutex_buf[i]);
    free(mutex_buf);
    mutex_buf = NULL;

    CU_cleanup_registry();
    est_apps_shutdown();

    return CU_get_error();
#else
    printf("\nlibcunit not installed, unit test are not enabled\n");
#endif
}
示例#25
0
int
main(int argc, char *argv[])
{
	char *testname_re = NULL;
	CU_BasicRunMode mode = CU_BRM_VERBOSE;
	CU_ErrorAction error_action = CUEA_IGNORE;
	int res;
	struct scsi_readcapacity10 *rc10;
	struct scsi_task *inq_task = NULL;
	struct scsi_task *inq_lbp_task = NULL;
	struct scsi_task *inq_bdc_task = NULL;
	struct scsi_task *inq_bl_task = NULL;
	struct scsi_task *rc16_task = NULL;
	struct scsi_task *rsop_task = NULL;
	int full_size;
	int xml_mode = 0;
	static struct option long_opts[] = {
		{ "help", no_argument, 0, '?' },
		{ "list", no_argument, 0, 'l' },
		{ "initiator-name", required_argument, 0, 'i' },
		{ "initiator-name-2", required_argument, 0, 'I' },
		{ "test", required_argument, 0, 't' },
		{ "dataloss", no_argument, 0, 'd' },
		{ "allow-sanitize", no_argument, 0, 'S' },
		{ "ignore", no_argument, 0, 'g' },
		{ "fail", no_argument, 0, 'f' },
		{ "abort", no_argument, 0, 'A' },
		{ "silent", no_argument, 0, 's' },
		{ "normal", no_argument, 0, 'n' },
		{ "verbose", no_argument, 0, 'v' },
		{ "xml", no_argument, 0, 'x' },
		{ "Verbose-scsi", no_argument, 0, 'V' },
		{ NULL, 0, 0, 0 }
	};
	int i, c;
	int opt_idx = 0;

	while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnvxV", long_opts,
		    &opt_idx)) > 0) {
		switch (c) {
		case 'h':
		case '?':
			print_usage();
			return 0;
		case 'l':
			list_all_tests();
			return 0;
		case 'i':
			initiatorname1 = strdup(optarg);
			break;
		case 'I':
			initiatorname2 = strdup(optarg);
			break;
		case 't':
			testname_re = strdup(optarg);
			break;
		case 'd':
			data_loss++;
			break;
		case 'g':
			error_action = CUEA_IGNORE; /* default */
			break;
		case 'f':
			error_action = CUEA_FAIL;
			break;
		case 'A':
			error_action = CUEA_ABORT;
			break;
		case 's':
			mode = CU_BRM_SILENT;
			break;
		case 'S':
			allow_sanitize = 1;
			break;
		case 'n':
			mode = CU_BRM_NORMAL;
			break;
		case 'v':
			mode = CU_BRM_VERBOSE;	/* default */
			break;
		case 'x':
		        xml_mode = 1;
			break;
		case 'V':
			loglevel = LOG_VERBOSE;
			break;
		default:
			fprintf(stderr,
			    "error: unknown option return: %c (option %s)\n",
			    c, argv[optind]);
			return 1;
		}
	}

	/* parse all trailing arguments as device paths */
	mp_num_sds = 0;
	while (optind < argc) {
		if (mp_num_sds >= MPATH_MAX_DEVS) {
			fprintf(stderr, "Too many multipath device URLs\n");
			print_usage();
			free(testname_re);
			return 10;
		}

		mp_sds[mp_num_sds] = malloc(sizeof(struct scsi_device));
		memset(mp_sds[mp_num_sds], '\0', sizeof(struct scsi_device));
		mp_sds[mp_num_sds]->sgio_fd = -1;

		if (!strncmp(argv[optind], "iscsi://", 8)) {
			mp_sds[mp_num_sds]->iscsi_url = strdup(argv[optind++]);
#ifdef HAVE_SG_IO
		} else {
			mp_sds[mp_num_sds]->sgio_dev = strdup(argv[optind++]);
#endif
		}
		mp_num_sds++;
	}

	/* So that we can override iscsi_queue_pdu in tests
	 * and replace or mutate the blob that we are about to write to the
	 * wire.
	 * This allows such tests to do their mutates and then call out
	 * to the real queueing function once they have modified the data.
	 */
	real_iscsi_queue_pdu = dlsym(RTLD_NEXT, "iscsi_queue_pdu");

	if ((mp_num_sds == 0) || (mp_sds[0]->iscsi_url == NULL
					&& mp_sds[0]->sgio_dev == NULL)) {
#ifdef HAVE_SG_IO
		fprintf(stderr, "You must specify either an iSCSI URL or a device file\n");
#else
		fprintf(stderr, "You must specify an iSCSI URL\n");
#endif
		print_usage();
		if (testname_re)
			free(testname_re);
		return 10;
	}

	/* sd remains an alias for the first device */
	sd = mp_sds[0];

	for (i = 0; i < mp_num_sds; i++) {
		res = connect_scsi_device(mp_sds[i], initiatorname1);
		if (res < 0) {
			fprintf(stderr,
				"Failed to connect to SCSI device %d\n", i);
			goto err_sds_free;
		}
	}

	if (mp_num_sds > 1) {
		/* check that all multipath sds identify as the same LU */
		res = mpath_check_matching_ids(mp_num_sds, mp_sds);
		if (res < 0) {
			fprintf(stderr, "multipath devices don't match\n");
			goto err_sds_free;
		}
	}

	/*
	 * find the size of the LUN
	 * All devices support readcapacity10 but only some support
	 * readcapacity16
	 */
	task = NULL;
	readcapacity10(sd, &task, 0, 0, EXPECT_STATUS_GOOD);
	if (task == NULL) {
		printf("Failed to send READCAPACITY10 command: %s\n", sd->error_str);
		goto err_sds_free;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("READCAPACITY10 command: failed with sense. %s\n", sd->error_str);
		scsi_free_scsi_task(task);
		goto err_sds_free;
	}
	rc10 = scsi_datain_unmarshall(task);
	if (rc10 == NULL) {
		printf("failed to unmarshall READCAPACITY10 data.\n");
		scsi_free_scsi_task(task);
		goto err_sds_free;
	}
	block_size = rc10->block_size;
	num_blocks = rc10->lba + 1;
	scsi_free_scsi_task(task);

	rc16_task = NULL;
	readcapacity16(sd, &rc16_task, 96, EXPECT_STATUS_GOOD);
	if (rc16_task == NULL) {
		printf("Failed to send READCAPACITY16 command: %s\n", sd->error_str);
		goto err_sds_free;
	}
	if (rc16_task->status == SCSI_STATUS_GOOD) {
		rc16 = scsi_datain_unmarshall(rc16_task);
		if (rc16 == NULL) {
			printf("failed to unmarshall READCAPACITY16 data. %s\n", sd->error_str);
			scsi_free_scsi_task(rc16_task);
			goto err_sds_free;
		}
		block_size = rc16->block_length;
		num_blocks = rc16->returned_lba + 1;
		lbppb = 1 << rc16->lbppbe;
	}

	inq_task = NULL;
	inquiry(sd, &inq_task, 0, 0, 64, EXPECT_STATUS_GOOD);
	if (inq_task == NULL || inq_task->status != SCSI_STATUS_GOOD) {
		printf("Inquiry command failed : %s\n", sd->error_str);
		goto err_sds_free;
	}
	full_size = scsi_datain_getfullsize(inq_task);
	if (full_size > inq_task->datain.size) {
		scsi_free_scsi_task(inq_task);

		/* we need more data for the full list */
		inq_task = NULL;
		inquiry(sd, &inq_task, 0, 0, full_size, EXPECT_STATUS_GOOD);
		if (inq_task == NULL) {
			printf("Inquiry command failed : %s\n", sd->error_str);
			goto err_sds_free;
		}
	}
	inq = scsi_datain_unmarshall(inq_task);
	if (inq == NULL) {
		printf("failed to unmarshall inquiry datain blob\n");
		scsi_free_scsi_task(inq_task);
		goto err_sds_free;
	}

	sbc3_support = 0;
	for (i = 0; i < 8; i++) {
		if (inq->version_descriptor[i] == 0x04C0) {
			sbc3_support = 1;
		}
	}

	/* try reading block limits vpd */
	inq_bl_task = NULL;
	inquiry(sd, &inq_bl_task, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 64, EXPECT_STATUS_GOOD);
	if (inq_bl_task && inq_bl_task->status != SCSI_STATUS_GOOD) {
		scsi_free_scsi_task(inq_bl_task);
		inq_bl_task = NULL;
	}
	if (inq_bl_task) {
		full_size = scsi_datain_getfullsize(inq_bl_task);
		if (full_size > inq_bl_task->datain.size) {
			scsi_free_scsi_task(inq_bl_task);

			inq_bl_task = NULL;
			inquiry(sd, &inq_bl_task, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, full_size,
				EXPECT_STATUS_GOOD);
			if (inq_bl_task == NULL) {
				printf("Inquiry command failed : %s\n", sd->error_str);
				goto err_sds_free;
			}
		}

		inq_bl = scsi_datain_unmarshall(inq_bl_task);
		if (inq_bl == NULL) {
			printf("failed to unmarshall inquiry datain blob\n");
			goto err_sds_free;
		}
	}

	/* try reading block device characteristics vpd */
	inquiry(sd, &inq_bdc_task, 1, SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS, 255,
		EXPECT_STATUS_GOOD);
	if (inq_bdc_task == NULL || inq_bdc_task->status != SCSI_STATUS_GOOD) {
		printf("Failed to read Block Device Characteristics page\n");
	} else {
		inq_bdc = scsi_datain_unmarshall(inq_bdc_task);
		if (inq_bdc == NULL) {
			printf("failed to unmarshall inquiry datain blob\n");
			goto err_sds_free;
		}
	}

	/* if thin provisioned we also need to read the VPD page for it */
	if (rc16 && rc16->lbpme != 0){
		inq_lbp_task = NULL;
		inquiry(sd, &inq_lbp_task, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64,
			EXPECT_STATUS_GOOD);
		if (inq_lbp_task == NULL || inq_lbp_task->status != SCSI_STATUS_GOOD) {
			printf("Inquiry command failed : %s\n", sd->error_str);
			goto err_sds_free;
		}
		full_size = scsi_datain_getfullsize(inq_lbp_task);
		if (full_size > inq_lbp_task->datain.size) {
			scsi_free_scsi_task(inq_lbp_task);

			/* we need more data for the full list */
			inq_lbp_task = NULL;
			inquiry(sd, &inq_lbp_task, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING,
				full_size, EXPECT_STATUS_GOOD);
			if (inq_lbp_task == NULL) {
				printf("Inquiry command failed : %s\n", sd->error_str);
				goto err_sds_free;
			}
		}

		inq_lbp = scsi_datain_unmarshall(inq_lbp_task);
		if (inq_lbp == NULL) {
			printf("failed to unmarshall inquiry datain blob\n");
			goto err_sds_free;
		}
	}

	rsop_task = NULL;
	report_supported_opcodes(sd, &rsop_task, 1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535,
				 EXPECT_STATUS_GOOD);
	if (rsop_task == NULL) {
		printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n", sd->error_str);
		goto err_sds_free;
	}
	if (rsop_task->status == SCSI_STATUS_GOOD) {
		rsop = scsi_datain_unmarshall(rsop_task);
		if (rsop == NULL) {
			printf("failed to unmarshall REPORT_SUPPORTED_OPCODES data.\n");
			scsi_free_scsi_task(rsop_task);
			rsop_task = NULL;
		}
	}

	/* check if the device is write protected or not */
	task = NULL;
	modesense6(sd, &task, 0, SCSI_MODESENSE_PC_CURRENT, SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255,
		   EXPECT_STATUS_GOOD);
	if (task == NULL) {
		printf("Failed to send MODE_SENSE6 command: %s\n", sd->error_str);
		goto err_sds_free;
	}
	if (task->status == SCSI_STATUS_GOOD) {
		struct scsi_mode_sense *ms;

		ms = scsi_datain_unmarshall(task);
		if (ms == NULL) {
			printf("failed to unmarshall mode sense datain blob\n");
			scsi_free_scsi_task(task);
			goto err_sds_free;
		}
		readonly = !!(ms->device_specific_parameter & 0x80);
	}
	scsi_free_scsi_task(task);

	if (maxsectbytes) {
		maximum_transfer_length = maxsectbytes / block_size;
		printf("Bus transfer size is limited to %d bytes. Clamping "
		       "max transfers accordingly.\n", maxsectbytes);
	}

	if (CU_initialize_registry() != 0) {
		fprintf(stderr, "error: unable to initialize test registry\n");
		goto err_sds_free;
	}
	if (CU_is_test_running()) {
		fprintf(stderr, "error: test suite(s) already running!?\n");
		exit(1);
	}

	parse_and_add_tests(testname_re);
	if (testname_re)
		free(testname_re);

	CU_basic_set_mode(mode);
	CU_set_error_action(error_action);
	printf("\n");

	/*
	 * this actually runs the tests ...
	 */

	if (xml_mode) {
	  CU_list_tests_to_file();
	  CU_automated_run_tests();
	} else {
	  res = CU_basic_run_tests();
	  printf("Tests completed with return value: %d\n", res);
	}

	CU_cleanup_registry();

	if (inq_task != NULL) {
		scsi_free_scsi_task(inq_task);
	}
	if (inq_bl_task != NULL) {
		scsi_free_scsi_task(inq_bl_task);
	}
	if (inq_lbp_task != NULL) {
		scsi_free_scsi_task(inq_lbp_task);
	}
	if (inq_bdc_task != NULL) {
		scsi_free_scsi_task(inq_bdc_task);
	}
	if (rc16_task != NULL) {
		scsi_free_scsi_task(rc16_task);
	}
	if (rsop_task != NULL) {
		scsi_free_scsi_task(rsop_task);
	}
	for (i = 0; i < mp_num_sds; i++) {
		free_scsi_device(mp_sds[i]);
	}

	return 0;

err_sds_free:
	for (i = 0; i < mp_num_sds; i++) {
		free_scsi_device(mp_sds[i]);
	}
	return -1;
}
示例#26
0
文件: runtest.c 项目: DDvO/libest
/* The main() function for setting up and running the tests.
 * Returns a CUE_SUCCESS on successful running, another
 * CUnit error code on failure.
 */
int main(int argc, char *argv[])
{
#ifdef HAVE_CUNIT
    int xml = 0;
    int con = 0;
    CU_pFailureRecord fr;
    int size;
    int i;
    int rv;

    if (argc >= 2 && !strcmp(argv[1], "-xml")) {
	xml = 1;
    } else 
    if (argc >= 2 && !strcmp(argv[1], "-con")) {
	con = 1;
    }

    est_apps_startup();
    est_set_log_source(EST_CLIENT);

    /*
     * Install thread locking mechanism for OpenSSL
     */
    size = sizeof(pthread_mutex_t) * CRYPTO_num_locks();
    if ((ssl_mutexes = (pthread_mutex_t*)malloc((size_t)size)) == NULL) {
        printf("Cannot allocate mutexes");
	exit(1);
    }

    for (i = 0; i < CRYPTO_num_locks(); i++) {
        pthread_mutex_init(&ssl_mutexes[i], NULL);
    }
    CRYPTO_set_locking_callback(&ssl_locking_callback);
    CRYPTO_set_id_callback(&ssl_id_callback);
    

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

    #define ADD(N) { extern int N##_add_suite(void); rv = N##_add_suite(); \
	    if (rv != CUE_SUCCESS) { fprintf(stderr, "Failed "#N"_add_suite (%d)\n", rv); exit(1); } }
    ADD(us748);
    ADD(us893);
    ADD(us894);
    ADD(us895);
    ADD(us896);
    ADD(us897);
    ADD(us898);
    ADD(us899);
    ADD(us900);
    ADD(us901);
    ADD(us902);
    ADD(us903);
    ADD(us1005);
    ADD(us1060);
    ADD(us1159);
    ADD(us1864);
    ADD(us1883);
    ADD(us1884);
    ADD(us2174);

    if (xml) {
	/* Run all test using automated interface, which
	 * generates XML output */
	CU_list_tests_to_file();
	CU_automated_run_tests();
    } else if (con) {
	CU_console_run_tests();
    } else {
	/* Run all tests using the CUnit Basic interface,
	 * which generates text output */
#if 0
	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
#else
	CU_set_test_start_handler   (test_start);
	CU_set_test_complete_handler(test_complete);
	CU_run_all_tests();
#endif
	fr = CU_get_failure_list();
	if (fr) {
	    fprintf(stderr, "\nHere is a summary of the failed test cases:\n");
	    print_failures(fr);
	} else {
	    fprintf(stderr, "\nAll enabled tests passed.\n");
	}
    }

    /*
     * Tear down the mutexes used by OpenSSL
     */
    CRYPTO_set_locking_callback(NULL);
    for (i = 0; i < CRYPTO_num_locks(); i++) {
        pthread_mutex_destroy(&ssl_mutexes[i]);
    }
    CRYPTO_set_locking_callback(NULL);
    CRYPTO_set_id_callback(NULL);
    free(ssl_mutexes);
    
    CU_cleanup_registry();
    est_apps_shutdown();

    return CU_get_error();
#else
    printf("\nlibcunit not installed, unit tests are not enabled\n");
    return 255;
#endif
}
示例#27
0
int
main(int argc, char *argv[])
{
	char *testname_re = NULL;
	int lun;
	CU_BasicRunMode mode = CU_BRM_VERBOSE;
	CU_ErrorAction error_action = CUEA_IGNORE;
	int res;
	struct scsi_readcapacity10 *rc10;
	struct scsi_task *inq_task = NULL;
	struct scsi_task *inq_lbp_task = NULL;
	struct scsi_task *inq_bdc_task = NULL;
	struct scsi_task *inq_bl_task = NULL;
	struct scsi_task *rc16_task = NULL;
	struct scsi_task *rsop_task = NULL;
	int full_size;
	int is_usb = 0;
	int xml_mode = 0;
	static struct option long_opts[] = {
		{ "help", no_argument, 0, '?' },
		{ "list", no_argument, 0, 'l' },
		{ "initiator-name", required_argument, 0, 'i' },
		{ "initiator-name-2", required_argument, 0, 'I' },
		{ "test", required_argument, 0, 't' },
		{ "dataloss", no_argument, 0, 'd' },
		{ "allow-sanitize", no_argument, 0, 'S' },
		{ "ignore", no_argument, 0, 'g' },
		{ "fail", no_argument, 0, 'f' },
		{ "abort", no_argument, 0, 'A' },
		{ "silent", no_argument, 0, 's' },
		{ "normal", no_argument, 0, 'n' },
		{ "usb", no_argument, 0, 'u' },
		{ "verbose", no_argument, 0, 'v' },
		{ "xml", no_argument, 0, 'x' },
		{ "Verbose-scsi", no_argument, 0, 'V' },
		{ NULL, 0, 0, 0 }
	};
	int i, c;
	int opt_idx = 0;

	while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnuvxV", long_opts,
		    &opt_idx)) > 0) {
		switch (c) {
		case 'h':
		case '?':
			print_usage();
			return 0;
		case 'l':
			list_all_tests();
			return 0;
		case 'i':
			initiatorname1 = strdup(optarg);
			break;
		case 'I':
			initiatorname2 = strdup(optarg);
			break;
		case 't':
			testname_re = strdup(optarg);
			break;
		case 'd':
			data_loss++;
			break;
		case 'g':
			error_action = CUEA_IGNORE; /* default */
			break;
		case 'f':
			error_action = CUEA_FAIL;
			break;
		case 'A':
			error_action = CUEA_ABORT;
			break;
		case 's':
			mode = CU_BRM_SILENT;
			break;
		case 'S':
			allow_sanitize = 1;
			break;
		case 'n':
			mode = CU_BRM_NORMAL;
			break;
		case 'u':
			is_usb = 1;
			break;
		case 'v':
			mode = CU_BRM_VERBOSE;	/* default */
			break;
		case 'x':
		        xml_mode = 1;
			break;
		case 'V':
			loglevel = LOG_VERBOSE;
			break;
		default:
			fprintf(stderr,
			    "error: unknown option return: %c (option %s)\n",
			    c, argv[optind]);
			return 1;
		}
	}

	if (optind < argc) {
		tgt_url = strdup(argv[optind++]);
	}
	if (optind < argc) {
		fprintf(stderr, "error: too many arguments\n");
		print_usage();
		return 1;
	}

	/* XXX why is this done? */
	real_iscsi_queue_pdu = dlsym(RTLD_NEXT, "iscsi_queue_pdu");

	if (tgt_url == NULL) {
		fprintf(stderr, "You must specify the URL\n");
		print_usage();
		if (testname_re)
			free(testname_re);
		return 10;
	}

	iscsic = iscsi_context_login(initiatorname1, tgt_url, &lun);
	if (iscsic == NULL) {
		printf("Failed to login to target\n");
		return -1;
	}

	/*
	 * find the size of the LUN
	 * All devices support readcapacity10 but only some support
	 * readcapacity16
	 */
	task = iscsi_readcapacity10_sync(iscsic, lun, 0, 0);
	if (task == NULL) {
		printf("Failed to send READCAPACITY10 command: %s\n",
		    iscsi_get_error(iscsic));
		iscsi_destroy_context(iscsic);
		return -1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("READCAPACITY10 command: failed with sense. %s\n",
		    iscsi_get_error(iscsic));
		scsi_free_scsi_task(task);
		iscsi_destroy_context(iscsic);
		return -1;
	}
	rc10 = scsi_datain_unmarshall(task);
	if (rc10 == NULL) {
		printf("failed to unmarshall READCAPACITY10 data. %s\n",
		    iscsi_get_error(iscsic));
		scsi_free_scsi_task(task);
		iscsi_destroy_context(iscsic);
		return -1;
	}
	block_size = rc10->block_size;
	num_blocks = rc10->lba + 1;
	scsi_free_scsi_task(task);

	rc16_task = iscsi_readcapacity16_sync(iscsic, lun);
	if (rc16_task == NULL) {
		printf("Failed to send READCAPACITY16 command: %s\n",
		    iscsi_get_error(iscsic));
		iscsi_destroy_context(iscsic);
		return -1;
	}
	if (rc16_task->status == SCSI_STATUS_GOOD) {
		rc16 = scsi_datain_unmarshall(rc16_task);
		if (rc16 == NULL) {
			printf("failed to unmarshall READCAPACITY16 data. %s\n",
			    iscsi_get_error(iscsic));
			scsi_free_scsi_task(rc16_task);
			iscsi_destroy_context(iscsic);
			return -1;
		}
		block_size = rc16->block_length;
		num_blocks = rc16->returned_lba + 1;
		lbppb = 1 << rc16->lbppbe;
	}

	inq_task = iscsi_inquiry_sync(iscsic, lun, 0, 0, 64);
	if (inq_task == NULL || inq_task->status != SCSI_STATUS_GOOD) {
		printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
		return -1;
	}
	full_size = scsi_datain_getfullsize(inq_task);
	if (full_size > inq_task->datain.size) {
		scsi_free_scsi_task(inq_task);

		/* we need more data for the full list */
		inq_task = iscsi_inquiry_sync(iscsic, lun, 0, 0, full_size);
		if (inq_task == NULL) {
			printf("Inquiry command failed : %s\n",
			    iscsi_get_error(iscsic));
			return -1;
		}
	}
	inq = scsi_datain_unmarshall(inq_task);
	if (inq == NULL) {
		printf("failed to unmarshall inquiry datain blob\n");
		scsi_free_scsi_task(inq_task);
		return -1;
	}

	sbc3_support = 0;
	for (i = 0; i < 8; i++) {
		if (inq->version_descriptor[i] == 0x04C0) {
			sbc3_support = 1;
		}
	}

	/* try reading block limits vpd */
	inq_bl_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 64);
	if (inq_bl_task && inq_bl_task->status != SCSI_STATUS_GOOD) {
		scsi_free_scsi_task(inq_bl_task);
		inq_bl_task = NULL;
	}
	if (inq_bl_task) {
		full_size = scsi_datain_getfullsize(inq_bl_task);
		if (full_size > inq_bl_task->datain.size) {
			scsi_free_scsi_task(inq_bl_task);

			if ((inq_bl_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, full_size)) == NULL) {
				printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
				return -1;
			}
		}

		inq_bl = scsi_datain_unmarshall(inq_bl_task);
		if (inq_bl == NULL) {
			printf("failed to unmarshall inquiry datain blob\n");
			return -1;
		}
	}

	/* try reading block device characteristics vpd */
	inq_bdc_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS, 255);
	if (inq_bdc_task == NULL) {
		printf("Failed to read Block Device Characteristics page\n");
	}
	if (inq_bdc_task) {
		inq_bdc = scsi_datain_unmarshall(inq_bdc_task);
		if (inq_bdc == NULL) {
			printf("failed to unmarshall inquiry datain blob\n");
			return -1;
		}
	}

	/* if thin provisioned we also need to read the VPD page for it */
	if (rc16 && rc16->lbpme != 0){
		inq_lbp_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64);
		if (inq_lbp_task == NULL || inq_lbp_task->status != SCSI_STATUS_GOOD) {
			printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
			return -1;
		}
		full_size = scsi_datain_getfullsize(inq_lbp_task);
		if (full_size > inq_lbp_task->datain.size) {
			scsi_free_scsi_task(inq_lbp_task);

			/* we need more data for the full list */
			if ((inq_lbp_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) {
				printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
				return -1;
			}
		}

		inq_lbp = scsi_datain_unmarshall(inq_lbp_task);
		if (inq_lbp == NULL) {
			printf("failed to unmarshall inquiry datain blob\n");
			return -1;
		}
	}

	rsop_task = iscsi_report_supported_opcodes_sync(iscsic, lun,
		1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535);
	if (rsop_task == NULL) {
		printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n",
		    iscsi_get_error(iscsic));
		iscsi_destroy_context(iscsic);
		return -1;
	}
	if (rsop_task->status == SCSI_STATUS_GOOD) {
		rsop = scsi_datain_unmarshall(rsop_task);
		if (rsop == NULL) {
			printf("failed to unmarshall REPORT_SUPPORTED_OPCODES "
			       "data. %s\n",
			       iscsi_get_error(iscsic));
			scsi_free_scsi_task(rsop_task);
		}
	}

	/* check if the device is write protected or not */
	task = iscsi_modesense6_sync(iscsic, lun, 0, SCSI_MODESENSE_PC_CURRENT,
				     SCSI_MODEPAGE_RETURN_ALL_PAGES,
				     0, 255);
	if (task == NULL) {
		printf("Failed to send MODE_SENSE6 command: %s\n",
		    iscsi_get_error(iscsic));
		iscsi_destroy_context(iscsic);
		return -1;
	}
	if (task->status == SCSI_STATUS_GOOD) {
		struct scsi_mode_sense *ms;

		ms = scsi_datain_unmarshall(task);
		if (ms == NULL) {
			printf("failed to unmarshall mode sense datain blob\n");
			scsi_free_scsi_task(task);
			return -1;
		}
		readonly = !!(ms->device_specific_parameter & 0x80);
	}
	scsi_free_scsi_task(task);

	iscsi_logout_sync(iscsic);
	iscsi_destroy_context(iscsic);

	if (is_usb) {
		printf("USB device. Clamping maximum transfer length to 120k\n");
		maximum_transfer_length = 120 *1024 / block_size;
	}

	if (CU_initialize_registry() != 0) {
		fprintf(stderr, "error: unable to initialize test registry\n");
		return 1;
	}
	if (CU_is_test_running()) {
		fprintf(stderr, "error: test suite(s) already running!?\n");
		exit(1);
	}

	parse_and_add_tests(testname_re);
	if (testname_re)
		free(testname_re);

	CU_basic_set_mode(mode);
	CU_set_error_action(error_action);
	printf("\n");

	/*
	 * this actually runs the tests ...
	 */

	if (xml_mode) {
	  CU_list_tests_to_file();
	  CU_automated_run_tests();
	} else {
	  res = CU_basic_run_tests();
	  printf("Tests completed with return value: %d\n", res);
	}

	CU_cleanup_registry();
	free(discard_const(tgt_url));

	if (inq_task != NULL) {
		scsi_free_scsi_task(inq_task);
	}
	if (inq_bl_task != NULL) {
		scsi_free_scsi_task(inq_bl_task);
	}
	if (inq_lbp_task != NULL) {
		scsi_free_scsi_task(inq_lbp_task);
	}
	if (inq_bdc_task != NULL) {
		scsi_free_scsi_task(inq_bdc_task);
	}
	if (rc16_task != NULL) {
		scsi_free_scsi_task(rc16_task);
	}
	if (rsop_task != NULL) {
		scsi_free_scsi_task(rsop_task);
	}

	return 0;
}
示例#28
0
int main(int argc, char **argv)
{
	CU_pSuite pSuite = NULL;


	if (CUE_SUCCESS != CU_initialize_registry())
		return CU_get_error();

	pSuite = CU_add_suite("suite_serverInit", NULL, NULL);
	if (NULL == pSuite)
	{
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_add_test(pSuite, "TEST: Server Initialization", test_serverInit))
	{
		CU_cleanup_registry();
		return CU_get_error();
	}

	pSuite = CU_add_suite("suite_serverHandlers", NULL, NULL);
	if (NULL == pSuite)
	{
		CU_cleanup_registry();
		return CU_get_error();
	}

	if ((NULL == CU_add_test(pSuite, "TEST: Server Handlers - Add users", test_serverHandler_userAdd)) ||
		(NULL == CU_add_test(pSuite, "TEST: Server Handlers - Add books", test_serverHandler_bookAdd)) ||
		(NULL == CU_add_test(pSuite, "TEST: Server Handlers - Retrieve book properties", test_serverHandler_bookProp)) ||
		(NULL == CU_add_test(pSuite, "TEST: Server Handlers - Create user activities and book history", test_serverHandler_createActy)) ||
		(NULL == CU_add_test(pSuite, "TEST: Server Handlers - Send/receive messages", test_serverHandler_msgs)) ||
		(NULL == CU_add_test(pSuite, "TEST: Server Handlers - Retrieve user activies and bok history", test_serverHandler_checkActies)))
	{
		CU_cleanup_registry();
		return CU_get_error();
	}

	pSuite = CU_add_suite("suite_serverTerm", NULL, NULL);
	if (NULL == pSuite)
	{
		CU_cleanup_registry();
		return CU_get_error();
	}

	if (NULL == CU_add_test(pSuite, "TEST: Server Termination", test_serverTerm))
	{
		CU_cleanup_registry();
		return CU_get_error();
	}

	/* Run all tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);
	/*CU_basic_run_tests();*/
	CU_automated_run_tests();
	CU_list_tests_to_file();

	printf("\n\n");
	printf("======================================\n");
	printf("    number of suites run: %d\n", CU_get_number_of_suites_run());
	printf("	number of suites failed: %d\n", CU_get_number_of_suites_failed());
	printf("	number of tests run: %d\n", CU_get_number_of_tests_run());
	printf("	number of tests failed: %d\n", CU_get_number_of_tests_failed());
	printf("	number of asserts done: %d\n", CU_get_number_of_asserts());
	printf("	number of asserts successful: %d\n", CU_get_number_of_successes());
	printf("	number of asserts failed: %d\n", CU_get_number_of_failures());
	printf("======================================\n");


	CU_cleanup_registry();
	return CU_get_error();
}
示例#29
0
int main(int argc, char *argv[])
{
  char configFile[1024], interface[25];
  int createflag, unitflag, cleanflag;
  extern int logflag;
  int create_f, clean_f, log_f;

  createflag = unitflag = cleanflag = FALSE;
  create_f = clean_f, FLAG_NOT_SET;

  // Begin command line parsing ***********************************************
  if (   (checkForOption("--help", argc, argv) != FLAG_NOT_SET)
      || (checkForOption("-h", argc, argv) != FLAG_NOT_SET)
      || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) {
      print_help();
  }
  get_asf_share_dir_with_argv0(argv[0]);
  handle_license_and_version_args(argc, argv, ASF_NAME_STRING);

  // Check which options were provided
  create_f = checkForOption("-create", argc, argv);
  clean_f  = checkForOption("-clean", argc, argv);
  log_f    = checkForOption("-log", argc, argv);

  // We need to make sure the user specified the proper number of arguments
  int needed_args = 1 + REQUIRED_ARGS;               // command & REQUIRED_ARGS
  int num_flags = 0;
  if (create_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option
  if (clean_f  != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option
  if (log_f    != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param

  // Make sure we have the right number of args
  if (argc != needed_args) {
    print_usage();
  }

  // Make sure argument for each flag (that requires an arg) is not another
  // option flag & is not a required argument
  if (log_f != FLAG_NOT_SET) {
    if ((argv[log_f+1][0]=='-') || (log_f>=(argc-REQUIRED_ARGS))) {
      print_usage();
    }
  }

  // Make sure all options occur before the config file name argument
  if (num_flags == 1 && (create_f > 1 || log_f > 1)) {
    print_usage();
  }
  else if (num_flags > 1 && 
	   (create_f >= argc - REQUIRED_ARGS - 1 ||
	    log_f    >= argc - REQUIRED_ARGS - 1)) {
    print_usage();
  }

  // Do the actual flagging & such for each flag
  if (create_f != FLAG_NOT_SET) {
    createflag = TRUE;
  }
  if (clean_f != FLAG_NOT_SET) {
    cleanflag = TRUE;
  }
  if (log_f != FLAG_NOT_SET) {
    strcpy(logFile, argv[log_f+1]);
    logflag = TRUE;
    fLog = FOPEN(logFile, "w");
  }

  // Fetch required arguments
  strcpy(interface, argv[argc-2]);
  strcpy(configFile, argv[argc-1]);

  // Report the command line
  asfSplashScreen(argc, argv);

  // End command line parsing *************************************************

  // Get test information from configuration file
  test_config *cfg;
  char line[1024];

  // Creating configuration files
  if (createflag && !fileExists(configFile)) {
    init_test_config(configFile);
    return(EXIT_SUCCESS);
  }
  else if (createflag && fileExists(configFile)) {
    cfg = read_test_config(configFile);
    check_return(write_test_config(configFile, cfg),
		 "Could not update configuration file");
    free_test_config(cfg);    
    return(EXIT_SUCCESS);
  }
  else if (!fileExists(configFile))
    asfPrintError("Could not find config file (%s)\n", configFile);
  
  // Unit tests or single configuration file?
  if (strcmp_case(interface, "basic") == 0 || 
      strcmp_case(interface, "automated") == 0)
    unitflag = TRUE;

  if (unitflag) {

    extern int quietflag;
    quietflag = 2;
    if (CUE_SUCCESS != CU_initialize_registry())
      return CU_get_error();

    int test = FALSE;
    FILE *fpList = FOPEN(configFile, "r");
    while(fgets(line, 1024, fpList)) {
      if (strcmp_case(trim_spaces(line), "uavsar_metadata") == 0)
	add_uavsar_metadata_tests();
      if (strcmp_case(trim_spaces(line), "uavsar_geotiff") == 0)
	add_uavsar_geotiff_tests();
      if (strcmp_case(trim_spaces(line), "rsat1_map_projections") == 0)
	add_rsat1_map_projections_tests();
      if (strcmp_case(trim_spaces(line), "rsat1_geotiff") == 0)
	add_rsat1_geotiff_tests();
      if (strcmp_case(trim_spaces(line), "alos_browse") == 0)
	add_alos_browse_tests();
      if (strcmp_case(trim_spaces(line), "alos_leader") == 0)
	add_alos_leader_tests();
      if (strcmp_case(trim_spaces(line), "rsat1_overlay") == 0)
	add_rsat1_overlay_tests();
      if (strcmp_case(trim_spaces(line), "alos_calibration") == 0)
	add_alos_calibration_tests();
      test = TRUE;
    }
    FCLOSE(fpList);

    if (test && strcmp_case(interface, "basic") == 0) {
      asfPrintStatus("Running tests in basic mode ...\n");
      CU_basic_set_mode(CU_BRM_VERBOSE);
      if (CUE_SUCCESS != CU_basic_run_tests()) {
	CU_cleanup_registry();
	return CU_get_error();
      }
    }
    if (test && strcmp_case(interface, "automated") == 0) {
      asfPrintStatus("Running tests in automated mode ...\n\n");
      CU_set_output_filename("asf_tools");
      CU_automated_run_tests();
      CU_list_tests_to_file();
    }
    CU_cleanup_registry();
    if (cleanflag)
      cleanup_test_results(configFile);
  }
  else { // Configuration file for manual mode
    cfg = read_test_config(configFile);
    asfPrintStatus("Running tests in manual mode ...\n\n");

    // Run metadata tests
    if (strcmp_case(cfg->general->type, "metadata") == 0)
      manual_metadata(configFile);
    // Run geotiff tests
    else if (strcmp_case(cfg->general->type, "geotiff") == 0)
      manual_geotiff(configFile);
    // Run binary tests
    else if (strcmp_case(cfg->general->type, "binary") == 0)
      manual_binary(configFile);
    // Run library tests
    else if (strcmp_case(cfg->general->type, "library") == 0)
      manual_library(configFile);
    
    free_test_config(cfg);
  }

  return(EXIT_SUCCESS);
}