コード例 #1
0
ファイル: main.c プロジェクト: lysannschlegel/libetpan
void parse_arguments(int argc, const char** argv) {
    if(argc <= 0) {
        /* run all tests of all suites */
        return;
    }

    /* selective runs: deactivate all tests of all suites */
    unsigned int ui_suite, ui_test;
    for(ui_suite = 1; ui_suite <= CU_get_registry()->uiNumberOfSuites; ui_suite++) {
        CU_pSuite suite = CU_get_suite_at_pos(ui_suite);
        for(ui_test = 1; ui_test <= suite->uiNumberOfTests; ui_test++)
            CU_set_test_active(CU_get_test_at_pos(suite, ui_test), CU_FALSE);
    }

    /* activate selected tests */
    int i;
    for(i = 0; i < argc; i++) {
        const char* pos = strchr(argv[i], '.');
        if(pos == NULL) {
            /* suite name: activate all tests of this suite */
            if(argv[i][0] == 0) OXWS_TEST_ARG_ERROR("warning: ignoring empty suite name.");
            CU_pSuite suite = CU_get_suite(argv[i]);
            if(suite == NULL) OXWS_TEST_ARG_ERROR_1("warning: ignoring unknown suite '%s'.", argv[i]);
            for(ui_test = 1; ui_test <= suite->uiNumberOfTests; ui_test++)
                CU_set_test_active(CU_get_test_at_pos(suite, ui_test), CU_TRUE);
        } else {
            /* test name: activate the test only */
            /*   find suite */
            if(pos == argv[i]) OXWS_TEST_ARG_ERROR_1("warning: ignoring empty suite name of argument '%s'.", argv[i]);
            char* suite_name = alloca(sizeof(char) * (pos - argv[i] + 1));
            strncpy(suite_name, argv[i], pos - argv[i]);
            suite_name[pos - argv[i]] = 0;
            CU_pSuite suite = CU_get_suite(suite_name);
            if(suite == NULL) OXWS_TEST_ARG_ERROR_1("warning: ignoring unknown suite '%s'.", suite_name);
            /* find test */
            const char* test_name = pos + 1;
            if(test_name[0] == 0) OXWS_TEST_ARG_ERROR_1("warning: ignoring empty test name of argument '%s'.", argv[i]);
            CU_pTest test = CU_get_test(suite, test_name);
            if(test == NULL) OXWS_TEST_ARG_ERROR_2("warning: ignoring unknown test '%s.%s'.", suite_name, test_name);
            /* activate it */
            CU_set_test_active(test, CU_TRUE);
        }
    }
}
コード例 #2
0
ファイル: odp_cunit_common.c プロジェクト: nmorey/odp
/* A wrapper for the suite's init function. This is done to allow for a
 * potential runtime check to determine whether each test in the suite
 * is active (enabled by using ODP_TEST_INFO_CONDITIONAL()). If present,
 * the conditional check is run after the suite's init function.
 */
static int _cunit_suite_init(void)
{
    int ret = 0;
    CU_pSuite cur_suite = CU_get_current_suite();
    odp_suiteinfo_t *sinfo;
    odp_testinfo_t *tinfo;

    /* find the suite currently being run */
    cur_suite = CU_get_current_suite();
    if (!cur_suite)
        return -1;

    sinfo = cunit_get_suite_info(cur_suite->pName);
    if (!sinfo)
        return -1;

    /* execute its init function */
    if (sinfo->pInitFunc) {
        ret = sinfo->pInitFunc();
        if (ret)
            return ret;
    }

    /* run any configured conditional checks and mark inactive tests */
    for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) {
        CU_pTest ptest;
        CU_ErrorCode err;

        if (!tinfo->check_active || tinfo->check_active())
            continue;

        /* test is inactive, mark it as such */
        ptest = CU_get_test_by_name(tinfo->pName, cur_suite);
        if (ptest)
            err = CU_set_test_active(ptest, CU_FALSE);
        else
            err = CUE_NOTEST;

        if (err != CUE_SUCCESS) {
            fprintf(stderr, "%s: failed to set test %s inactive\n",
                    __func__, tinfo->pName);
            return -1;
        }
    }

    return ret;
}
コード例 #3
0
ファイル: amdgpu_test.c プロジェクト: freedreno/libdrm
/* 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 c;			/* Character received from getopt */
	int i = 0;
	int suite_id = -1;	/* By default run everything */
	int test_id  = -1;	/* By default run all tests in the suite */
	int pci_bus_id = -1;    /* By default PC bus ID is not specified */
	int pci_device_id = 0;  /* By default PC device ID is zero */
	int display_devices = 0;/* By default not to display devices' info */
	CU_pSuite pSuite = NULL;
	CU_pTest  pTest  = NULL;
	int test_device_index;
	int display_list = 0;
	int force_run = 0;

	for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
		drm_amdgpu[i] = -1;


	/* Parse command line string */
	opterr = 0;		/* Do not print error messages from getopt */
	while ((c = getopt(argc, argv, options)) != -1) {
		switch (c) {
		case 'l':
			display_list = 1;
			break;
		case 's':
			suite_id = atoi(optarg);
			break;
		case 't':
			test_id = atoi(optarg);
			break;
		case 'b':
			pci_bus_id = atoi(optarg);
			break;
		case 'd':
			sscanf(optarg, "%x", &pci_device_id);
			break;
		case 'p':
			display_devices = 1;
			break;
		case 'r':
			open_render_node = 1;
			break;
		case 'f':
			force_run = 1;
			break;
		case '?':
		case 'h':
			fprintf(stderr, usage, argv[0]);
			exit(EXIT_SUCCESS);
		default:
			fprintf(stderr, usage, argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	if (amdgpu_open_devices(open_render_node) <= 0) {
		perror("Cannot open AMDGPU device");
		exit(EXIT_FAILURE);
	}

	if (drm_amdgpu[0] < 0) {
		perror("Cannot open AMDGPU device");
		exit(EXIT_FAILURE);
	}

	if (display_devices) {
		amdgpu_print_devices();
		amdgpu_close_devices();
		exit(EXIT_SUCCESS);
	}

	if (pci_bus_id > 0 || pci_device_id) {
		/* A device was specified to run the test */
		test_device_index = amdgpu_find_device(pci_bus_id,
						       pci_device_id);

		if (test_device_index >= 0) {
			/* Most tests run on device of drm_amdgpu[0].
			 * Swap the chosen device to drm_amdgpu[0].
			 */
			i = drm_amdgpu[0];
			drm_amdgpu[0] = drm_amdgpu[test_device_index];
			drm_amdgpu[test_device_index] = i;
		} else {
			fprintf(stderr,
				"The specified GPU device does not exist.\n");
			exit(EXIT_FAILURE);
		}
	}

	/* Initialize test suites to run */

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

	/* Register suites. */
	if (CU_register_suites(suites) != CUE_SUCCESS) {
		fprintf(stderr, "suite registration failed - %s\n",
				CU_get_error_msg());
		CU_cleanup_registry();
		amdgpu_close_devices();
		exit(EXIT_FAILURE);
	}

	/* Run tests using the CUnit Basic interface */
	CU_basic_set_mode(CU_BRM_VERBOSE);

	/* Disable suites and individual tests based on misc. conditions */
	amdgpu_disable_suites();

	if (display_list) {
		display_test_suites();
		goto end;
	}

	if (suite_id != -1) {	/* If user specify particular suite? */
		pSuite = CU_get_suite_by_index((unsigned int) suite_id,
						CU_get_registry());

		if (pSuite) {

			if (force_run)
				CU_set_suite_active(pSuite, CU_TRUE);

			if (test_id != -1) {   /* If user specify test id */
				pTest = CU_get_test_by_index(
						(unsigned int) test_id,
						pSuite);
				if (pTest) {
					if (force_run)
						CU_set_test_active(pTest, CU_TRUE);

					CU_basic_run_test(pSuite, pTest);
				}
				else {
					fprintf(stderr, "Invalid test id: %d\n",
								test_id);
					CU_cleanup_registry();
					amdgpu_close_devices();
					exit(EXIT_FAILURE);
				}
			} else
				CU_basic_run_suite(pSuite);
		} else {
			fprintf(stderr, "Invalid suite id : %d\n",
					suite_id);
			CU_cleanup_registry();
			amdgpu_close_devices();
			exit(EXIT_FAILURE);
		}
	} else
		CU_basic_run_tests();

end:
	CU_cleanup_registry();
	amdgpu_close_devices();
	return CU_get_error();
}