Ejemplo n.º 1
0
static void testSuccess1(void)
{
    CU_ASSERT(1);
}
Ejemplo n.º 2
0
void TEST_COPY_OBJECT_WITH_BLANK_DST_BUCKET_NAME() {
    int error;
    buffer* resp = NULL;

    const char* src_obj_key = "unit_test_dir/src_object1";
    const char* filename = "./lib/libcunit.a";

    // upload first
    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = upload_file_object(host, src_bucket, src_obj_key, filename,
            ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    buffer_free(resp);

    // copy obj 
    const char* dst_bucket = NULL;
    const char* dst_obj_key = src_obj_key;
    resp = copy_object(host, src_bucket, src_obj_key,
            dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(405 == resp->status_code);
    if (405 != resp->status_code) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // delete dst obj
    resp = delete_object(host, dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(405 == resp->status_code);
    if (resp->status_code != 405) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // delete dst bucket
    resp = delete_bucket(host, dst_bucket, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(405 == resp->status_code);
    if (resp->status_code != 405) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // delete src obj
    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);
}
Ejemplo n.º 3
0
void test_nghttp2_nv_array_copy(void)
{
  nghttp2_nv *nva;
  ssize_t rv;
  nghttp2_nv emptynv[] = {MAKE_NV("", ""),
                          MAKE_NV("", "")};
  nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"),
                     MAKE_NV("charlie", "delta")};
  nghttp2_nv bignv;

  bignv.name = (uint8_t*)"echo";
  bignv.namelen = strlen("echo");
  bignv.valuelen = (1 << 14) - 1;
  bignv.value = malloc(bignv.valuelen);
  memset(bignv.value, '0', bignv.valuelen);

  rv = nghttp2_nv_array_copy(&nva, NULL, 0);
  CU_ASSERT(0 == rv);
  CU_ASSERT(NULL == nva);

  rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv));
  CU_ASSERT(0 == rv);
  CU_ASSERT(nva[0].namelen == 0);
  CU_ASSERT(nva[0].valuelen == 0);
  CU_ASSERT(nva[1].namelen == 0);
  CU_ASSERT(nva[1].valuelen == 0);

  nghttp2_nv_array_del(nva);

  rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
  CU_ASSERT(0 == rv);
  CU_ASSERT(nva[0].namelen == 5);
  CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
  CU_ASSERT(nva[0].valuelen = 5);
  CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
  CU_ASSERT(nva[1].namelen == 7);
  CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
  CU_ASSERT(nva[1].valuelen == 5);
  CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));

  nghttp2_nv_array_del(nva);

  /* Large header field is acceptable */
  rv = nghttp2_nv_array_copy(&nva, &bignv, 1);
  CU_ASSERT(0 == rv);

  nghttp2_nv_array_del(nva);

  free(bignv.value);
}
Ejemplo n.º 4
0
static void reset_sw(of_version_t version){
	CU_ASSERT(__of1x_destroy_switch(sw) == ROFL_SUCCESS);
	sw = of1x_init_switch("Test switch", version, 0x0101,4,ma_list);
	CU_ASSERT(sw != NULL);
}
Ejemplo n.º 5
0
void TEST_COPY_OBJECT_WITH_DIFF_BUCKET_AND_EXIST_KEY() {
    int error;
    buffer* resp = NULL;

    // upload first
    const char* src_obj_key = "unit_test_dir/src_object1";
    const char* filename = "./lib/libcunit.a";

    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = upload_file_object(host, src_bucket, src_obj_key, filename,
            ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (resp->status_code != 200) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // copy obj first time
    const char* dst_obj_key = "unit-test-dir/dst_obj1";

    resp = delete_object(host, dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = copy_object(host, src_bucket, src_obj_key,
            dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (200 != resp->status_code) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // copy obj second time
    resp = copy_object(host, src_bucket, src_obj_key,
            dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(400 == resp->status_code);
    if (400 != resp->status_code) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    // delete dst obj
    resp = delete_object(host, dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);

    // delete src obj
    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);
}
Ejemplo n.º 6
0
/* Veiller à tester pb_sommet avant pb_valeurk ! */
void test_pb_valeurk(void)
{
    int i, j;

    for (i = 1; i <= TAILLE_PILEB; i++)
        CU_ASSERT(pb_valeurk(premplief, i) == FAUX);
    CU_ASSERT(pb_valeurk(premplief, 1) == pb_sommet(premplief));

    for (j = 1; j <= TAILLE_PILEB; j++)
        CU_ASSERT(pb_valeurk(prempliev, j) == VRAI);
    CU_ASSERT(pb_valeurk(prempliev, 1) == pb_sommet(prempliev));

    CU_ASSERT(pb_valeurk(pvrai, 1) == VRAI);
    CU_ASSERT(pb_valeurk(pvrai, 1) == pb_sommet(pvrai));
    
    CU_ASSERT(pb_valeurk(pfaux, 1) == FAUX);
    CU_ASSERT(pb_valeurk(pfaux, 1) == pb_sommet(pfaux));

    CU_ASSERT(pb_valeurk(ph4, 1) == FAUX);
    CU_ASSERT(pb_valeurk(ph4, 2) == VRAI);
    CU_ASSERT(pb_valeurk(ph4, 3) == FAUX);
    CU_ASSERT(pb_valeurk(ph4, 4) == VRAI);
    CU_ASSERT(pb_valeurk(ph4, 1) == pb_sommet(ph4));
}
Ejemplo n.º 7
0
void test_pb_remplacer(void)
{
    PileB pbv = pb_remplacer(pb_empiler(pb_pilenouv(), VRAI), FAUX);
    PileB pbf = pb_remplacer(pb_empiler(pb_pilenouv(), FAUX), VRAI);
    PileB pbvv = pb_remplacer(pb_empiler(pb_empiler(pb_pilenouv(), VRAI), VRAI), FAUX);
    PileB pbff = pb_remplacer(pb_empiler(pb_empiler(pb_pilenouv(), FAUX), FAUX), VRAI);

    CU_ASSERT(pb_vide(pbv) == FAUX);
    CU_ASSERT(pb_remplie(pbv) == FAUX);
    CU_ASSERT(pb_hauteur(pbv) == 1);
    CU_ASSERT(pb_sommet(pbv) == FAUX);

    CU_ASSERT(pb_vide(pbf) == FAUX);
    CU_ASSERT(pb_remplie(pbf) == FAUX);
    CU_ASSERT(pb_hauteur(pbf) == 1);
    CU_ASSERT(pb_sommet(pbf) == VRAI);

    CU_ASSERT(pb_vide(pbvv) == FAUX);
    CU_ASSERT(pb_remplie(pbvv) == FAUX);
    CU_ASSERT(pb_hauteur(pbvv) == 2);
    CU_ASSERT(pb_sommet(pbvv) == FAUX);
    CU_ASSERT(pb_valeurk(pbvv, 2) == VRAI);

    CU_ASSERT(pb_vide(pbff) == FAUX);
    CU_ASSERT(pb_remplie(pbff) == FAUX);
    CU_ASSERT(pb_hauteur(pbff) == 2);
    CU_ASSERT(pb_sommet(pbff) == VRAI);
    CU_ASSERT(pb_valeurk(pbff, 2) == FAUX);

    free(pbv);
    free(pbf);
    free(pbvv);
    free(pbff);
}
Ejemplo n.º 8
0
void regexp_02_test() {
	char *msg = "354- nope\r\n";
	CU_ASSERT(!re_match(r354, msg, strlen(msg)));
}
Ejemplo n.º 9
0
void regexp_03_test() {
	char *msg = "MAIL FROM:  <*****@*****.**>\r\n";
	CU_ASSERT(re_match(RE_mail_from, msg, strlen(msg)));
}
Ejemplo n.º 10
0
void maildir_06_test() {
	CU_ASSERT(read_mail_file("testmail6") == 0);
}
Ejemplo n.º 11
0
void regexp_01_test() {
	char *msg = "220 hello!\r\n";
	CU_ASSERT(re_match(r220, msg, strlen(msg)));
}
Ejemplo n.º 12
0
void maildir_03_test() {
	CU_ASSERT(read_mail_file("testmail3") != 0);
}
Ejemplo n.º 13
0
static void testSuccess3(void)
{
    CU_ASSERT(3);
}
Ejemplo n.º 14
0
static void testSuccess2(void)
{
    CU_ASSERT(2);
}
Ejemplo n.º 15
0
void
test_writeverify10_residuals(void)
{
        struct scsi_task *task_ret;
        unsigned char buf[10000];
        struct iscsi_data data;
        int ok;
        unsigned int i;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test WRITEVERIFY10 commands with residuals");
        logging(LOG_VERBOSE, "Block size is %zu", block_size);

        CHECK_FOR_DATALOSS;
        CHECK_FOR_SBC;

        if (sd->iscsi_ctx == NULL) {
                const char *err = "[SKIPPED] This WRITEVERIFY10 test is only "
                        "supported for iSCSI backends";
                logging(LOG_NORMAL, "%s", err);
                CU_PASS(err);
                return;
        }

        /* check if writeverify10 is supported */
        WRITEVERIFY10(sd, 0, 0, block_size, 0, 0, 0, 0, NULL,
                      EXPECT_STATUS_GOOD);

        /* Try a writeverify10 of 1 block but xferlength == 0 */
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE_VERIFY10;
        task->cdb[1] = 2; /* BYTCHK = 1 */
        task->cdb[8] = 1;
        task->cdb_size = 10;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 0;

        /*
         * we don't want autoreconnect since some targets will drop the session
         * on this condition.
         */
        iscsi_set_noautoreconnect(sd->iscsi_ctx, 1);

        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0");

        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);
        CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */

        if (task->status        == SCSI_STATUS_CHECK_CONDITION
            && task->sense.key  == SCSI_SENSE_ILLEGAL_REQUEST
            && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
                logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY10 is not implemented.");
                CU_PASS("WRITEVERIFY10 is not implemented.");
                return;
        }        
        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
                block_size);
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        /* in case the previous test failed the session */
        iscsi_set_noautoreconnect(sd->iscsi_ctx, 0);


        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE_VERIFY10;
        task->cdb[1] = 2; /* BYTCHK = 1 */
        task->cdb[8] = 1;
        task->cdb_size = 10;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 10000;

        memset(buf, 0xa6, sizeof(buf));
        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual underflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "underflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual underflow",
                10000 - block_size);
        if (task->residual != 10000 - block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        10000 - block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, 10000 - block_size);
        scsi_free_scsi_task(task);
        task = NULL;


        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==200");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE_VERIFY10;
        task->cdb[1] = 2; /* BYTCHK = 1 */
        task->cdb[8] = 1;
        task->cdb_size = 10;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 200;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        ok = task->status == SCSI_STATUS_GOOD ||
                (task->status == SCSI_STATUS_CHECK_CONDITION &&
                 task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
                 task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT);
        if (!ok) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT(ok);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
                block_size - 200);
        if (task->residual != block_size - 200) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size - 200, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size - 200);

        scsi_free_scsi_task(task);
        task = NULL;



        logging(LOG_VERBOSE, "Try writing two blocks but iSCSI expected "
                "transfer length==%zu (==one block)", block_size);
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE_VERIFY10;
        task->cdb[1] = 2; /* BYTCHK = 1 */
        task->cdb[8] = 2;
        task->cdb_size = 10;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);

        scsi_free_scsi_task(task);
        task = NULL;




        logging(LOG_VERBOSE, "Verify that if iSCSI EDTL > SCSI TL then we only write SCSI TL amount of data");

        logging(LOG_VERBOSE, "Write two blocks of 'a'");
        memset(buf, 'a', 10000);
        WRITE10(sd, 0, 2 * block_size, block_size, 0, 0, 0, 0, 0, buf,
                EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks.");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(buf, 'b', 10000);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE_VERIFY10;
        task->cdb[1] = 2; /* BYTCHK = 1 */
        task->cdb[8] = 1;
        task->cdb_size = 10;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 2 * block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual underflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "underflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual underflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        logging(LOG_VERBOSE, "Read the two blocks");
        READ10(sd, NULL, 0, 2* block_size, block_size, 0, 0, 0, 0, 0, buf,
               EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'");
        for (i = 0; i < block_size; i++) {
                if (buf[i] != 'b') {
                        logging(LOG_NORMAL, "First block did not contain expected 'b'");
                        CU_FAIL("Block was not written correctly");
                        break;
                }
        }

        logging(LOG_VERBOSE, "Verify that the second block was NOT overwritten and still contains 'a'");
        for (i = block_size; i < 2 * block_size; i++) {
                if (buf[i] != 'a') {
                        logging(LOG_NORMAL, "Second block was overwritten and no longer contain 'a'");
                        CU_FAIL("Second block was incorrectly overwritten");
                        break;
                }
        }


        logging(LOG_VERBOSE, "Verify that if iSCSI EDTL < SCSI TL then we only write iSCSI EDTL amount of data");

        logging(LOG_VERBOSE, "Write two blocks of 'a'");
        memset(buf, 'a', 10000);
        WRITE10(sd, 0, 2 * block_size, block_size, 0, 0, 0, 0, 0, buf,
                EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks.");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(buf, 'b', 10000);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE_VERIFY10;
        task->cdb[1] = 2; /* BYTCHK = 1 */
        task->cdb[8] = 2;
        task->cdb_size = 10;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        logging(LOG_VERBOSE, "Read the two blocks");
        READ10(sd, NULL, 0, 2* block_size, block_size, 0, 0, 0, 0, 0, buf,
               EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'");
        for (i = 0; i < block_size; i++) {
                if (buf[i] != 'b') {
                        logging(LOG_NORMAL, "First block did not contain expected 'b'");
                        CU_FAIL("Block was not written correctly");
                        break;
                }
        }

        logging(LOG_VERBOSE, "Verify that the second block was NOT overwritten and still contains 'a'");
        for (i = block_size; i < 2 * block_size; i++) {
                if (buf[i] != 'a') {
                        logging(LOG_NORMAL, "Second block was overwritten and no longer contain 'a'");
                        CU_FAIL("Second block was incorrectly overwritten");
                        break;
                }
        }
}
Ejemplo n.º 16
0
void regexp_05_test() {
	char *msg = "RCPT TO:<[email protected]\r\n";
	CU_ASSERT(!re_match(RE_rcpt_to, msg, strlen(msg)));
}
Ejemplo n.º 17
0
void TEST_VBLOCK_GP_N(void)
{
	NVM_DEV dev;
	NVM_GEO geo;

	NVM_VBLK *vblocks;	/* Array of vblocks */
	int vblocks_total;	/* Number of vblocks on device / allocated */
	int vblocks_reserved;	/* Number of vblocks successfully reserved */

	int ngets;		/* Total number of ngets */
	int ngets_failed;	/* Total number of failed ngets */
	int *ngets_lun;		/* Number of gets per lun */
	int *ngets_lun_failed;	/* Number of failed gets per lun */

	int i;

	dev = nvm_dev_open(nvm_dev_path);
	CU_ASSERT_PTR_NOT_NULL(dev);

	geo = nvm_dev_attr_geo(dev);

	ngets = 0;
	ngets_lun = malloc(sizeof(ngets_lun)*geo.nluns);
	memset(ngets_lun, 0, sizeof(ngets_lun)*geo.nluns);

	ngets_failed = 0;
	ngets_lun_failed = malloc(sizeof(ngets_lun_failed)*geo.nluns);
	memset(ngets_lun_failed, 0, sizeof(ngets_lun_failed)*geo.nluns);

	vblocks_total = geo.nluns * geo.nblocks;	/* Allocate vblocks */
	vblocks = malloc(sizeof(NVM_VBLK) * vblocks_total);
	CU_ASSERT_PTR_NOT_NULL(vblocks);

	for (i=0; i < vblocks_total; i++) {
		vblocks[i] = nvm_vblk_new();
		CU_ASSERT_PTR_NOT_NULL(vblocks[i]);
	}

	vblocks_reserved = 0;
	for (i=0; i < vblocks_total; i++) {		/* Reserve vblocks */
		int err, ch, lun;

		ch = i % geo.nchannels;
		lun = i % geo.nluns;
		err = nvm_vblk_gets(vblocks[vblocks_reserved], dev, ch, lun);
		ngets++;
		ngets_lun[lun]++;
		if (err) {
			ngets_failed++;
			ngets_lun_failed[lun]++;
			continue;
		}

		vblocks_reserved++;
	}

	/* Check that we did as much as we expected */
	CU_ASSERT(ngets == vblocks_total);

	/* Check that we got a sufficient amount of vblocks */
	CU_ASSERT(vblocks_total - vblocks_reserved < k)

	/* That is... no more than k failures */
	CU_ASSERT(ngets_failed <= k);

	/* Print counters / totals
	printf("vblocks_total(%d)\n", vblocks_total);
	printf("vblocks_reserved(%d)\n", vblocks_reserved);
	printf("ngets(%d), ngets_failed(%d)\n", ngets, ngets_failed);
	for(i=0; i < geo.nluns; i++) {
		printf("i(%d), ngets_lun(%d) / ngets_lun_failed(%d)\n",
			i, ngets_lun[i], ngets_lun_failed[i]);
	}
	*/

	for (i=0; i < vblocks_reserved; i++) {		/* Release vblocks */
		int err = nvm_vblk_put(vblocks[i]);
		CU_ASSERT(!err);
		if (err) {
			continue;
		}
	}

	for (i=0; i < vblocks_total; i++) {		/* Deallocate vblocks */
		nvm_vblk_free(vblocks[i]);
	}
	free(vblocks);
}
Ejemplo n.º 18
0
void regexp_06_test() {
	char *msg = "250 OK\r\n";
	CU_ASSERT(re_match_any(msg, strlen(msg)) == r250);
}
Ejemplo n.º 19
0
void test_pb_depiler(void)
{
    PileB pbv = pb_depiler(pb_empiler(pb_pilenouv(), VRAI));
    PileB pbf = pb_depiler(pb_empiler(pb_pilenouv(), FAUX));
    PileB pbvf = pb_depiler(pb_empiler(pb_empiler(pb_pilenouv(), VRAI), FAUX));
    PileB pbfv = pb_depiler(pb_empiler(pb_empiler(pb_pilenouv(), FAUX), VRAI));

    CU_ASSERT(pb_vide(pbv) == VRAI);
    CU_ASSERT(pb_remplie(pbv) == FAUX);
    CU_ASSERT(pb_hauteur(pbv) == 0);

    CU_ASSERT(pb_vide(pbf) == VRAI);
    CU_ASSERT(pb_remplie(pbf) == FAUX);
    CU_ASSERT(pb_hauteur(pbf) == 0);

    CU_ASSERT(pb_vide(pbvf) == FAUX);
    CU_ASSERT(pb_remplie(pbvf) == FAUX);
    CU_ASSERT(pb_hauteur(pbvf) == 1);
    CU_ASSERT(pb_sommet(pbvf) == VRAI);

    CU_ASSERT(pb_vide(pbfv) == FAUX);
    CU_ASSERT(pb_remplie(pbfv) == FAUX);
    CU_ASSERT(pb_hauteur(pbfv) == 1);
    CU_ASSERT(pb_sommet(pbfv) == FAUX);

    free(pbv);
    free(pbf);
    free(pbvf);
    free(pbfv);
}
Ejemplo n.º 20
0
void regexp_07_test() {
	char *msg = "DATA\r\n";
	CU_ASSERT(re_match_any(msg, strlen(msg)) == RE_data);
}
Ejemplo n.º 21
0
void test_purge(){

	unsigned int i;
	of1x_flow_entry_t* entry;

	//Install a flow in each table
	for(i=0;i<4;i++){
		entry = of1x_init_flow_entry(false); 
		CU_ASSERT(of1x_add_match_to_entry(entry,of1x_init_port_in_match(1)) == ROFL_SUCCESS);
	
		CU_ASSERT(entry != NULL);
		CU_ASSERT(of1x_add_flow_entry_table(&sw->pipeline, i, &entry, false,false) == ROFL_OF1X_FM_SUCCESS);
	}

	//Check real size of the table
	CU_ASSERT(sw->pipeline.tables[0].num_of_entries == 1);
	CU_ASSERT(sw->pipeline.tables[1].num_of_entries == 1);
	CU_ASSERT(sw->pipeline.tables[2].num_of_entries == 1);
	CU_ASSERT(sw->pipeline.tables[3].num_of_entries == 1);
	
	//Purge 
	CU_ASSERT(__of1x_purge_pipeline_entries(&sw->pipeline) == ROFL_SUCCESS);

	//Check size of the table again
	CU_ASSERT(sw->pipeline.tables[0].num_of_entries == 0);
	CU_ASSERT(sw->pipeline.tables[1].num_of_entries == 0);
	CU_ASSERT(sw->pipeline.tables[2].num_of_entries == 0);
	CU_ASSERT(sw->pipeline.tables[3].num_of_entries == 0);
}
Ejemplo n.º 22
0
void regexp_08_test() {
	char *msg = "RCPT TO: <*****@*****.**>\r\n";
	CU_ASSERT(re_match_any(msg, strlen(msg)) == RE_rcpt_to);
}
Ejemplo n.º 23
0
void test_reconfigure(){

	/*
	* initially OF12
	*/
	//OF12->OF10
	reset_sw(OF_VERSION_12);
	CU_ASSERT(of_reconfigure_switch((of_switch_t*)sw, OF_VERSION_10) == ROFL_SUCCESS);
	CU_ASSERT(compare(sw, sw10) == 0);

	//OF12->OF13
	reset_sw(OF_VERSION_12);
	CU_ASSERT(of_reconfigure_switch((of_switch_t*)sw, OF_VERSION_13) == ROFL_SUCCESS);
	CU_ASSERT(compare(sw, sw13) == 0);

	/*
	* initially OF10
	*/
	//OF10->OF12
	reset_sw(OF_VERSION_10);
	CU_ASSERT(of_reconfigure_switch((of_switch_t*)sw, OF_VERSION_12) == ROFL_SUCCESS);
	CU_ASSERT(compare(sw, sw12) == 0);

	//OF10->OF13
	reset_sw(OF_VERSION_10);
	CU_ASSERT(of_reconfigure_switch((of_switch_t*)sw, OF_VERSION_13) == ROFL_SUCCESS);
	CU_ASSERT(compare(sw, sw13) == 0);



	/*
	* initially OF13
	*/
	//OF13->OF10
	reset_sw(OF_VERSION_13);
	CU_ASSERT(of_reconfigure_switch((of_switch_t*)sw, OF_VERSION_10) == ROFL_SUCCESS);
	CU_ASSERT(compare(sw, sw10) == 0);

	//OF13->OF12
	reset_sw(OF_VERSION_13);
	CU_ASSERT(of_reconfigure_switch((of_switch_t*)sw, OF_VERSION_12) == ROFL_SUCCESS);
	CU_ASSERT(compare(sw, sw12) == 0);
}
Ejemplo n.º 24
0
void regexp_09_test() {
	char *msg = "MAIL FROM: <*****@*****.**>\r\n";
	CU_ASSERT(!re_match(RE_rcpt_to, msg, strlen(msg)));
}
Ejemplo n.º 25
0
void TEST_COPY_OBJECT_WITH_SAME_BUCKET(void) {
    int error;
    buffer* resp = NULL;

    const char* src_obj_key = "unit_test_dir/src_object1";
    const char* filename = "./lib/libcunit.a";

    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = upload_file_object(host, src_bucket, src_obj_key, filename,
            ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (resp->status_code != 200) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    const char* l_dst_bucket = src_bucket;
    const char* dst_obj_key = "unit_test_dir/dst_object1";

    resp = delete_object(host, l_dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code || 404 == resp->status_code);
    buffer_free(resp);

    resp = copy_object(host, src_bucket, src_obj_key,
            l_dst_bucket, dst_obj_key, ak, sk, NULL, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(200 == resp->status_code);
    if (resp->status_code != 200) {
        printf("status code = %ld\n", resp->status_code);
        printf("status msg = %s\n", resp->status_msg);
        printf("error msg = %s\n", resp->body);
    }
    buffer_free(resp);

    resp = delete_object(host, src_bucket, src_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);

    resp = delete_object(host, l_dst_bucket, dst_obj_key, ak, sk, NULL, &error);
    CU_ASSERT(0 == error);
    CU_ASSERT(204 == resp->status_code);
    buffer_free(resp);
}
Ejemplo n.º 26
0
void testSaveMatrixRectangle(void) {
    FILE *matrixFile = fopen("test/matrix_to_save2","wb");
    if(matrixFile == NULL) {
        return;
    } 
    
    size_t columns = 4;
    size_t rows = 3;
    floattype **matrix = AllocMatrix(rows, columns);
    matrix[0][0] = 1;
    matrix[0][1] = 2;
    matrix[0][2] = 3;
    matrix[0][3] = 4;
    
    matrix[1][0] = 1;
    matrix[1][1] = 2;
    matrix[1][2] = 3;
    matrix[1][3] = 4;
    
    matrix[2][0] = 1;
    matrix[2][1] = 2;
    matrix[2][2] = 3;
    matrix[2][3] = 4;
    
    floattype **expected = AllocMatrix(rows, columns);
    expected[0][0] = 1;
    expected[0][1] = 2;
    expected[0][2] = 3;
    expected[0][3] = 4;
    
    expected[1][0] = 1;
    expected[1][1] = 2;
    expected[1][2] = 3;
    expected[1][3] = 4;
    
    expected[2][0] = 1;
    expected[2][1] = 2;
    expected[2][2] = 3;
    expected[2][3] = 4;
    
    CU_ASSERT(CODE_OK == saveMatrix(matrix, matrixFile, rows, columns));
    FreeMatrix(matrix, rows);
    fclose(matrixFile);
    
    Matrix *matrixLoaded;
    FILE *loadFile = fopen("test/matrix_to_save2","rb");
    matrixLoaded = loadMatrix(loadFile);
    fclose(loadFile);
    
    CU_ASSERT(NULL != matrixLoaded);
    if(NULL == matrixLoaded) {
        FreeMatrix(expected, rows);
        return;
    }
    
    CU_ASSERT(4 == matrixLoaded->header.colcount);
    CU_ASSERT(3 == matrixLoaded->header.rowcount);
    
    assertMatricesAreSame(expected, matrixLoaded->matrix, &(matrixLoaded->header));
    
    FreeMatrix(matrixLoaded->matrix, matrixLoaded->header.rowcount);
    free(matrixLoaded);
    FreeMatrix(expected, rows);
}
Ejemplo n.º 27
0
void test_nghttp2_frame_pack_altsvc(void)
{
  nghttp2_extension frame, oframe;
  nghttp2_ext_altsvc altsvc, oaltsvc;
  nghttp2_bufs bufs;
  nghttp2_buf *buf;
  size_t protocol_id_len, host_len, origin_len;
  uint8_t *protocol_id, *host, *origin;
  uint8_t *data;
  size_t datalen;
  int rv;
  size_t payloadlen;

  protocol_id_len = strlen("h2");
  host_len = strlen("h2.example.org");
  origin_len = strlen("www.example.org");

  datalen = protocol_id_len + host_len + origin_len;
  data = malloc(datalen);

  memcpy(data, "h2", protocol_id_len);
  protocol_id = data;

  memcpy(data + protocol_id_len, "h2.example.org", host_len);
  host = data + protocol_id_len;

  memcpy(data + protocol_id_len + host_len,
         "http://www.example.org", origin_len);
  origin = data + protocol_id_len + host_len;

  frame_pack_bufs_init(&bufs);

  frame.payload = &altsvc;

  nghttp2_frame_altsvc_init(&frame, 1000000007, 1u << 31, 4000,
                            protocol_id, protocol_id_len,
                            host, host_len, origin, origin_len);

  rv = nghttp2_frame_pack_altsvc(&bufs, &frame);

  CU_ASSERT(0 == rv);

  CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_MINLEN + datalen) ==
            nghttp2_bufs_len(&bufs));

  oframe.payload = &oaltsvc;

  CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));

  check_frame_header(NGHTTP2_ALTSVC_MINLEN + datalen,
                     NGHTTP2_EXT_ALTSVC, NGHTTP2_FLAG_NONE,
                     1000000007, &oframe.hd);
  CU_ASSERT(1u << 31 == oaltsvc.max_age);
  CU_ASSERT(4000 == oaltsvc.port);

  CU_ASSERT(protocol_id_len == oaltsvc.protocol_id_len);
  CU_ASSERT(memcmp(protocol_id, oaltsvc.protocol_id, protocol_id_len) == 0);

  CU_ASSERT(host_len == oaltsvc.host_len);
  CU_ASSERT(memcmp(host, oaltsvc.host, host_len) == 0);

  CU_ASSERT(origin_len == oaltsvc.origin_len);
  CU_ASSERT(memcmp(origin, oaltsvc.origin, origin_len) == 0);

  nghttp2_frame_altsvc_free(&oframe);
  nghttp2_frame_altsvc_free(&frame);

  memset(&oframe, 0, sizeof(oframe));
  memset(&oaltsvc, 0, sizeof(oaltsvc));

  buf = &bufs.head->buf;

  CU_ASSERT(buf->pos - buf->begin == 1);

  /* Check no origin case */

  payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len + host_len;
  nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));

  oframe.payload = &oaltsvc;

  CU_ASSERT(0 ==
            nghttp2_frame_unpack_altsvc_payload
            (&oframe,
             buf->pos + NGHTTP2_FRAME_HDLEN,
             NGHTTP2_ALTSVC_FIXED_PARTLEN,
             buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
             payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));

  CU_ASSERT(protocol_id_len == oaltsvc.protocol_id_len);
  CU_ASSERT(host_len == oaltsvc.host_len);
  CU_ASSERT(0 == oaltsvc.origin_len);

  memset(&oframe, 0, sizeof(oframe));
  memset(&oaltsvc, 0, sizeof(oaltsvc));

  /* Check insufficient payload length for host */
  payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len + host_len - 1;
  nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));

  oframe.payload = &oaltsvc;

  CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR ==
            nghttp2_frame_unpack_altsvc_payload
            (&oframe,
             buf->pos + NGHTTP2_FRAME_HDLEN,
             NGHTTP2_ALTSVC_FIXED_PARTLEN,
             buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
             payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));

  memset(&oframe, 0, sizeof(oframe));
  memset(&oaltsvc, 0, sizeof(oaltsvc));

  /* Check no host case */
  payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len;
  nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));
  buf->pos[NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN
           + protocol_id_len] = 0;

  oframe.payload = &oaltsvc;

  CU_ASSERT(0 ==
            nghttp2_frame_unpack_altsvc_payload
            (&oframe,
             buf->pos + NGHTTP2_FRAME_HDLEN,
             NGHTTP2_ALTSVC_FIXED_PARTLEN,
             buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
             payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));

  CU_ASSERT(protocol_id_len == oaltsvc.protocol_id_len);
  CU_ASSERT(0 == oaltsvc.host_len);
  CU_ASSERT(0 == oaltsvc.origin_len);

  memset(&oframe, 0, sizeof(oframe));
  memset(&oaltsvc, 0, sizeof(oaltsvc));

  /* Check missing Host-Len */
  payloadlen = NGHTTP2_ALTSVC_FIXED_PARTLEN + protocol_id_len;
  nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));

  oframe.payload = &oaltsvc;

  CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR ==
            nghttp2_frame_unpack_altsvc_payload
            (&oframe,
             buf->pos + NGHTTP2_FRAME_HDLEN,
             NGHTTP2_ALTSVC_FIXED_PARTLEN,
             buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
             payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));

  memset(&oframe, 0, sizeof(oframe));
  memset(&oaltsvc, 0, sizeof(oaltsvc));

  nghttp2_bufs_free(&bufs);
}
Ejemplo n.º 28
0
void passphrase_read_turns_on_newline_echo_during_read()
{
	static const int read_nbyte = 11;
	int masterfd, slavefd;
	char* slavedevice = NULL;
	char read_buf[read_nbyte];
	fd_set fd_set_write;
	struct termios term_flags;

	masterfd = posix_openpt(O_RDWR|O_NOCTTY);

	if (masterfd == -1
		|| grantpt (masterfd) == -1
		|| unlockpt (masterfd) == -1
		|| (slavedevice = ptsname (masterfd)) == NULL)
		CU_FAIL_FATAL("Could not create pty");

	slavefd = open(slavedevice, O_RDWR|O_NOCTTY);
	if (slavefd == -1)
		CU_FAIL_FATAL("Could not open slave end of pty");

	if (tcgetattr(slavefd, &term_flags) != 0)
		CU_FAIL_FATAL("Could not get slave pty attributes");
	if (term_flags.c_lflag & ECHONL)
	{
		term_flags.c_lflag &= ~ECHONL;
		if (tcsetattr(slavefd, TCSANOW, &term_flags) != 0)
			CU_FAIL_FATAL("Could not turn ECHO on on slave pty");
	}

	switch (fork())
	{
	case -1:
		CU_FAIL_FATAL("Could not fork");
	case 0:
		{
			static const int password_size = 512;
			int child_slavefd;
			char buffer[password_size];
			if (setsid() == (pid_t) -1)
				CU_FAIL_FATAL("Could not create new session");

			if ((child_slavefd = open(slavedevice, O_RDWR)) == 0)
				CU_FAIL_FATAL("Could not open slave end of pty");
			close(STDIN_FILENO);
			close(STDOUT_FILENO);
			close(STDERR_FILENO);
			close(masterfd);
			close(slavefd);
			freerdp_passphrase_read("Password: "******"Master end of pty not writeable");
	if (read(masterfd, read_buf, read_nbyte) == (ssize_t) -1)
		CU_FAIL_FATAL("Nothing written to slave end of pty");

	if (tcgetattr(slavefd, &term_flags) != 0)
		CU_FAIL_FATAL("Could not get slave pty attributes");
	CU_ASSERT(term_flags.c_lflag & ECHONL)
	write(masterfd, "\n", (size_t) 2);
	close(masterfd);
	close(slavefd);
	return;
}
Ejemplo n.º 29
0
void test_nghttp2_iv_check(void)
{
  nghttp2_settings_entry iv[5];

  iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
  iv[0].value = 100;
  iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
  iv[1].value = 1024;

  CU_ASSERT(nghttp2_iv_check(iv, 2));

  iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
  iv[1].value = NGHTTP2_MAX_WINDOW_SIZE;
  CU_ASSERT(nghttp2_iv_check(iv, 2));

  /* Too large window size */
  iv[1].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1;
  CU_ASSERT(0 == nghttp2_iv_check(iv, 2));

  /* ENABLE_PUSH only allows 0 or 1 */
  iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH;
  iv[1].value = 0;
  CU_ASSERT(nghttp2_iv_check(iv, 2));
  iv[1].value = 1;
  CU_ASSERT(nghttp2_iv_check(iv, 2));
  iv[1].value = 3;
  CU_ASSERT(!nghttp2_iv_check(iv, 2));

  /* Undefined SETTINGS ID is allowed */
  iv[1].settings_id = 1000000009;
  iv[1].value = 0;
  CU_ASSERT(nghttp2_iv_check(iv, 2));

  /* Too large SETTINGS_HEADER_TABLE_SIZE */
  iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
  iv[1].value = UINT32_MAX;
  CU_ASSERT(!nghttp2_iv_check(iv, 2));

  /* Too small SETTINGS_MAX_FRAME_SIZE */
  iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
  iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN - 1;
  CU_ASSERT(!nghttp2_iv_check(iv, 1));

  /* Too large SETTINGS_MAX_FRAME_SIZE */
  iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
  iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MAX + 1;
  CU_ASSERT(!nghttp2_iv_check(iv, 1));

  /* Max and min SETTINGS_MAX_FRAME_SIZE */
  iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
  iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN;
  iv[1].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
  iv[1].value = NGHTTP2_MAX_FRAME_SIZE_MAX;
  CU_ASSERT(nghttp2_iv_check(iv, 2));
}
Ejemplo n.º 30
0
void case_cmd_lrange_found()
{
        answer_t *ans;
        answer_iter_t *iter;
        answer_value_t *value;
        

        CU_ASSERT(kv_init(NULL) == ERR_NONE);

        ans = kv_ask("lpush mylist a b c", strlen("lpush mylist a b c"));
        CU_ASSERT(ans->errnum == ERR_NONE);
        answer_release(ans);

        ans = kv_ask("lrange mylist 0 0", strlen("lrange mylist 0 0"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_NONE);
        iter = answer_get_iter(ans, ANSWER_HEAD);
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "c");
        CU_ASSERT_PTR_EQUAL(answer_value_to_string(answer_next(iter)), NULL);
        answer_release_iter(iter);
        answer_release(ans);

        ans = kv_ask("lrange mylist 0 2", strlen("lrange mylist 0 2"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_NONE);
        iter = answer_get_iter(ans, ANSWER_HEAD);
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "c");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "b");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "a");
        value = answer_next(iter);
        CU_ASSERT_PTR_EQUAL(answer_value_to_string(value), NULL);
        answer_release_iter(iter);
        answer_release(ans);

        ans = kv_ask("lrange mylist 0 3", strlen("lrange mylist 0 3"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_NONE);
        iter = answer_get_iter(ans, ANSWER_HEAD);
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "c");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "b");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "a");
        value = answer_next(iter);
        CU_ASSERT_PTR_EQUAL(answer_value_to_string(value), NULL);
        answer_release_iter(iter);
        answer_release(ans);

        ans = kv_ask("lrange mylist 0 -1", strlen("lrange mylist 0 -1"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_NONE);
        iter = answer_get_iter(ans, ANSWER_HEAD);
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "c");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "b");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "a");
        value = answer_next(iter);
        CU_ASSERT_PTR_EQUAL(answer_value_to_string(value), NULL);
        answer_release_iter(iter);
        answer_release(ans);

        ans = kv_ask("lrange mylist -1 -1", strlen("lrange mylist -1 -1"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_NONE);
        iter = answer_get_iter(ans, ANSWER_HEAD);
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "a");
        value = answer_next(iter);
        CU_ASSERT_PTR_EQUAL(answer_value_to_string(value), NULL);
        answer_release_iter(iter);
        answer_release(ans);

        ans = kv_ask("lrange mylist -1 1", strlen("lrange mylist -1 1"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_OUT_OF_RANGE);
        answer_release(ans);

        ans = kv_ask("lrange mylist 1 -1", strlen("lrange mylist 1 -1"));
        CU_ASSERT_EQUAL(ans->errnum, ERR_NONE);
        iter = answer_get_iter(ans, ANSWER_HEAD);
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "b");
        value = answer_next(iter);
        CU_ASSERT_STRING_EQUAL(answer_value_to_string(value), "a");
        value = answer_next(iter);
        CU_ASSERT_PTR_EQUAL(answer_value_to_string(value), NULL);
        answer_release_iter(iter);
        answer_release(ans);

        kv_uninit();
}