static void print_client(struct client *client) { if(client == NULL) fprintf(stderr, "NO_CLIENT"); else { fprintf(stderr, "(%p): ", client); switch(client->type) { case REQ_RESP: fprintf(stderr, "FD = '%d'; TYPE = '%s'; ARCH = '%s'; STATE = '%s'\n", client->fd, client_type_2_str(client->type), aconv_arch2str(client->arch), client_state_2_str(client->state)); print_buffer(client->rbuf, "Read buffer"); print_buffer(client->wbuf, "Write buffer"); break; case EVENT_SUB: fprintf(stderr, "FD = '%d'; TYPE = '%s'; STATE = '%s''\n", client->fd, client_type_2_str(client->type), client_state_2_str(client->state)); print_buffer(client->rbuf, "Read buffer"); print_buffer(client->wbuf, "Write buffer"); break; default: fprintf(stderr, "DATA_FD = '%d'; TYPE = '%s'; EVENT SUB FD INDEX = %d", client->fd, client_type_2_str(client->type), client->esfd_index); break; } } }
int main(int argc, const char* argv[]) { FILE *fp; // 需从流中读或写才能建立缓冲区,获取准确的默认缓冲大小,否则会获取到0 fputs("enter to activate stdin buffer size\n", stdout); if (getc(stdin) == EOF) { err_sys("getc error"); } //fputs("activate stdout\n", stderr); print_buffer("stdin", stdin); print_buffer("stdout", stdout); print_buffer("stderr", stderr); if ((fp = fopen("file.txt", "a+")) == NULL) { err_sys("fopen error"); } // 需从流中读或写才能建立缓冲区,获取准确的默认缓冲大小 if (putc('A', fp) == EOF) { err_sys("putc error"); } print_buffer("file.txt", fp); exit(0); }
int delete_from_buffer(bool right) { if(right) { forward_buffer(); } else { wprintf(L"\033[1D"); } if(buffer->current == NULL) { return RET_OK; } else { wprintf(L"\033[K"); } delete_elem(buffer); if(buffer->current == NULL) { print_buffer(true); wprintf(L"\033[1D"); return RET_OK; } if(buffer->current->next != NULL) { forward_buffer(); print_buffer(true); backward_buffer(); wprintf(L"\033[1D"); } return RET_OK; }
static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { int ret = 0; struct iwreq *iwr = (struct iwreq *) ifr; struct iw_request_info info; #ifdef DEBUG printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd); #endif if (cmd >= SIOCIWFIRSTPRIV) { info.cmd = cmd; info.flags = 0; ret = wlcompat_private_ioctl(dev, &info, &(iwr->u), (char *) &(iwr->u)); #ifdef DEBUG } else if (cmd==SIOCDEVPRIVATE) { wl_ioctl_t *ioc = (wl_ioctl_t *)ifr->ifr_data; unsigned char *buf = ioc->buf; printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len); printk(" send: ->"); print_buffer(ioc->len, buf); ret = old_ioctl(dev,ifr,cmd); printk(" recv: ->"); print_buffer(ioc->len, buf); printk(" ret: %d\n", ret); #endif } else { ret = old_ioctl(dev,ifr,cmd); } return ret; }
TEST () { GeglBuffer *buffer, *sub, *subsub, *foo; GeglRectangle subrect = {5, 5, 10, 10}; GeglRectangle foor = {0, 0, 10, 10}; GeglRectangle rect = {0, 0, 20, 20}; test_start (); buffer = gegl_buffer_new (&rect, babl_format ("Y float")); sub = gegl_buffer_create_sub_buffer (buffer, &subrect); vgrad (buffer); vgrad (sub); subsub = g_object_new (GEGL_TYPE_BUFFER, "source", sub, "x", 0, "y", 0, "width", 40, "height", 40, "shift-x", 0, "shift-y", 0, NULL); foo = gegl_buffer_create_sub_buffer (subsub, &foor); /*fill (subsub, 0.2);*/ print_buffer (buffer); print_buffer (foo); g_object_unref (sub); g_object_unref (subsub); g_object_unref (buffer); g_object_unref (foo); test_end (); }
bool open_device( struct pclta_device * device ) { CALL_MSG( "Starting open_device()", ++pclta_call_level ); // allocate and initialize buffers device->rx = kmalloc( sizeof(struct pclta_packet_buffer), GFP_KERNEL ); if( device->rx == NULL ) { RETURN_MSG( "open_device() ERROR= device->rx == NULL", pclta_call_level-- ); return false; } device->tx = kmalloc( sizeof(struct pclta_packet_buffer), GFP_KERNEL ); if( device->tx == NULL ) { kfree( device->rx ); RETURN_MSG( "open_device() ERROR= device->tx == NULL", pclta_call_level-- ); return false; } init_buffers( device->rx ); DEBUG_MSG("RECEIVE BUFFER"); print_buffer(device->rx); init_buffers( device->tx ); DEBUG_MSG("TRANSMIT BUFFER"); print_buffer(device->tx); // set initial state of device device->restart_uplink = false; device->pclta_wait_queue = NULL; // last_packet_read_complete=true; // for incomplete reads RETURN_MSG( "open_device() SUCCESS", pclta_call_level-- ); return true; }
/* Test 1: Add temperature and humidity */ static void test01(lora_serialization_t *serialization) { puts("Test 1"); puts("Temperature and humidity"); puts("---------------------------------"); lora_serialization_reset(serialization); // Always reset puts("- Writing temperature: 80.12"); lora_serialization_write_temperature(serialization, 80.12); puts("- Writing humidity: 99.99"); lora_serialization_write_humidity(serialization, 99.99); printf("- Encoded: "); print_buffer(serialization->buffer, LORA_SERIALIZATION_TEMPERATURE_SIZE + LORA_SERIALIZATION_HUMIDITY_SIZE); puts(""); printf("- Expected:"); print_buffer(test01Expected, sizeof(test01Expected)); puts(""); puts("---------------------------------"); if (memcmp(serialization->buffer, test01Expected, sizeof(test01Expected)) != 0) { puts("FAILED"); } else { puts("SUCCESS"); } }
// Consumer 2 consumes the first node from the list if its value is even consume2(){ int i; for(i=0;i<10;i++){ pthread_mutex_lock(&mymutex); printf("\nConsumer 2 Running"); if(buffer_size>1){ if(((bhead->value)%2)==0){ print_buffer(); bhead = bhead->next; free(bhead->prev); bhead->prev = 0; buffer_size--; print_buffer(); } } else if(buffer_size==1){ if(((bhead->value)%2)==0){ print_buffer(); free(bhead); bhead = 0; buffer_size--; print_buffer(); } } else { printf("\nBuffer underflow on Consumer 2!"); } pthread_mutex_unlock(&mymutex); sleep(1); } return; }
// Producer 1 generates a new node at the end of the buffer with an odd value produce1(){ int i; for(i=0;i<10;i++){ pthread_mutex_lock(&mymutex); if(buffer_size<BUFFER_MAX){ printf("\nProducer 1 Running"); print_buffer(); struct node* new_node = malloc(sizeof(struct node)); int new_value = rand()%39; if((new_value%2)==0){ new_value++; } new_node->value = new_value; new_node->next = 0; // Special case if list is empty: if(buffer_size==0){ new_node->prev = 0; bhead = new_node; } else { new_node->prev = btail; btail->next = new_node; } btail = new_node; buffer_size++; print_buffer(); } else { printf("\nBuffer overflow on Producer 1!"); } pthread_mutex_unlock(&mymutex); sleep(1); } return; }
/* Test 2: Add GPS coordinates and unix time */ static void test02(lora_serialization_t *serialization) { puts("Test 2"); puts("Coordinates and unix time"); puts("---------------------------------"); lora_serialization_reset(serialization); // Always reset puts("- Writing coordinates: -33.905052, 151.26641"); lora_serialization_write_coordinates(serialization, -33.905052, 151.26641); puts("- Writing unix time: 1467632413"); lora_serialization_write_unix_time(serialization, 1467632413); printf("- Encoded: "); print_buffer(serialization->buffer, LORA_SERIALIZATION_GPS_SIZE + LORA_SERIALIZATION_UNIX_TIME_SIZE); puts(""); printf("- Expected:"); print_buffer(test02Expected, sizeof(test02Expected)); puts(""); puts("---------------------------------"); if (memcmp(serialization->buffer, test02Expected, sizeof(test02Expected)) != 0) { puts("FAILED"); } else { puts("SUCCESS"); } }
/* This test check append mode initial position (a/a+) based on POSIX defition (BZ#6544 and BZ#13151) for buffer without null byte end. */ static int do_test_write_append_without_null (const char *mode) { char buf[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }; char exp[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }; /* If '\0' is not found in buffer, POSIX states that SEEK_SET should be the size argument. */ FILE *fp = fmemopen (buf, sizeof (buf) - 2, "a"); fflush (fp); fputc (0x70, fp); fseek (fp, 0, SEEK_SET); fputc (0x70, fp); fputc (0x70, fp); fclose (fp); /* POSIX also states that a write operation on the stream shall not advance the current buffer size beyond the size given in fmemopen, so the string should be same. */ if (memcmp (buf, exp, sizeof (buf)) != 0) { printf ("%s: check failed: ", __FUNCTION__); print_buffer (buf, sizeof (buf)); printf ("!= "); print_buffer (exp, sizeof (exp)); printf ("\n"); return 1; } return 0; }
/* This test check for fseek (SEEK_END) using negative offsets (BZ#14292). The starting position of descriptor is different base on the opening mode. */ static int do_test_read_seek_neg (const char *mode, const char *expected) { char buf[] = "abcdefghijklmnopqrstuvxz0123456789"; char tmp[10]; size_t tmps = sizeof (tmps); long offset = -11; FILE *fp = fmemopen (buf, sizeof (buf), mode); fseek (fp, offset, SEEK_END); fread (tmp, tmps, 1, fp); if (memcmp (tmp, expected, tmps) != 0) { printf ("%s: fmemopen(%s) - fseek (fp, %li, SEEK_END):\n", __FUNCTION__, mode, offset); printf (" returned: "); print_buffer (tmp, tmps); printf ("\n"); printf (" expected: "); print_buffer (expected, tmps); printf ("\n"); return 1; } fclose (fp); return 0; }
void testHash() { unsigned char Digest[32]; sha256_context ctx; sha256_init( &ctx ); sha256_starts( &ctx, 0 ); sha256_update( &ctx, sha256_test_buf[0], sha256_test_buflen[0] ); sha256_finish( &ctx, Digest ); print_buffer(Digest, sizeof(Digest)); memset(Digest, 0, sizeof(Digest)); uint8 buffer[1]; sha256_init( &ctx ); sha256_starts( &ctx, 0 ); buffer[0] = 'a'; sha256_update( &ctx, buffer, 1 ); buffer[0] = 'b'; sha256_update( &ctx, buffer, 1 ); buffer[0] = 'c'; sha256_update( &ctx, buffer, 1 ); buffer[0] = '\0'; sha256_update( &ctx, buffer, 1 ); sha256_finish( &ctx, Digest ); print_buffer(Digest, sizeof(Digest)); }
TEST () { GeglBuffer *buffer, *sub1, *sub2, *sub3; GeglRectangle subrect1 = {5, 5, 10, 10}; GeglRectangle subrect2 = {8, 8, 30, 30}; GeglRectangle subrect3 = {-2, -2, 24, 24}; GeglRectangle rect = {0, 0, 20, 20}; test_start (); buffer = gegl_buffer_new (&rect, babl_format ("Y float")); sub1 = gegl_buffer_create_sub_buffer (buffer, &subrect1); sub2 = gegl_buffer_create_sub_buffer (buffer, &subrect2); sub3 = gegl_buffer_create_sub_buffer (buffer, &subrect3); fill (sub1, 0.5); print (("root with sub1 filled in:\n")); print_buffer (buffer); print (("sub2 before fill:\n")); print_buffer (sub2); fill (sub2, 1.0); print (("final root:\n")); print_buffer (buffer); print (("final sub1:\n")); print_buffer (sub1); print (("final sub3:\n")); print_buffer (sub3); gegl_buffer_destroy (sub1); gegl_buffer_destroy (sub2); gegl_buffer_destroy (sub3); gegl_buffer_destroy (buffer); test_end (); }
/* prints a newline at the end of the address info */ void print_ia (struct internet_addr * ia) { printf ("v %d, port %d, addr ", ia->ip_version, ntohs (ia->port)); if (ia->ip_version == 4) print_buffer (((char *) &(ia->ip)) + 12, 4, NULL, 4, 1); else print_buffer ((char *) &(ia->ip), 16, NULL, 16, 1); }
//////////////////////////////////////////////////////////////////////////// // // AES Encryption / Decryption - ECB Blocks // //////////////////////////////////////////////////////////////////////////// status TestAESCrypto( void ) { uint8 ret; uint8 buffer[512]; // AES - CBC can take less than 256 bytes as input uint8 key[16]; // Key can be 16 bytes ~ 128 AES or 32 bytes 256 AES uint8 iv[16]; // iv fixed random value of 16 bytes uint8 updated_iv[16]; entropy_init( &entropy ); if( ( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { proj_printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret ); return ( FAIL ); } //DRBG test proj_printf("INF: DRBG test - generate Random number"); PrngGenerateBytes( buffer, sizeof(buffer)); print_buffer(buffer,sizeof(buffer)); // Setting key, iv and buffer values memset(buffer, 0xA5, sizeof(buffer)); print_buffer(buffer,sizeof(buffer)); PrngGenerateBytes(key,sizeof(key)); print_buffer(key,sizeof(key)); PrngGenerateBytes(iv,sizeof(iv)); print_buffer(iv,sizeof(iv)); // AES -CBC test memcpy(updated_iv, iv, sizeof(iv)); AESCryptCBC( key, sizeof(key), AES_ENCRYPT, updated_iv, sizeof(buffer), buffer, buffer ); print_buffer(buffer, sizeof(buffer)); AESCryptCBC( key, sizeof(key), AES_DECRYPT, iv, sizeof(buffer), buffer, buffer ); print_buffer(buffer, sizeof(buffer)); // AES - ECB AESCryptECB( key, sizeof(key), AES_ENCRYPT, buffer, buffer ); print_buffer(buffer, sizeof(buffer)); AESCryptECB( key, sizeof(key), AES_DECRYPT, buffer, buffer ); print_buffer(buffer, sizeof(buffer)); // AES - ECB Blocks AESCryptECB_Blocks( key, sizeof(key), AES_ENCRYPT, sizeof(buffer)/16, buffer, buffer ); print_buffer(buffer, sizeof(buffer)); AESCryptECB_Blocks( key, sizeof(key), AES_DECRYPT, sizeof(buffer)/16, buffer, buffer ); print_buffer(buffer, sizeof(buffer)); return ( PASS ); }
int main() { interrupt_count = 0; transfer_count = 0; tx_count = 0; rx_count = 0; uint32_t output_count = 0; uint32_t sum = 0; init(); // initialize buffers with some known value memset(tx_buffer,0x55,sizeof(tx_buffer)); memset(rx_buffer,0x22,sizeof(rx_buffer)); // configure SPI MAP_SPIReset(GSPI_BASE); MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI), SPI_IF_BIT_RATE,SPI_MODE_SLAVE,SPI_SUB_MODE_0, (SPI_HW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF | SPI_CS_ACTIVEHIGH | SPI_WL_8)); MAP_SPIIntRegister(GSPI_BASE,interrupt_handler); MAP_SPIIntEnable(GSPI_BASE,SPI_INT_RX_FULL|SPI_INT_TX_EMPTY); MAP_SPIEnable(GSPI_BASE); Message("Enabled SPI Interface in Slave Mode!\n\r"); Message("Starting while\n\r"); while(1) { memcpy(tx_buffer,rx_buffer,TR_BUFF_SIZE); // here we could also change the tx_buffer // e.g. tx_buffer[TR_BUFF_SIZE - 1] = 18; sum = 0; if(output_count < transfer_count) { for(int i = 0; i < TR_BUFF_SIZE; i++) { sum += rx_buffer[i]; } Report("The sum in the Rx buffer is: %d\n\r",sum); Report("Checksum Rx buffer is: 0x%02x\n\r",crc(rx_buffer)); Report("interrupt: %d, tx: %d, rx: %d, transfer: %d\n\r",interrupt_count,tx_count,rx_count, transfer_count); Message("TX-"); print_buffer(tx_buffer,TR_BUFF_SIZE); Message("RX-"); print_buffer(rx_buffer,TR_BUFF_SIZE); output_count++; } } return 0; }
int run_tests() { int i; int success = 0, total = 0; for (i = 0; i < (sizeof(test_cases) / sizeof(test_cases[0])); i++) { struct in6_addr addr, correct; uint8_t buf[512]; char *rv; uint8_t *btr = test_cases[i].buf; size_t len = 32; int ret; uint8_t stateful; ieee154_addr_t l2addr; total++; inet_pton6(test_cases[i].address, &correct); ieee154_parse(test_cases[i].l2addr, &l2addr); ieee154_print(&l2addr, buf, 512); printf("%s\n", buf); printf("in6_addr: %s\n", test_cases[i].address); ret = unpack_address(&addr, test_cases[i].dispatch, test_cases[i].context, &btr, &len, &l2addr, test_cases[i].panid, &stateful); inet_ntop6(&addr, buf, 512); printf("result: %s length: %li\n", buf, 32 - len); if (test_cases[i].len != 32 - len) { printf("case %u: result len: %li expected: %i\n", i, 32 - len, test_cases[i].len); continue; } if (memcmp(&addr, &correct, 16) != 0) { printf("case %u: unexpected result\n", i); print_buffer(correct.s6_addr, 16); print_buffer(addr.s6_addr, 16); continue; } if (test_cases[i].stateful != stateful) { printf("case %u: stateful compression was used!\n", test_cases[i].stateful); continue; } success++; } printf("%s: %i/%i tests succeeded\n", __FILE__, success, total); if (success == total) return 0; return 1; }
int check_test(struct ip6_packet *pkt, struct lowpan_reconstruct *recon) { char buf[2048]; memset(buf, 0, 2048); memcpy(buf, &pkt->ip6_hdr, sizeof(struct ip6_hdr)); iov_read(pkt->ip6_data, 0, iov_len(pkt->ip6_data), &buf[sizeof(struct ip6_hdr)]); // printf("CMP: %i", memcmp(buf, recon->r_buf, recon->r_bytes_rcvd)); print_buffer(buf, 50); print_buffer(recon->r_buf, 50); printf("CMP: %i\n", memcmp(buf, recon->r_buf, 50)); }
void edit_vocab(vocab_t *pnodoedit, char secmea[]) { pantalla_t *pant = get_curses(); char opcion = '0'; char *str=NULL; str = (char *)malloc(sizeof(char)*TAM_BUF); if (!str) { exit_mem(EXIT_FAILURE, "Not enough memory."); } //wprintw(pant->buffer,"\n"); print_buffer_new_line(); while ((opcion != 'y') && (opcion != 'n')) { if (pnodoedit->pkanji) { snprintf(str, TAM_BUF, "%s (%s) -> \"%s\" ¿ok? (y/n): ",pnodoedit->pkanji,pnodoedit->phiragana,secmea); } else { snprintf(str, TAM_BUF, "%s -> %s \"¿ok?\" (y/n): ",pnodoedit->phiragana,secmea); } print_buffer(str, true); upgrade_buffer(true); opcion = wgetch(pant->ppal); print_buffer_new_line(); } if (opcion == 'y') { if (!pnodoedit->pmeaning) { pnodoedit->pmeaning = (char *)malloc ((strlen(secmea)+1)*sizeof(char)); if (!pnodoedit->pmeaning) exit_mem(EXIT_FAILURE,"Not enough memory."); } else { pnodoedit->pmeaning = (char *)realloc (pnodoedit->pmeaning,(strlen(secmea)+1)*sizeof(char)); if (!pnodoedit->pmeaning) exit_mem(EXIT_FAILURE,"Not enough memory."); } strcpy(pnodoedit->pmeaning, secmea); print_buffer("\nRenaming...", true); } else { print_buffer("\nCancelling...", true); } if (str) { free(str); str=NULL; } }
int main(int argc, char** argv) { unsigned char randomness[LEN_TEST]; int retval = init_randombytes(); memset(randomness, 0, LEN_TEST); print_buffer(randomness); randombytes(randomness, LEN_TEST); print_buffer(randomness); cleanup_randombytes(); return 0; }
TEST () { GeglBuffer *buffer2, *buffer; GeglRectangle bound = {0, 0, 20, 20}; GeglRectangle dest = {4, 4, 4, 6}; float *blank = g_malloc0 (100000); gchar *temp = g_malloc0 (100000); test_start (); buffer2 = gegl_buffer_new (&bound, babl_format ("Y float")); buffer = gegl_buffer_new (&bound, babl_format ("Y float")); vgrad (buffer2); gegl_buffer_set (buffer2, &dest, 1, babl_format ("Y float"), blank, GEGL_AUTO_ROWSTRIDE); print_buffer (buffer2); gegl_buffer_get (buffer2, &bound, 0.5, babl_format ("Y float"), temp, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (buffer, &bound, 0, babl_format ("Y float"), temp, GEGL_AUTO_ROWSTRIDE); print_buffer (buffer); vgrad (buffer2); { GeglBufferIterator *iterator = gegl_buffer_iterator_new (buffer2, &dest, 1, babl_format ("Y float"), GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE); while (gegl_buffer_iterator_next (iterator)) { int i; gfloat *d = iterator->data[0]; for (i = 0; i < iterator->length; i++) d[i] = 0; } } print_buffer (buffer2); gegl_buffer_get (buffer2, &bound, 0.5, babl_format ("Y float"), temp, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (buffer, &bound, 0, babl_format ("Y float"), temp, GEGL_AUTO_ROWSTRIDE); print_buffer (buffer); g_object_unref (buffer); g_object_unref (buffer2); test_end (); }
/** * remove_item - thread safe(?) function to remove items to the bounded buffer * @param item the address of the variable that the removed value will be written * @return 0 in case of sucess -1 otherwise */ int remove_item(int *item, int id) { /* TODO: Check and wait if the buffer is empty. Ensure exclusive * access to the buffer and use the existing code to remove an item. */ sem_wait(&c); pthread_mutex_lock(&lockOut); int myOut = buffer.next_out; buffer.next_out = (buffer.next_out + 1) % BUFFER_SIZE; pthread_mutex_unlock(&lockOut); do { printf("C%d @ %d waiting...\n", id, myOut); sleep(rand() % BUFFER_SIZE); } while (buffer.value[myOut] <= 0); *item = buffer.value[myOut]; printf("C%d @ %d woke up, consumed %d\n", id, myOut, *item); buffer.value[myOut] = 0; print_buffer(); sem_post(&p); return 0; }
/* * * insert_item - thread safe(?) function to insert items to the bounded buffer * @param item the value to be inserted * @return 0 in case of sucess -1 otherwise */ int insert_item(int item, int id) { /* TODO: Check and wait if the buffer is full. Ensure exclusive * access to the buffer and use the existing code to remove an item. */ sem_wait(&p); pthread_mutex_lock(&lockIn); int myIn = buffer.next_in; buffer.next_in = (buffer.next_in + 1) % BUFFER_SIZE; pthread_mutex_unlock(&lockIn); printf("P%d @ %d producing...\n", id, myIn); sleep(rand() % BUFFER_SIZE); printf("P%d @ %d produced %d\n", id, myIn, item); buffer.value[myIn] = item; print_buffer(); sem_post(&c); return 0; }
/** Access the pages of this process through /proc/self/task/<tid>/mem in order to safely print the contents of a memory address range. @param addr The address at the start of the memory region. @param max_len The length of the memory region. @return Zero on success. */ static int safe_print_str(const char *addr, int max_len) { int fd; pid_t tid; off_t offset; ssize_t nbytes= 0; size_t total, count; char buf[256]; tid= (pid_t) syscall(SYS_gettid); sprintf(buf, "/proc/self/task/%d/mem", tid); if ((fd= open(buf, O_RDONLY)) < 0) return -1; /* Ensure that off_t can hold a pointer. */ compile_time_assert(sizeof(off_t) >= sizeof(intptr)); total= max_len; offset= (intptr) addr; /* Read up to the maximum number of bytes. */ while (total) { count= min(sizeof(buf), total); if ((nbytes= pread(fd, buf, count, offset)) < 0) { /* Just in case... */ if (errno == EINTR) continue; else break; } /* Advance offset into memory. */ total-= nbytes; offset+= nbytes; addr+= nbytes; /* Output the printable characters. */ print_buffer(buf, nbytes); /* Break if less than requested... */ if ((count - nbytes)) break; } /* Output a new line if something was printed. */ if (total != (size_t) max_len) my_safe_printf_stderr("%s", "\n"); if (nbytes == -1) my_safe_printf_stderr("Can't read from address %p\n", addr); close(fd); return 0; }
void SelectorTest::processFileEvents( int fd, short events, jh_ptr_int_t private_data ) { TRACE_BEGIN( LOG_LVL_INFO ); uint8_t buffer[ 10 ]; LOG_NOTICE( "fd %d, events %x private data %d", fd, events, private_data ); if ( events & POLLNVAL ) { TestFailed( "Recieved POLLNVAL" ); } if ( fd == mPipe[ 0 ] && private_data == 10 && ( events & POLLIN ) ) { mTestState++; } else { TestFailed( "First Listener Bad Params" ); } if ( events & POLLIN ) { int res = read( fd, buffer, 10 ); print_buffer( "READ", buffer, res ); } }
static int axiemac_recv(struct udevice *dev, int flags, uchar **packetp) { u32 length; struct axidma_priv *priv = dev_get_priv(dev); u32 temp; /* Wait for an incoming packet */ if (!isrxready(priv)) return -1; debug("axiemac: RX data ready\n"); /* Disable IRQ for a moment till packet is handled */ temp = readl(&priv->dmarx->control); temp &= ~XAXIDMA_IRQ_ALL_MASK; writel(temp, &priv->dmarx->control); if (!priv->eth_hasnobuf) length = rx_bd.app4 & 0xFFFF; /* max length mask */ else length = rx_bd.status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK; #ifdef DEBUG print_buffer(&rxframe, &rxframe[0], 1, length, 16); #endif *packetp = rxframe; return length; }
int main() { // Init buffer uint8_t test1[] = {0xff, 0xff, 0x01, 0x03, 0x01, 0x01, 0xf9}; uint8_t test2[] = {0xff, 0xff, 0x01, 0x04, 0x02, 0x2b, 0x01, 0xcc}; uint8_t test3[] = {0xff, 0xff, 0x01, 0x04, 0x02, 0x2b, 0x01, 0xcc}; uint8_t test4[] = {0xff, 0xff, 0x01, 0x03, 0x00, 0x20, 0xdb}; uint8_t test5[] = {0xff, 0xff, 0x01, 0x04, 0x03, 0x03, 0x01, 0xf3};// Fallo ID uint8_t test6[] = {0xff, 0xff, 0x01, 0x04, 0x03, 0x03, 0x01, 0xf3}; uint8_t* tests[] = {test1, test2, test3, test4, test5, test6}; uint8_t lengths[] = {7,8,8,7,8,8}; uint8_t results[] = {1,1,1,1,1,1}; init_buffer(); int i; for(i=0; i<6; ++i) { printf("TEST %i: ", i); exec_test(tests[i], lengths[i]); if (msgFinish_ == results[i]) { printf("[OK]\n"); } else { printf("[FAILED]\n"); print_buffer(lengths[i]); } reset(); init_buffer(); } return(0); }
void consume(unsigned char tag, unsigned char * payload) { #ifndef CSEC_VERIFY printf("received\n"); print_buffer(payload, PAYLOAD_LEN); #endif }
int run_tests() { int i; int success = 0, total = 0; for (i = 0; i < (sizeof(test_cases) / sizeof(test_cases[0])); i++) { uint8_t buf[512], *rb; struct in6_addr addr; uint8_t dispatch = 0; total ++; scribble(buf, 512); inet_pton6(test_cases[i].addr, &addr); printf("addr: %s\n", test_cases[i].addr); rb = pack_multicast(buf, &addr, &dispatch); print_buffer(buf, rb - buf); if (test_cases[i].result_len != (rb - buf)) continue; if (memcmp(test_cases[i].result, buf, rb - buf) != 0) continue; if (test_cases[i].result_dispatch != dispatch) continue; printf("SUCCESS!\n"); success++; } printf("%s: %i/%i tests succeeded\n", __FILE__, success, total); if (success == total) return 0; return 1; }