本文整理汇总了C++中EXPECT函数的典型用法代码示例。如果您正苦于以下问题:C++ EXPECT函数的具体用法?C++ EXPECT怎么用?C++ EXPECT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EXPECT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: json_events
/**
* json_events - Read JSON event file from disk and call event callback.
* @fn: File name to read or NULL for default.
* @func: Callback to call for each event
* @data: Abstract pointer to pass to func.
*
* The callback gets the data pointer, the event name, the event
* in perf format and a description passed.
*
* Call func with each event in the json file
* Return: -1 on failure, otherwise 0.
*/
int json_events(const char *fn,
int (*func)(void *data, char *name, char *event, char *desc),
void *data)
{
int err = -EIO;
size_t size;
jsmntok_t *tokens, *tok;
int i, j, len;
char *map;
if (!fn)
fn = json_default_name();
tokens = parse_json(fn, &map, &size, &len);
if (!tokens)
return -EIO;
EXPECT(tokens->type == JSMN_ARRAY, tokens, "expected top level array");
tok = tokens + 1;
for (i = 0; i < tokens->size; i++) {
char *event = NULL, *desc = NULL, *name = NULL;
struct msrmap *msr = NULL;
jsmntok_t *msrval = NULL;
jsmntok_t *precise = NULL;
jsmntok_t *obj = tok++;
EXPECT(obj->type == JSMN_OBJECT, obj, "expected object");
for (j = 0; j < obj->size; j += 2) {
jsmntok_t *field, *val;
int nz;
field = tok + j;
EXPECT(field->type == JSMN_STRING, tok + j,
"Expected field name");
val = tok + j + 1;
EXPECT(val->type == JSMN_STRING, tok + j + 1,
"Expected string value");
nz = !json_streq(map, val, "0");
if (match_field(map, field, nz, &event, val)) {
/* ok */
} else if (json_streq(map, field, "EventName")) {
addfield(map, &name, "", "", val);
} else if (json_streq(map, field, "BriefDescription")) {
addfield(map, &desc, "", "", val);
fixdesc(desc);
} else if (json_streq(map, field, "PEBS") && nz && desc &&
!strstr(desc, "(Precise Event)")) {
precise = val;
} else if (json_streq(map, field, "MSRIndex") && nz) {
msr = lookup_msr(map, val);
} else if (json_streq(map, field, "MSRValue")) {
msrval = val;
} else if (json_streq(map, field, "Errata") &&
!json_streq(map, val, "null")) {
addfield(map, &desc, ". ",
" Spec update: ", val);
} else if (json_streq(map, field, "Data_LA") && nz) {
addfield(map, &desc, ". ",
" Supports address when precise",
NULL);
}
/* ignore unknown fields */
}
if (precise) {
if (json_streq(map, precise, "2"))
addfield(map, &desc, " ", "(Must be precise)",
NULL);
else
addfield(map, &desc, " ",
"(Precise event)", NULL);
}
if (msr != NULL)
addfield(map, &event, ",", msr->pname, msrval);
err = -EIO;
if (name && event) {
fixname(name);
err = func(data, name, event, desc);
}
free(event);
free(desc);
free(name);
if (err)
break;
tok += j;
}
EXPECT(tok - tokens == len, tok, "unexpected objects at end");
err = 0;
out_free:
free_json(map, size, tokens);
//.........这里部分代码省略.........
示例2: test_tcp_recv_ooseq_double_FINs
/* this test uses 4 packets:
* - data (len=TCP_MSS)
* - FIN
* - data after FIN (len=1) (invalid)
* - 2nd FIN (invalid)
*
* the parameter 'delay_packet' is a bitmask that choses which on these packets is ooseq
*/
static void test_tcp_recv_ooseq_double_FINs(int delay_packet)
{
int i, k;
struct test_tcp_counters counters;
struct tcp_pcb* pcb;
struct pbuf *p_normal_fin, *p_data_after_fin, *p, *p_2nd_fin_ooseq;
struct netif netif;
u32_t exp_rx_calls = 0, exp_rx_bytes = 0, exp_close_calls = 0, exp_oos_pbufs = 0, exp_oos_tcplen = 0;
int first_dropped = 0xff;
for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
data_full_wnd[i] = (char)i;
}
/* initialize local vars */
test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));
counters.expected_data_len = TCP_WND;
counters.expected_data = data_full_wnd;
/* create and initialize the pcb */
pcb = test_tcp_new_counters_pcb(&counters);
EXPECT_RET(pcb != NULL);
tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
pcb->rcv_nxt = 0x8000;
/* create segments */
p = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
p_normal_fin = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS, 0, TCP_ACK|TCP_FIN);
k = 1;
p_data_after_fin = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS+1], k, TCP_MSS+1, 0, TCP_ACK);
p_2nd_fin_ooseq = tcp_create_rx_segment(pcb, NULL, 0, TCP_MSS+1+k, 0, TCP_ACK|TCP_FIN);
if(delay_packet & 1) {
/* drop normal data */
first_dropped = 1;
} else {
/* send normal data */
test_tcp_input(p, &netif);
exp_rx_calls++;
exp_rx_bytes += TCP_MSS;
}
/* check if counters are as expected */
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
if(delay_packet & 2) {
/* drop FIN */
if(first_dropped > 2) {
first_dropped = 2;
}
} else {
/* send FIN */
test_tcp_input(p_normal_fin, &netif);
if (first_dropped < 2) {
/* already dropped packets, this one is ooseq */
exp_oos_pbufs++;
exp_oos_tcplen++;
} else {
/* inseq */
exp_close_calls++;
}
}
/* check if counters are as expected */
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
if(delay_packet & 4) {
/* drop data-after-FIN */
if(first_dropped > 3) {
first_dropped = 3;
}
} else {
/* send data-after-FIN */
test_tcp_input(p_data_after_fin, &netif);
if (first_dropped < 3) {
/* already dropped packets, this one is ooseq */
if (delay_packet & 2) {
/* correct FIN was ooseq */
exp_oos_pbufs++;
exp_oos_tcplen += k;
}
} else {
/* inseq: no change */
}
}
/* check if counters are as expected */
check_rx_counters(pcb, &counters, exp_close_calls, exp_rx_calls, exp_rx_bytes, 0, exp_oos_pbufs, exp_oos_tcplen);
if(delay_packet & 8) {
/* drop 2nd-FIN */
if(first_dropped > 4) {
first_dropped = 4;
//.........这里部分代码省略.........
示例3: TestAdvance
static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
int numChannels, PaSampleFormat format )
{
PaStreamParameters inputParameters, outputParameters, *ipp, *opp;
PaStream *stream = NULL;
PaError result = paNoError;
PaQaData myData;
#define FRAMES_PER_BUFFER (64)
/* Setup data for synthesis thread. */
myData.framesLeft = (unsigned long) (sampleRate * 100); /* 100 seconds */
myData.numChannels = numChannels;
myData.mode = mode;
myData.format = format;
switch( format )
{
case paFloat32:
case paInt32:
case paInt24:
myData.bytesPerSample = 4;
break;
/* case paPackedInt24:
myData.bytesPerSample = 3;
break; */
default:
myData.bytesPerSample = 2;
break;
}
if( mode == MODE_INPUT )
{
inputParameters.device = deviceID;
inputParameters.channelCount = numChannels;
inputParameters.sampleFormat = format;
inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
inputParameters.hostApiSpecificStreamInfo = NULL;
ipp = &inputParameters;
}
else
ipp = NULL;
if( mode == MODE_OUTPUT ) /* Pa_GetDeviceInfo(paNoDevice) COREDUMPS!!! */
{
outputParameters.device = deviceID;
outputParameters.channelCount = numChannels;
outputParameters.sampleFormat = format;
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
opp = &outputParameters;
}
else
opp = NULL;
if(paFormatIsSupported == Pa_IsFormatSupported( ipp, opp, sampleRate ))
{
printf("------ TestAdvance: %s, device = %d, rate = %g, numChannels = %d, format = %lu -------\n",
( mode == MODE_INPUT ) ? "INPUT" : "OUTPUT",
deviceID, sampleRate, numChannels, (unsigned long)format);
EXPECT( ((result = Pa_OpenStream( &stream,
ipp,
opp,
sampleRate,
FRAMES_PER_BUFFER,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
QaCallback,
&myData ) ) == 0) );
if( stream )
{
PaTime oldStamp, newStamp;
unsigned long oldFrames;
int minDelay = ( mode == MODE_INPUT ) ? 1000 : 400;
/* Was:
int minNumBuffers = Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate );
int msec = (int) ((minNumBuffers * 3 * 1000.0 * FRAMES_PER_BUFFER) / sampleRate);
*/
int msec = (int)( 3.0 *
(( mode == MODE_INPUT ) ? inputParameters.suggestedLatency : outputParameters.suggestedLatency ));
if( msec < minDelay ) msec = minDelay;
printf("msec = %d\n", msec); /**/
EXPECT( ((result=Pa_StartStream( stream )) == 0) );
/* Check to make sure PortAudio is advancing timeStamp. */
oldStamp = Pa_GetStreamTime(stream);
Pa_Sleep(msec);
newStamp = Pa_GetStreamTime(stream);
printf("oldStamp = %g,newStamp = %g\n", oldStamp, newStamp ); /**/
EXPECT( (oldStamp < newStamp) );
/* Check to make sure callback is decrementing framesLeft. */
oldFrames = myData.framesLeft;
Pa_Sleep(msec);
printf("oldFrames = %lu, myData.framesLeft = %lu\n", oldFrames, myData.framesLeft ); /**/
EXPECT( (oldFrames > myData.framesLeft) );
EXPECT( ((result=Pa_CloseStream( stream )) == 0) );
stream = NULL;
}
}
error:
if( stream != NULL ) Pa_CloseStream( stream );
return result;
}
示例4: test_queue
void test_queue (void){
struct queue queue;
struct foo buf[5];
init_queue(&queue, &buf, sizeof(struct foo), 5);
((struct foo *) enqueue(&queue))->a = 1;
((struct foo *) enqueue(&queue))->a = 2;
((struct foo *) enqueue(&queue))->a = 3;
((struct foo *) enqueue(&queue))->a = 4;
((struct foo *) enqueue(&queue))->a = 5;
EXPECT(!enqueue(&queue));
EXPECT(!enqueue(&queue));
EXPECT(((struct foo *) dequeue(&queue))->a == 1);
EXPECT(((struct foo *) dequeue(&queue))->a == 2);
((struct foo *) enqueue(&queue))->a = 6;
((struct foo *) enqueue(&queue))->a = 7;
EXPECT(((struct foo *) dequeue(&queue))->a == 3);
EXPECT(((struct foo *) dequeue(&queue))->a == 4);
EXPECT(((struct foo *) dequeue(&queue))->a == 5);
EXPECT(((struct foo *) dequeue(&queue))->a == 6);
EXPECT(((struct foo *) dequeue(&queue))->a == 7);
EXPECT(!dequeue(&queue));
EXPECT(!dequeue(&queue));
}
示例5: START_TEST
END_TEST
/** similar to above test, except seqno starts near the max rxwin */
START_TEST(test_tcp_recv_ooseq_overrun_rxwin_edge)
{
#if !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS
int i, k;
struct test_tcp_counters counters;
struct tcp_pcb* pcb;
struct pbuf *pinseq, *p_ovr;
struct netif netif;
int datalen = 0;
int datalen2;
for(i = 0; i < (int)sizeof(data_full_wnd); i++) {
data_full_wnd[i] = (char)i;
}
/* initialize local vars */
test_tcp_init_netif(&netif, NULL, &test_local_ip, &test_netmask);
/* initialize counter struct */
memset(&counters, 0, sizeof(counters));
counters.expected_data_len = TCP_WND;
counters.expected_data = data_full_wnd;
/* create and initialize the pcb */
pcb = test_tcp_new_counters_pcb(&counters);
EXPECT_RET(pcb != NULL);
tcp_set_state(pcb, ESTABLISHED, &test_local_ip, &test_remote_ip, TEST_LOCAL_PORT, TEST_REMOTE_PORT);
pcb->rcv_nxt = 0xffffffff - (TCP_WND / 2);
/* create segments */
/* pinseq is sent as last segment! */
pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
int count, expected_datalen;
struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
EXPECT_RET(p != NULL);
/* pass the segment to tcp_input */
test_tcp_input(p, &netif);
/* check if counters are as expected */
EXPECT(counters.close_calls == 0);
EXPECT(counters.recv_calls == 0);
EXPECT(counters.recved_bytes == 0);
EXPECT(counters.err_calls == 0);
/* check ooseq queue */
count = tcp_oos_count(pcb);
EXPECT_OOSEQ(count == k+1);
datalen = tcp_oos_tcplen(pcb);
if (i + TCP_MSS < TCP_WND) {
expected_datalen = (k+1)*TCP_MSS;
} else {
expected_datalen = TCP_WND - TCP_MSS;
}
if (datalen != expected_datalen) {
EXPECT_OOSEQ(datalen == expected_datalen);
}
}
/* pass in one more segment, cleary overrunning the rxwin */
p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
EXPECT_RET(p_ovr != NULL);
/* pass the segment to tcp_input */
test_tcp_input(p_ovr, &netif);
/* check if counters are as expected */
EXPECT(counters.close_calls == 0);
EXPECT(counters.recv_calls == 0);
EXPECT(counters.recved_bytes == 0);
EXPECT(counters.err_calls == 0);
/* check ooseq queue */
EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
datalen2 = tcp_oos_tcplen(pcb);
EXPECT_OOSEQ(datalen == datalen2);
/* now pass inseq */
test_tcp_input(pinseq, &netif);
EXPECT(pcb->ooseq == NULL);
/* make sure the pcb is freed */
EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 1);
tcp_abort(pcb);
EXPECT(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0);
#endif /* !TCP_OOSEQ_MAX_BYTES && !TCP_OOSEQ_MAX_PBUFS */
LWIP_UNUSED_ARG(_i);
}
示例6: unit_test_string
void
unit_test_string(void)
{
static const char test_path[] = "/path/to/file";
const char *ret;
char buf[MAXIMUM_PATH];
unsigned long num;
print_file(STDERR, "testing string\n");
/* strchr */
ret = strchr(identity(test_path), '/');
EXPECT(ret == test_path, true);
ret = strchr(identity(test_path), '\0');
EXPECT(ret != NULL, true);
EXPECT(*ret, '\0');
/* strrchr */
ret = strrchr(identity(test_path), '/');
EXPECT(strcmp(ret, "/file"), 0);
ret = strrchr(identity(test_path), '\0');
EXPECT(ret != NULL, true);
EXPECT(*ret, '\0');
/* strncpy, strncat */
strncpy(buf, test_path, sizeof(buf));
EXPECT(is_region_memset_to_char((byte *) buf + strlen(test_path),
sizeof(buf) - strlen(test_path), '\0'),
true);
strncat(buf, "/foo_wont_copy", 4);
EXPECT(strcmp(buf, "/path/to/file/foo"), 0);
/* strtoul */
num = strtoul(identity("-10"), NULL, 0);
EXPECT((long)num, -10); /* negative */
num = strtoul(identity("0777"), NULL, 0);
EXPECT(num, 0777); /* octal */
num = strtoul(identity("0xdeadBEEF"), NULL, 0);
EXPECT(num, 0xdeadbeef); /* hex */
num = strtoul(identity("deadBEEF next"), (char **) &ret, 16);
EXPECT(num, 0xdeadbeef); /* non-0x prefixed hex */
EXPECT(strcmp(ret, " next"), 0); /* end */
num = strtoul(identity("1001a"), NULL, 2);
EXPECT(num, 9); /* binary */
num = strtoul(identity("1aZ"), NULL, 36);
EXPECT(num, 1 * 36 * 36 + 10 * 36 + 35); /* weird base */
num = strtoul(identity("1aZ"), (char **) &ret, 37);
EXPECT(num, ULONG_MAX); /* invalid base */
EXPECT(ret == NULL, true);
/* memmove */
strncpy(buf, test_path, sizeof(buf));
memmove(buf + 4, buf, strlen(buf) + 1);
strncpy(buf, "/foo", 4);
EXPECT(strcmp(buf, "/foo/path/to/file"), 0);
print_file(STDERR, "done testing string\n");
}
示例7: GC_register_finalizer_inner
/* finalized when this finalizer is invoked. */
GC_API void GC_register_finalizer_inner(void * obj,
GC_finalization_proc fn, void *cd,
GC_finalization_proc *ofn, void **ocd,
finalization_mark_proc mp)
{
ptr_t base;
struct finalizable_object * curr_fo, * prev_fo;
size_t index;
struct finalizable_object *new_fo;
hdr *hhdr;
DCL_LOCK_STATE;
# ifdef THREADS
LOCK();
# endif
if (log_fo_table_size == -1
|| GC_fo_entries > ((word)1 << log_fo_table_size)) {
GC_grow_table((struct hash_chain_entry ***)(&fo_head),
&log_fo_table_size);
if (GC_print_stats) {
GC_log_printf("Grew fo table to %u entries\n",
(1 << log_fo_table_size));
}
}
/* in the THREADS case signals are disabled and we hold allocation */
/* lock; otherwise neither is true. Proceed carefully. */
base = (ptr_t)obj;
index = HASH2(base, log_fo_table_size);
prev_fo = 0; curr_fo = fo_head[index];
while (curr_fo != 0) {
GC_ASSERT(GC_size(curr_fo) >= sizeof(struct finalizable_object));
if (curr_fo -> fo_hidden_base == HIDE_POINTER(base)) {
/* Interruption by a signal in the middle of this */
/* should be safe. The client may see only *ocd */
/* updated, but we'll declare that to be his */
/* problem. */
if (ocd) *ocd = (void *) (curr_fo -> fo_client_data);
if (ofn) *ofn = curr_fo -> fo_fn;
/* Delete the structure for base. */
if (prev_fo == 0) {
fo_head[index] = fo_next(curr_fo);
} else {
fo_set_next(prev_fo, fo_next(curr_fo));
}
if (fn == 0) {
GC_fo_entries--;
/* May not happen if we get a signal. But a high */
/* estimate will only make the table larger than */
/* necessary. */
# if !defined(THREADS) && !defined(DBG_HDRS_ALL)
GC_free((void *)curr_fo);
# endif
} else {
curr_fo -> fo_fn = fn;
curr_fo -> fo_client_data = (ptr_t)cd;
curr_fo -> fo_mark_proc = mp;
/* Reinsert it. We deleted it first to maintain */
/* consistency in the event of a signal. */
if (prev_fo == 0) {
fo_head[index] = curr_fo;
} else {
fo_set_next(prev_fo, curr_fo);
}
}
# ifdef THREADS
UNLOCK();
# endif
return;
}
prev_fo = curr_fo;
curr_fo = fo_next(curr_fo);
}
if (ofn) *ofn = 0;
if (ocd) *ocd = 0;
if (fn == 0) {
# ifdef THREADS
UNLOCK();
# endif
return;
}
GET_HDR(base, hhdr);
if (0 == hhdr) {
/* We won't collect it, hence finalizer wouldn't be run. */
# ifdef THREADS
UNLOCK();
# endif
return;
}
new_fo = (struct finalizable_object *)
GC_INTERNAL_MALLOC(sizeof(struct finalizable_object),NORMAL);
if (EXPECT(0 == new_fo, FALSE)) {
# ifdef THREADS
UNLOCK();
# endif
new_fo = (struct finalizable_object *)
GC_oom_fn(sizeof(struct finalizable_object));
if (0 == new_fo) {
GC_finalization_failures++;
return;
//.........这里部分代码省略.........
示例8: printf
//.........这里部分代码省略.........
LOGI("requesting seek to %lld us (%.2f secs)",
requestedSeekTimeUs, requestedSeekTimeUs / 1E6);
}
MediaBuffer *buffer = NULL;
options.setSeekTo(
requestedSeekTimeUs, MediaSource::ReadOptions::SEEK_NEXT_SYNC);
if (seekSource->read(&buffer, &options) != OK) {
CHECK_EQ(buffer, NULL);
actualSeekTimeUs = -1;
} else {
CHECK(buffer != NULL);
CHECK(buffer->meta_data()->findInt64(kKeyTime, &actualSeekTimeUs));
CHECK(actualSeekTimeUs >= 0);
buffer->release();
buffer = NULL;
}
LOGI("nearest keyframe is at %lld us (%.2f secs)",
actualSeekTimeUs, actualSeekTimeUs / 1E6);
}
status_t err;
MediaBuffer *buffer;
for (;;) {
err = codec->read(&buffer, &options);
options.clearSeekTo();
if (err == INFO_FORMAT_CHANGED) {
CHECK_EQ(buffer, NULL);
continue;
}
if (err == OK) {
CHECK(buffer != NULL);
if (buffer->range_length() == 0) {
buffer->release();
buffer = NULL;
continue;
}
} else {
CHECK_EQ(buffer, NULL);
}
break;
}
if (requestedSeekTimeUs < 0) {
// Linear read.
if (err != OK) {
CHECK_EQ(buffer, NULL);
} else {
CHECK(buffer != NULL);
buffer->release();
buffer = NULL;
}
} else if (actualSeekTimeUs < 0) {
EXPECT(err != OK,
"We attempted to seek beyond EOS and expected "
"ERROR_END_OF_STREAM to be returned, but instead "
"we got a valid buffer.");
EXPECT(err == ERROR_END_OF_STREAM,
"We attempted to seek beyond EOS and expected "
"ERROR_END_OF_STREAM to be returned, but instead "
"we found some other error.");
CHECK_EQ(err, ERROR_END_OF_STREAM);
CHECK_EQ(buffer, NULL);
} else {
EXPECT(err == OK,
"Expected a valid buffer to be returned from "
"OMXCodec::read.");
CHECK(buffer != NULL);
int64_t bufferTimeUs;
CHECK(buffer->meta_data()->findInt64(kKeyTime, &bufferTimeUs));
if (!CloseEnough(bufferTimeUs, actualSeekTimeUs)) {
printf("\n * Attempted seeking to %lld us (%.2f secs)",
requestedSeekTimeUs, requestedSeekTimeUs / 1E6);
printf("\n * Nearest keyframe is at %lld us (%.2f secs)",
actualSeekTimeUs, actualSeekTimeUs / 1E6);
printf("\n * Returned buffer was at %lld us (%.2f secs)\n\n",
bufferTimeUs, bufferTimeUs / 1E6);
buffer->release();
buffer = NULL;
CHECK_EQ(codec->stop(), OK);
return UNKNOWN_ERROR;
}
buffer->release();
buffer = NULL;
}
}
CHECK_EQ(codec->stop(), OK);
return OK;
}
示例9: http_readRequest
/*----------------------------------------------------------------------------*/
int http_readRequest(HttpRequest* request)
{
/*
* Request constitutes of
* request-lineCRLF
* Header1: *Value1CRLF
* ...CRLF
* CRLF
* Body
*/
enum {None, Cr1, Lf1, Cr2, Lf2} crLfReadingState;
int numCrLf = 0;
signed char c = 0;
signed char c2 = 0;
enum { BEFORE, READING, DONE } readingState = BEFORE;
/* Read method */
while(DONE != readingState)
{
NEXT_CHAR(c);
switch( toupper(c) )
{
case LF:
case CR:
if(BEFORE != readingState)
{
LOG_CON(ERROR, socketFd, "Premature end of HTTP request\n");
return -1;
}
break;
case 'G':
request->type = GET;
EXPECT('E', c);
EXPECT('T', c);
EXPECT(SPACE, c);
readingState = DONE;
LOG_CON(INFO, socketFd, "Got GET request");
break;
case 'H':
request->type = HEAD;
EXPECT('E', c);
EXPECT('A', c);
EXPECT('D', c);
EXPECT(SPACE, c);
readingState = DONE;
LOG_CON(INFO, socketFd, "Got HEAD request");
break;
default:
LOG_CON(ERROR, socketFd,
"Could not parse HTTP request - "
" Unsupported HTTP method?\n");
return -1;
};
};
if(SPACE != getToken(request->url, &request->urlMaxLength) )
{
LOG_CON(ERROR, socketFd, "Could not read URL for HTTP requst\n");
return -1;
}
LOG_CON(INFO, socketFd, "Read URL");
EXPECT('H', c);
EXPECT('T', c);
EXPECT('T', c);
EXPECT('P', c);
EXPECT('/', c);
NEXT_CHAR(request->majVersion);
EXPECT('.', c);
NEXT_CHAR(request->minVersion);
EXPECT(CR, c);
EXPECT(LF, c);
crLfReadingState = Lf1;
/* Read until end of header */
while(Lf2 != crLfReadingState)
{
NEXT_CHAR(c);
if(CR == c)
{
if(Lf1 == crLfReadingState)
{
crLfReadingState = Cr2;
}
else
{
crLfReadingState = Cr1;
}
}
else if(LF == c)
{
if(Cr1 == crLfReadingState)
{
crLfReadingState = Lf1;
}
else if(Cr2 == crLfReadingState)
{
crLfReadingState = Lf2;
}
else
{
crLfReadingState = None;
}
//.........这里部分代码省略.........
示例10: RPCNametoOutletList
static int
RPCNametoOutletList(struct pluginDevice* bt, const char * name
, int outletlist[])
{
char NameMapping[128];
int sockno;
char sockname[32];
int maxfound = 0;
/* Verify that we're in the top-level menu */
SEND(bt->wrfd, "\r");
/* Expect "RPC-x Menu" */
EXPECT(bt->rdfd, RPC, 5);
EXPECT(bt->rdfd, Menu, 5);
/* OK. Request sub-menu 1 (Outlet Control) */
SEND(bt->wrfd, "1\r");
/* Verify that we're in the sub-menu */
/* Expect: "RPC-x>" */
EXPECT(bt->rdfd, RPC, 5);
EXPECT(bt->rdfd, GTSign, 5);
/* The status command output contains mapping of hosts to outlets */
SEND(bt->wrfd, "STATUS\r");
/* Expect: "emperature:" so we can skip over it... */
EXPECT(bt->rdfd, bt->modelinfo->expect, 5);
EXPECT(bt->rdfd, CRNL, 5);
/* Looks Good! Parse the status output */
do {
char * last;
NameMapping[0] = EOS;
SNARF(bt->rdfd, NameMapping, 5);
if (!parse_socket_line(bt, NameMapping, &sockno, sockname)) {
continue;
}
last = sockname+bt->modelinfo->socklen;
*last = EOS;
--last;
/* Strip off trailing blanks */
for(; last > sockname; --last) {
if (*last == ' ') {
*last = EOS;
}else{
break;
}
}
if (strcasecmp(name, sockname) == 0) {
outletlist[maxfound] = sockno;
++maxfound;
}
} while (strlen(NameMapping) > 2 && maxfound < MAXOUTLET);
/* Pop back out to the top level menu */
SEND(bt->wrfd, "MENU\r");
return(maxfound);
}
示例11: MemoryDealer
status_t Harness::testStateTransitions(
const char *componentName, const char *componentRole) {
if (strncmp(componentName, "OMX.", 4)) {
// Non-OMX components, i.e. software decoders won't execute this
// test.
return OK;
}
sp<MemoryDealer> dealer = new MemoryDealer(16 * 1024 * 1024, "OMXHarness");
IOMX::node_id node;
status_t err =
mOMX->allocateNode(componentName, this, &node);
EXPECT_SUCCESS(err, "allocateNode");
NodeReaper reaper(this, node);
err = setRole(node, componentRole);
EXPECT_SUCCESS(err, "setRole");
// Initiate transition Loaded->Idle
err = mOMX->sendCommand(node, OMX_CommandStateSet, OMX_StateIdle);
EXPECT_SUCCESS(err, "sendCommand(go-to-Idle)");
omx_message msg;
err = dequeueMessageForNode(node, &msg, DEFAULT_TIMEOUT);
// Make sure node doesn't just transition to idle before we are done
// allocating all input and output buffers.
EXPECT(err == TIMED_OUT,
"Component must not transition from loaded to idle before "
"all input and output buffers are allocated.");
// Now allocate buffers.
Vector<Buffer> inputBuffers;
err = allocatePortBuffers(dealer, node, 0, &inputBuffers);
EXPECT_SUCCESS(err, "allocatePortBuffers(input)");
err = dequeueMessageForNode(node, &msg, DEFAULT_TIMEOUT);
CHECK_EQ(err, TIMED_OUT);
Vector<Buffer> outputBuffers;
err = allocatePortBuffers(dealer, node, 1, &outputBuffers);
EXPECT_SUCCESS(err, "allocatePortBuffers(output)");
err = dequeueMessageForNode(node, &msg, DEFAULT_TIMEOUT);
EXPECT(err == OK
&& msg.type == omx_message::EVENT
&& msg.u.event_data.event == OMX_EventCmdComplete
&& msg.u.event_data.data1 == OMX_CommandStateSet
&& msg.u.event_data.data2 == OMX_StateIdle,
"Component did not properly transition to idle state "
"after all input and output buffers were allocated.");
// Initiate transition Idle->Executing
err = mOMX->sendCommand(node, OMX_CommandStateSet, OMX_StateExecuting);
EXPECT_SUCCESS(err, "sendCommand(go-to-Executing)");
err = dequeueMessageForNode(node, &msg, DEFAULT_TIMEOUT);
EXPECT(err == OK
&& msg.type == omx_message::EVENT
&& msg.u.event_data.event == OMX_EventCmdComplete
&& msg.u.event_data.data1 == OMX_CommandStateSet
&& msg.u.event_data.data2 == OMX_StateExecuting,
"Component did not properly transition from idle to "
"executing state.");
for (size_t i = 0; i < outputBuffers.size(); ++i) {
err = mOMX->fillBuffer(node, outputBuffers[i].mID);
EXPECT_SUCCESS(err, "fillBuffer");
outputBuffers.editItemAt(i).mFlags |= kBufferBusy;
}
err = mOMX->sendCommand(node, OMX_CommandFlush, 1);
EXPECT_SUCCESS(err, "sendCommand(flush-output-port)");
err = dequeueMessageForNodeIgnoringBuffers(
node, &inputBuffers, &outputBuffers, &msg, DEFAULT_TIMEOUT);
EXPECT(err == OK
&& msg.type == omx_message::EVENT
&& msg.u.event_data.event == OMX_EventCmdComplete
&& msg.u.event_data.data1 == OMX_CommandFlush
&& msg.u.event_data.data2 == 1,
"Component did not properly acknowledge flushing the output port.");
for (size_t i = 0; i < outputBuffers.size(); ++i) {
EXPECT((outputBuffers[i].mFlags & kBufferBusy) == 0,
"Not all output buffers have been returned to us by the time "
"we received the flush-complete notification.");
}
for (size_t i = 0; i < outputBuffers.size(); ++i) {
err = mOMX->fillBuffer(node, outputBuffers[i].mID);
EXPECT_SUCCESS(err, "fillBuffer");
outputBuffers.editItemAt(i).mFlags |= kBufferBusy;
}
// Initiate transition Executing->Idle
err = mOMX->sendCommand(node, OMX_CommandStateSet, OMX_StateIdle);
//.........这里部分代码省略.........
示例12: RPCReset
/* Reset (power-cycle) the given outlet number */
static int
RPCReset(struct pluginDevice* bt, int unitnum, const char * rebootid)
{
char unum[32];
SEND(bt->wrfd, "\r");
/* Make sure we're in the top level menu */
/* Expect "RPC-x Menu" */
EXPECT(bt->rdfd, RPC, 5);
EXPECT(bt->rdfd, Menu, 5);
/* OK. Request sub-menu 1 (Outlet Control) */
SEND(bt->wrfd, "1\r");
/* Verify that we're in the sub-menu */
/* Expect: "RPC-x>" */
EXPECT(bt->rdfd, RPC, 5);
EXPECT(bt->rdfd, GTSign, 5);
/* Send REBOOT command for given outlet */
snprintf(unum, sizeof(unum), "REBOOT %d\r", unitnum);
SEND(bt->wrfd, unum);
/* Expect "ebooting "... or "(Y/N)" (if confirmation turned on) */
retry:
switch (StonithLookFor(bt->rdfd, Rebooting, 5)) {
case 0: /* Got "Rebooting" Do nothing */
break;
case 1: /* Got that annoying command confirmation :-( */
SEND(bt->wrfd, "Y\r");
goto retry;
case 2: /* Outlet is turned off */
LOG(PIL_CRIT, "Host is OFF: %s.", rebootid);
return(S_ISOFF);
default:
return(errno == ETIMEDOUT ? S_RESETFAIL : S_OOPS);
}
LOG(PIL_INFO, "Host %s (outlet %d) being rebooted."
, rebootid, unitnum);
/* Expect "ower applied to outlet" */
if (StonithLookFor(bt->rdfd, PowerApplied, 30) < 0) {
return(errno == ETIMEDOUT ? S_RESETFAIL : S_OOPS);
}
/* All Right! Power is back on. Life is Good! */
LOG(PIL_INFO, "Power restored to host %s (outlet %d)."
, rebootid, unitnum);
/* Expect: "RPC-x>" */
EXPECT(bt->rdfd, RPC,5);
EXPECT(bt->rdfd, GTSign, 5);
/* Pop back to main menu */
SEND(bt->wrfd, "MENU\r");
return(S_OK);
}
示例13: RPCLogin
static int
RPCLogin(struct pluginDevice * bt)
{
char IDinfo[128];
static char IDbuf[128];
char * idptr = IDinfo;
char * delim;
int j;
EXPECT(bt->rdfd, RPC, 10);
/* Look for the unit type info */
if (EXPECT_TOK(bt->rdfd, BayTechAssoc, 2, IDinfo
, sizeof(IDinfo), Debug) < 0) {
LOG(PIL_CRIT, "No initial response from %s.", bt->idinfo);
return(errno == ETIMEDOUT ? S_TIMEOUT : S_OOPS);
}
idptr += strspn(idptr, WHITESPACE);
/*
* We should be looking at something like this:
* RPC-5 Telnet Host
* Revision F 4.22, (C) 1999
* Bay Technical Associates
*/
/* Truncate the result after the RPC-5 part */
if ((delim = strchr(idptr, ' ')) != NULL) {
*delim = EOS;
}
snprintf(IDbuf, sizeof(IDbuf), "BayTech RPC%s", idptr);
REPLSTR(bt->idinfo, IDbuf);
if (bt->idinfo == NULL) {
return(S_OOPS);
}
bt->modelinfo = &ModelInfo[0];
for (j=0; ModelInfo[j].type != NULL; ++j) {
/*
* TIMXXX -
* Look at device ID as this really describes the model.
*/
if (strcasecmp(ModelInfo[j].type, IDbuf) == 0) {
bt->modelinfo = &ModelInfo[j];
break;
}
}
/* Look for the unit id info */
EXPECT(bt->rdfd, UnitId, 10);
SNARF(bt->rdfd, IDbuf, 2);
delim = IDbuf + strcspn(IDbuf, WHITESPACE);
*delim = EOS;
REPLSTR(bt->unitid, IDbuf);
if (bt->unitid == NULL) {
return(S_OOPS);
}
/* Expect "username>" */
EXPECT(bt->rdfd, login, 2);
SEND(bt->wrfd, bt->user);
SEND(bt->wrfd, "\r");
/* Expect "password>" */
switch (StonithLookFor(bt->rdfd, password, 5)) {
case 0: /* Good! */
break;
case 1: /* OOPS! got another username prompt */
LOG(PIL_CRIT, "Invalid username for %s.", bt->idinfo);
return(S_ACCESS);
default:
return(errno == ETIMEDOUT ? S_TIMEOUT : S_OOPS);
}
SEND(bt->wrfd, bt->passwd);
SEND(bt->wrfd, "\r");
/* Expect "RPC-x Menu" */
switch (StonithLookFor(bt->rdfd, LoginOK, 5)) {
case 0: /* Good! */
break;
case 1: /* Uh-oh - bad password */
LOG(PIL_CRIT, "Invalid password for %s.", bt->idinfo);
return(S_ACCESS);
default:
return(errno == ETIMEDOUT ? S_TIMEOUT : S_OOPS);
}
EXPECT(bt->rdfd, Menu, 2);
return(S_OK);
}
示例14: read_config
int read_config(char *file_name)
{
FILE *f;
if (!(f = fopen(file_name,"r"))) return 1;
EXPECT(1, "unsigned Seed = %u;", &Seed);
EXPECT(1, "int Runs = %d;", &Runs);
EXPECT(1, "int N = %d;", &N);
EXPECT(1, "int G = %d;", &G);
EXPECT(1, "double T = %lf;", &T);
EXPECT(1, "double PE[0] = %lf;", PE+0);
EXPECT(1, "double PE[1] = %lf;", PE+1);
EXPECT(1, "double PE[2] = %lf;", PE+2);
EXPECT(1, "double F0 = %lf;", &F0);
EXPECT(1, "double B = %lf;", &B);
EXPECT(1, "double C = %lf;", &C);
EXPECT(1, "double X0 = %lf;", &X0);
EXPECT(1, "double Discount = %lf;", &Discount);
EXPECT(1, "double Omega = %lf;", &Omega);
EXPECT(1, "double Alpha = %lf;", &Alpha);
EXPECT(1, "double Beta = %lf;", &Beta);
EXPECT(1, "double Gamma = %lf;", &Gamma);
EXPECT(1, "double Delta = %lf;", &Delta);
EXPECT(1, "int PROTOCOL = %d;", &PROTOCOL);
EXPECT(1, "int K = %d;", &K);
EXPECT(1, "double Eta = %lf;", &Eta);
EXPECT(1, "double E = %lf;", &E);
EXPECT(1, "double S0 = %lf;", &S0);
EXPECT(1, "double Phi = %lf;", &Phi);
EXPECT(1, "double e = %lf;", &e);
EXPECT(1, "double Mu = %lf;", &Mu);
EXPECT(1, "double Sigma = %lf;", &Sigma);
EXPECT(1, "double Sigma_B = %lf;", &Sigma_B);
EXPECT(1, "double Sigma_dxi = %lf;", &Sigma_dxi);
EXPECT(1, "double Sigma_dsi = %lf;", &Sigma_dsi);
fclose(f); return 0;
}
示例15: test_self_direct
static void
test_self_direct(dcontext_t *dcontext)
{
app_pc base_pc;
size_t size;
uint found;
uint newfound;
#ifdef WINDOWS
/* this will get both code and data FIXME: data2data reference
* will be the majority
*/
size = get_allocation_size((app_pc)test_self_direct, &base_pc);
#else
/* platform agnostic but only looks for current CODE section, and
* on windows is not quite what we want - since base_pc will just
* be just page aligned
*/
get_memory_info((app_pc)test_self_direct, &base_pc, &size, NULL);
#endif
mutex_lock(&rct_module_lock);
found = find_address_references(dcontext,
base_pc, base_pc+size,
base_pc, base_pc+size);
mutex_unlock(&rct_module_lock);
/* guesstimate */
EXPECT_RELATION(found, >, 140);
#ifdef WINDOWS
/* FIXME: note data2data have a huge part here */
EXPECT_RELATION(found, <, 20000);
#else
EXPECT_RELATION(found, <, 1000);
#endif
EXPECT(is_address_taken(dcontext, (app_pc)f3), true);
EXPECT(is_address_taken(dcontext, (app_pc)f2), true);
EXPECT(is_address_taken(dcontext, (app_pc)f7), true); /* array reference only */
/* it is pretty hard to produce the address of a static
* (e.g. test_self) without making it address taken ;) so we just
* add a number to known to be good one's */
EXPECT(is_address_taken(dcontext, (app_pc)f3 + 1), false);
EXPECT(is_address_taken(dcontext, (app_pc)f3 + 2), false);
EXPECT(is_address_taken(dcontext, (app_pc)f2 + 1), false);
EXPECT(is_address_taken(dcontext, (app_pc)f7 + 1), false);
mutex_lock(&rct_module_lock);
EXPECT(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1),
found);
EXPECT_RELATION(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1)
, == , 0); /* nothing missed */
mutex_unlock(&rct_module_lock);
/* now try manually rct_analyze_module_at_violation */
mutex_lock(&rct_module_lock);
EXPECT(rct_analyze_module_at_violation(dcontext, (app_pc)test_self_direct), true);
/* should be all found */
/* FIXME: with the data2data in fact a few noisy entries show up
* since second lookup in data may differ from original
*/
newfound = find_address_references(dcontext,
base_pc, base_pc+size,
base_pc, base_pc+size);
EXPECT_RELATION(newfound, <, 4);
EXPECT_RELATION(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1)
, > , found + newfound - 5); /* FIXME: data references uncomparable */
EXPECT_RELATION(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1)
, == , 0); /* nothing missed */
mutex_unlock(&rct_module_lock);
}