示例#1
0
void remove_allocs(ibp_capset_t *caps_list, int nallocs)
{
    int i, err;
    opque_t *q;
    op_generic_t *op;

    q = new_opque();

    for (i=0; i<nallocs; i++) {
        op = new_ibp_remove_op(ic, get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP), ibp_timeout);
        opque_add(q, op);
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("remove_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    //** Lastly free all the caps and the array
    for (i=0; i<nallocs; i++) {
        destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_READCAP));
        destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_WRITECAP));
        destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP));
    }

    free(caps_list);

    return;
}
示例#2
0
int cmd_split_allocate(ibp_connect_context_t *cc, char **argv, int argc)
{
    ibp_attributes_t attr;
    ibp_capset_t caps;
    ibp_cap_t *mcap;
    ibp_op_t op;
    int size;
    int err, timeout;

    if (argc < 6) {
        printf("cmd_split_allocate: Not enough parameters.  Received %d need 6\n", argc);
        return(0);
    }

    mcap = argv[0];
    store_attr(&attr, &(argv[1]));
    size = atol(argv[4]);
    timeout = atoi(argv[5]);

    set_ibp_split_alloc_op(&op, mcap, &caps, size, &attr, timeout, NULL, cc);

    err = ibp_sync_command(&op);

    if (err != IBP_OK) {
        printf("cmd_split_allocate: Error %s(%d)\n", _ibp_error_map[-err], err);
        return(0);
    }

    printf("Read cap: %s\n", get_ibp_cap(&caps, IBP_READCAP));
    printf("Write cap: %s\n", get_ibp_cap(&caps, IBP_WRITECAP));
    printf("Manage cap: %s\n", get_ibp_cap(&caps, IBP_MANAGECAP));

    return(0);
}
示例#3
0
void remove_allocs(ibp_capset_t *caps_list, int nallocs)
{
  int i, err;
  oplist_t *iolist;
  ibp_op_t *op;

  iolist = new_ibp_oplist(NULL);

  for (i=0; i<nallocs; i++) {
     op = new_ibp_remove_op(get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iolist, op);
  }
 
  io_start(iolist);
  err = io_waitall(iolist);  
  if (err != IBP_OK) {
     printf("remove_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); 
     abort();
  }    
  free_oplist(iolist);

  //** Lastly free all the caps and the array
  for (i=0; i<nallocs; i++) {
     destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_READCAP));   
     destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_WRITECAP));   
     destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP));   
  }

  free(caps_list);

  return;
}
示例#4
0
double small_random_allocs(ibp_capset_t *caps, int n, int asize, double readfrac, int small_count, int min_size, int max_size)
{
  int i, io_size, offset, slot, err;
  oplist_t *iolist;
  ibp_op_t *op;
  double rnd, lmin, lmax;
  double nbytes;

  iolist = new_ibp_oplist(NULL);

  lmin = log(min_size);  lmax = log(max_size);

  if (asize < max_size) {
     max_size = asize;
     log_printf(0, "small_random_allocs:  Adjusting max_size=%d\n", max_size);
  }

  char *buffer = (char *)malloc(max_size);
  memset(buffer, 0, max_size);

  nbytes = 0;
  for (i=0; i<small_count; i++) {
     rnd = rand()/(RAND_MAX+1.0);     
     slot = n * rnd;

     rnd = rand()/(RAND_MAX+1.0);     
     rnd = lmin + (lmax - lmin) * rnd;
     io_size = exp(rnd);
     if (io_size == 0) io_size = 1;
     nbytes = nbytes + io_size;

     rnd = rand()/(RAND_MAX+1.0);
     offset = (asize - io_size) * rnd;

//     log_printf(15, "small_random_allocs: slot=%d offset=%d size=%d\n", slot, offset, io_size);

     rnd = rand()/(RAND_MAX+1.0);     
     if (rnd < readfrac) {
        op = new_ibp_read_op(get_ibp_cap(&(caps[slot]), IBP_READCAP), offset, io_size, buffer, ibp_timeout, NULL, cc);
     } else {
        op = new_ibp_write_op(get_ibp_cap(&(caps[slot]), IBP_WRITECAP), offset, io_size, buffer, ibp_timeout, NULL, cc);
     }

     add_ibp_oplist(iolist, op);
  }
 
  io_start(iolist);
  err = io_waitall(iolist);  
  if (err != IBP_OK) {
     printf("small_random_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); 
  }    
  free_oplist(iolist);

  free(buffer);

  return(nbytes);
}
示例#5
0
void random_allocs(ibp_capset_t *caps, int n, int asize, int block_size, double rfrac)
{
    int i, err, bslot;
    int j, nblocks, rem, len;
    opque_t *q;
    op_generic_t *op;
    double rnd;
    tbuffer_t *buf;

    char *rbuffer = (char *)malloc(block_size);
    char *wbuffer = (char *)malloc(block_size);
    init_buffer(rbuffer, 'r', block_size);
    init_buffer(wbuffer, 'w', block_size);

    q = new_opque();

    nblocks = asize / block_size;
    rem = asize % block_size;
    if (rem > 0) nblocks++;

    type_malloc_clear(buf, tbuffer_t, n*nblocks);

    for (j=0; j<nblocks; j++) {
        for (i=0; i<n; i++) {
            rnd = rand()/(RAND_MAX + 1.0);

            if ((j==(nblocks-1)) && (rem > 0)) {
                len = rem;
            } else {
                len = block_size;
            }

            bslot = j*n + i;

            if (rnd < rfrac) {
                tbuffer_single(&(buf[bslot]), len, rbuffer);
                op = new_ibp_read_op(ic, get_ibp_cap(&(caps[i]), IBP_READCAP), j*block_size, &(buf[bslot]), 0, len, ibp_timeout);
            } else {
                tbuffer_single(&(buf[bslot]), len, wbuffer);
                op = new_ibp_write_op(ic, get_ibp_cap(&(caps[i]), IBP_WRITECAP), j*block_size, &(buf[bslot]), 0, len, ibp_timeout);
            }
            opque_add(q, op);
        }
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("random_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    free(buf);
    free(rbuffer);
    free(wbuffer);
}
示例#6
0
void read_allocs(ibp_capset_t *caps, int n, int asize, int block_size)
{
  int i, j, nblocks, rem, len, err;
  oplist_t *iolist;
  ibp_op_t *op;

  char *buffer = (char *)malloc(asize);
    
  iolist = new_ibp_oplist(NULL);

  nblocks = asize / block_size;
  rem = asize % block_size;
  if (rem > 0) nblocks++;

//  for (j=0; j<nblocks; j++) {
  for (j=nblocks-1; j>= 0; j--) {
     for (i=0; i<n; i++) {
         if ((j==(nblocks-1)) && (rem > 0)) { len = rem; } else { len = block_size; }
         op = new_ibp_read_op(get_ibp_cap(&(caps[i]), IBP_READCAP), j*block_size, len, buffer, ibp_timeout, NULL, cc);
         add_ibp_oplist(iolist, op);
     }
  }
 
  io_start(iolist);
  err = io_waitall(iolist);  
  if (err != IBP_OK) {
     printf("read_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); 
  }    
  free_oplist(iolist);

  free(buffer);
}
示例#7
0
ibp_capset_t *create_alias_allocs(int nallocs, ibp_capset_t *base_caps, int n_base)
{
    int i, err;
    opque_t *q;
    op_generic_t *op;
    ibp_capset_t *bcap;

    ibp_capset_t *caps = (ibp_capset_t *)malloc(sizeof(ibp_capset_t)*nallocs);

    q = new_opque();

    for (i=0; i<nallocs; i++) {
        bcap = &(base_caps[i % n_base]);
        op = new_ibp_alias_alloc_op(ic, &(caps[i]), get_ibp_cap(bcap, IBP_MANAGECAP), 0, 0, 0, ibp_timeout);
        opque_add(q, op);
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("create_alias_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    return(caps);
}
示例#8
0
ibp_capset_t *create_alias_allocs(int nallocs, ibp_capset_t *base_caps, int n_base)
{
  int i, err;
  oplist_t *iolist;
  ibp_op_t *op;
  ibp_capset_t *bcap;

  ibp_capset_t *caps = (ibp_capset_t *)malloc(sizeof(ibp_capset_t)*nallocs);

  iolist = new_ibp_oplist(NULL);

  for (i=0; i<nallocs; i++) {
     bcap = &(base_caps[i % n_base]);
     op = new_ibp_alias_alloc_op(&(caps[i]), get_ibp_cap(bcap, IBP_MANAGECAP), 0, 0, 0, ibp_timeout, NULL, NULL);
     add_ibp_oplist(iolist, op);
  }

  io_start(iolist);
  err = io_waitall(iolist);  
  if (err != IBP_OK) {
     printf("create_alias_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); 
  }    
  free_oplist(iolist);

  return(caps);
}
示例#9
0
void random_allocs(ibp_capset_t *caps, int n, int asize, int block_size, double rfrac)
{
  int i, slot, err;
  int j, nblocks, rem, len;
  oplist_t *iolist;
  ibp_op_t *op;
  double rnd;

  char *buffer = (char *)malloc(asize);    
  memset(buffer, 'R', asize);

  iolist = new_ibp_oplist(NULL);

  nblocks = asize / block_size;
  rem = asize % block_size;
  if (rem > 0) nblocks++;

  for (j=0; j<nblocks; j++) {
     for (i=0; i<n; i++) {
         rnd = rand()/(RAND_MAX+1.0);     
         slot = n * rnd;

         rnd = rand()/(RAND_MAX + 1.0);

         if ((j==(nblocks-1)) && (rem > 0)) { len = rem; } else { len = block_size; }
//         op = new_ibp_read_op(get_ibp_cap(&(caps[i]), IBP_READCAP), j*block_size, len, buffer, ibp_timeout, NULL, cc);

         if (rnd < rfrac) {
            op = new_ibp_read_op(get_ibp_cap(&(caps[i]), IBP_READCAP), j*block_size, len, buffer, ibp_timeout, NULL, cc);
         } else {
            op = new_ibp_write_op(get_ibp_cap(&(caps[i]), IBP_WRITECAP), j*block_size, len, buffer, ibp_timeout, NULL, cc);
         }
         add_ibp_oplist(iolist, op);
     }
  }
 
  io_start(iolist);
  err = io_waitall(iolist);  
  if (err != IBP_OK) {
     printf("random_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); 
  }    
  free_oplist(iolist);

  free(buffer);
}
示例#10
0
double small_read_allocs(ibp_capset_t *caps, int n, int asize, int small_count, int min_size, int max_size)
{
    int i, io_size, offset, slot, err;
    opque_t *q;
    op_generic_t *op;
    double rnd, lmin, lmax;
    double nbytes;
    tbuffer_t *buf;

    q = new_opque();

    lmin = log(min_size);
    lmax = log(max_size);

    if (asize < max_size) {
        max_size = asize;
        log_printf(0, "small_read_allocs:  Adjusting max_size=%d\n", max_size);
    }

    char *buffer = (char *)malloc(max_size);
    init_buffer(buffer, 'r', max_size);

    type_malloc_clear(buf, tbuffer_t, small_count);

    nbytes = 0;
    for (i=0; i<small_count; i++) {
        rnd = rand()/(RAND_MAX+1.0);
        slot = n * rnd;

        rnd = rand()/(RAND_MAX+1.0);
        rnd = lmin + (lmax - lmin) * rnd;
        io_size = exp(rnd);
        if (io_size == 0) io_size = 1;
        nbytes = nbytes + io_size;

        rnd = rand()/(RAND_MAX+1.0);
        offset = (asize - io_size) * rnd;

        tbuffer_single(&(buf[i]), io_size, buffer);

        op = new_ibp_read_op(ic, get_ibp_cap(&(caps[slot]), IBP_READCAP), offset, &(buf[i]), 0, io_size, ibp_timeout);
        opque_add(q, op);
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("small_read_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    free(buf);
    free(buffer);

    return(nbytes);
}
示例#11
0
void save_allocs(FILE *fd, ibp_capset_t *caps_list, int nallocs)
{
    int i;

    //** Print the ds_read compatible portion of the file
    fprintf(fd, "%d\n", nallocs);
    for (i=0; i<nallocs; i++) {
        fprintf(fd,"%s\n", get_ibp_cap(&(caps_list[i]), IBP_READCAP));
    }

    //** Now print the full caps
    fprintf(fd, "=========FULL CAPS FOLLOW===========\n");
    for (i=0; i<nallocs; i++) {
        fprintf(fd,"%s\n", get_ibp_cap(&(caps_list[i]), IBP_READCAP));
        fprintf(fd,"%s\n", get_ibp_cap(&(caps_list[i]), IBP_WRITECAP));
        fprintf(fd,"%s\n", get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP));
    }

    return;
}
示例#12
0
void validate_allocs(ibp_capset_t *caps_list, int nallocs)
{
    int i, err;
    int nalloc_bad, nblocks_bad;
    opque_t *q;
    op_generic_t *op;
    int *bad_blocks = (int *) malloc(sizeof(int)*nallocs);
    int correct_errors = 0;

    q = new_opque();

    for (i=0; i<nallocs; i++) {
        bad_blocks[i] = 0;
        op = new_ibp_validate_chksum_op(ic, get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP), correct_errors, &(bad_blocks[i]),
                                        ibp_timeout);
        opque_add(q, op);
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("validate_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
        nalloc_bad = 0;
        nblocks_bad = 0;
        for (i=0; i<nallocs; i++) {
            if (bad_blocks[i] != 0) {
                printf("  %d   cap=%s  blocks_bad=%d\n", i, get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP), bad_blocks[i]);
                nalloc_bad++;
                nblocks_bad = nblocks_bad + bad_blocks[i];
            }
        }

        printf("  Total Bad allocations: %d   Total Bad blocks: %d\n", nalloc_bad, nblocks_bad);
    }
    opque_free(q, OP_DESTROY);

    free(bad_blocks);

    return;
}
示例#13
0
void write_allocs(ibp_capset_t *caps, int n, int asize, int block_size)
{
    int i, j, nblocks, rem, len, err, slot;
    opque_t *q;
    op_generic_t *op;
    tbuffer_t *buf;

    char *buffer = (char *)malloc(block_size);
    init_buffer(buffer, 'W', block_size);

    q = new_opque();

    nblocks = asize / block_size;
    rem = asize % block_size;
    if (rem > 0) nblocks++;

    type_malloc_clear(buf, tbuffer_t, n*nblocks);

//for (j=0; j<nblocks; j++) {
    for (j=nblocks-1; j>= 0; j--) {
        for (i=0; i<n; i++) {
            if ((j==(nblocks-1)) && (rem > 0)) {
                len = rem;
            } else {
                len = block_size;
            }
            slot = j*n + i;
            tbuffer_single(&(buf[slot]), len, buffer);
            op = new_ibp_write_op(ic, get_ibp_cap(&(caps[i]), IBP_WRITECAP), j*block_size, &(buf[slot]), 0, len, ibp_timeout);
            opque_add(q, op);
        }
    }

    io_start(q);
    err = io_waitall(q);
    if (err != 0) {
        printf("write_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    free(buf);
    free(buffer);
}
示例#14
0
void perform_pushpull_tests(ibp_depot_t *depot1, ibp_depot_t *depot2)
{
  int bufsize = 2048;
  char wbuf[bufsize+1], rbuf[bufsize+1];
  ibp_op_t op;
  ibp_attributes_t attr;
  ibp_capset_t caps1, caps2;
  int nbytes, err;
  ibp_timer_t timer;
  int start_nfailed = failed_tests;

  printf("perform_pushpull_tests:  Starting tests!\n");

  set_ibp_timer(&timer, ibp_timeout, ibp_timeout);

  //** Initialize the buffers **
  memset(wbuf, '0', sizeof(wbuf));  wbuf[1023]='1'; wbuf[1024]='2'; wbuf[bufsize] = '\0';
  memset(rbuf, 0, sizeof(rbuf));
  nbytes = 1024;

  //*** Make the allocation used in the tests ***
  set_ibp_attributes(&attr, time(NULL) + A_DURATION, IBP_HARD, IBP_BYTEARRAY);
  set_ibp_alloc_op(&op, &caps1, bufsize, depot1, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error creating allocation 1 for tests!! error=%d\n", err);
     return;
  }

  set_ibp_alloc_op(&op, &caps2, bufsize, depot2, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error creating allocation 2 for tests!! error=%d\n", err);
     return;
  }

  //** Fill caps1="1" with data **
  err = IBP_store(get_ibp_cap(&caps1, IBP_WRITECAP), &timer, "1", 1);
  if (err != 1) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with master IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Append it to cap2="1"
  set_ibp_copy_op(&op, IBP_PUSH, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_READCAP), 
          get_ibp_cap(&caps2, IBP_WRITECAP), 0, -1, 1, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 1!! error=%d\n", err);
     return;
  }

  //** Append cap2 to cap1="11"
  set_ibp_copy_op(&op, IBP_PULL, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_WRITECAP), 
          get_ibp_cap(&caps2, IBP_READCAP), -1, 0, 1, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 2!! error=%d\n", err);
     return;
  }

  //** Append it to cap2="111"
  set_ibp_copy_op(&op, IBP_PUSH, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_READCAP), 
          get_ibp_cap(&caps2, IBP_WRITECAP), 0, -1, 2, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 3!! error=%d\n", err);
     return;
  }

  //** Change  caps1="123"
  err = IBP_write(get_ibp_cap(&caps1, IBP_WRITECAP), &timer, "23", 2, 1);
  if (err != 2) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with IBP_store 2! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** offset it to also make cap2="123"
  set_ibp_copy_op(&op, IBP_PUSH, NS_TYPE_SOCK, NULL, get_ibp_cap(&caps1, IBP_READCAP), 
          get_ibp_cap(&caps2, IBP_WRITECAP), 1, 1, 2, ibp_timeout, ibp_timeout, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Error with copy 4!! error=%d\n", err);
     return;
  }

  //** Now read them back and check them
  //** verify caps1
  memset(rbuf, 0, sizeof(rbuf));
  memcpy(wbuf, "123", 4);
  err = IBP_load(get_ibp_cap(&caps1, IBP_READCAP), &timer, rbuf, 3, 0);
  if (err == 3) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("perform_pushpull_tests: Read some data with the cap1 but it wasn't correct!\n");
        printf("perform_pushpull_tests: Original=%s\n", wbuf);
        printf("perform_pushpull_tests:      Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Failed reading cap1! err=%d\n", err);
  }

  //** and also caps2
  memset(rbuf, 0, sizeof(rbuf));
  err = IBP_load(get_ibp_cap(&caps2, IBP_READCAP), &timer, rbuf, 3, 0);
  if (err == 3) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("perform_pushpull_tests: Read some data with the cap2 but it wasn't correct!\n");
        printf("perform_pushpull_tests: Original=%s\n", wbuf);
        printf("perform_pushpull_tests:      Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("perform_pushpull_tests: Oops! Failed reading cap2! err=%d\n", err);
  }

  //** Lastly Remove the allocations **
  set_ibp_remove_op(&op, get_ibp_cap(&caps1, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("perform_pushpull_tests: Oops! Error removing allocation 1!  ibp_errno=%d\n", err);
  }
  set_ibp_remove_op(&op, get_ibp_cap(&caps2, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("perform_pushpull_tests: Oops! Error removing allocation 2!  ibp_errno=%d\n", err);
  }

  if (start_nfailed == failed_tests) {
     printf("perform_pushpull_tests: Passed!\n");
  } else {
     printf("perform_pushpull_tests: Oops! FAILED!\n");
  }
}
示例#15
0
void simple_test()
{
  int size = 1024*1024;
  int block = 5000;
  char buffer[size+1];
  char buffer_cmp[size+1];
  char block_buf[block+1];
  ibp_attributes_t attr;
  ibp_depot_t *depot;
  ibp_capset_t caps;
  ibp_cap_t *cap;
  int err, i, offset, bcount, remainder;
  ibp_op_t *op;
  oplist_t *iol;

  //** Make the allocation ***
  depot = &(depot_list[0]);

  //** Create the list for handling the commands
  iol = new_ibp_oplist(NULL);
  oplist_start_execution(iol);  //** and start executing the commands

  //** Create the allocation used for test
  set_ibp_attributes(&attr, time(NULL) + a_duration, IBP_HARD, IBP_BYTEARRAY);
  op = new_ibp_alloc_op(&caps, size, depot, &attr, ibp_timeout, NULL, NULL);
  add_ibp_oplist(iol, op);
  err = oplist_waitall(iol);  
  if (err != IBP_OK) { 
     printf("simple_test: ibp_allocate error! * ibp_errno=%d\n", err); 
     abort();
  }
  
  printf("simple_test: rcap=%s\n", get_ibp_cap(&caps, IBP_READCAP));
  printf("simple_test: wcap=%s\n", get_ibp_cap(&caps, IBP_WRITECAP));
  printf("simple_test: mcap=%s\n", get_ibp_cap(&caps, IBP_MANAGECAP));

  //** Init the buffers
  buffer[size] = '\0'; memset(buffer, '*', size);
  buffer_cmp[size] = '\0'; memset(buffer_cmp, '_', size);
  block_buf[block] = '\0'; memset(block_buf, '0', block);

  //-------------------------------
  //** Do the initial upload
  op = new_ibp_write_op(get_ibp_cap(&caps, IBP_WRITECAP), 0, size, buffer_cmp, ibp_timeout, NULL, NULL);
  add_ibp_oplist(iol, op);
  err = oplist_waitall(iol);
  if (err != IBP_OK) {
     printf("simple_test: Initial ibp_write error! * ibp_errno=%d\n", err); 
     abort();
  }    

  bcount = size / (2*block);
  remainder = size - bcount * (2*block);

  //** Now do the striping **
  offset = 0;      // Now store the data in chunks
  cap = get_ibp_cap(&caps, IBP_WRITECAP);
  for (i=0; i<bcount; i++) {
     op = new_ibp_write_op(cap, offset, block, block_buf, ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);
   
     memset(&(buffer_cmp[offset]), '0', block);

     offset = offset + 2*block;
  }

  if (remainder>0)  {
     if (remainder > block) remainder = block;
     op = new_ibp_write_op(cap, offset, remainder, block_buf, ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);

     memset(&(buffer_cmp[offset]), '0', remainder);
  }

  //** Now wait for them to complete
  err = oplist_waitall(iol);
  if (err != IBP_OK) {
     printf("simple_test: Error in stripe write! * ibp_errno=%d\n", err); 
     abort();
  }

  //-------------------------------
  bcount = size / block;
  remainder = size - bcount * block;

  //** Generate the Read list
  offset = 0;      // Now store the data in chunks
  cap = get_ibp_cap(&caps, IBP_READCAP);
  for (i=0; i<bcount; i++) {
     op = new_ibp_read_op(cap, offset, block, &(buffer[offset]), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);

     offset = offset + block;
  }

  if (remainder>0)  {
     op = new_ibp_read_op(cap, offset, remainder, &(buffer[offset]), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);
  }

  //** Now wait for them to complete
  err = oplist_waitall(iol);
  if (err != IBP_OK) {
     printf("simple_test: Error in stripe read! * ibp_errno=%d\n", err); 
     abort();
  }

  //-------------------------------
  
  //** Do the comparison **
  i = strcmp(buffer, buffer_cmp);
  if (i == 0) {
     printf("simple_test: Success!\n");
  } else {
     printf("simple_test: Failed! strcmp = %d\n", i);
  }

//  printf("simple_test: buffer_cmp=%s\n", buffer_cmp);
//  printf("simple_test:     buffer=%s\n", buffer);


  //-------------------------------


  //** Remove the allocation **
  op = new_ibp_remove_op(get_ibp_cap(&caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  add_ibp_oplist(iol, op);
  err = oplist_waitall(iol);
  if (err != IBP_OK) { 
     printf("simple_test: Error removing the allocation!  ibp_errno=%d\n", err); 
     abort(); 
  } 

  free_oplist(iol);
}
示例#16
0
void base_async_test(int nthreads, ibp_depot_t *depot)
{
//  int size = 115;
//  int block = 10;
  int size = 10*1024*1024;
  int block = 5000;
//  char buffer[size+1];
//  char buffer_cmp[size+1];
  char *buffer, *buffer_cmp;
  char c;
  char block_buf[block+1];
  ibp_attributes_t attr;
  ibp_capset_t caps;
  ibp_cap_t *cap;
  int err, i, offset, bcount, remainder;
  ibp_op_t *op;
  oplist_t *iol;

  buffer = (char *)malloc(size+1);
  buffer_cmp = (char *)malloc(size+1);
  assert(buffer != NULL);
  assert(buffer_cmp != NULL);
  
  printf("base_async_test:  Starting simple test\n"); fflush(stdout);

  //** Create the list for handling the commands
  iol = new_ibp_oplist(NULL);
  oplist_start_execution(iol);  //** and start executing the commands

  //** Create the allocation used for test
  set_ibp_attributes(&attr, time(NULL) + A_DURATION, IBP_HARD, IBP_BYTEARRAY);
  op = new_ibp_alloc_op(&caps, size, depot, &attr, ibp_timeout, NULL, NULL);
  add_ibp_oplist(iol, op);
  err = oplist_waitall(iol);  
  if (err != IBP_OK) { 
     printf("base_async_test: ibp_allocate error! * ibp_errno=%d\n", err); 
     abort();
  }
  
  printf("base_async_test: rcap=%s\n", get_ibp_cap(&caps, IBP_READCAP));
  printf("base_async_test: wcap=%s\n", get_ibp_cap(&caps, IBP_WRITECAP));
  printf("base_async_test: mcap=%s\n", get_ibp_cap(&caps, IBP_MANAGECAP));

  //** Init the buffers
  buffer[size] = '\0'; memset(buffer, '*', size);
  buffer_cmp[size] = '\0'; memset(buffer_cmp, '_', size);
  block_buf[block] = '\0'; memset(block_buf, '0', block);

  //-------------------------------
  //** Do the initial upload
//  op = new_ibp_write_op(get_ibp_cap(&caps, IBP_WRITECAP), 0, size, buffer_cmp, ibp_timeout, NULL, NULL);
//  add_ibp_oplist(iol, op);
//  err = oplist_waitall(iol);
//  if (err != IBP_OK) {
//     printf("base_async_test: Initial ibp_write error! * ibp_errno=%d\n", err); 
//     abort();
//  }    

  bcount = size / (2*block);
  remainder = size - bcount * (2*block);

  //** Now do the striping **
  offset = (bcount-1)*(2*block);      // Now store the data in chunks
  cap = get_ibp_cap(&caps, IBP_WRITECAP);
  for (i=0; i<bcount; i++) {
     c = 'A' + (i%27);
     memset(&(buffer_cmp[offset]), c, 2*block);

     op = new_ibp_write_op(cap, offset, 2*block, &(buffer_cmp[offset]), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);
   
     offset = offset - 2*block;
  }

  if (remainder>0)  {
     offset = bcount*2*block;
     memset(&(buffer_cmp[offset]), '@', remainder);
     op = new_ibp_write_op(cap, offset, remainder, &(buffer_cmp[offset]), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);
  }

  //** Now wait for them to complete
  err = oplist_waitall(iol);
  if (err != IBP_OK) {
     printf("base_async_test: Error in stripe write! * ibp_errno=%d\n", err); 
     abort();
  }

  //-------------------------------
  bcount = size / block;
  remainder = size % block;

  //** Generate the Read list
  offset = 0;      // Now read the data in chunks
  cap = get_ibp_cap(&caps, IBP_READCAP);
  for (i=0; i<bcount; i++) {
     op = new_ibp_read_op(cap, offset, block, &(buffer[offset]), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);

     offset = offset + block;
  }

  if (remainder>0)  {
//printf("read remainder: rem=%d offset=%d\n", remainder, offset);
     op = new_ibp_read_op(cap, offset, remainder, &(buffer[offset]), ibp_timeout, NULL, NULL);
     add_ibp_oplist(iol, op);
  }

  //** Now wait for them to complete
  err = oplist_waitall(iol);
  if (err != IBP_OK) {
     printf("base_async_test: Error in stripe read! * ibp_errno=%d\n", err); 
     abort();
  }

  //-------------------------------
  
  //** Do the comparison **
  i = strcmp(buffer, buffer_cmp);
  if (i == 0) {
     printf("base_async_test: Success!\n");
  } else {
     failed_tests++;
     printf("base_async_test: Failed! strcmp = %d\n", i);
  }

//  printf("base_async_test: buffer_cmp=%s\n", buffer_cmp);
//  printf("base_async_test:     buffer=%s\n", buffer);
//  printf("base_async_test:block_buffer=%s\n", block_buf);


  //-------------------------------


  //** Remove the allocation **
  op = new_ibp_remove_op(get_ibp_cap(&caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  add_ibp_oplist(iol, op);
  err = oplist_waitall(iol);
  if (err != IBP_OK) { 
     printf("base_async_test: Error removing the allocation!  ibp_errno=%d\n", err); 
     abort(); 
  } 

//  free_oplist(iol);
  oplist_finished_submission(iol, OPLIST_AUTO_FREE);

  free(buffer);
  free(buffer_cmp);
}
示例#17
0
int main(int argc, char **argv)
{
  ibp_depotinfo_t *depotinfo;
  ibp_depot_t depot1, depot2;
  ibp_attributes_t attr;
  ibp_timer_t timer;
  ibp_capset_t *caps, *caps2, *caps4;
  ibp_capset_t caps3, caps5;
  ibp_capstatus_t astat;
  ibp_alias_capstatus_t alias_stat;
  int err, i, len, offset;
  int bufsize = 1024*1024;
  char wbuf[bufsize];
  char rbuf[bufsize];
  char *host1, *host2;
  int port1, port2;
  rid_t rid1, rid2;

  failed_tests = 0;

  if (argc < 6) {
     printf("ibp_test [-d loglevel] [-config ibp.cfg] host1 port1 rid1 host2 port2 rid2\n");
     printf("\n");
     printf("     2 depots are requred to test depot-depot copies.\n");
     printf("     Can use the same depot if necessary\n");
     printf("\n");
     printf("\n");
     return(-1);
  }

  ibp_init();  //** Initialize IBP


  //*** Read in the arguments ***    
  i = 1;
  if (strcmp(argv[i], "-d") == 0) {
     i++;
     set_log_level(atoi(argv[i]));
     i++;
  }

  if (strcmp(argv[i], "-config") == 0) { //** Read the config file
     i++;
     ibp_load_config(argv[i]);
     i++;
  }

  host1 = argv[i];  i++;
  port1 = atoi(argv[i]); i++;
  rid1 = ibp_str2rid(argv[i]); i++;  

  host2 = argv[i];  i++;
  port2 = atoi(argv[i]); i++;
  rid2 = ibp_str2rid(argv[i]); i++;  

  //*** Print the ibp client version ***
  printf("\n");
  printf("================== IBP Client Version =================\n");
  printf("%s\n", ibp_client_version());

  //*** Init the structures ***
  ibp_timeout = 5;
  set_ibp_depot(&depot1, host1, port1, rid1);
  set_ibp_depot(&depot2, host2, port2, rid2);
  set_ibp_attributes(&attr, time(NULL) + 60, IBP_HARD, IBP_BYTEARRAY); 
  set_ibp_timer(&timer, ibp_timeout, ibp_timeout);

//printf("Before allocate\n"); fflush(stdout);

  //*** Perform single allocation
  caps = IBP_allocate(&depot1, &timer, bufsize, &attr);

  if (caps == NULL) {
     printf("Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Read: %s\n", caps->readCap);
     printf("Write: %s\n", caps->writeCap);
     printf("Manage: %s\n", caps->manageCap);
  }  

  printf("ibp_manage(IBP_PROBE):-----------------------------------\n");
  memset(&astat, 0, sizeof(astat));
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("read count = %d\n", astat.readRefCount);
     printf("write count = %d\n", astat.writeRefCount);
     printf("current size = %d\n", astat.currentSize);
     printf("max size = %lu\n", astat.maxSize);
     printf("duration = %ld\n", astat.attrib.duration - time(NULL));
     printf("reliability = %d\n", astat.attrib.reliability);
     printf("type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }


  printf("ibp_manage(IBP_DECR for write cap):-----------------------------------\n");
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_DECR, IBP_WRITECAP, &astat);
  if (err != 0) { printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno); }
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("read count = %d\n", astat.readRefCount);
     printf("write count = %d\n", astat.writeRefCount);
     printf("current size = %d\n", astat.currentSize);
     printf("max size = %lu\n", astat.maxSize);
     printf("duration = %lu\n", astat.attrib.duration - time(NULL));
     printf("reliability = %d\n", astat.attrib.reliability);
     printf("type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }


  printf("ibp_manage(IBP_CHNG - incresing size to 2MB and changing duration to 20 sec):-----------------------------------\n");
  set_ibp_attributes(&(astat.attrib), time(NULL) + 20, IBP_HARD, IBP_BYTEARRAY);
  astat.maxSize = 2*1024*1024;
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_CHNG, 0, &astat);
  if (err != 0) { printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno); }
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("read count = %d\n", astat.readRefCount);
     printf("write count = %d\n", astat.writeRefCount);
     printf("current size = %d\n", astat.currentSize);
     printf("max size = %lu\n", astat.maxSize);
     printf("duration = %lu\n", astat.attrib.duration - time(NULL));
     printf("reliability = %d\n", astat.attrib.reliability);
     printf("type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  //**** Basic Write tests ****
  printf("write tests..................................\n");
  for (i=0; i<bufsize; i++) wbuf[i] = '0';
  len = 3*bufsize/4;
  err = IBP_store(get_ibp_cap(caps, IBP_WRITECAP), &timer, wbuf, len);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_store1! wrote=%d err=%d\n", err, IBP_errno);
  }    

  len = bufsize - len;
  err = IBP_store(get_ibp_cap(caps, IBP_WRITECAP), &timer, wbuf, len);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_store2! wrote=%d err=%d\n", err, IBP_errno);
  }    

  for (i=0; i<bufsize; i++) wbuf[i] = '1';
  len = bufsize/2;
  offset = 10;
  err = IBP_write(get_ibp_cap(caps, IBP_WRITECAP), &timer, wbuf, len, offset);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_Write! wrote=%d err=%d\n", err, IBP_errno);
  }    


  printf("ibp_load test...............................\n");
  len = bufsize;
  offset = 0;
  err = IBP_load(get_ibp_cap(caps, IBP_READCAP), &timer, rbuf, len, offset);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_load! wrote=%d err=%d\n", err, IBP_errno);
  } else {
    rbuf[50] = '\0';
    printf("rbuf=%s\n", rbuf);
  }

  printf("ibp_copy test................................\n");
  //*** Perform single allocation
  caps2 = IBP_allocate(&depot2, &timer, bufsize, &attr);
  if (caps2 == NULL) {
     failed_tests++;
     printf("Error with allocation of dest cap!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("dest Read: %s\n", caps2->readCap);
     printf("dest Write: %s\n", caps2->writeCap);
     printf("dest Manage: %s\n", caps2->manageCap);
  }  
  err = IBP_copy(get_ibp_cap(caps, IBP_READCAP), get_ibp_cap(caps2, IBP_WRITECAP), &timer, &timer, 1024, 0);
  if (err != 1024) { failed_tests++; printf("ibp_copy size = %d * ibp_errno=%d\n", err, IBP_errno); }

  printf("ibp_phoebus_copy test................................\n");
  //*** Perform single allocation
  caps4 = IBP_allocate(&depot2, &timer, bufsize, &attr);
  if (caps4 == NULL) {
     printf("Error with allocation of dest cap!!!! ibp_errno = %d\n", IBP_errno);
     failed_tests++;
     return(1);
  } else {
     printf("dest Read: %s\n", caps4->readCap);
     printf("dest Write: %s\n", caps4->writeCap);
     printf("dest Manage: %s\n", caps4->manageCap);
  }  
  err = IBP_phoebus_copy(NULL, get_ibp_cap(caps, IBP_READCAP), get_ibp_cap(caps4, IBP_WRITECAP), &timer, &timer, 1024, 0);
  if (err != 1024) { failed_tests++; printf("ibp_copy size = %d * ibp_errno=%d\n", err, IBP_errno); }

  //** Remove the cap
  err = IBP_manage(get_ibp_cap(caps4, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting phoebus dest cap error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }
  destroy_ibp_capset(caps4); caps4 = NULL;

  printf("ibp_manage(IBP_DECR):-Removing allocations----------------------------------\n");
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { failed_tests++; printf("ibp_manage(decr) for caps1 error = %d * ibp_errno=%d\n", err, IBP_errno); }
  err = IBP_manage(get_ibp_cap(caps2, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { failed_tests++; printf("ibp_manage(decr) for caps2 error = %d * ibp_errno=%d\n", err, IBP_errno); }

  printf("ibp_status: IBP_ST_INQ--------------------------------------------------------\n");
  depotinfo = IBP_status(&depot1, IBP_ST_INQ, &timer, "ibp", 10,11,12);
  if (depotinfo != NULL) {
     printf("rid=%d * duration=%ld\n", depotinfo->rid, depotinfo->Duration);
     printf("hc=" LL " hs=" LL " ha=" LL "\n",depotinfo->HardConfigured, depotinfo->HardServed, depotinfo->HardAllocable);
     printf("tc=" LL " ts=" LL " tu=" LL "\n", depotinfo->TotalConfigured, depotinfo->TotalServed, depotinfo->TotalUsed);
  } else {
     failed_tests++;
     printf("ibp_status error=%d\n", IBP_errno);
  }

  //** Perform some basic async R/W alloc/remove tests
  base_async_test(2, &depot1);

  //** Now do a few of the extra tests for async only
  ibp_op_t op;

  //*** Print the depot version ***
  set_ibp_version_op(&op, &depot1, rbuf, sizeof(rbuf), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     printf("Printing depot version information......................................\n");
     printf("%s\n", rbuf);
  } else {
     failed_tests++;
     printf("Error getting ibp_version. err=%d\n", err);
  }
  
  //*** Query the depot resources ***
  ibp_ridlist_t rlist;
  set_ibp_query_resources_op(&op, &depot1, &rlist, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     printf("Number of resources: %d\n", ridlist_get_size(&rlist));
     for (i=0; i<ridlist_get_size(&rlist); i++) {
        printf("  %d: %s\n", i, ibp_rid2str(ridlist_get_element(&rlist, i), rbuf));
     }
  } else {
     failed_tests++;
     printf("Error querying depot resource list. err=%d\n", err);
  }  

  perform_user_rw_tests(&depot1);  //** Perform the "user" version of the R/W functions

  //-----------------------------------------------------------------------------------------------------
  //** check ibp_rename ****

  printf("Testing IBP_RENAME...............................................\n");
  caps = IBP_allocate(&depot1, &timer, bufsize, &attr);
  if (caps == NULL) {
     failed_tests++;
     printf("Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Original Cap..............\n");
     printf("Read: %s\n", caps->readCap);
     printf("Write: %s\n", caps->writeCap);
     printf("Manage: %s\n", caps->manageCap);
  }  

  //** Upload the data
  char *data = "This is a test....";
  len = strlen(data)+1;
  err = IBP_store(get_ibp_cap(caps, IBP_WRITECAP), &timer, data, len);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_store1! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Rename the allocation
  set_ibp_rename_op(&op, caps2, get_ibp_cap(caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_rename. err=%d\n", err);
  } else {
     printf("Renamed Cap..............\n");
     printf("Read: %s\n", caps2->readCap);
     printf("Write: %s\n", caps2->writeCap);
     printf("Manage: %s\n", caps2->manageCap);
  }  
  
  //** Try reading the original which should fail
  rbuf[0] = '\0';
  err = IBP_load(get_ibp_cap(caps, IBP_READCAP), &timer, rbuf, len, 0);
  if (err != len) {
     printf("Can't read the original cap after the rename which is good!  Got err err=%d\n", err);
  } else {
     failed_tests++;
    printf("Oops!  The read of the original cap succeeded! rbuf=%s\n", rbuf);
  }

  //** Try reading with the new cap
  rbuf[0] = '\0';
  err = IBP_load(get_ibp_cap(caps2, IBP_READCAP), &timer, rbuf, len, 0);
  if (err == len) {
     if (strcmp(rbuf, data) == 0) {
        printf("Read using the new cap the original data!\n");
     } else {
        failed_tests++;
        printf("Read some data with the new cap but it wasn't correct!\n");
        printf("Original=%s\n", data);
        printf("     Got=%s\n", wbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading with new cap! err=%d\n", err);
  }

  //** Remove the cap
  err = IBP_manage(get_ibp_cap(caps2, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting new cap after rename caps2 error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }
  printf("Completed ibp_rename test...........................\n");

  //-----------------------------------------------------------------------------------------------------
  //** check ibp_alias_allocate/manage ****

//**** GOOD
  printf("Testing IBP_alias_ALLOCATE/MANAGE...............................................\n");
  caps = IBP_allocate(&depot1, &timer, bufsize, &attr);
  if (caps == NULL) {
     failed_tests++;
     printf("Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Original Cap..............\n");
     printf("Read: %s\n", caps->readCap);
     printf("Write: %s\n", caps->writeCap);
     printf("Manage: %s\n", caps->manageCap);
  }  

  set_ibp_alias_alloc_op(&op, caps2, get_ibp_cap(caps, IBP_MANAGECAP), 0, 0, 0, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_alloc. err=%d\n", err);
  } else {
     printf("Alias Cap..............\n");
     printf("Read: %s\n", caps2->readCap);
     printf("Write: %s\n", caps2->writeCap);
     printf("Manage: %s\n", caps2->manageCap);
  }  


  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("Actual cap info\n");
     printf(" read count = %d\n", astat.readRefCount);
     printf(" write count = %d\n", astat.writeRefCount);
     printf(" current size = %d\n", astat.currentSize);
     printf(" max size = %lu\n", astat.maxSize);
     printf(" duration = %lu\n", astat.attrib.duration - time(NULL));
     printf(" reliability = %d\n", astat.attrib.reliability);
     printf(" type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  err = IBP_manage(get_ibp_cap(caps2, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("Using alias to get actual cap info\n");
     printf(" read count = %d\n", astat.readRefCount);
     printf(" write count = %d\n", astat.writeRefCount);
     printf(" current size = %d\n", astat.currentSize);
     printf(" max size = %lu\n", astat.maxSize);
     printf(" duration = %lu\n", astat.attrib.duration - time(NULL));
     printf(" reliability = %d\n", astat.attrib.reliability);
     printf(" type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  set_ibp_alias_probe_op(&op, get_ibp_cap(caps2, IBP_MANAGECAP), &alias_stat, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_probe. err=%d\n", err);
  } else {
     printf("Alias stat..............\n");
     printf(" read count = %d\n", alias_stat.read_refcount);
     printf(" write count = %d\n", alias_stat.write_refcount);
     printf(" offset = " ST "\n", alias_stat.offset);
     printf(" size = " ST "\n", alias_stat.size);
     printf(" duration = %lu\n", alias_stat.duration - time(NULL));
  }

  set_ibp_alias_alloc_op(&op, &caps3, get_ibp_cap(caps, IBP_MANAGECAP), 10, 40, 0, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_alloc_op. err=%d\n", err);
  } else {
     printf("Alias Cap with range 10-50.............\n");
     printf("Read: %s\n", caps3.readCap);
     printf("Write: %s\n", caps3.writeCap);
     printf("Manage: %s\n", caps3.manageCap);
  }  

  err = IBP_manage(get_ibp_cap(&caps3, IBP_MANAGECAP), &timer, IBP_PROBE, 0, &astat);
  if (err == 0) {
     printf("Using limited alias to get actual cap info\n");
     printf(" read count = %d\n", astat.readRefCount);
     printf(" write count = %d\n", astat.writeRefCount);
     printf(" current size = %d\n", astat.currentSize);
     printf(" max size = %lu *** This should be 40\n", astat.maxSize);
     printf(" duration = %lu\n", astat.attrib.duration - time(NULL));
     printf(" reliability = %d\n", astat.attrib.reliability);
     printf(" type = %d\n", astat.attrib.type);
  } else {
     failed_tests++;
     printf("ibp_manage error = %d * ibp_errno=%d\n", err, IBP_errno);
  }

  printf("*append* using the full alias..................................\n");
  for (i=0; i<bufsize; i++) wbuf[i] = '0';
  err = IBP_store(get_ibp_cap(caps2, IBP_WRITECAP), &timer, wbuf, bufsize);
  if (err != bufsize) {
     failed_tests++;
     printf("Error with IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  printf("write using the limited alias..................................\n");  
  data = "This is a test.";
  len = strlen(data)+1;
  err = IBP_write(get_ibp_cap(&caps3, IBP_WRITECAP), &timer, data, len, 0);
  if (err != len) {
     failed_tests++;
     printf("Error with IBP_Write! wrote=%d err=%d\n", err, IBP_errno);
  }    

  memcpy(&(wbuf[10]), data, strlen(data)+1);
  len = 10 + strlen(data)+1;
  err = IBP_load(get_ibp_cap(caps2, IBP_READCAP), &timer, rbuf, len, 0);
  if (err == len) {
     if (strcmp(rbuf, wbuf) == 0) {
        printf("Read using the new full alias the original data!\n");
        printf("  read=%s\n", rbuf);       
     } else {
        failed_tests++;
        printf("Read some data with the new cap but it wasn't correct!\n");
        printf("Original=%s\n", wbuf);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading with new cap! err=%d\n", err);
  }


  //** Try to R/W beyond the end of the limited cap **
  printf("attempting to R/W beyond the end of the limited alias......\n");
  data = "This is a test.";
  len = strlen(data)+1;
  err = IBP_write(get_ibp_cap(&caps3, IBP_WRITECAP), &timer, data, len, 35);
  if (err != len) {
     printf("Correctly got an IBP_Write error! wrote=%d err=%d\n", err, IBP_errno);
  } else {
     failed_tests++;
     printf("Oops! Was able to write beyond the end of the limited cap with new cap!\n");
  }

  err = IBP_load(get_ibp_cap(&caps3, IBP_READCAP), &timer, rbuf, len, 35);
  if (err != len) {
     printf("Correctly got an IBP_read error! wrote=%d err=%d\n", err, IBP_errno);
  } else {
     failed_tests++;
     printf("Oops! Was able to read beyond the end of the limited cap with new cap!\n");
  }

  //** Perform a alias->alias copy.  The src alias is restricted
  printf("Testing restricted alias->full alias depot-depot copy\n");
  caps4 = IBP_allocate(&depot1, &timer, bufsize, &attr);
  if (caps == NULL) {
     failed_tests++;
     printf("alias-alias allocate Error!!!! ibp_errno = %d\n", IBP_errno);
     return(1);
  } else {
     printf("Depot-Depot copy OriginalDestiniation Cap..............\n");
     printf("Read: %s\n", caps4->readCap);
     printf("Write: %s\n", caps4->writeCap);
     printf("Manage: %s\n", caps4->manageCap);
  }  

  set_ibp_alias_alloc_op(&op, &caps5, get_ibp_cap(caps4, IBP_MANAGECAP), 0, 0, 0, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error with ibp_alias_alloc_op. err=%d\n", err);
  } else {
     printf("Destination Alias Cap with full range.............\n");
     printf("Read: %s\n", caps5.readCap);
     printf("Write: %s\n", caps5.writeCap);
     printf("Manage: %s\n", caps5.manageCap);
  }  

//BAD!!!!!!!!!!!
  //** Perform the copy
  data = "This is a test.";
  len = strlen(data)+1;
  err = IBP_copy(get_ibp_cap(&caps3, IBP_READCAP), get_ibp_cap(&caps5, IBP_WRITECAP), &timer, &timer, len, 0);
  if (err != len) { printf("ibp_copy size = %d * ibp_errno=%d\n", err, IBP_errno); }

  //** Load it back and verify **
  err = IBP_load(get_ibp_cap(&caps5, IBP_READCAP), &timer, rbuf, len, 0);
  if (err == len) {
     if (strcmp(rbuf, data) == 0) {
        printf("Read using the new full alias the original data!\n");
        printf("  read=%s\n", rbuf);       
     } else {
        failed_tests++;
        printf("Read some data with the new cap but it wasn't correct!\n");
        printf("Original=%s\n", data);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading with new cap! err=%d\n", err);
  }

  //** Remove the cap5 (full alias)
  set_ibp_alias_remove_op(&op, get_ibp_cap(&caps5, IBP_MANAGECAP), get_ibp_cap(caps4, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error dest deleting alias cap error = %d\n", err); 
  }

  //** Remove the dest cap
  err = IBP_manage(get_ibp_cap(caps4, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting dest caps error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }

  printf("completed alias depot->depot copy test\n");

  //** Try to remove the cap2 (full alias) with a bad cap
  set_ibp_alias_remove_op(&op, get_ibp_cap(caps2, IBP_MANAGECAP), get_ibp_cap(&caps3, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("Correctly detected error deleting alias cap with an invalid master cap error = %d\n", err); 
  } else {
     failed_tests++;
     printf("Oops! Was able to delete the alias with an invalid master cap!!!!!!!!\n");
  }

  //** Remove the cap2 (full alias)
  set_ibp_alias_remove_op(&op, get_ibp_cap(caps2, IBP_MANAGECAP), get_ibp_cap(caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error deleting alias cap error = %d\n", err); 
  }

  printf("Try to read the deleted full falias.  This should generate an error\n");
  err = IBP_load(get_ibp_cap(caps2, IBP_READCAP), &timer, rbuf, len, 35);
  if (err != len) {
     printf("Correctly got an IBP_read error! wrote=%d err=%d\n", err, IBP_errno);
  } else {
     failed_tests++;
     printf("Oops! Was able to write beyond the end of the limited cap with new cap!\n");
  }

  //** Remove the limited alias (cap3)
  set_ibp_alias_remove_op(&op, get_ibp_cap(&caps3, IBP_MANAGECAP), get_ibp_cap(caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("Error deleting the limited alias cap  error = %d\n", err); 
  }

  //** Remove the original cap
  err = IBP_manage(get_ibp_cap(caps, IBP_MANAGECAP), &timer, IBP_DECR, IBP_READCAP, &astat);
  if (err != 0) { 
     failed_tests++;
     printf("Error deleting original caps error = %d * ibp_errno=%d\n", err, IBP_errno); 
  }

//GOOD!!!!!!!!!!!!!!!!!!!!

  printf("finished testing IBP_alias_ALLOCATE/MANAGE...............................................\n");

  perform_splitmerge_tests(&depot1);
  perform_pushpull_tests(&depot1, &depot2);

  printf("\n\n");
  printf("Final network connection counter: %d\n", network_counter(NULL));
  printf("Tests that failed: %d\n", failed_tests);

  ibp_finalize();

  return(0);
}
示例#18
0
double write_allocs(ibp_capset_t *caps, int qlen, int n, int asize, int block_size)
{
    int count, i, j, nleft, nblocks, rem, len, err, block_start, alloc_start;
    int *slot;
    op_status_t status;
    int64_t nbytes, last_bytes, print_bytes, delta_bytes;
    apr_int32_t nfds, finished;
    double dbytes, r1, r2;
    apr_pool_t *pool;
    apr_file_t *fd_in;
    opque_t *q;
    op_generic_t *op;
    char *buffer = (char *)malloc(block_size);
    apr_interval_time_t dt = 10;
    apr_pollfd_t pfd;
    apr_time_t stime, dtime;
    int *tbuf_index;
    tbuffer_t *buf;
    Stack_t *tbuf_free;


    tbuf_free = new_stack();
    type_malloc_clear(tbuf_index, int, qlen);
    type_malloc_clear(buf, tbuffer_t, qlen);
    for (i=0; i<qlen; i++) {
        tbuf_index[i] = i;
        push(tbuf_free, &(tbuf_index[i]));
    }

    //** Make the stuff to capture the kbd
    apr_pool_create(&pool, NULL);

    nfds = 1;
    apr_file_open_stdin(&fd_in, pool);

    pfd.p = pool;
    pfd.desc_type = APR_POLL_FILE;
    pfd.reqevents = APR_POLLIN|APR_POLLHUP;
    pfd.desc.f = fd_in;
    pfd.client_data = NULL;


    //** Init the ibp stuff
    init_buffer(buffer, 'W', block_size);
    q = new_opque();
    opque_start_execution(q);

    nblocks = asize / block_size;
    rem = asize % block_size;
    if (rem > 0) nblocks++;
    block_start = 0;
    alloc_start = 0;

    finished = 0;
    apr_poll(&pfd, nfds, &finished, dt);
    count = 0;
    nbytes=0;
    last_bytes = 0;
    delta_bytes = 1024 * 1024 * 1024;
    print_bytes = delta_bytes;
    stime = apr_time_now();

    while (finished == 0) {
//    nleft = qlen - opque_tasks_left(q);
        nleft = stack_size(tbuf_free);
//    printf("\nLOOP: nleft=%d qlen=%d\n", nleft, qlen);
        if (nleft > 0) {
            for (j=block_start; j < nblocks; j++) {
                for (i=alloc_start; i<n; i++) {
                    nleft--;
                    if (nleft <= 0) {
                        block_start = j;
                        alloc_start = i;
                        goto skip_submit;
                    }

                    slot = (int *)pop(tbuf_free);

                    if ((j==(nblocks-1)) && (rem > 0)) {
                        len = rem;
                    } else {
                        len = block_size;
                    }
//             printf("%d=(%d,%d) ", count, j, i);

                    tbuffer_single(&(buf[*slot]), len, buffer);
                    op = new_ibp_write_op(ic, get_ibp_cap(&(caps[i]), IBP_WRITECAP), j*block_size, &(buf[*slot]), 0, len, ibp_timeout);
                    gop_set_id(op, *slot);
                    ibp_op_set_cc(ibp_get_iop(op), cc);
                    ibp_op_set_ncs(ibp_get_iop(op), ncs);
                    opque_add(q, op);
                }

                alloc_start = 0;
            }

            block_start = 0;
        }

skip_submit:
        finished = 1;
        apr_poll(&pfd, nfds, &finished, dt);

        do {  //** Empty the finished queue.  Always wait for for at least 1 to complete
            op = opque_waitany(q);
            status = gop_get_status(op);
            if (status.error_code != IBP_OK) {
                printf("ERROR: Aborting with error code %d\n", status.error_code);
                finished = 0;
            }

            count++;
            i = gop_get_id(op);
            nbytes = nbytes + tbuffer_size(&(buf[i]));
            if (nbytes > print_bytes) {
                dbytes = nbytes / (1.0*1024*1024*1024);
                dtime = apr_time_now() - stime;
                r2 = dtime / (1.0 * APR_USEC_PER_SEC);
                r1 = nbytes - last_bytes;
                r1 = r1 / (r2 * 1024.0 * 1024.0);
                printf("%.2lfGB written (%.2lfMB/s : %.2lf secs)\n", dbytes, r1, r2);
                print_bytes = print_bytes + delta_bytes;
                last_bytes = nbytes;
                stime = apr_time_now();
            }

            push(tbuf_free, &(tbuf_index[i]));
            gop_free(op, OP_DESTROY);
        } while (opque_tasks_finished(q) > 0);
    }

    err = opque_waitall(q);
    if (err != OP_STATE_SUCCESS) {
        printf("write_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, opque_tasks_failed(q));
    }
    opque_free(q, OP_DESTROY);

    free_stack(tbuf_free, 0);
    free(tbuf_index);
    free(buf);
    free(buffer);

    apr_pool_destroy(pool);

    dbytes = nbytes;
    return(dbytes);
}
示例#19
0
void perform_splitmerge_tests(ibp_depot_t *depot)
{
  int bufsize = 2048;
  char wbuf[bufsize+1], rbuf[bufsize+1];
  ibp_op_t op;
  ibp_attributes_t attr;
  ibp_capset_t mcaps, caps, caps2;
  ibp_capstatus_t probe;
  int nbytes, err, max_size, curr_size, dummy;
  ibp_timer_t timer;

  printf("perform_splitmerge_tests:  Starting tests!\n");

  set_ibp_timer(&timer, ibp_timeout, ibp_timeout);

  //** Initialize the buffers **
  memset(wbuf, '0', sizeof(wbuf));  wbuf[1023]='1'; wbuf[1024]='2'; wbuf[bufsize] = '\0';
  memset(rbuf, 0, sizeof(rbuf));
  nbytes = 1024;

  //*** Make the allocation used in the tests ***
  set_ibp_attributes(&attr, time(NULL) + A_DURATION, IBP_HARD, IBP_BYTEARRAY);
  set_ibp_alloc_op(&op, &mcaps, bufsize, depot, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error creating initial allocation for tests!! error=%d\n", err);
     return;
  }

  //** Fill the master with data **
  err = IBP_store(get_ibp_cap(&mcaps, IBP_WRITECAP), &timer, wbuf, bufsize);
  if (err != bufsize) {
     failed_tests++;
     printf("perform_splitmerge_tests: Error with master IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Split the allocation
  set_ibp_split_alloc_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &caps, 1024, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error creating child allocation for tests!! error=%d\n", err);
     return;
  }
  
  //** Check the new size of the master
  set_ibp_probe_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error probing master allocation for tests!! error=%d\n", err);
     return;
  }

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr);
  if ((curr_size != 1024) && (max_size != 1024)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size!! curr_size=%d * max_size=%d should both be 1024\n", curr_size, max_size);
     return;
  }   

  //** Check the size of the child allocation
  set_ibp_probe_op(&op, get_ibp_cap(&caps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error probing child allocation for tests!! error=%d\n", err);
     return;
  }

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr); 
  if ((curr_size != 0) && (max_size != 1024)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size!! curr_size=%d * max_size=%d should be 0 and 1024\n", curr_size, max_size);
     return;
  }   

  //** Verify the master data
  wbuf[1024] = '\0';
  err = IBP_load(get_ibp_cap(&mcaps, IBP_READCAP), &timer, rbuf, 1024, 0);
  if (err == 1024) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("Read some data with the mastercap but it wasn't correct!\n");
        printf("Original=%s\n", wbuf);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading master cap! err=%d\n", err);
  }

  //** Load data into the child
  err = IBP_store(get_ibp_cap(&caps, IBP_WRITECAP), &timer, wbuf, 1024);
  if (err != 1024) {
     failed_tests++;
     printf("perform_splitmerge_tests: Error with child IBP_store! wrote=%d err=%d\n", err, IBP_errno);
  }    

  //** Read it back
  memset(rbuf, 0, sizeof(rbuf));
  err = IBP_load(get_ibp_cap(&caps, IBP_READCAP), &timer, rbuf, 1024, 0);
  if (err == 1024) {
     if (strcmp(rbuf, wbuf) != 0) {
        failed_tests++;
        printf("Read some data with the childcap but it wasn't correct!\n");
        printf("Original=%s\n", wbuf);
        printf("     Got=%s\n", rbuf);
     }
  } else {
     failed_tests++;
     printf("Oops! Failed reading child cap! err=%d\n", err);
  }

  //** Split the master again but htis time make it to big so it should fail
  set_ibp_split_alloc_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &caps2, 2048, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error created child allocation when I shouldn't have! error=%d\n", err);
     return;
  }

  //** Check the size of the master to make sure it didn't change
  set_ibp_probe_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error probing master allocation2 for tests!! error=%d\n", err);
     return;
  }

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr);
  if ((curr_size != 1024) && (max_size != 1024)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size2!! curr_size=%d * max_size=%d should both be 1024\n", curr_size, max_size);
     return;
  }   

//GOOD!!!!!!!!!!!!!!!!!

  //** Merge the 2 allocations
  set_ibp_merge_alloc_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), get_ibp_cap(&caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with merge! error=%d\n", err);
     return;
  }

  //** Verify the child is gone
  set_ibp_probe_op(&op, get_ibp_cap(&caps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err == IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Oops!  Child allocation is available after merge! ccap=%s\n", get_ibp_cap(&caps, IBP_MANAGECAP));
     return;
  }


  //** Verify the max/curr size of the master
  set_ibp_probe_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), &probe, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with probe of mcapafter mergs! ccap=%s err=%d\n", get_ibp_cap(&mcaps, IBP_MANAGECAP), err);
     return;
  }

//GOOD!!!!!!!!!!!!!!!!!

  get_ibp_capstatus(&probe, &dummy, &dummy, &curr_size, &max_size, &attr);
  if ((curr_size != 1024) && (max_size != 2048)) {
     failed_tests++;
     printf("perform_splitmerge_tests:  Error with master allocation size after merge!! curr_size=%d * max_size=%d should both 1024 and 2048\n", curr_size, max_size);
     return;
  }   

  //** Lastly Remove the master allocation **
  set_ibp_remove_op(&op, get_ibp_cap(&mcaps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     printf("perform_splitmerge_tests: Error removing master allocation!  ibp_errno=%d\n", err);
  }

  printf("perform_splitmerge_tests:  Passed!\n");
}
示例#20
0
void perform_user_rw_tests(ibp_depot_t *depot)
{
  int bufsize = 1024*1024;
//  int bufsize = 100;
  char buffer[bufsize], rbuf[bufsize];
  ibp_op_t op;
  ibp_attributes_t attr;
  ibp_capset_t caps;
  rw_arg_t rw_arg;
  int err, i, b, nbytes, size;

  //** Fill the buffer **
  memset(rbuf, 0, bufsize);
  nbytes = 1024;
  for (i=0; i<bufsize; i=i+nbytes) {
     size = nbytes;
     if ((i+nbytes) >= bufsize) size = bufsize - i;
     b = i % 27;
     b = b + 'A';
     memset(&(buffer[i]), b, size);
  }  
  buffer[bufsize-1] = '\0';

  //*** Make the allocation used in the tests ***
  set_ibp_attributes(&attr, time(NULL) + A_DURATION, IBP_HARD, IBP_BYTEARRAY);
  set_ibp_alloc_op(&op, &caps, bufsize, depot, &attr, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) {
     failed_tests++;
     printf("perform_user_rw_tests:  Error creating initial allocation for tests!! error=%d\n", err);
     return;
  }

  //** Perform the upload **
  rw_arg.buffer = buffer;
  rw_arg.size = bufsize;
  rw_arg.pos = 0;
  rw_arg.nbytes = nbytes + 1;
  set_ibp_user_write_op(&op, get_ibp_cap(&caps, IBP_WRITECAP), 0, bufsize, my_next_block, (void *)&rw_arg, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) { 
     failed_tests++;
     printf("perform_user_rw_tests: Error during upload!  ibp_errno=%d\n", err); 
     return;
  } 

  //** Now download it with a different block size **
  rw_arg.buffer = rbuf;
  rw_arg.size = bufsize;
  rw_arg.pos = 0;
  rw_arg.nbytes = nbytes -1;
  set_ibp_user_read_op(&op, get_ibp_cap(&caps, IBP_READCAP), 0, bufsize, my_next_block, (void *)&rw_arg, ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) { 
     failed_tests++;
     printf("perform_user_rw_tests: Error during upload!  ibp_errno=%d\n", err); 
     return;
  } 

  //** Check to see if they are the same ***
  if (strcmp(buffer, rbuf) == 0) {
     printf("perform_user_rw_tests: Success!\n");
  } else {
     failed_tests++;
     printf("perform_user_rw_tests: Failed!!!!!  buffers differ!\n");
     printf("perform_user_rw_tests: wbuf=%50s\n", buffer); 
     printf("perform_user_rw_tests: rbuf=%50s\n", rbuf); 
  }
  
  //** Remove the allocation **
  set_ibp_remove_op(&op, get_ibp_cap(&caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL);
  err = ibp_sync_command(&op);
  if (err != IBP_OK) { 
     printf("perform_user_rw_tests: Error removing the allocation!  ibp_errno=%d\n", err); 
     abort(); 
  } 

}