Example #1
0
static void testAircraftHandling (void)
{
	const vec2_t destination = { 10, 10 };
	campaign_t *campaign;
	base_t *base;
	aircraft_t *aircraft;
	aircraft_t *newAircraft;
	aircraft_t *aircraftTemplate;
	int firstIdx;
	int initialCount;
	int count;
	int newFound;

	ResetCampaignData();

	campaign = GetCampaign();

	base = CreateBase("unittestaircraft", destination);
	CU_ASSERT_PTR_NOT_NULL_FATAL(base);

	/** @todo we should not assume that initial base has aircraft. It's a campaign parameter */
	aircraft = AIR_GetFirstFromBase(base);
	CU_ASSERT_PTR_NOT_NULL_FATAL(aircraft);

	/* aircraft should have a template */
	aircraftTemplate = aircraft->tpl;
	CU_ASSERT_PTR_NOT_NULL_FATAL(aircraftTemplate);

	firstIdx = aircraft->idx;
	initialCount = AIR_BaseCountAircraft(base);

	/* test deletion (part 1) */
	AIR_DeleteAircraft(aircraft);
	count = AIR_BaseCountAircraft(base);
	CU_ASSERT_EQUAL(count, initialCount - 1);

	/* test addition (part 1) */
	newAircraft = AIR_NewAircraft(base, aircraftTemplate);
	CU_ASSERT_PTR_NOT_NULL_FATAL(newAircraft);
	count = AIR_BaseCountAircraft(base);
	CU_ASSERT_EQUAL(count, initialCount);

	/* new aircraft assigned to the right base */
	CU_ASSERT_EQUAL(newAircraft->homebase, base);

	newFound = 0;
	AIR_Foreach(aircraft) {
		/* test deletion (part 2) */
		CU_ASSERT_NOT_EQUAL(firstIdx, aircraft->idx);
		/* for test addition (part 2) */
		if (aircraft->idx == newAircraft->idx)
			newFound++;
	}
	/* test addition (part 2) */
	CU_ASSERT_EQUAL(newFound, 1);

	/* check if AIR_Foreach iterates through all aircraft */
	AIR_Foreach(aircraft) {
		AIR_DeleteAircraft(aircraft);
	}
	aircraft = AIR_GetFirstFromBase(base);
	CU_ASSERT_PTR_NULL_FATAL(aircraft);
	count = AIR_BaseCountAircraft(base);
	CU_ASSERT_EQUAL(count, 0);

	/* cleanup for the following tests */
	E_DeleteAllEmployees(NULL);

	base->founded = qfalse;
}
void test_VIDIOC_G_FREQUENCY() {
    int ret_get, errno_get;
    __u32 tuner;
    struct v4l2_frequency freq;

    tuner = 0;

    memset(&freq, 0xff, sizeof(freq));
    freq.tuner = tuner;
    ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &freq);
    errno_get = errno;

    dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
            __FILE__, __LINE__, ret_get, errno_get);

    if (ret_get == 0) {
        CU_ASSERT_EQUAL(ret_get, 0);

        CU_ASSERT_EQUAL(freq.tuner, tuner);

        //CU_ASSERT(freq.type, ???);
        //CU_ASSERT_EQUAL(freq.frequency, ???);

        CU_ASSERT_EQUAL(freq.reserved[0], 0);
        CU_ASSERT_EQUAL(freq.reserved[1], 0);
        CU_ASSERT_EQUAL(freq.reserved[2], 0);
        CU_ASSERT_EQUAL(freq.reserved[3], 0);
        CU_ASSERT_EQUAL(freq.reserved[4], 0);
        CU_ASSERT_EQUAL(freq.reserved[5], 0);
        CU_ASSERT_EQUAL(freq.reserved[6], 0);
        CU_ASSERT_EQUAL(freq.reserved[7], 0);

        dprintf("\tfreq = { "
                ".tuner = %u, "
                ".type = 0x%X, "
                ".frequency = %u "
                ".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X } }\n",
                freq.tuner,
                freq.type,
                freq.frequency,
                freq.reserved[0],
                freq.reserved[1],
                freq.reserved[2],
                freq.reserved[3],
                freq.reserved[4],
                freq.reserved[5],
                freq.reserved[6],
                freq.reserved[7]
               );
    } else {
        CU_ASSERT_EQUAL(ret_get, -1);
        CU_ASSERT_EQUAL(errno_get, EINVAL);
    }

}
void
test_compareandwrite_miscompare(void)
{
	int i, ret;
	unsigned j;
	unsigned char *buf = alloca(2 * 256 * block_size);

	CHECK_FOR_DATALOSS;
	CHECK_FOR_SBC;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
		"start of the LUN. One Byte miscompare in the final block.");
	for (i = 1; i < 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:0", i);
		memset(buf, 'A', 2 * i * block_size);
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}
		ret = write16(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented.");
			CU_PASS("WRITE16 is not implemented.");
			return;
		}	
		CU_ASSERT_EQUAL(ret, 0);

		
		logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match.");
		buf[i * block_size - 27] = 'C';


		memset(buf + i * block_size, 'B', i * block_size);

		logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' "
			"at LBA:0 (if they all contain 'A')", i);
		ret = compareandwrite_miscompare(iscsic, tgt_lun, 0,
			buf, 2 * i * block_size, block_size, 0, 0, 0, 0);
		if (ret == -2) {
			CU_PASS("[SKIPPED] Target does not support "
				"COMPARE_AND_WRITE. Skipping test");
			return;
		}
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify "
			"they are still unchanged as 'A'", i);
		ret = read16(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		for (j = 0; j < i * block_size; j++) {
			if (buf[j] != 'A') {
				logging(LOG_VERBOSE, "[FAILED] Data changed "
					"eventhough there was a miscompare");
				CU_FAIL("Block was written to");
				return;
			}
		}
	}


	logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
		"end of the LUN");
	for (i = 1; i < 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:%" PRIu64,
			i, num_blocks - i);
		memset(buf, 'A', 2 * i * block_size);
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}
		ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match.");
		buf[i * block_size - 27] = 'C';


		memset(buf + i * block_size, 'B', i * block_size);

		logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' "
			"at LBA:%" PRIu64 " (if they all contain 'A')",
			i, num_blocks - i);
		ret = compareandwrite_miscompare(iscsic, tgt_lun,
			num_blocks - i,
			buf, 2 * i * block_size, block_size, 0, 0, 0, 0);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64 
			"they are still unchanged as 'A'",
			i, num_blocks - i);
		ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		for (j = 0; j < i * block_size; j++) {
			if (buf[j] != 'A') {
				logging(LOG_VERBOSE, "[FAILED] Data changed "
					"eventhough there was a miscompare");
				CU_FAIL("Block was written to");
				return;
			}
		}
	}
}
static void
test_packet_output_ipv6_to_gre(void)
{
	odp_packet_t pkt = ODP_PACKET_INVALID;
	odp_event_t ev;
	int res;
	struct ofp_ether_header *eth;
	struct ofp_ip6_hdr *ip6, *ip6_orig;
	struct ofp_ip *ip;
	struct ofp_greip *greip;

	(void)tcp_frame;
	(void)icmp_frame;
	(void)arp_frame;
	(void)icmp6_frame;

	if (create_odp_packet_ip6(&pkt, ip6udp_frame, sizeof(ip6udp_frame))) {
		CU_FAIL("Fail to create packet");
		return;
	}

	ip6 = odp_packet_l3_ptr(pkt, NULL);

	ofp_set_route6_params(OFP_ROUTE6_ADD, 0 /*vrf*/, 100 /*vlan*/, GRE_PORTS,
			      ip6->ip6_dst.__u6_addr.__u6_addr8, 64 /*masklen*/,
			      0 /*gw*/, OFP_RTF_NET /* flags */);

	res = ofp_ip6_output(pkt, NULL);
	CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED);

	res = ofp_send_pending_pkt();
	CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED);

	ev = odp_queue_deq(dev->outq_def);
	CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID);

	pkt = odp_packet_from_event(ev);
	CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt),
			      sizeof(ip6udp_frame) + 20 + 4);

	eth = odp_packet_l2_ptr(pkt, NULL);
	if (memcmp(eth->ether_dhost, tun_rem_mac, OFP_ETHER_ADDR_LEN))
		CU_FAIL("Bad destination mac address.");
	if (memcmp(eth->ether_shost, dev->mac, OFP_ETHER_ADDR_LEN))
		CU_FAIL("Bad source mac address.");

	ip = odp_packet_l3_ptr(pkt, NULL);
	CU_ASSERT_EQUAL(ip->ip_src.s_addr, dev_ip);
	CU_ASSERT_EQUAL(ip->ip_dst.s_addr, tun_rem_ip);
	CU_ASSERT_EQUAL(ip->ip_p, OFP_IPPROTO_GRE);

	greip = (struct ofp_greip *)ip;
	CU_ASSERT_EQUAL(greip->gi_g.flags, 0);
	CU_ASSERT_EQUAL(greip->gi_g.ptype,
			odp_cpu_to_be_16(OFP_ETHERTYPE_IPV6));

	/* inner ip */
	ip6 = (struct ofp_ip6_hdr *)(greip + 1);
	ip6_orig = (struct ofp_ip6_hdr *)
		(&orig_pkt_data[OFP_ETHER_HDR_LEN]);
	if (memcmp(ip6, ip6_orig,
		   odp_be_to_cpu_16(ip6_orig->ofp_ip6_plen) + sizeof(*ip6)))
		CU_FAIL("Inner IP packet error.");
}
void test_VIDIOC_S_FREQUENCY() {
    int ret_get, errno_get;
    int ret_set, errno_set;
    __u32 tuner;
    struct v4l2_frequency orig_freq;
    struct v4l2_frequency freq;
    struct v4l2_frequency new_freq;

    tuner = 0;

    /* fetch the current frequency setting */
    memset(&orig_freq, 0xff, sizeof(orig_freq));
    orig_freq.tuner = tuner;
    ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &orig_freq);
    errno_get = errno;

    dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
            __FILE__, __LINE__, ret_get, errno_get);

    if (ret_get == 0) {
        CU_ASSERT_EQUAL(orig_freq.tuner, tuner);

        /* try to set the frequency again to the actual value */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = tuner;
        freq.frequency = orig_freq.frequency;
        freq.type = V4L2_TUNER_ANALOG_TV;
        ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &orig_freq);
        errno_set = errno;

        dprintf("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i\n",
                __FILE__, __LINE__, ret_set, errno_set);

        CU_ASSERT_EQUAL(ret_set, 0);
        if (ret_set == 0) {

            /* check wheteher the frequency has not been changed */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = tuner;
            ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);
            errno_get = errno;

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i\n",
                    __FILE__, __LINE__, ret_get, errno_get);

            CU_ASSERT_EQUAL(ret_get, 0);
            if (ret_get == 0) {
                dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                        __FILE__, __LINE__,
                        new_freq.frequency, orig_freq.frequency);
                CU_ASSERT_EQUAL(new_freq.frequency, orig_freq.frequency);
            }

        }

    } else {
        CU_ASSERT_EQUAL(ret_get, -1);
        CU_ASSERT_EQUAL(errno_get, EINVAL);

        /* VIDIOC_G_FREQUENCY not supported, so shall be VIDIOC_S_FREQUENCY */

        memset(&freq, 0, sizeof(freq));
        freq.tuner = tuner;
        freq.type = V4L2_TUNER_ANALOG_TV;
        freq.frequency = 0;
        ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
        errno_set = errno;

        dprintf("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i\n",
                __FILE__, __LINE__, ret_set, errno_set);

        CU_ASSERT_EQUAL(ret_set, -1);
        CU_ASSERT_EQUAL(errno_set, EINVAL);

    }

}
Example #6
0
void test_parser(void)
{
	CALC_ELEMENT *e1 = NULL, *e2 = NULL;
	double a, b;
	strcpy(in_line, "(3+(4-1))*5");
	line_len = 11;
	CU_ASSERT_EQUAL(parse_line(&e1, &e2), 0);
	CU_ASSERT_PTR_NOT_NULL(e1);
	CU_ASSERT_PTR_NULL(e2);
	CU_ASSERT_EQUAL(canonical_form(&e1), 0);
	CU_ASSERT_EQUAL(e1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(e1->value, 30);
	free_calc_element(e1);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "2 * x + 0.5 = 1");
	line_len = 15;
	CU_ASSERT_EQUAL(parse_line(&e1, &e2), 0);
	CU_ASSERT_PTR_NOT_NULL(e1);
	CU_ASSERT_PTR_NOT_NULL(e2);
	CU_ASSERT_EQUAL(canonical_form(&e1), 0);
	CU_ASSERT_EQUAL(canonical_form(&e2), 0);
	CU_ASSERT_EQUAL(get_ax_b(e1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 2);
	CU_ASSERT_EQUAL(b, 0.5);
	CU_ASSERT_EQUAL(e2->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(e2->value, 1);
	free_calc_element(e1);
	free_calc_element(e2);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "2x + 1 = 2(1-x)");
	line_len = 15;
	CU_ASSERT_EQUAL(parse_line(&e1, &e2), 0);
	CU_ASSERT_PTR_NOT_NULL(e1);
	CU_ASSERT_PTR_NOT_NULL(e2);
	CU_ASSERT_EQUAL(canonical_form(&e1), 0);
	CU_ASSERT_EQUAL(canonical_form(&e2), 0);
	CU_ASSERT_EQUAL(get_ax_b(e1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 2);
	CU_ASSERT_EQUAL(b, 1);
	CU_ASSERT_EQUAL(get_ax_b(e2, &a, &b), 0);
	CU_ASSERT_EQUAL(a, -2);
	CU_ASSERT_EQUAL(b, 2);
	free_calc_element(e1);
	free_calc_element(e2);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "14.9 + 1 - 2 3.44");
	line_len = 17;
	CU_ASSERT_NOT_EQUAL(parse_line(&e1, &e2), 0);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "((12)");
	line_len = 5;
	CU_ASSERT_NOT_EQUAL(parse_line(&e1, &e2), 0);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "3x + -");
	line_len = 6;
	CU_ASSERT_NOT_EQUAL(parse_line(&e1, &e2), 0);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "60/5/3*8/4");
	line_len = 10;
	CU_ASSERT_EQUAL(parse_line(&e1, &e2), 0);
	CU_ASSERT_EQUAL(canonical_form(&e1), 0);
	CU_ASSERT_EQUAL(e1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(e1->value, 8);
	free_calc_element(e1);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	/* log torturing */
	strcpy(in_line, "log 5)");
	line_len = 6;
	CU_ASSERT_NOT_EQUAL(parse_line(&e1, &e2), 0);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "log(9 ");
	line_len = 6;
	CU_ASSERT_NOT_EQUAL(parse_line(&e1, &e2), 0);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "leg(9)");
	line_len = 6;
	CU_ASSERT_NOT_EQUAL(parse_line(&e1, &e2), 0);
	clear_line();
	e1 = NULL;
	e2 = NULL;

	strcpy(in_line, "(2x - 2x + 6) * 4x = 12");
	line_len = 23;
	CU_ASSERT_EQUAL(parse_line(&e1, &e2), 0);
	CU_ASSERT_EQUAL(canonical_form(&e1), 0);
	CU_ASSERT_EQUAL(get_ax_b(e1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 24);
	CU_ASSERT_EQUAL(b, 0);
	clear_line();
	free_calc_element(e1);
	free_calc_element(e2);
	e1 = NULL;
	e2 = NULL;
}
void
test_inquiry_block_limits(void)
{
	int ret;
	struct scsi_inquiry_block_limits *bl;
	struct scsi_task *bl_task = NULL;
	struct scsi_inquiry_logical_block_provisioning *lbp = NULL;
	struct scsi_task *lbp_task = NULL;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test of the INQUIRY Block Limits");

	CHECK_FOR_SBC;

	logging(LOG_VERBOSE, "Block device. Verify that we can read Block Limits VPD");
	ret = inquiry(iscsic, tgt_lun,
		      1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS,
		      64, &bl_task);
	CU_ASSERT_EQUAL(ret, 0);
	if (ret != 0) {
		logging(LOG_NORMAL, "[FAILURE] failed to send inquiry.");
		goto finished;
	}

	bl = scsi_datain_unmarshall(bl_task);
	if (bl == NULL) {
		logging(LOG_NORMAL, "[FAILURE] failed to unmarshall inquiry "
			"datain blob.");
		CU_FAIL("[FAILURE] failed to unmarshall inquiry "
			"datain blob.");
		goto finished;
	}

	logging(LOG_VERBOSE, "Verify that the PageLength matches up with the size of the DATA-IN buffer.");
	CU_ASSERT_EQUAL(bl_task->datain.size, bl_task->datain.data[3] + 4);
	if (bl_task->datain.size != bl_task->datain.data[3] + 4) {
		logging(LOG_NORMAL, "[FAILURE] Invalid PageLength returned. "
			"Was %d but expected %d",
			bl_task->datain.data[3], bl_task->datain.size - 4);
	} else {
		logging(LOG_VERBOSE, "[SUCCESS] PageLength matches DataIn buffer size");
	}

	logging(LOG_VERBOSE, "Verify that the PageLength matches SCSI-level.");
	/* if it is not SBC3 then we assume it must be SBC2 */
	if (sbc3_support) {
		logging(LOG_VERBOSE, "Device claims SBC-3. Verify that "				"PageLength == 0x3C");
	} else {
		logging(LOG_VERBOSE, "Device is not SBC-3. Verify that "
			"PageLength == 0x0C (but allow 0x3C too. Some SBC-2 "
			"devices support some SBC-3 features.");
	}
	switch (bl_task->datain.data[3]) {
	case 0x3c:
		/* accept 0x3c (==SBC-3) for all levels */
		if (!sbc3_support) {
			logging(LOG_NORMAL, "[WARNING] SBC-3 pagelength (0x3C) "
				"returned but SBC-3 support was not claimed "
				"in the standard inquiry page.");
		}
		break;
	case 0x0c:
		/* only accept 0x0c for levels < SBC-3 */
		if (!sbc3_support) {
			break;
		}
		/* fallthrough */
	default:
		CU_FAIL("[FAILED] Invalid pagelength returned");
		logging(LOG_NORMAL, "[FAILURE] Invalid PageLength returned.");
	}


	if (bl_task->datain.data[3] != 0x3c) {
		goto finished;
	}


	/*
	 * MAXIMUM UNMAP LBA COUNT
	 * MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT
	 */
	logging(LOG_VERBOSE, "Try reading the logical block provisioning VPD");
	ret = inquiry(iscsic, tgt_lun,
		      1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING,
		      64, &lbp_task);
	if (ret == 0) {
		lbp = scsi_datain_unmarshall(lbp_task);
		if (lbp == NULL) {
			logging(LOG_NORMAL, "[FAILURE] failed to unmarshall "
			"inquiry datain blob.");
		}
	}

	if (lbp && lbp->lbpu) {
		/* We support UNMAP so MAXIMUM UNMAP LBA COUNT and
		 * MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT.
		 * They must be > 0.
		 * It can be 0xffffffff which means no limit, but if there is
		 * an explicit limit set, then we check that it looks sane.
		 * Sane here means < 1M.
		 */
		logging(LOG_VERBOSE, "Device claims UNMAP support via LBPU");
		logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP LBA COUNT is "
			"not 0");
		CU_ASSERT_NOT_EQUAL(bl->max_unmap, 0);

		logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP LBA COUNT is "
			"at least 2^LBPPBE");
		CU_ASSERT_EQUAL(bl->max_unmap >= (1U << rc16->lbppbe), 1);

		if (bl->max_unmap != 0xffffffff) {
			logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP LBA "
				"COUNT is not insanely big");
			CU_ASSERT_TRUE(bl->max_unmap <= 1024*1024);
		}

		logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP BLOCK "
			"DESCRIPTOR COUNT is not 0");
		CU_ASSERT_NOT_EQUAL(bl->max_unmap_bdc, 0);
		if (bl->max_unmap_bdc != 0xffffffff) {
			logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP "
				"BLOCK DESCRIPTOR COUNT is not insanely big");
			CU_ASSERT_TRUE(bl->max_unmap_bdc <= 1024*1024);
		}
	} else {
		logging(LOG_VERBOSE, "Device does not claim UNMAP support via "
			"LBPU");
		logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP LBA COUNT is "
			"0");
		CU_ASSERT_EQUAL(bl->max_unmap, 0);

		logging(LOG_VERBOSE, "Verify that MAXIMUM UNMAP BLOCK "
			"DESCRIPTOR COUNT is 0");
		CU_ASSERT_EQUAL(bl->max_unmap_bdc, 0);
	}



finished:
	if (bl_task != NULL) {
		scsi_free_scsi_task(bl_task);
	}
	if (lbp_task != NULL) {
		scsi_free_scsi_task(lbp_task);
	}
}
Example #8
0
void test_string_lenth(void){
	string test = "Hello";
	int len = string_lenth(test);
	CU_ASSERT_EQUAL(len,5);
}
Example #9
0
static void test_raster_to_gdal() {
	rt_pixtype pixtype = PT_64BF;
	rt_raster raster = NULL;
	rt_band band = NULL;
	uint32_t x;
	uint32_t width = 100;
	uint32_t y;
	uint32_t height = 100;
	char srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";

	uint64_t gdalSize;
	uint8_t *gdal = NULL;

	raster = rt_raster_new(width, height);
	CU_ASSERT(raster != NULL); /* or we're out of virtual memory */

	band = cu_add_band(raster, pixtype, 1, 0);
	CU_ASSERT(band != NULL);

	rt_raster_set_offsets(raster, -500000, 600000);
	rt_raster_set_scale(raster, 1000, -1000);

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
		}
	}

	gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
	/*printf("gdalSize: %d\n", (int) gdalSize);*/
	CU_ASSERT(gdalSize);

	/*
	FILE *fh = NULL;
	fh = fopen("/tmp/out.tif", "w");
	fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
	fclose(fh);
	*/

	if (gdal) CPLFree(gdal);

	cu_free_raster(raster);

	raster = rt_raster_new(width, height);
	CU_ASSERT(raster != NULL); /* or we're out of virtual memory */

	band = cu_add_band(raster, pixtype, 1, 0);
	CU_ASSERT(band != NULL);

	rt_raster_set_offsets(raster, -500000, 600000);
	rt_raster_set_scale(raster, 1000, -1000);

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			rt_band_set_pixel(band, x, y, x, NULL);
		}
	}

	/* add check that band isn't NODATA */
	CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);

	gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
	/*printf("gdalSize: %d\n", (int) gdalSize);*/
	CU_ASSERT(gdalSize);

	if (gdal) CPLFree(gdal);

	cu_free_raster(raster);
}
Example #10
0
static void
test_patch_wkb()
{
    int i;
    int npts = 20;
    PCPOINTLIST *pl1;
    PCPATCH_UNCOMPRESSED *pu1, *pu2;
    PCPATCH *pa1, *pa2, *pa3, *pa4;
    size_t z1, z2;
    uint8_t *wkb1, *wkb2;

    pl1 = pc_pointlist_make(npts);

    for ( i = 0; i < npts; i++ )
    {
        PCPOINT *pt = pc_point_make(simpleschema);
        pc_point_set_double_by_name(pt, "x", i*2.123);
        pc_point_set_double_by_name(pt, "y", i*2.9);
        pc_point_set_double_by_name(pt, "Z", i*0.3099);
        pc_point_set_double_by_name(pt, "intensity", 13);
        pc_pointlist_add_point(pl1, pt);
    }

    pa1 = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1);
    wkb1 = pc_patch_to_wkb(pa1, &z1);
    // str = hexbytes_from_bytes(wkb1, z1);
    // printf("str\n%s\n",str);
    pa2 = pc_patch_from_wkb(simpleschema, wkb1, z1);

    // printf("pa2\n%s\n",pc_patch_to_string(pa2));

    pa3 = pc_patch_compress(pa2, NULL);

    // printf("pa3\n%s\n",pc_patch_to_string(pa3));

    wkb2 = pc_patch_to_wkb(pa3, &z2);
    pa4 = pc_patch_from_wkb(simpleschema, wkb2, z2);
    pcfree(wkb2);

    // printf("pa4\n%s\n",pc_patch_to_string(pa4));

    pu1 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa1);
    pu2 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa4);

    // printf("pu1\n%s\n", pc_patch_to_string((PCPATCH*)pu1));
    // printf("pu2\n%s\n", pc_patch_to_string((PCPATCH*)pu2));

    CU_ASSERT_EQUAL(pu1->datasize, pu2->datasize);
    CU_ASSERT_EQUAL(pu1->npoints, pu2->npoints);
    CU_ASSERT(memcmp(pu1->data, pu2->data, pu1->datasize) == 0);


    pc_pointlist_free(pl1);
    pc_patch_free(pa1);
    pc_patch_free(pa2);
    pc_patch_free(pa3);
    pc_patch_free(pa4);
    pc_patch_free((PCPATCH*)pu1);
    pc_patch_free((PCPATCH*)pu2);
    pcfree(wkb1);
}
Example #11
0
static void
test_endian_flip()
{
	PCPOINT *pt;
	double a1, a2, a3, a4, b1, b2, b3, b4;
	int rv;
	uint8_t *ptr;

	/* All at once */
	pt = pc_point_make(schema);
	a1 = 1.5;
	a2 = 1501500.12;
	a3 = 19112;
	a4 = 200;
	rv = pc_point_set_double_by_name(pt, "X", a1);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_set_double_by_name(pt, "Z", a2);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_set_double_by_name(pt, "Intensity", a3);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_set_double_by_name(pt, "UserData", a4);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "X", &b1);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Z", &b2);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Intensity", &b3);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "UserData", &b4);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);

	ptr = uncompressed_bytes_flip_endian(pt->data, schema, 1);
	pcfree(pt->data);
	pt->data = uncompressed_bytes_flip_endian(ptr, schema, 1);
	pcfree(ptr);

	rv = pc_point_get_double_by_name(pt, "X", &b1);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Z", &b2);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "Intensity", &b3);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	rv = pc_point_get_double_by_name(pt, "UserData", &b4);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);
	CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001);
	CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001);

	pc_point_free(pt);
}
Example #12
0
void lingot_config_test() {

    lingot_config_create_parameter_specs();
    LingotConfig* config = lingot_config_new();

    CU_ASSERT_PTR_NOT_NULL_FATAL(config);

    lingot_config_load(config, "resources/lingot-001.conf");

    CU_ASSERT_EQUAL(config->audio_system, AUDIO_SYSTEM_PULSEAUDIO);
    CU_ASSERT(
        !strcmp(config->audio_dev[config->audio_system], "alsa_input.pci-0000_00_1b.0.analog-stereo"));
    CU_ASSERT_EQUAL(config->sample_rate, 44100);
    CU_ASSERT_EQUAL(config->oversampling, 25);
    CU_ASSERT_EQUAL(config->root_frequency_error, 0.0);
    CU_ASSERT_EQUAL(config->min_frequency, 15.0);
    CU_ASSERT_EQUAL(config->sample_rate, 44100);
    CU_ASSERT_EQUAL(config->fft_size, 512);
    CU_ASSERT_EQUAL(config->temporal_window, ((FLT) 0.32));
    CU_ASSERT_EQUAL(config->min_overall_SNR, 20.0);
    CU_ASSERT_EQUAL(config->calculation_rate, 20.0);
    CU_ASSERT_EQUAL(config->visualization_rate, 30.0);
    CU_ASSERT_EQUAL(config->peak_number, 3);
    CU_ASSERT_EQUAL(config->peak_half_width, 1);

    lingot_config_destroy(config);
}
Example #13
0
static void
test_ofp_packet_input_gre_processed_inner_pkt_forwarded(void)
{
    odp_packet_t pkt;
    odp_event_t ev;
    int res;
    struct ofp_ether_header *eth;
    struct ofp_ip *ip;
    struct ofp_ip *ip_encap;
    uint32_t dst_ip;
    uint8_t dst_mac_addr[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};

    my_test_val = TEST_LOCAL_HOOK_GRE;
    /* Call ofp_packet_input using a GRE pkt with destination ip
     * that matches the local ip on ifnet, tunnel found, GRE processed.
     * Inner packet does not match local ip, route found,
     * packet forwarded */

    ifnet->ip_addr = local_ip;
    if (create_odp_packet_ip4(&pkt, gre_frame, sizeof(gre_frame),
                              local_ip, tun_rem_ip)) {
        CU_FAIL("Fail to create packet");
        return;
    }

    ip_encap = (struct ofp_ip *)&in_pkt_data[38];

    dst_ip = local_ip + 10;
    test_ofp_add_route(port, vrf, vlan, ip_encap->ip_dst.s_addr, 24, 4,
                       dst_ip);
    ofp_arp_ipv4_insert(dst_ip, dst_mac_addr, ifnet);

    res = ofp_packet_input(pkt, interface_queue[port],
                           ofp_eth_vlan_processing);

    CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED);

    CU_ASSERT_NOT_EQUAL_FATAL(ev = odp_queue_deq(ifnet->outq_def),
                              ODP_EVENT_INVALID);
#ifdef SP
    CU_ASSERT_EQUAL(odp_queue_deq(ifnet->spq_def), ODP_EVENT_INVALID);
#endif
    CU_ASSERT_EQUAL(odp_queue_deq(ifnet->outq_def), ODP_EVENT_INVALID);

    pkt = odp_packet_from_event(ev);
    eth = odp_packet_data(pkt);
    ip = odp_packet_l3_ptr(pkt, NULL);

    if (memcmp(eth->ether_dhost, dst_mac_addr, OFP_ETHER_ADDR_LEN))
        CU_FAIL("Bad destination mac address.");
    if (memcmp(eth->ether_shost, ifnet->mac, OFP_ETHER_ADDR_LEN))
        CU_FAIL("Bad source mac address.");

    CU_ASSERT_EQUAL(ip->ip_src.s_addr, ip_encap->ip_src.s_addr);
    CU_ASSERT_EQUAL(ip->ip_dst.s_addr, ip_encap->ip_dst.s_addr);

    if (memcmp(ip + (ip->ip_hl << 2), ip_encap + (ip->ip_hl << 2),
               odp_be_to_cpu_16(ip_encap->ip_len) - (ip->ip_hl << 2)))
        CU_FAIL("corrupt l3 + data");

    odp_packet_free(odp_packet_from_event(ev));
    ifnet->ip_addr = 0;
    CU_PASS("ofp_packet_input_gre_processed_inner_pkt_to_sp");
}
Example #14
0
static void
test_ofp_packet_input_forwarding_to_output(void)
{
    odp_packet_t pkt;
    odp_event_t ev;
    int res;

    /* Call ofp_packet_input using a pkt with destination ip
     * that does NOT match the local ip on ifnet and a route is found.
     * ARP is found for gateway IP.
     * Function returns OFP_PKT_PROCESSED and
     * packet is forwarded to ofp_ip_output.*/
    unsigned char ll_addr[13] = "123456789012";

    my_test_val = TEST_FORWARD_HOOK;

    CU_ASSERT_EQUAL(
        ofp_ipv4_lookup_mac(dst_ipaddr + 1, ll_addr, ifnet), -1);
    CU_ASSERT_EQUAL(
        ofp_arp_ipv4_insert(dst_ipaddr + 1, ll_addr, ifnet), 0);

    if (create_odp_packet_ip4(&pkt, test_frame, sizeof(test_frame),
                              dst_ipaddr, 0)) {
        CU_FAIL("Fail to create packet");
        return;
    }

    res = ofp_packet_input(pkt, interface_queue[port],
                           ofp_eth_vlan_processing);
    CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED);
    CU_ASSERT_NOT_EQUAL(ev = odp_queue_deq(ifnet->outq_def),
                        ODP_EVENT_INVALID);
    CU_ASSERT_EQUAL(odp_queue_deq(ifnet->outq_def), ODP_EVENT_INVALID);

#ifdef SP
    CU_ASSERT_EQUAL(odp_queue_deq(ifnet->spq_def), ODP_EVENT_INVALID);
#endif /* SP */

    CU_ASSERT_EQUAL(odp_packet_len(pkt), sizeof(test_frame));

    pkt = odp_packet_from_event(ev);
    struct ofp_ip *ip_in_pkt_data =
        (struct ofp_ip *)(in_pkt_data + OFP_ETHER_HDR_LEN);
    ip_in_pkt_data->ip_ttl--;

#ifdef OFP_PERFORMANCE
    /*checksum is not filled on ip_output*/
    ip_in_pkt_data->ip_sum =
        ((struct ofp_ip *)odp_packet_l3_ptr(pkt, NULL))->ip_sum;
#else
    ip_in_pkt_data->ip_sum = 0;
    ip_in_pkt_data->ip_sum = ofp_cksum_buffer((uint16_t *)ip_in_pkt_data,
                             ip_in_pkt_data->ip_hl<<2);

#endif

    if (memcmp((uint8_t *)odp_packet_data(pkt) + odp_packet_l3_offset(pkt),
               in_pkt_data + OFP_ETHER_HDR_LEN,
               sizeof(test_frame) - OFP_ETHER_HDR_LEN))
        CU_FAIL("corrupt l3 + data forwarded");
    struct ofp_ether_header *eth =
        (struct ofp_ether_header *)odp_packet_l2_ptr(pkt, NULL);

    if (memcmp(eth->ether_dhost, ll_addr, OFP_ETHER_ADDR_LEN))
        CU_FAIL("Bad destination mac address on the forwarded packet");
    CU_ASSERT_EQUAL(eth->ether_type, odp_cpu_to_be_16(OFP_ETHERTYPE_IP));

    CU_PASS("ofp_packet_input_forwarding_to_output");
}
Example #15
0
void test_binop_cf(void)
{
	/* + */
	CALC_ELEMENT *e1 = create_number(3.0), *e2 = create_number(-4.0);
	CALC_ELEMENT *expr = create_bin_op('+', e1, e2);
	CU_ASSERT_PTR_NOT_NULL(expr);
	CU_ASSERT_EQUAL(expr->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(expr->bin_op, '+');
	CU_ASSERT_EQUAL(expr->status, 0);
	CU_ASSERT_EQUAL(expr->value, 1.0);
	CU_ASSERT_PTR_NOT_NULL(expr->left);
	CU_ASSERT_PTR_NOT_NULL(expr->right);
	free_calc_element(expr);

	/* - */
	e1 = create_number(-7.0);
	e2 = create_number(9.0);
	expr = create_bin_op('-', e1, e2);
	CU_ASSERT_PTR_NOT_NULL(expr);
	CU_ASSERT_EQUAL(expr->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(expr->bin_op, '+');
	CU_ASSERT_EQUAL(expr->status, 0);
	CU_ASSERT_EQUAL(expr->value, 1.0);
	CU_ASSERT_PTR_NOT_NULL(expr->left);
	CU_ASSERT_PTR_NOT_NULL(expr->right);
	CU_ASSERT_EQUAL(expr->right->value, -9.0);
	free_calc_element(expr);

	/* * */
	e1 = create_number(3.0);
	e2 = create_number(11.5);
	expr = create_bin_op('*', e1, e2);
	CU_ASSERT_PTR_NOT_NULL(expr);
	CU_ASSERT_EQUAL(expr->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(expr->bin_op, '*');
	CU_ASSERT_EQUAL(expr->status, 0);
	CU_ASSERT_EQUAL(expr->value, 1.0);
	CU_ASSERT_PTR_NOT_NULL(expr->left);
	CU_ASSERT_PTR_NOT_NULL(expr->right);
	free_calc_element(expr);

	/* /, only numbers */
	e1 = create_number(-7.0);
	e2 = create_number(5.0);
	expr = create_bin_op('/', e1, e2);
	CU_ASSERT_PTR_NOT_NULL(expr);
	CU_ASSERT_EQUAL(expr->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(expr->bin_op, '/');
	CU_ASSERT_EQUAL(expr->status, 0);
	CU_ASSERT_EQUAL(expr->value, 1.0);
	CU_ASSERT_PTR_NOT_NULL(expr->left);
	CU_ASSERT_PTR_NOT_NULL(expr->right);
	free_calc_element(expr);

	/* /, with an x */
	e1 = create_x();
	e2 = create_number(2.0);
	expr = create_bin_op('/', e1, e2);
	CU_ASSERT_PTR_NOT_NULL(expr);
	CU_ASSERT_EQUAL(expr->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(expr->bin_op, '/');
	CU_ASSERT_EQUAL(expr->status, STATUS_X_PRESENT | STATUS_X_IN_DIV);
	CU_ASSERT_EQUAL(expr->value, 1.0);
	CU_ASSERT_PTR_NOT_NULL(expr->left);
	CU_ASSERT_PTR_NOT_NULL(expr->right);
	free_calc_element(expr);
}
Example #16
0
static void test_gdal_to_raster() {
	rt_pixtype pixtype = PT_64BF;
	rt_band band = NULL;

	rt_raster raster;
	rt_raster rast;
	const uint32_t width = 100;
	const uint32_t height = 100;
	uint32_t x;
	uint32_t y;
	int v;
	double values[width][height];
	int rtn = 0;
	double value;

	GDALDriverH gddrv = NULL;
	int destroy = 0;
	GDALDatasetH gdds = NULL;

	raster = rt_raster_new(width, height);
	CU_ASSERT(raster != NULL); /* or we're out of virtual memory */

	band = cu_add_band(raster, pixtype, 1, 0);
	CU_ASSERT(band != NULL);

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1);
			rt_band_set_pixel(band, x, y, values[x][y], NULL);
		}
	}

	gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
	CU_ASSERT(gddrv != NULL);
	CU_ASSERT_EQUAL(destroy, 0);
	CU_ASSERT(gdds != NULL);
	CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
	CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);

	rast = rt_raster_from_gdal_dataset(gdds);
	CU_ASSERT(rast != NULL);
	CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);

	band = rt_raster_get_band(rast, 0);
	CU_ASSERT(band != NULL);

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			rtn = rt_band_get_pixel(band, x, y, &value, NULL);
 			CU_ASSERT_EQUAL(rtn, ES_NONE);
			CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], DBL_EPSILON);
		}
	}

	GDALClose(gdds);
	gdds = NULL;
	gddrv = NULL;

	cu_free_raster(rast);
	cu_free_raster(raster);

	raster = rt_raster_new(width, height);
	CU_ASSERT(raster != NULL); /* or we're out of virtual memory */

	pixtype = PT_8BSI;
	band = cu_add_band(raster, pixtype, 1, 0);
	CU_ASSERT(band != NULL);

	v = -127;
	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			values[x][y] = v++;
			rt_band_set_pixel(band, x, y, values[x][y], NULL);
			if (v == 128)
				v = -127;
		}
	}

	gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
	CU_ASSERT(gddrv != NULL);
	CU_ASSERT_EQUAL(destroy, 0);
	CU_ASSERT(gdds != NULL);
	CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
	CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);

	rast = rt_raster_from_gdal_dataset(gdds);
	CU_ASSERT(rast != NULL);
	CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);

	band = rt_raster_get_band(rast, 0);
	CU_ASSERT(band != NULL);
	CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_16BSI);

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			rtn = rt_band_get_pixel(band, x, y, &value, NULL);
 			CU_ASSERT_EQUAL(rtn, ES_NONE);
			CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], 1.);
		}
	}

	GDALClose(gdds);
	gdds = NULL;
	gddrv = NULL;

	cu_free_raster(rast);
	cu_free_raster(raster);
}
Example #17
0
void test_lexer(void)
{
	strcpy(in_line, "14.5");
	line_len = 4;
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(14.5, get_current_number());
	clear_line();

	strcpy(in_line, "(3+(4-1))*5");
	line_len = 11;
	CU_ASSERT_TRUE(accept(PARSE_LPAREN));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(3, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_ADD));
	CU_ASSERT_TRUE(accept(PARSE_LPAREN));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(4, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_SUB));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(1, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_RPAREN));
	CU_ASSERT_TRUE(accept(PARSE_RPAREN));
	CU_ASSERT_TRUE(accept(PARSE_MULT));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(5, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_NLINE));
	clear_line();

	strcpy(in_line, "2 * x + 0.5 = 1");
	line_len = 15;
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(2, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_MULT));
	CU_ASSERT_TRUE(accept(PARSE_X));
	CU_ASSERT_TRUE(accept(PARSE_ADD));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(0.5, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_EQUAL));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(1, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_NLINE));
	clear_line();

	strcpy(in_line, "2x + 1 = 2(1-x)");
	line_len = 15;
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(2, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_MULT));
	CU_ASSERT_TRUE(accept(PARSE_X));
	CU_ASSERT_TRUE(accept(PARSE_ADD));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(1, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_EQUAL));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(2, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_MULT));
	CU_ASSERT_TRUE(accept(PARSE_LPAREN));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(1, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_SUB));
	CU_ASSERT_TRUE(accept(PARSE_X));
	CU_ASSERT_TRUE(accept(PARSE_RPAREN));
	CU_ASSERT_TRUE(accept(PARSE_NLINE));
	clear_line();

	strcpy(in_line, "8a - 4b = 3");
	line_len = 11;
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(8, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_BAD));
	CU_ASSERT_TRUE(accept(PARSE_SUB));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(4, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_BAD));
	CU_ASSERT_TRUE(accept(PARSE_EQUAL));
	CU_ASSERT_TRUE(accept(PARSE_NUMBER));
	CU_ASSERT_EQUAL(3, get_current_number());
	CU_ASSERT_TRUE(accept(PARSE_NLINE));
	clear_line();
}
Example #18
0
void
test_writesame16_unmap(void)
{
	int i, ret;
	unsigned int j;
	unsigned char *buf;

	CHECK_FOR_DATALOSS;
	CHECK_FOR_THIN_PROVISIONING;
	CHECK_FOR_LBPWS;
	CHECK_FOR_SBC;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN");
	buf = malloc(65536 * block_size);
	for (i = 1; i <= 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(iscsic, tgt_lun, 0,
			      i * block_size, block_size,
			      0, 0, 0, 0, 0, buf);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(iscsic, tgt_lun, 0,
				  block_size, i,
				  0, 1, 0, 0, buf);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented.");
			CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test");
			goto finished;
		}
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");
			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(iscsic, tgt_lun, 0,
				     i * block_size, block_size,
				     0, 0, 0, 0, 0, buf);
			for (j = 0; j < block_size * i; j++) {
				if (buf[j] != 0) {
					CU_ASSERT_EQUAL(buf[j], 0);
				}
			}
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	}


	logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN");
	for (i = 1; i <= 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(iscsic, tgt_lun, num_blocks - i,
			      i * block_size, block_size,
			      0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(iscsic, tgt_lun, num_blocks - i,
				  block_size, i,
				  0, 1, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");
			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(iscsic, tgt_lun, num_blocks - i,
				     i * block_size, block_size,
				     0, 0, 0, 0, 0, buf);
			for (j = 0; j < block_size * i; j++) {
				if (buf[j] != 0) {
					CU_ASSERT_EQUAL(buf[j], 0);
				}
			}
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	}

	logging(LOG_VERBOSE, "Verify that WRITESAME16 ANCHOR==1 + UNMAP==0 is invalid");
	ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0,
					    block_size, 1,
					    1, 0, 0, 0, buf);
	CU_ASSERT_EQUAL(ret, 0);



	if (inq_lbp->anc_sup) {
		logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0");
		memset(buf, 0, block_size);
		ret = writesame16(iscsic, tgt_lun, 0,
				  block_size, 1,
				  1, 1, 0, 0, buf);
	} else {
		logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0 no ANC_SUP so expecting to fail");
		ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0,
						    block_size, 1,
						    1, 1, 0, 0, buf);
	}

	CU_ASSERT_EQUAL(ret, 0);


	if (inq_bl == NULL) {
		logging(LOG_VERBOSE, "[FAILED] WRITESAME16 works but "
			"BlockLimits VPD is missing.");
		CU_FAIL("[FAILED] WRITESAME16 works but "
			"BlockLimits VPD is missing.");
		goto finished;
	}

	i = 256;
	if (inq_bl->max_ws_len == 0 || inq_bl->max_ws_len >= 256) {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as either 0 (==no limit) or >= 256. Test Unmapping "
			"256 blocks to verify that it can handle 2-byte "
			"lengths");

		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(iscsic, tgt_lun, 0,
			      i * block_size, block_size,
			      0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(iscsic, tgt_lun, 0,
				  block_size, i,
				  0, 1, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");

			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(iscsic, tgt_lun, 0,
				i * block_size, block_size,
				0, 0, 0, 0, 0, buf);
			for (j = 0; j < block_size * i; j++) {
				if (buf[j] != 0) {
					CU_ASSERT_EQUAL(buf[j], 0);
				}
			}
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	} else {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as <256. Verify that a 256 block unmap fails with "
			"INVALID_FIELD_IN_CDB.");

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0,
				  block_size, i,
				  0, 1, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);
	}


	i = 65536;
	if (inq_bl->max_ws_len == 0 || inq_bl->max_ws_len >= 256) {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as either 0 (==no limit) or >= 256. Test Unmapping "
			"256 blocks to verify that it can handle 2-byte "
			"lengths");

		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(iscsic, tgt_lun, 0,
			      i * block_size, block_size,
			      0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(iscsic, tgt_lun, 0,
				  block_size, i,
				  0, 1, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");

			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(iscsic, tgt_lun, 0,
				i * block_size, block_size,
				0, 0, 0, 0, 0, buf);
			for (j = 0; j < block_size * i; j++) {
				if (buf[j] != 0) {
					CU_ASSERT_EQUAL(buf[j], 0);
				}
			}
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	} else {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as <256. Verify that a 256 block unmap fails with "
			"INVALID_FIELD_IN_CDB.");

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0,
				  block_size, i,
				  0, 1, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);
	}

finished:
	free(buf);
}
Example #19
0
void test_memory_is_copied_1(void)
{
	ihex_recordset_t *rs  = ihex_rs_from_file("res/big-a.hex");
	uint8_t          *dst = (uint8_t*) malloc(8192);

	if (rs == NULL)
	{
		CU_FAIL("File \"res/big-a.hex\" does not exist.");
		return;
	}
	
	ihex_mem_copy(rs, dst, 8192, IHEX_WIDTH_8BIT, IHEX_ORDER_BIGENDIAN);
	
	// :100400000B 0B 0B 98 B0 2D 0B 0B 0B 88 80 04 00 00 00 00 29
	CU_ASSERT_EQUAL(dst[0x400], 0x0B);
	CU_ASSERT_EQUAL(dst[0x401], 0x0B);
	CU_ASSERT_EQUAL(dst[0x402], 0x0B);
	CU_ASSERT_EQUAL(dst[0x403], 0x98);
	CU_ASSERT_EQUAL(dst[0x404], 0xB0);
	CU_ASSERT_EQUAL(dst[0x405], 0x2D);
	CU_ASSERT_EQUAL(dst[0x406], 0x0B);
	CU_ASSERT_EQUAL(dst[0x407], 0x0B);
	CU_ASSERT_EQUAL(dst[0x408], 0x0B);
	CU_ASSERT_EQUAL(dst[0x409], 0x88);
	CU_ASSERT_EQUAL(dst[0x40A], 0x80);
	CU_ASSERT_EQUAL(dst[0x40B], 0x04);
	CU_ASSERT_EQUAL(dst[0x40C], 0x00);
	CU_ASSERT_EQUAL(dst[0x40D], 0x00);
	CU_ASSERT_EQUAL(dst[0x40E], 0x00);
	CU_ASSERT_EQUAL(dst[0x40F], 0x00);
}
Example #20
0
//--------------------------------------------------------------------------------------------------
void Test_pa_audio_SetGain()
{
    uint32_t gain;

    for(gain=0; gain<150;gain+=5) {
        if (gain>100) {
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_CODEC_MIC,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_CODEC_SPEAKER,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_FRONTEND_USB_RX,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_FRONTEND_USB_TX,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_RX,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_TX,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_FILE_PLAYING,gain),LE_OUT_OF_RANGE);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_END,gain),LE_OUT_OF_RANGE);
        } else {
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_CODEC_MIC,gain),LE_OK);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_CODEC_SPEAKER,gain),LE_OK);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_FRONTEND_USB_RX,gain),LE_FAULT);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_FRONTEND_USB_TX,gain),LE_FAULT);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_RX,gain),LE_FAULT);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_TX,gain),LE_FAULT);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_FILE_PLAYING,gain),LE_FAULT);
            CU_ASSERT_EQUAL(pa_audio_SetGain(PA_AUDIO_IF_END,gain),LE_FAULT);
        }
    }


}
Example #21
0
void test_basic(dict *dct, const struct key_info *keys, const unsigned nkeys) {
    CU_ASSERT_TRUE(dict_verify(dct));

    for (unsigned i = 0; i < nkeys; ++i) {
	void **datum_location = NULL;
	CU_ASSERT_TRUE(dict_insert(dct, keys[i].key, &datum_location));
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	*datum_location = keys[i].value;

	CU_ASSERT_TRUE(dict_verify(dct));

	for (unsigned j = 0; j <= i; ++j)
	    CU_ASSERT_EQUAL(dict_search(dct, keys[j].key), keys[j].value);
	for (unsigned j = i + 1; j < nkeys; ++j)
	    CU_ASSERT_EQUAL(dict_search(dct, keys[j].key), NULL);
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);

    if (dct->_vtable->insert == (dict_insert_func)hashtable_insert) {
	/* Verify that hashtable_resize works as expected. */
	dict *clone = dict_clone(dct, NULL);
	CU_ASSERT_TRUE(dict_verify(dct));
	CU_ASSERT_TRUE(hashtable_resize(dict_private(clone), 3));
	CU_ASSERT_TRUE(dict_verify(dct));
	for (unsigned j = 0; j < nkeys; ++j)
	    CU_ASSERT_EQUAL(dict_search(clone, keys[j].key), keys[j].value);
	dict_free(clone);
    }

    if (dct->_vtable->clone) {
	dict *clone = dict_clone(dct, NULL);
	CU_ASSERT_PTR_NOT_NULL(clone);
	CU_ASSERT_TRUE(dict_verify(clone));
	CU_ASSERT_EQUAL(dict_count(clone), nkeys);
	for (unsigned i = 0; i < nkeys; ++i) {
	    CU_ASSERT_EQUAL(dict_search(clone, keys[i].key), keys[i].value);
	}
	for (unsigned i = 0; i < nkeys; ++i) {
	    CU_ASSERT_TRUE(dict_remove(clone, keys[i].key));
	}
	dict_free(clone);
    }

    for (unsigned i = 0; i < nkeys; ++i)
	CU_ASSERT_EQUAL(dict_search(dct, keys[i].key), keys[i].value);

    for (unsigned i = 0; i < nkeys; ++i) {
	void **datum_location = NULL;
	CU_ASSERT_FALSE(dict_insert(dct, keys[i].key, &datum_location));
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	CU_ASSERT_EQUAL(*datum_location, keys[i].value);

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);

    dict_itor *itor = dict_itor_new(dct);
    CU_ASSERT_PTR_NOT_NULL(itor);
    char *last_key = NULL;
    unsigned n = 0;
    for (dict_itor_first(itor); dict_itor_valid(itor); dict_itor_next(itor)) {
	CU_ASSERT_PTR_NOT_NULL(dict_itor_key(itor));
	CU_ASSERT_PTR_NOT_NULL(dict_itor_data(itor));
	++n;
	if (dct->_vtable->insert != (dict_insert_func)hashtable_insert) {
	    if (last_key) {
		CU_ASSERT_TRUE(strcmp(last_key, dict_itor_key(itor)) < 0);
	    }
	    last_key = dict_itor_key(itor);
	}
    }
    CU_ASSERT_EQUAL(n, nkeys);
    last_key = NULL;
    n = 0;
    for (dict_itor_last(itor); dict_itor_valid(itor); dict_itor_prev(itor)) {
	CU_ASSERT_PTR_NOT_NULL(dict_itor_key(itor));
	CU_ASSERT_PTR_NOT_NULL(dict_itor_data(itor));
	++n;
	if (dct->_vtable->insert != (dict_insert_func)hashtable_insert) {
	    if (last_key) {
		CU_ASSERT_TRUE(strcmp(last_key, dict_itor_key(itor)) > 0);
	    }
	    last_key = dict_itor_key(itor);
	}
    }
    CU_ASSERT_EQUAL(n, nkeys);
    dict_itor_free(itor);

    for (unsigned i = 0; i < nkeys; ++i) {
	void **datum_location = NULL;
	CU_ASSERT_FALSE(dict_insert(dct, keys[i].key, &datum_location));
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	*datum_location = keys[i].alt;

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);

    for (unsigned i = 0; i < nkeys; ++i)
	CU_ASSERT_EQUAL(dict_search(dct, keys[i].key), keys[i].alt);

    for (unsigned i = 0; i < nkeys; ++i) {
	CU_ASSERT_EQUAL(dict_search(dct, keys[i].key), keys[i].alt);
	CU_ASSERT_TRUE(dict_remove(dct, keys[i].key));
	CU_ASSERT_TRUE(dict_verify(dct));

	CU_ASSERT_EQUAL(dict_remove(dct, keys[i].key), false);
	for (unsigned j = 0; j <= i; ++j) {
	    CU_ASSERT_EQUAL(dict_search(dct, keys[j].key), NULL);
	}
	for (unsigned j = i + 1; j < nkeys; ++j) {
	    CU_ASSERT_EQUAL(dict_search(dct, keys[j].key), keys[j].alt);
	}
    }

    for (unsigned i = 0; i < nkeys; ++i) {
	void **datum_location = NULL;
	CU_ASSERT_TRUE(dict_insert(dct, keys[i].key, &datum_location));
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	*datum_location = keys[i].value;

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);
    CU_ASSERT_EQUAL(dict_clear(dct), nkeys);

    for (unsigned i = 0; i < nkeys; ++i) {
	void **datum_location = NULL;
	CU_ASSERT_TRUE(dict_insert(dct, keys[i].key, &datum_location));
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	*datum_location = keys[i].value;

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);
    CU_ASSERT_EQUAL(dict_free(dct), nkeys);
}
Example #22
0
void
test_orwrite_verify(void)
{
	int i, ret;
	unsigned char *buf     = alloca(256 * block_size);
	unsigned char *readbuf = alloca(256 * block_size);


	CHECK_FOR_DATALOSS;
	CHECK_FOR_SBC;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test ORWRITE of 1-256 blocks at the start of the LUN");
	for (i = 1; i <= 256; i++) {
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}

		logging(LOG_VERBOSE, "Write %d blocks of all-zero", i);
		memset(buf, 0, block_size * i);
		ret = write10(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "OrWrite %d blocks with 0xa5", i);
		memset(buf, 0xa5, block_size * i);
		ret = orwrite(iscsic, tgt_lun, 0, i * block_size,
			      block_size, 0, 0, 0, 0, 0, buf);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented.");
			CU_PASS("ORWRITE is not implemented.");
			return;
		}	
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks back", i);
		ret = read10(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, readbuf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Verify that the blocks are all 0xa5");
		ret = memcmp(buf, readbuf, block_size * i);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "OrWrite %d blocks with 0x5a", i);
		memset(buf, 0x5a, block_size * i);
		ret = orwrite(iscsic, tgt_lun, 0, i * block_size,
			      block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks back", i);
		ret = read10(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, readbuf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Verify that the blocks are all 0xff");
		memset(buf, 0xff, block_size * i);
		ret = memcmp(buf, readbuf, block_size * i);
		CU_ASSERT_EQUAL(ret, 0);
	}

	logging(LOG_VERBOSE, "Test ORWRITE of 1-256 blocks at the end of the LUN");
	for (i = 1; i <= 256; i++) {
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}

		logging(LOG_VERBOSE, "Write %d blocks of all-zero", i);
		memset(buf, 0, block_size * i);
		ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "OrWrite %d blocks with 0xa5", i);
		memset(buf, 0xa5, block_size * i);
		ret = orwrite(iscsic, tgt_lun, num_blocks - i, i * block_size,
			      block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks back", i);
		ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, readbuf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Verify that the blocks are all 0xa5");
		ret = memcmp(buf, readbuf, block_size * i);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "OrWrite %d blocks with 0x5a", i);
		memset(buf, 0x5a, block_size * i);
		ret = orwrite(iscsic, tgt_lun, num_blocks - i, i * block_size,
			      block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks back", i);
		ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, readbuf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Verify that the blocks are all 0xff");
		memset(buf, 0xff, block_size * i);
		ret = memcmp(buf, readbuf, block_size * i);
		CU_ASSERT_EQUAL(ret, 0);
	}
}
void
test_modesense6_control_swp(void)
{
	struct scsi_task *ms_task = NULL;
	struct scsi_mode_sense *ms;
	struct scsi_mode_page *page;
	unsigned char *buf = alloca(block_size);
	int ret;

	CHECK_FOR_DATALOSS;
	CHECK_FOR_SBC;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test of MODESENSE6 CONTROL SWP flag");


	logging(LOG_VERBOSE, "Set SWP to enable write protect");
	ret = set_swp(sd);
	CU_ASSERT_EQUAL(ret, 0);
	if (ret) {
		goto finished;
	}

	logging(LOG_VERBOSE, "Read the CONTROL page back from the device");
	ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT,
			 SCSI_MODEPAGE_CONTROL, 0, 255,
			 EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);
	logging(LOG_VERBOSE, "[SUCCESS] CONTROL page fetched.");

	logging(LOG_VERBOSE, "Try to unmarshall the DATA-IN buffer.");
	ms = scsi_datain_unmarshall(ms_task);
	if (ms == NULL) {
		logging(LOG_NORMAL, "[FAILED] failed to unmarshall mode sense "
			"datain buffer");
		CU_FAIL("[FAILED] Failed to unmarshall the data-in buffer.");
		goto finished;
	}
	logging(LOG_VERBOSE, "[SUCCESS] Unmarshalling successful.");
	for (page = ms->pages; page; page = page->next) {
		if (page->page_code == SCSI_MODEPAGE_CONTROL) {
			break;
		}
	}
	if(page == NULL) {
		logging(LOG_NORMAL, "[WARNING] CONTROL page was not returned."
			"All devices SHOULD implement this page.");
	}

	logging(LOG_VERBOSE, "Verify that the SWP bit is set");
	if (page->control.swp == 0) {
		logging(LOG_NORMAL, "[FAILED] SWP bit is not set");
		CU_FAIL("[FAILED] SWP is not set");
		goto finished;
	}
	logging(LOG_VERBOSE, "[SUCCESS] SWP was set successfully");


	logging(LOG_VERBOSE, "Read a block from the now Read-Only device");
	ret = read10(sd, NULL, 0, block_size,
		     block_size, 0, 0, 0, 0, 0, buf,
		     EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Try to write a block to the Read-Only device");
	ret = write10(sd, 0, block_size,
		      block_size, 0, 0, 0, 0, 0, buf,
		      EXPECT_WRITE_PROTECTED);
	CU_ASSERT_EQUAL(ret, 0);


 finished:
	if (ms_task != NULL) {
		scsi_free_scsi_task(ms_task);
	}
	logging(LOG_VERBOSE, "Clear SWP to disable write protect");
	clear_swp(sd);
}
Example #24
0
void test_create_access_axb(void)
{
	CALC_ELEMENT *t1 = create_ax_b(0.0, 0.0);
	double a, b;
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 0.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	get_ax_b(t1, &a, &b);
	CU_ASSERT_EQUAL(a, 0.0);
	CU_ASSERT_EQUAL(b, 0.0);
	free_calc_element(t1);

	t1 = create_ax_b(6.0, 0.0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_X);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(t1->value, 6.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	get_ax_b(t1, &a, &b);
	CU_ASSERT_EQUAL(a, 6.0);
	CU_ASSERT_EQUAL(b, 0.0);
	free_calc_element(t1);

	t1 = create_ax_b(-3.0, 2.25);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(t1->value, 1.0);
	CU_ASSERT_PTR_NOT_NULL(t1->left);
	CU_ASSERT_PTR_NOT_NULL(t1->right);
	get_ax_b(t1, &a, &b);
	CU_ASSERT_EQUAL(a, -3.0);
	CU_ASSERT_EQUAL(b, 2.25);
	free_calc_element(t1);

	t1 = create_ax_b(2, -3);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	t1->value *= -0.5;
	get_ax_b(t1, &a, &b);
	CU_ASSERT_EQUAL(a, -1.0);
	CU_ASSERT_EQUAL(b, 1.5);
	free_calc_element(t1);
}
void test_VIDIOC_S_FREQUENCY_boundaries() {
    int ret_g_tuner = 0;
    int ret_g_freq = 0;
    int errno_g_tuner = 0;
    int errno_g_freq = 0;
    int ret;
    __u32 index;
    struct v4l2_frequency orig_freq;
    struct v4l2_frequency freq;
    struct v4l2_frequency new_freq;
    struct v4l2_tuner tuner;

    /* this test case depends on working VIDIOC_G_TUNER and VIDIOC_G_FREQUENCY commands */

    index = 0;

    /* fetch the minimum (tuner.rangelow) and maximum (tuner.rangehigh) frequency */
    memset(&tuner, 0xff, sizeof(tuner));
    tuner.index = index;
    ret_g_tuner = ioctl(get_video_fd(), VIDIOC_G_TUNER, &tuner);
    errno_g_tuner = errno;

    dprintf("\t%s:%u: VIDIOC_G_TUNER, ret=%i, tuner.rangelow=%u, tuner.rangehigh=%u\n",
            __FILE__, __LINE__,
            ret_g_tuner, tuner.rangelow, tuner.rangehigh);
    CU_ASSERT_EQUAL(tuner.index, index);

    /* fetch the current frequency setting */
    memset(&orig_freq, 0xff, sizeof(orig_freq));
    orig_freq.tuner = index;
    ret_g_freq = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &orig_freq);
    errno_g_freq = errno;

    dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_g_freq=%i, orig_freq.frequency=%u\n",
            __FILE__, __LINE__,
            ret_g_freq, orig_freq.frequency);
    CU_ASSERT_EQUAL(orig_freq.tuner, index);

    if (ret_g_tuner == 0 && ret_g_freq == 0) {
        CU_ASSERT_EQUAL(orig_freq.tuner, index);

        /* try to set the frequency to zero */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = index;
        freq.type = orig_freq.type;
        freq.frequency = 0;
        ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
        dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                __FILE__, __LINE__,
                0, ret);

        CU_ASSERT_EQUAL(ret, 0);
        if (ret == 0) {

            /* check wheteher the frequency has been changed to the lowest
             * possible value
             */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = index;
            ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret, new_freq.frequency);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {
                CU_ASSERT_EQUAL(new_freq.frequency, tuner.rangelow);
            }
        }

        /* try to set the frequency to tuner.rangelow-1, if applicable */
        if (0 < tuner.rangelow) {
            memset(&freq, 0xff, sizeof(freq));
            freq.tuner = index;
            freq.type = orig_freq.type;
            freq.frequency = tuner.rangelow-1;
            ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);

            dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                    __FILE__, __LINE__,
                    tuner.rangelow-1, ret);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {

                /* check wheteher the frequency has been changed to the lowest
                 * possible value
                 */
                memset(&new_freq, 0xff, sizeof(new_freq));
                new_freq.tuner = index;
                ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

                dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                        __FILE__, __LINE__,
                        ret, new_freq.frequency);
                CU_ASSERT_EQUAL(ret, 0);
                if (ret == 0) {
                    dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                            __FILE__, __LINE__,
                            new_freq.frequency, tuner.rangelow);
                    CU_ASSERT_EQUAL(new_freq.frequency, tuner.rangelow);
                }
            }
        }

        /* try to set the frequency to tuner.rangelow */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = index;
        freq.type = orig_freq.type;
        freq.frequency = tuner.rangelow;
        ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);

        dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                __FILE__, __LINE__,
                tuner.rangelow, ret);

        CU_ASSERT_EQUAL(ret, 0);
        if (ret == 0) {

            /* check wheteher the frequency has been changed to the lowest
             * possible value
             */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = index;
            ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret, new_freq.frequency);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {
                dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                        __FILE__, __LINE__,
                        new_freq.frequency, tuner.rangelow);
                CU_ASSERT_EQUAL(new_freq.frequency, tuner.rangelow);
            }
        }

        /* try to set the frequency to tuner.rangehigh */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = index;
        freq.type = orig_freq.type;
        freq.frequency = tuner.rangehigh;
        ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);

        dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                __FILE__, __LINE__,
                tuner.rangehigh, ret);

        CU_ASSERT_EQUAL(ret, 0);
        if (ret == 0) {

            /* check wheteher the frequency has been changed to the highest
             * possible value
             */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = index;
            ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret, new_freq.frequency);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {
                dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                        __FILE__, __LINE__,
                        new_freq.frequency, tuner.rangehigh);
                CU_ASSERT_EQUAL(new_freq.frequency, tuner.rangehigh);
            }
        }

        /* try to set the frequency to tuner.rangehigh+1, if applicable */
        if (tuner.rangehigh < U32_MAX) {
            memset(&freq, 0xff, sizeof(freq));
            freq.tuner = index;
            freq.type = orig_freq.type;
            freq.frequency = tuner.rangehigh+1;
            ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);

            dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                    __FILE__, __LINE__,
                    tuner.rangehigh+1, ret);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {

                /* check wheteher the frequency has been changed to the highest
                 * possible value
                 */
                memset(&new_freq, 0xff, sizeof(new_freq));
                new_freq.tuner = index;
                ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

                dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                        __FILE__, __LINE__,
                        ret, new_freq.frequency);

                CU_ASSERT_EQUAL(ret, 0);
                if (ret == 0) {
                    dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                            __FILE__, __LINE__,
                            new_freq.frequency, tuner.rangehigh);
                    CU_ASSERT_EQUAL(new_freq.frequency, tuner.rangehigh);
                }
            }
        }

        /* try to set the frequency to U32_MAX */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = index;
        freq.type = orig_freq.type;
        freq.frequency = U32_MAX;
        ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);

        dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                __FILE__, __LINE__,
                U32_MAX, ret);
        CU_ASSERT_EQUAL(ret, 0);
        if (ret == 0) {

            /* check wheteher the frequency has been changed to the highest
             * possible value
             */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = index;
            ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret, new_freq.frequency);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {
                dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                        __FILE__, __LINE__,
                        new_freq.frequency, tuner.rangehigh);
                CU_ASSERT_EQUAL(new_freq.frequency, tuner.rangehigh);
            }
        }

        /* try restore the original frequency settings */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = index;
        freq.type = orig_freq.type;
        freq.frequency = orig_freq.frequency;
        ret = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);

        dprintf("\t%s:%u: set to %u: VIDIOC_S_FREQUENCY, ret=%i\n",
                __FILE__, __LINE__,
                orig_freq.frequency, ret);

        CU_ASSERT_EQUAL(ret, 0);
        if (ret == 0) {

            /* check wheteher the frequency has been restored */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = index;
            ret = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret=%i, new_freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret, new_freq.frequency);

            CU_ASSERT_EQUAL(ret, 0);
            if (ret == 0) {
                dprintf("\t%s:%u: current frequency=%u (expected %u)\n",
                        __FILE__, __LINE__,
                        new_freq.frequency, orig_freq.frequency);
                CU_ASSERT_EQUAL(new_freq.frequency, orig_freq.frequency);
            }
        }
    }

    if (ret_g_freq != 0) {
        dprintf("\t%s:%u: ret_g_freq=%d (expected %d)\n", __FILE__, __LINE__, ret_g_freq, -1);
        dprintf("\t%s:%u: errno_g_freq=%d (expected %d)\n", __FILE__, __LINE__, errno_g_freq, EINVAL);
        CU_ASSERT_EQUAL(ret_g_freq, -1);
        CU_ASSERT_EQUAL(errno, EINVAL);
    }

    if (ret_g_tuner != 0) {
        dprintf("\t%s:%u: ret_g_tuner=%d (expected %d)\n", __FILE__, __LINE__, ret_g_tuner, -1);
        dprintf("\t%s:%u: errno_g_tuner=%d (expected %d)\n", __FILE__, __LINE__, errno_g_tuner, EINVAL);
        CU_ASSERT_EQUAL(ret_g_tuner, -1);
        CU_ASSERT_EQUAL(errno, EINVAL);
    }

}
Example #26
0
void test_canon_calc_good(void)
{
	CALC_ELEMENT *t1, *t2;
	/* single number */
	t1 = create_number(12.0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 12.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	/* addition */
	t1 = create_number(2.0);
	t2 = create_number(-3.5);
	t1 = create_bin_op('+', t1, t2);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, -1.5);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	/* substraction */
	t1 = create_number(-3.0);
	t2 = create_number(-4.25);
	t1 = create_bin_op('-', t1, t2);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 1.25);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	/* multiplication */
	t1 = create_number(4);
	t2 = create_number(1.25);
	t1 = create_bin_op('*', t1, t2);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 5.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	/* division */
	t1 = create_number(8.0);
	t2 = create_number(16.0);
	t1 = create_bin_op('/', t1, t2);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 0.5);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	/* natural logarithm */
	t1 = create_number(1.0);
	t1 = create_log(t1);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 0.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	t1 = create_number(M_E);
	t1 = create_log(t1);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 1.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);

	/* a slightly more complex example (3 + (4 - 1)) * 5 */
	t1 = create_number(4);
	t2 = create_number(1);
	t2 = create_bin_op('-', t1, t2);
	t1 = create_number(3);
	t1 = create_bin_op('+', t1, t2);
	t2 = create_number(5);
	t1 = create_bin_op('*', t1, t2);
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_PTR_NOT_NULL(t1);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_NUM);
	CU_ASSERT_EQUAL(t1->status, 0);
	CU_ASSERT_EQUAL(t1->value, 30.0);
	CU_ASSERT_PTR_NULL(t1->left);
	CU_ASSERT_PTR_NULL(t1->right);
	free_calc_element(t1);
}
void test_VIDIOC_S_FREQUENCY_scan() {
    int ret_g_tuner, errno_g_tuner;
    int ret_g_freq, errno_g_freq;
    int ret_get, errno_get;
    int ret_set, errno_set;
    __u32 index;
    struct v4l2_frequency orig_freq;
    struct v4l2_frequency freq;
    struct v4l2_frequency new_freq;
    struct v4l2_frequency prev_freq;
    struct v4l2_tuner tuner;
    __u32 i;

    /* this test case depends on working VIDIOC_G_FREQUENCY command */

    index = 0;

    /* fetch the minimum (tuner.rangelow) and maximum (tuner.rangehigh) frequency */
    memset(&tuner, 0xff, sizeof(tuner));
    tuner.index = index;
    ret_g_tuner = ioctl(get_video_fd(), VIDIOC_G_TUNER, &tuner);
    errno_g_tuner = errno;

    dprintf("\t%s:%u: VIDIOC_G_TUNER, ret_g_tuner=%i, errno_g_tuner=%i\n",
            __FILE__, __LINE__, ret_g_tuner, errno_g_tuner);
    CU_ASSERT_EQUAL(tuner.index, index);

    /* fetch the current frequency setting */
    memset(&orig_freq, 0xff, sizeof(orig_freq));
    orig_freq.tuner = index;
    ret_g_freq = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &orig_freq);
    errno_g_freq = errno;

    dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_g_freq=%i, errno_g_freq=%i, orig_freq.frequency=%u\n",
            __FILE__, __LINE__, ret_g_freq, errno_g_freq, orig_freq.frequency);
    CU_ASSERT_EQUAL(orig_freq.tuner, index);

    if (ret_g_freq == 0) {
        CU_ASSERT_EQUAL(orig_freq.tuner, index);

        dprintf("\t%s:%u: tuner.rangelow=%u, tuner.rangehigh=%u\n",
                __FILE__, __LINE__,
                tuner.rangelow, tuner.rangehigh);

        i = tuner.rangelow;
        prev_freq.frequency = 0;
        do {
            /* try to set the frequency */
            memset(&freq, 0xff, sizeof(freq));
            freq.tuner = index;
            freq.type = orig_freq.type;

            freq.frequency = i;
            ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
            errno_set = errno;
            dprintf("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i, freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret_set, errno_set, i);

            CU_ASSERT_EQUAL(ret_set, 0);
            if (ret_set == 0) {

                memset(&new_freq, 0xff, sizeof(new_freq));
                new_freq.tuner = index;
                ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);
                errno_get = errno;

                dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i, new_freq.frequency=%u\n",
                        __FILE__, __LINE__,
                        ret_get, errno_get, new_freq.frequency);

                CU_ASSERT_EQUAL(ret_get, 0);
                if (ret_get == 0) {
                    CU_ASSERT(prev_freq.frequency <= new_freq.frequency);
                    CU_ASSERT(tuner.rangelow <= new_freq.frequency);
                    CU_ASSERT(new_freq.frequency <= tuner.rangehigh);
                    prev_freq = new_freq;
                }
            } else {
                printf("\tError %i while setting to %u\n", errno_set, i);
            }
            i++;
        } while (i <= tuner.rangehigh);

        /* try restore the original frequency settings */
        memset(&freq, 0xff, sizeof(freq));
        freq.tuner = index;
        freq.type = orig_freq.type;
        freq.frequency = orig_freq.frequency;
        ret_set = ioctl(get_video_fd(), VIDIOC_S_FREQUENCY, &freq);
        errno_set = errno;

        dprintf("\t%s:%u: VIDIOC_S_FREQUENCY, ret_set=%i, errno_set=%i\n",
                __FILE__, __LINE__, ret_set, errno_set);

        CU_ASSERT_EQUAL(ret_set, 0);
        if (ret_set == 0) {

            /* check wheteher the frequency has been restored */
            memset(&new_freq, 0xff, sizeof(new_freq));
            new_freq.tuner = index;
            ret_get = ioctl(get_video_fd(), VIDIOC_G_FREQUENCY, &new_freq);
            errno_get = errno;

            dprintf("\t%s:%u: VIDIOC_G_FREQUENCY, ret_get=%i, errno_get=%i, new_freq.frequency=%u\n",
                    __FILE__, __LINE__,
                    ret_get, errno_get, new_freq.frequency);

            CU_ASSERT_EQUAL(ret_get, 0);
            if (ret_get == 0) {
                CU_ASSERT_EQUAL(new_freq.frequency, orig_freq.frequency);
            }
        }
    }

    if (ret_g_freq != 0) {
        CU_ASSERT_EQUAL(ret_g_freq, -1);
        CU_ASSERT_EQUAL(errno, EINVAL);
    }

    if (ret_g_tuner != 0) {
        CU_ASSERT_EQUAL(ret_g_tuner, -1);
        CU_ASSERT_EQUAL(errno, EINVAL);
    }

}
Example #28
0
void test_canon_x(void)
{
	CALC_ELEMENT *t1;
	double a, b;
	/* addition x + a * x */
	t1 = create_bin_op('+', create_x(),
			   create_bin_op('*', create_number(2.5), create_x()));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_X);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(t1->value, 3.5);
	free_calc_element(t1);

	/* addition a * x + b */
	t1 = create_bin_op('+',
			   create_bin_op('*', create_number(1.25), create_x()),
			   create_number(14));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 1.25);
	CU_ASSERT_EQUAL(b, 14);
	free_calc_element(t1);

	/* addition a * x + b + c */
	t1 = create_bin_op('+',
			   create_bin_op('+',
					 create_bin_op('*', create_number(0.75),
						       create_x()),
					 create_number(6)),
			   create_number(-3.5));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 0.75);
	CU_ASSERT_EQUAL(b, 2.5);
	free_calc_element(t1);

	/* addition (a1 * x + b1) + (a2 * x + b2) */
	t1 = create_bin_op('+', create_ax_b(9.0, -1.25), create_ax_b(2.0, 6.5));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 11.0);
	CU_ASSERT_EQUAL(b, 5.25);
	free_calc_element(t1);

	/* multiplication a * x */
	t1 = create_bin_op('*', create_x(), create_number(-9.0));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_X);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, -9.0);
	CU_ASSERT_EQUAL(b, 0);
	free_calc_element(t1);

	/* multiplication x * a */
	t1 = create_bin_op('*', create_number(7.5), create_x());
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_X);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 7.5);
	CU_ASSERT_EQUAL(b, 0);
	free_calc_element(t1);

	/* multiplication c * (a * x + b) */
	t1 = create_bin_op('*', create_number(19), create_ax_b(4, -0.5));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 76);
	CU_ASSERT_EQUAL(b, -9.5);
	free_calc_element(t1);

	/* multiplication (a * x + b) * c */
	t1 = create_bin_op('*', create_ax_b(-6, 4.5), create_number(0.5));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_PRESENT);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, -3.0);
	CU_ASSERT_EQUAL(b, 2.25);
	free_calc_element(t1);

	/* multiplication x * x */
	t1 = create_bin_op('*', create_x(), create_x());
	CU_ASSERT_NOT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_NON_LINEAR | STATUS_X_PRESENT);
	free_calc_element(t1);

	/* multiplication x * (a * x + b) */
	t1 = create_bin_op('*', create_x(), create_x());
	CU_ASSERT_NOT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_NON_LINEAR | STATUS_X_PRESENT);
	free_calc_element(t1);

	/* multiplication (2*x - (2*x - 3)) * (3x - 4) - false square, actually linear */
	t1 = create_bin_op('*', create_bin_op('-', create_ax_b(2.0, 0.0),
					      create_ax_b(2, -3)),
			   create_ax_b(3.0, -4.0));
	CU_ASSERT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(get_ax_b(t1, &a, &b), 0);
	CU_ASSERT_EQUAL(a, 9.0);
	CU_ASSERT_EQUAL(b, -12.0);
	free_calc_element(t1);

	/* division x / a */
	t1 = create_bin_op('/', create_x(), create_number(2.0));
	CU_ASSERT_NOT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_BIN_OP);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_IN_DIV | STATUS_X_PRESENT);
	free_calc_element(t1);

	/* log (ax + b) */
	t1 = create_log(create_ax_b(9.0, -3.0));
	CU_ASSERT_NOT_EQUAL(canonical_form(&t1), 0);
	CU_ASSERT_EQUAL(t1->calc_t, CALC_LOG);
	CU_ASSERT_EQUAL(t1->status, STATUS_X_IN_LOG | STATUS_X_PRESENT);
	free_calc_element(t1);
}
/* Test MB_Iterator_CreateSorted */
void test_mb_p_iter_create_sorted(void) {
    
    int rc;
    MBIt_Board  *board;
    MBIt_Iterator  *iterator;
    
    /* Try invalid mboard */
    mb_s = 99999999;
    rc = MB_Iterator_CreateSorted(mb_s, &itr_s, &my_sort);
    CU_ASSERT_EQUAL(rc, MB_ERR_INVALID);
    CU_ASSERT_EQUAL(itr_s, MB_NULL_ITERATOR);
    
    /* Try NULL mboard */
    mb_s = MB_NULL_MBOARD;
    rc = MB_Iterator_CreateSorted(mb_s, &itr_s, &my_sort);
    CU_ASSERT_EQUAL(rc, MB_ERR_INVALID);
    CU_ASSERT_EQUAL(itr_s, MB_NULL_ITERATOR);
    
    /* Populate mboard. Abort on failure */
    rc = init_mb_with_content(&mb_s);
    CU_ASSERT_EQUAL_FATAL(rc, MB_SUCCESS);
    
    /* Try locked board */
    board = (MBIt_Board *)MBI_getMBoardRef(mb_s);
    CU_ASSERT_PTR_NOT_NULL_FATAL(board);
    board->locked = MB_TRUE;
    rc = MB_Iterator_CreateSorted(mb_s, &itr_s, &my_sort);
    CU_ASSERT_EQUAL(rc, MB_ERR_LOCKED);
    CU_ASSERT_EQUAL(itr_s, MB_NULL_ITERATOR);
    board->locked = MB_FALSE; 
    
    /* Try on "unreadable" boards */
    board->is_reader = MB_FALSE;
    rc = MB_Iterator_Create(mb_s, &itr_s);
    CU_ASSERT_EQUAL(rc, MB_ERR_DISABLED);
    CU_ASSERT_EQUAL(itr_s, MB_NULL_ITERATOR);
    board->is_reader = MB_TRUE;
    
    /* Create sorted Iterator */
    itr_s = MB_NULL_ITERATOR;
    rc = MB_Iterator_CreateSorted(mb_s, &itr_s, &my_sort);
    CU_ASSERT_EQUAL(rc, MB_SUCCESS);
    CU_ASSERT_NOT_EQUAL(itr_s, MB_NULL_ITERATOR);
    
    iterator = (MBIt_Iterator *)MBI_getIteratorRef(itr_s);
    board = (MBIt_Board *)MBI_getMBoardRef(mb_s);
    CU_ASSERT_PTR_NOT_NULL_FATAL(board);
    CU_ASSERT_PTR_NOT_NULL_FATAL(board->data);
    CU_ASSERT_PTR_NOT_NULL_FATAL(iterator);
    CU_ASSERT_EQUAL(board->data->elem_size, iterator->msgsize);
    CU_ASSERT_EQUAL(iterator->iterating, 0);
    CU_ASSERT_PTR_NULL(iterator->cursor);
    CU_ASSERT_EQUAL(iterator->mb, mb_s);
}
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;
                }
        }
}