コード例 #1
0
/**
 * Initialize permanently existing procfs files.
 */
static int init_permanent_files(void)
{
    struct procfs_file ** file;

    procfs_read_funcs = kcalloc(SET_COUNT(procfs_files),
            sizeof(procfs_readfn_t *));
    procfs_write_funcs = kcalloc(SET_COUNT(procfs_files),
            sizeof(procfs_writefn_t *));
    procfs_rele_funcs = kcalloc(SET_COUNT(procfs_files),
            sizeof(procfs_relefn_t *));

    if (!(procfs_read_funcs && procfs_write_funcs && procfs_rele_funcs))
        return -ENOMEM;

    SET_FOREACH(file, procfs_files) {
        enum procfs_filetype filetype = (*file)->filetype;

        procfs_read_funcs[filetype] = (*file)->readfn;
        procfs_write_funcs[filetype] = (*file)->writefn;
        procfs_rele_funcs[filetype] = (*file)->relefn;

        if (filetype > PROCFS_KERNEL_SEPARATOR) {
            const char * filename = (*file)->filename;

            create_proc_file(vn_procfs, 0, filename, filetype);
        }
    }

    return 0;
}
コード例 #2
0
ファイル: test.c プロジェクト: JabirTech/Source
void
run_tests(void)
{
	struct regression_test **testp;

	printf("1..%td\n", SET_COUNT(regression_tests_set));
	test_index = 1;
	SET_FOREACH(testp, regression_tests_set) {
		test_acknowleged = 0;
		test = *testp;
		test->rt_function();
		if (!test_acknowleged)
			print_status("not ok", "unknown status");
		test_index++;
	}
コード例 #3
0
ファイル: wordGhost.cpp プロジェクト: sprax/cpp
    int unitTest()
    {
        // debugging diagnostics:
        int dbgWinLose = 0, dbgNumTurnsNeStrlen = 0, dbgNumTurnsNeEndDepth = 0;
        int dbgRobotWinsEven = 0, dbgHumanWinsOdd = 0;
        int dbgRobotNotBranch = 0, dbgBranchNotRobot = 0;
        int numCombos = 0;

        for (char c = 'a'; c <= 'z'; c++) {
            printf("\n%c                                                  1 3 5 7 9 1 3 5 7 9 1\n", toupper(c));
            const EvOdNode *ghostNode = getRoot()->getBranchAtLetter(c);
            int j = 0, totalCount = 0, humanWins = 0, robotWins = 0;
            WordLenT numTurns = 8888, tmpDepth = 0;
            const char *aLastWord = NULL, *maxWord = NULL;
            for (const EvOdNode *branch = ghostNode->getFirstChild(); branch != NULL; branch = branch->getNextSibling()) {
                numCombos++;
                SET_COUNT(0);
                bool isRobotWinner = branch->evalIsWinnerGetEnds(numTurns, &aLastWord);
                bool isRobotWinWin = branch->isWinnerMemo();
                bool isRobotLoser  = isLoserNode(branch);
                if (isRobotWinner != isRobotWinWin || isRobotWinner == isRobotLoser) {
                    dbgWinLose++;
                }
                if ( isRobotWinner ) {
                    robotWins++;
                } else {
                    humanWins++;
                }
                if (tmpDepth < numTurns) {
                    tmpDepth = numTurns;
                    maxWord  = aLastWord;
                }
                totalCount += fsCounter;
                //if (isRobotWinner)
                printf("%2d %c %s:  %2d == %2d turns: %c -> %-16s %-16s  %5d\n"
                    , ++j
                    , (branch->getIsWinner() ? 'r' : 'H')
                    , (isRobotWinner ? "roBOT" : "HUMan")
                    , branch->getEndDepth()
                    , numTurns
                    , branch->getLetter()
                    , (aLastWord ? aLastWord : "----")
                    , branch->getEndWord()
                    , fsCounter 
                    );
                if (  isRobotWinner && (numTurns % 2) == 0) {
                    dbgRobotWinsEven++;
                }
                if (! isRobotWinner && (numTurns % 2) == 1) {
                    dbgHumanWinsOdd++;
                }
                int lastLen =  aLastWord ? strlen(aLastWord) : 0;
                if (numTurns != lastLen) {
                    dbgNumTurnsNeStrlen++;
                }
                if (isRobotWinner &&  ! branch->getIsWinner()) {
                    dbgRobotNotBranch++;
                }
                if ( ! isRobotWinner && branch->getIsWinner()) {
                    dbgBranchNotRobot++;
                }
                if (branch->getEndDepth() != numTurns) {
                    dbgNumTurnsNeEndDepth++;
                }
            }
            printf("%s takes %c, max turns %d:    %s\n", (robotWins > 0 ? "ROBOT (Player 2)" : "HUMAN (Player 1)")
                , toupper(c), tmpDepth, maxWord); 
        }
        if (dbgRobotNotBranch || dbgBranchNotRobot) {
            printf("Bugs: RobotNotBranch: %d  BranchNotRobot: %d\n", dbgRobotNotBranch, dbgBranchNotRobot);
        }
        if (dbgNumTurnsNeEndDepth) {
            printf("Bugs: Of %d trials, TurnsNEmSteps: %d\n", numCombos, dbgNumTurnsNeEndDepth);
        }
        return 0;
    }
コード例 #4
0
/**
 * Probe to see if an NVRAM data class in @p classes supports parsing
 * of the data mapped by @p io, returning the parsed data in @p data.
 * 
 * The caller is responsible for deallocating the returned instance via
 * bhnd_nvram_data_release().
 * 
 * @param[out] data On success, the parsed NVRAM data instance.
 * @param io An I/O context mapping the NVRAM data to be copied and parsed.
 * @param classes An array of NVRAM data classes to be probed, or NULL to
 * probe the default supported set.
 * @param num_classes The number of NVRAM data classes in @p classes.
 * 
 * @retval 0 success
 * @retval ENXIO if no class is found capable of parsing @p io.
 * @retval non-zero if an error otherwise occurs during allocation,
 * initialization, or parsing of the NVRAM data, a regular unix error code
 * will be returned.
 */
int
bhnd_nvram_data_probe_classes(struct bhnd_nvram_data **data,
    struct bhnd_nvram_io *io, bhnd_nvram_data_class *classes[],
    size_t num_classes)
{
	bhnd_nvram_data_class	*cls;
	int			 error, prio, result;

	cls = NULL;
	prio = 0;
	*data = NULL;

	/* If class array is NULL, default to our linker set */
	if (classes == NULL) {
		classes = SET_BEGIN(bhnd_nvram_data_class_set);
		num_classes = SET_COUNT(bhnd_nvram_data_class_set);
	}

	/* Try to find the best data class capable of parsing io */
	for (size_t i = 0; i < num_classes; i++) {
		bhnd_nvram_data_class *next_cls;

		next_cls = classes[i];

		/* Try to probe */
		result = bhnd_nvram_data_probe(next_cls, io);

		/* The parser did not match if an error was returned */
		if (result > 0)
			continue;

		/* Lower priority than previous match; keep
		 * searching */
		if (cls != NULL && result <= prio)
			continue;

		/* Drop any previously parsed data */
		if (*data != NULL) {
			bhnd_nvram_data_release(*data);
			*data = NULL;
		}

		/* If this is a 'maybe' match, attempt actual parsing to
		 * verify that this does in fact match */
		if (result <= BHND_NVRAM_DATA_PROBE_MAYBE) {
			/* If parsing fails, keep searching */
			error = bhnd_nvram_data_new(next_cls, data, io);
			if (error)
				continue;
		}

		/* Record best new match */
		prio = result;
		cls = next_cls;


		/* Terminate search immediately on
		 * BHND_NVRAM_DATA_PROBE_SPECIFIC */
		if (result == BHND_NVRAM_DATA_PROBE_SPECIFIC)
			break;
	}

	/* If no match, return error */
	if (cls == NULL)
		return (ENXIO);

	/* If the NVRAM data was not parsed above, do so now */
	if (*data == NULL) {
		if ((error = bhnd_nvram_data_new(cls, data, io)))
			return (error);
	}

	return (0);
}