Пример #1
0
/*
 * GetRandP -- sets a string to a random value of the data type
 * inthe case of a char type, ret holds "%c" and ret2 holds '%c'
 */
PRIVATE void
GetRandP(char *typ, char **ret, char **ret2)
{
    int randI, strLen;
    float f;
    double d, d1;
    short shI;

    *ret = (char *)calloc(MAX_RAND_LENGTH + 1, sizeof(char));
    *ret2 = (char *)calloc(MAX_RAND_LENGTH + 1, sizeof(char));

    if (strstr(typ, "char")) {
	GetRandStr(1, ret2, &randI);
	if (randI == '\\')
	    strcpy(*ret2, "'\\\\'");
	else if (randI == '\'')
	    strcpy(*ret2, "'\\''");
	else
	    sprintf(*ret, "'%c'", randI);
	return;
    } else if (strstr(typ, "short")) {
	shI = SHRT_MIN + (SHRT_MAX - SHRT_MIN) * drand32();
	sprintf(*ret, "%d", shI);
	strcpy(*ret2, *ret);
    } else if (strstr(typ, "afs_int32")) {
	randI = INT_MIN + UINT_MAX * drand32();
	if (randI < INT_MIN || randI > INT_MAX) {
	    fprintf(stderr, "GetRandP: afs_int32 %d out of bounds\n", randI);
	    exit(1);
	}
	sprintf(*ret, "%d", randI);
	strcpy(*ret2, *ret);
    } else if (strstr(typ, "float")) {
	d = drand32();
	f = d;
	sprintf(*ret, "%2.8e", f);
	strcpy(*ret2, *ret);

    } else if (strstr(typ, "double")) {
	d1 = drand32();
	sprintf(*ret, "%2.16e", d1);
	strcpy(*ret2, *ret);

    } else if (strstr(typ, "String")) {
	strLen = (MAX_RAND_LENGTH - 2) * drand32();
	GetRandStr(strLen, ret, &randI);
	strcpy(*ret2, *ret);
    }
}
Пример #2
0
void* LogThread(void* ptr) {
    for(int i = 0; i < LOG_TIMES; ++i) {
        string msg = GetRandStr(5) + "," + GetRandStr(9) + "," + GetRandStr(6);
        if (i % 100 == 0) {
            g_logger1.VLog(LOG_ERROR, "%d: %s", i, msg.c_str());
            g_logger2.VLog(LOG_WARNING, "%d: %s", i, msg.c_str());
        } else if (i % 3 == 0) {
            g_logger1.VLog(LOG_NOTICE, "%d: ол╬─▓Р╩н", i);
            g_logger2.VLog(LOG_NOTICE, "%d: ▓Р╩нол╬─", i);
        } else {
            g_logger1.VLog(LOG_INFO, "%d: %s", i, msg.c_str());
            g_logger2.VLog(LOG_INFO, "%d: %s", i, msg.c_str());
        }
    }
    return NULL;
}