Beispiel #1
0
static void
no_instance(struct tesla_class *tcp, uint32_t symbol,
            const struct tesla_key *tkp)
{
    char instbuf[200];
    char *c = instbuf;
    const char *end = instbuf + sizeof(instbuf);

    SAFE_SPRINTF(c, end, "%d/%d instances\n",
                 tcp->tc_limit - tcp->tc_free, tcp->tc_limit);

    for (uint32_t i = 0; i < tcp->tc_limit; i++) {
        const struct tesla_instance *inst = tcp->tc_instances + i;
        if (!tesla_instance_active(inst))
            continue;

        SAFE_SPRINTF(c, end, "    %2u: state %d, ", i, inst->ti_state);
        c = key_string(c, end, &inst->ti_key);
        SAFE_SPRINTF(c, end, "\n");
    }

    char keybuf[20];
    key_string(keybuf, keybuf + sizeof(keybuf), tkp);

    SDT_PROBE(tesla, automata, fail, no_instance,
              tcp, instbuf, symbol, keybuf, 0);
}
int CRoleDBThread::InitCodeQueue(bool bResume, const int iThreadIdx)
{
	//initialize codequeue


	const int SHMPATHLEN = 256;
	const int CODEQUEUESIZE = 16777216;
	
	//in codequeue
	char szInShmPath[SHMPATHLEN]={};
	SAFE_SPRINTF(szInShmPath, sizeof(szInShmPath) - 1, "roledbthreadin%d.shm", m_iThreadIdx);
	m_pInputQueue = CCodeQueue::CreateBySharedMemory(szInShmPath, m_iThreadIdx, CODEQUEUESIZE);
	if (!m_pInputQueue)
	{
		TRACE_THREAD(m_iThreadIdx, "Error: init input queue fail. thread idx:%d\n", m_iThreadIdx);
		return -1;
	}

	m_pInputQueue->Initialize(bResume);

	//out codequeue
	char szOutShmPath[SHMPATHLEN]={};
	SAFE_SPRINTF(szOutShmPath, sizeof(szOutShmPath) - 1, "roledbthreadout%d.shm", m_iThreadIdx);
	m_pOutputQueue = CCodeQueue::CreateBySharedMemory(szOutShmPath, m_iThreadIdx, CODEQUEUESIZE);
	if (!m_pOutputQueue)
	{
		TRACE_THREAD(m_iThreadIdx, "Error: init output queue fail. thread idx:%d\n", m_iThreadIdx);
		return -3;
	}

	m_pOutputQueue->Initialize(bResume);

	return 0;
}
Beispiel #3
0
char*
sprint_transitions(char *buffer, const char *end,
    const struct tesla_transitions *tp)
{
	char *c = buffer;

	SAFE_SPRINTF(c, end, "[ ");

	for (size_t i = 0; i < tp->length; i++)
		c = sprint_transition(c, end, tp->transitions + i);

	SAFE_SPRINTF(c, end, "]");

	return c;
}
int CAccountDBLogManager::Initialize(const int iLogNum, const TLogConfig& rLogConfig)
{
	if (iLogNum <= 0)
	{
		return -1;
	}

	m_iLogNum = iLogNum;
	m_pLogAdapter = new CServerLogAdapter[iLogNum];
	if (!m_pLogAdapter)
	{
		return -3;
	}

	char szBaseName[sizeof(rLogConfig.m_szBaseName)];
	for (int i = 0; i < iLogNum; i++)
	{
		TLogConfig stLogConfig = rLogConfig;
		SAFE_STRCPY(szBaseName, stLogConfig.m_szBaseName, sizeof(stLogConfig.m_szBaseName));
		//加上线程的index到日志名字的末尾
		SAFE_SPRINTF(stLogConfig.m_szBaseName, sizeof(stLogConfig.m_szBaseName), "%s%d", szBaseName, i);
		m_pLogAdapter[i].ReloadLogConfig(stLogConfig);
	}
		
	return 0;
}
Beispiel #5
0
char*
key_string(char *buffer, const char *end, const struct tesla_key *key)
{
	char *c = buffer;

	SAFE_SPRINTF(c, end, "0x%tx [ ", key->tk_mask);

	for (int32_t i = 0; i < TESLA_KEY_SIZE; i++) {
		if (key->tk_mask & (1 << i))
			SAFE_SPRINTF(c, end, "%tx ", key->tk_keys[i]);
		else
			SAFE_SPRINTF(c, end, "X ");
	}

	SAFE_SPRINTF(c, end, "]");

	return c;
}
static void dump_all_fds(const char *extra_msg)
{
int i;
    fdevent *fde;
    // per fd: 4 digits (but really: log10(FD_SETSIZE)), 1 staus, 1 blank
    char msg_buff[FD_SETSIZE*6 + 1], *pb=msg_buff;
    size_t max_chars = FD_SETSIZE * 6 + 1;
    int printed_out;
#define SAFE_SPRINTF(...)                                                    \
    do {                                                                     \
        printed_out = snprintf(pb, max_chars, __VA_ARGS__);                  \
        if (printed_out <= 0) {                                              \
            D("... snprintf failed.\n");                                     \
            return;                                                          \
        }                                                                    \
        if (max_chars < (unsigned int)printed_out) {                         \
            D("... snprintf out of space.\n");                               \
            return;                                                          \
        }                                                                    \
        pb += printed_out;                                                   \
        max_chars -= printed_out;                                            \
    } while(0)

    for(i = 0; i < select_n; i++) {
        fde = fd_table[i];
        SAFE_SPRINTF("%d", i);
        if(fde == 0) {
            SAFE_SPRINTF("? ");
            continue;
        }
        if(fcntl(i, F_GETFL, NULL) < 0) {
            SAFE_SPRINTF("b");
        }
        SAFE_SPRINTF(" ");
    }
    D("%s fd_table[]->fd = {%s}\n", extra_msg, msg_buff);
}
Beispiel #7
0
static void make_command_line(/*@notnull@*/ test_runner * runner)
/*@modifies
	runner->buffer
@*/
{

	SAFE_SPRINTF(
		SAFE_ARRAY(runner->buffer),
		"%s %u %u > %s 2> %s",
		runner->file_path,
		(unsigned int)runner->suite_number,
		(unsigned int)runner->test_number,
		runner->out,
		runner->err
	);
}
Beispiel #8
0
	static void open_report(/*@notnull@*/ test_runner * runner)
	/*@globals
		fileSystem,
		internalState
	@*/
	/*@modifies
		fileSystem,
		internalState,

		runner->buffer
	@*/
	{

		SAFE_SPRINTF(SAFE_ARRAY(runner->buffer), PLATFORM_OPEN_REPORT, runner->report);

		(void)system(runner->buffer);
	}
Beispiel #9
0
	static void open_report(/*@notnull@*/ test_runner * runner)
	/*@globals
		fileSystem,
		internalState
	@*/
	/*@modifies
		fileSystem,
		internalState,

		runner->buffer
	@*/
	{

		SAFE_SPRINTF(SAFE_ARRAY(runner->buffer), PLATFORM_OPEN_REPORT, runner->report);

		if( system(runner->buffer) == -1 ){

			fprintf(stderr, "\nCould not open report: %s\n", runner->report);
		}
	}
Beispiel #10
0
char*
sprint_transition(char *buf, const char *end, const struct tesla_transition *t)
{
	char *c = buf;

	/* Note: On at least one Mac, combining the following
	 *       into a single snprintf() causes the wrong thing
	 *       to be printed (instead of t->mask, we get an address!).
	 */
	SAFE_SPRINTF(c, end, "(%d:", t->from);
	SAFE_SPRINTF(c, end, "0x%tx", t->from_mask);
	SAFE_SPRINTF(c, end, " -> %d:", t->to);
	SAFE_SPRINTF(c, end, "0x%tx", t->to_mask);

	if (t->flags & TESLA_TRANS_INIT)
		SAFE_SPRINTF(c, end, " <init>");

	if (t->flags & TESLA_TRANS_CLEANUP)
		SAFE_SPRINTF(c, end, " <clean>");

	SAFE_SPRINTF(c, end, ") ");

	return c;
}