Beispiel #1
0
int
main (int argc, const char *argv[])
{
  int child_idx;
  int fd;
  size_t ofs;

  quiet = true;

  CHECK (argc == 2, "argc must be 2, actually %d", argc);
  child_idx = atoi (argv[1]);

  random_init (0);
  random_bytes (buf1, sizeof buf1);

  CHECK ( (fd = open (file_name)) > 1, "open \"%s\"", file_name);
  ofs = 0;
  while (ofs < sizeof buf2)
    {
      int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs);
      CHECK (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs),
             "%zu-byte read on \"%s\" returned invalid value of %d",
             sizeof buf2 - ofs, file_name, bytes_read);
      if (bytes_read > 0)
        {
          compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, file_name);
          ofs += bytes_read;
        }
    }
  close (fd);

  return child_idx;
}
int
main (int argc, const char *argv[]) 
{
  int child_idx;
  int fd;
  size_t i;

  quiet = true;
  
  CHECK (argc == 2, "argc must be 2, actually %d", argc);
  child_idx = atoi (argv[1]);

  random_init (0);
  random_bytes (buf, sizeof buf);

  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
  for (i = 0; i < sizeof buf; i++) 
    {
      char c;
      CHECK (read (fd, &c, 1) > 0, "read \"%s\"", file_name);
      compare_bytes (&c, buf + i, 1, i, file_name);
    }
  close (fd);

  return child_idx;
}
Beispiel #3
0
void
check_file_handle (int fd,
                   const char *file_name, const void *buf_, size_t size) 
{
  const char *buf = buf_;
  size_t ofs = 0;
  size_t file_size;

  /* Warn about file of wrong size.  Don't fail yet because we
     may still be able to get more information by reading the
     file. */
  file_size = filesize (fd);
  //printf(" ERROR %d, %d \n ", file_size,size);
  if (file_size != size)
    msg ("size of %s (%zu) differs from expected (%zu)",
          file_name, file_size, size);

  /* Read the file block-by-block, comparing data as we go. */
  //printf(" SIZE %d \n", size);
  while (ofs < size)
    {
      char block[512];
      size_t block_size, ret_val;
	 
      block_size = size - ofs;
      //printf(" BLOCK SIZE : %d , OFFSET : %d ",block_size, ofs);
	  if (block_size > sizeof block)
        block_size = sizeof block;
	  //printf(" SIZEOFBLOCK%d ",sizeof block); 
      ret_val = read (fd, block, block_size);
	  //printf(" RET_VAL %d \n",ret_val);
      if (ret_val != block_size){
        fail ("read of %zu bytes at offset %zu in \"%s\" returned %zu",
              block_size, ofs, file_name, ret_val);
		//printf("ERROR\n");
	  }

      compare_bytes (block, buf + ofs, block_size, ofs, file_name);
      ofs += block_size;
    }

  /* Now fail due to wrong file size. */
  if (file_size != size)
    fail ("size of %s (%zu) differs from expected (%zu)",
          file_name, file_size, size);

  msg ("verified contents of \"%s\"", file_name);
}
Beispiel #4
0
void
test_main (void) 
{
  pid_t children[CHILD_CNT];
  int fd;

  CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);

  exec_children ("child-syn-wrt", children, CHILD_CNT);
  wait_children (children, CHILD_CNT);

  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
  CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", file_name);
  random_bytes (buf2, sizeof buf2);
  compare_bytes (buf1, buf2, sizeof buf1, 0, file_name);
}
Beispiel #5
0
int compare_strings(NlString* left, NlString* right){
	return compare_bytes(left->s, left->length, right->s, right->length);
}
Beispiel #6
0
int compare_string_with_cstr(NlString* left, const char* cstr){
	return compare_bytes(left->s, left->length, cstr, strlen(cstr));
}