Esempio n. 1
0
void TestAttachDetachWmk()
{
	BOOL KernelSupported;
	JPKFBT_SESSION Session;

	TEST( ! IsDriverLoaded( L"jpkfaw" ) );
	TEST_SUCCESS( JpkfbtIsKernelTypeSupported( 
		JpkfbtKernelWmk, &KernelSupported ) );
	if ( ! KernelSupported )
	{
		CFIX_INCONCLUSIVE( L"Kernel not WMK-compatible." );
	}

	TEST_SUCCESS( JpkfbtAttach( JpkfbtKernelWmk, &Session ) );
	TEST( Session );
	TEST_SUCCESS( JpkfbtDetach( Session, FALSE ) );

	Session = NULL;

	TEST( IsDriverLoaded( L"jpkfaw" ) );

	//
	// Again, but this time unload.
	//
	TEST_SUCCESS( JpkfbtAttach( JpkfbtKernelWmk, &Session ) );
	TEST( Session );
	TEST_SUCCESS( JpkfbtDetach( Session, TRUE ) );

	TEST( ! IsDriverLoaded( L"jpkfaw" ) );
}
void frameq_enqueue_send_and_recv_vr(void* arg, struct modtest_result* result) {
	//int ret = 0;
	const char buf[] = { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x56, 0x52, 0x4E };
	const int count = 8;

	struct xb_device* xbdev = (struct xb_device*)arg;
	struct sk_buff* send_buf = alloc_skb(128, GFP_KERNEL);
	struct sk_buff* skb;

	unsigned char* tail = skb_put(send_buf, count);
	memcpy(tail, buf, count);
	frameq_enqueue_send(&xbdev->send_queue, send_buf);

	FAIL_IF_NOT_EQ(1, skb_queue_len(&xbdev->send_queue));
	FAIL_IF_NOT_EQ(0, xbdev->recv_buf->len);

	xb_send(xbdev);
	skb = xb_recv(xbdev, 1, 1000);

	FAIL_IF_NULL(skb);

	FAIL_IF_NOT_EQ(0, skb_queue_len(&xbdev->send_queue));

	TEST_SUCCESS();
}
void xbee_ieee802154_set_csma_params_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	const char buf[] =  { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x52, 0x4E, 0x56 };
	const int count = 8;
	const char buf2[] = { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x52, 0x52, 0x52 };
	const int count2 = 8;
	struct sk_buff* send_buf = NULL;
	unsigned char* tail = NULL;
	struct xb_device* xbdev = NULL;
	struct xbee_sub_if_data *sdata = netdev_priv(xbdev->dev);
	xbdev = (struct xb_device*)arg;
	xbee_cfg802154_set_backoff_exponent(xbdev->phy, &sdata->wpan_dev, 2, 5);

	send_buf = alloc_skb(128, GFP_KERNEL);
	tail = skb_put(send_buf, count);
	memcpy(tail, buf, count);
	frameq_enqueue_send(&xbdev->send_queue, send_buf);

	send_buf = alloc_skb(128, GFP_KERNEL);
	tail = skb_put(send_buf, count);
	memcpy(tail, buf2, count2);
	frameq_enqueue_send(&xbdev->send_queue, send_buf);

	ret = xb_sendrecv(xbdev, xbdev->frameid);

	FAIL_IF_ERROR(ret);

	//FAIL_IF_NOT_EQ(1, skb_queue_len(&xbdev->send_queue));

	//FAIL_IF_NOT_EQ(0, xbdev->recv_buf->len);

	// TODO inspect received data

	TEST_SUCCESS();
}
void frame_verify_zerobyte(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;
	ret = frame_verify(xbdev->recv_buf);

	FAIL_IF_NOT_EQ(-EAGAIN, ret);
	TEST_SUCCESS();
}
void buffer_find_delimiter_non_exists(void* arg, struct modtest_result* result) {
	const char buf[] = {0x23, 0x70, 0x11};
	const int count = 3;
	int ret = 0;
	ret = buffer_find_delimiter_unescaped(buf, count);
	FAIL_IF_NOT_EQ(-1, ret);
	TEST_SUCCESS();
}
void buffer_calc_checksum_example(void* arg, struct modtest_result* result) {
	const char buf[] = {0x23, 0x11};
	const int count = 2;
	int ret = 0;
	ret = buffer_calc_checksum(buf, count);
	
	FAIL_IF_NOT_EQ(0xCB, ret);
	TEST_SUCCESS();
}
void buffer_unescape_zero(void* arg, struct modtest_result* result) {
	char buf[] = {};
	const int count = 0;
	int ret = 0;
	ret = buffer_unescape(buf, count);

	FAIL_IF_NOT_EQ(0, ret);
	TEST_SUCCESS();
}
void xb_set_backoffs_exponent_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	ret = xb_set_max_csma_backoffs(xbdev, 2);

	FAIL_IF_NOT_ERROR(ret);

	TEST_SUCCESS();
}
void buffer_calc_checksum_zero(void* arg, struct modtest_result* result) {
	const char buf[] = {};
	const int count = 0;
	int ret = 0;
	ret = buffer_calc_checksum(buf, count);

	FAIL_IF_NOT_EQ(0xFF, ret);

	TEST_SUCCESS();
}
void buffer_escaped_len_exampe(void* arg, struct modtest_result* result) {
	const char buf[] =    { 0x7E, 0x00, 0x02, 0x23, 0x11, 0xCB };
	const char escbuf[] = { 0x7E, 0x00, 0x02, 0x23, 0x7D, 0x31, 0xCB };

	size_t esclen = buffer_escaped_len(buf, sizeof(buf) );

	FAIL_IF_NOT_EQ(sizeof(escbuf), esclen);

	TEST_SUCCESS();
}
void buffer_unescape_end_escape(void* arg, struct modtest_result* result) {
	char buf[] = {0x7E, 0x00, 0x02, 0x23, 0x7D, 0x31, 0x7D};
	char ans[] = {0x7E, 0x00, 0x02, 0x23, 0x11, 0x7D};
	const int count = 7;
	int ret = 0;
	ret = buffer_unescape(buf, count);

	FAIL_IF_NOT_EQ(6, ret);
	FAIL_IF_NOT_EQ(0,  memcmp(buf, ans, 6));
	TEST_SUCCESS();
}
void frame_calc_checksum_example(void* arg, struct modtest_result* result) {
	struct xb_device* xbdev = (struct xb_device*)arg;
	const char buf[] = {0x7E, 0x00, 0x02, 0x23, 0x11, 0xCB};
	const int count = 6;
	int ret = 0;
	unsigned char* tail = skb_put(xbdev->recv_buf, count);
	memcpy(tail, buf, count);
	ret = frame_calc_checksum(xbdev->recv_buf);

	FAIL_IF_NOT_EQ(0xCB, ret);
	TEST_SUCCESS();
}
void frame_alloc_test(void* arg, struct modtest_result* result) {
	struct sk_buff* skb = frame_alloc(9, 0x0F, true);
	struct xb_frameheader* frm = NULL;

	frm = (struct xb_frameheader*)skb->data;

	FAIL_IF_NOT_EQ(0x7E, skb->data[0]);
	FAIL_IF_NOT_EQ(0x00, skb->data[1]);
	FAIL_IF_NOT_EQ(0x0a, skb->data[2]);
	FAIL_IF_NOT_EQ(0x0F, skb->data[3]);
	TEST_SUCCESS();
}
Esempio n. 14
0
void TestQueryStats()
{
	BOOL KernelSupported;
	JPKFBT_SESSION Session;
	JPKFBT_STATISTICS Stat;

	TEST( ! IsDriverLoaded( L"jpkfar" ) );
	TEST_SUCCESS( JpkfbtIsKernelTypeSupported( 
		JpkfbtKernelRetail, &KernelSupported ) );
	if ( ! KernelSupported )
	{
		CFIX_INCONCLUSIVE( L"Kernel not Retail-compatible." );
	}

	TEST_SUCCESS( JpkfbtAttach( JpkfbtKernelRetail, &Session ) );
	TEST( Session );
	
	DeleteFile( L"__testkfbt.log" );
	TEST_SUCCESS( JpkfbtInitializeTracing(
		Session,
		JpkfbtTracingTypeDefault,
		0x10,
		0x1000, 
		L"__testkfbt.log" ) );

	TEST_SUCCESS( JpkfbtQueryStatistics( Session, &Stat ) );
	TEST( Stat.Buffers.Free == 0x10 );
	TEST( Stat.Buffers.Dirty == 0 );

	TEST_SUCCESS( JpkfbtShutdownTracing( Session ) );
	TEST_SUCCESS( JpkfbtDetach( Session, TRUE ) );

	TEST( ! IsDriverLoaded( L"jpkfar" ) );
}
void xb_get_short_addr_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	__le16 short_addr = 0;

	ret = xb_get_short_addr(xbdev, &short_addr);

	FAIL_IF_ERROR(ret);
	FAIL_IF_NOT_EQ(0x0, short_addr);

	TEST_SUCCESS();
}
void xb_get_extended_addr_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	__le64 extended_adder = 0;

	ret = xb_get_extended_addr(xbdev, &extended_adder);

	FAIL_IF_ERROR(ret);
	FAIL_IF_NOT_EQ(xbee_serialno, extended_adder);

	TEST_SUCCESS();
}
void xb_get_tx_power_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	s32 power = 0;

	ret = xb_get_tx_power(xbdev, &power);

	FAIL_IF_ERROR(ret);
	FAIL_IF_NOT_EQ(0, power);

	TEST_SUCCESS();
}
void xb_get_pan_id_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	__le16 panid = 0;

	ret = xb_get_pan_id(xbdev, &panid);

	FAIL_IF_ERROR(ret);
	FAIL_IF_NOT_EQ(0x3332, panid);

	TEST_SUCCESS();
}
void xb_get_cca_ed_level_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	s32 ed_level= 0;

	ret = xb_get_cca_ed_level(xbdev, &ed_level);

	FAIL_IF_ERROR(ret);
	FAIL_IF_NOT_EQ(-4400, ed_level);

	TEST_SUCCESS();
}
Esempio n. 20
0
File: run.cpp Progetto: trtikm/E2
static void do_the_test()
{
    natural_32_bit wcounter = 0U;
    natural_32_bit counter = 0U;
    std::vector<std::string> whistory;
    std::vector<std::string> history;
    {
        instance_wrapper<my_object> wobj;
        TEST_FAILURE(wobj->foo());
        TEST_FAILURE(wobj.reference_to_instance().foo());
        wobj.construct_instance(
                pair_of_functions(
                    std::bind(&generate_id,std::ref(wcounter)),
                    std::bind(&push_message,std::ref(whistory),std::placeholders::_1,std::placeholders::_2)
                    )
                );
        TEST_SUCCESS(wobj->foo());
        TEST_SUCCESS(wobj.reference_to_instance().foo());
        wobj->log_message("initial logged message!");

        my_object obj(
                pair_of_functions(
                    std::bind(&generate_id,std::ref(counter)),
                    std::bind(&push_message,std::ref(history),std::placeholders::_1,std::placeholders::_2)
                    )
                );
        obj.foo();
        obj.foo();
        obj.log_message("initial logged message!");

        test_copy_construction_and_copy_assignment(wobj,obj);
    }
    TEST_SUCCESS(wcounter == counter);
    TEST_SUCCESS(whistory.size() == history.size());
    for (natural_32_bit i = 0; i < std::min(whistory.size(), history.size()); ++i)
        TEST_SUCCESS(whistory.at(i) == history.at(i));
}
Esempio n. 21
0
int main() {
#define TEST_ERROR(a, b) new CConfigErrorTest(a, b)
#define TEST_SUCCESS(a, b) new CConfigSuccessTest(a, b)
#define ARRAY_SIZE(a) (sizeof(a)/(sizeof((a)[0])))
	CConfigTest *tests[] = {
		TEST_SUCCESS("", ""),
		/* duplicate entries */
		TEST_SUCCESS("Foo = bar\nFoo = baz\n", "foo=bar\nfoo=baz\n"),
		TEST_SUCCESS("Foo = baz\nFoo = bar\n", "foo=baz\nfoo=bar\n"),
		/* sub configs */
		TEST_ERROR("</foo>", "Error on line 1: Closing tag \"foo\" which is not open."),
		TEST_ERROR("<foo a>\n</bar>\n", "Error on line 2: Closing tag \"bar\" which is not open."),
		TEST_ERROR("<foo bar>", "Error on line 1: Not all tags are closed at the end of the file. Inner-most open tag is \"foo\"."),
		TEST_ERROR("<foo>\n</foo>", "Error on line 1: Empty block name at begin of block."),
		TEST_ERROR("<foo 1>\n</foo>\n<foo 1>\n</foo>", "Error on line 4: Duplicate entry for tag \"foo\" name \"1\"."),
		TEST_SUCCESS("<foo a>\n</foo>", "->foo/a\n<-\n"),
		TEST_SUCCESS("<a b>\n  <c d>\n </c>\n</a>", "->a/b\n->c/d\n<-\n<-\n"),
		TEST_SUCCESS(" \t <A B>\nfoo = bar\n\tFooO = bar\n</a>", "->a/B\nfoo=bar\nfooo=bar\n<-\n"),
		/* comments */
		TEST_SUCCESS("Foo = bar // baz\n// Bar = baz", "foo=bar // baz\n"),
		TEST_SUCCESS("Foo = bar /* baz */\n/*** Foo = baz ***/\n   /**** asdsdfdf \n Some quite invalid stuff ***/\n", "foo=bar /* baz */\n"),
		TEST_ERROR("<foo foo>\n/* Just a comment\n</foo>", "Error on line 3: Comment not closed at end of file."),
		TEST_SUCCESS("/* Foo\n/* Bar */", ""),
		TEST_SUCCESS("/* Foo\n// */", ""),
	};
	unsigned int i;
	unsigned int failed = 0;

	for (i = 0; i < ARRAY_SIZE(tests); i++) {
		if (!tests[i]->Test())
			failed++;
		delete tests[i];
	}

	return failed;
}
void frame_verify_startmark(void* arg, struct modtest_result* result) {
	int ret = 0;
	const char buf[] = { 0x7e };
	const int count = 1;

	struct xb_device* xbdev = (struct xb_device*)arg;

	unsigned char* tail = skb_put(xbdev->recv_buf, count);
	memcpy(tail, buf, count);

	ret = frame_verify(xbdev->recv_buf);

	FAIL_IF_NOT_EQ(-EAGAIN, ret);
	TEST_SUCCESS();
}
void frame_verify_length_zero_valid_large(void* arg, struct modtest_result* result) {
	int ret = 0;
	const char buf[] = { 0x7e, 0x00, 0x00, 0xFF, 0x01};
	const int count = 5;

	struct xb_device* xbdev = (struct xb_device*)arg;

	unsigned char* tail = skb_put(xbdev->recv_buf, count);
	memcpy(tail, buf, count);

	ret = frame_verify(xbdev->recv_buf);

	FAIL_IF_NOT_EQ(4, ret);
	TEST_SUCCESS();
}
void frameq_enqueue_received_zerobyte(void* arg, struct modtest_result* result) {
	int ret = 0;
	//const char buf[] = {};
	//const int count = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	//unsigned char* tail = skb_put(xbdev->recv_buf, count);
	//memcpy(tail, buf, count);
	ret = frameq_enqueue_received(&xbdev->recv_queue, xbdev->recv_buf, 1);

	FAIL_IF_NOT_EQ(0, ret);
	FAIL_IF_NOT_EQ(0, skb_queue_len(&xbdev->recv_queue));
	FAIL_IF_NOT_EQ(0, xbdev->recv_buf->len);
	TEST_SUCCESS();
}
void frameq_enqueue_received_startmark_len(void* arg, struct modtest_result* result) {
	int ret = 0;
	const char buf[] = { 0x7e , 0x00, 0x3 };
	const int count = 3;
	struct xb_device* xbdev = (struct xb_device*)arg;

	unsigned char* tail = skb_put(xbdev->recv_buf, count);
	memcpy(tail, buf, count);
	ret = frameq_enqueue_received(&xbdev->recv_queue, xbdev->recv_buf, 1);

	FAIL_IF_NOT_EQ(0, ret);
	FAIL_IF_NOT_EQ(0, skb_queue_len(&xbdev->recv_queue));
	FAIL_IF_NOT_EQ(3, xbdev->recv_buf->len);
	TEST_SUCCESS();
}
void xb_get_channel_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	u8 page = 0;
	u8 channel = 0;

	ret = xb_get_channel(xbdev, &page, &channel);

	FAIL_IF_ERROR(ret);

	FAIL_IF_NOT_EQ(0, page);
	FAIL_IF_NOT_EQ(12, channel);

	TEST_SUCCESS();
}
void frame_verify_modem_status(void* arg, struct modtest_result* result) {
	int ret = 0;
	const char buf[] = { 0x7E, 0x00, 0x02, 0x8A, 0x01, 0x74 };
	const int count = 6;

	struct xb_device* xbdev = (struct xb_device*)arg;

	unsigned char* tail = skb_put(xbdev->recv_buf, count);
	memcpy(tail, buf, count);

	ret = frame_verify(xbdev->recv_buf);

	FAIL_IF_NOT_EQ(6, ret);

	TEST_SUCCESS();
}
void frameq_enqueue_received_valid_invalid(void* arg, struct modtest_result* result) {
	int ret = 0;
	const char buf[] = { 0x7E, 0x00, 0x02, 0x23, 0x11, 0xCB, 0x11 };
	const int count = 7;

	struct xb_device* xbdev = (struct xb_device*)arg;

	unsigned char* tail = skb_put(xbdev->recv_buf, count);
	memcpy(tail, buf, count);
	ret = frameq_enqueue_received(&xbdev->recv_queue, xbdev->recv_buf, 1);

	FAIL_IF_NOT_EQ(1, ret);
	FAIL_IF_NOT_EQ(1, skb_queue_len(&xbdev->recv_queue));
	FAIL_IF_NOT_EQ(0, xbdev->recv_buf->len);

	TEST_SUCCESS();
}
void xb_set_ackreq_default_test(void* arg, struct modtest_result* result) {
	int ret = 0;
	struct xb_device* xbdev = (struct xb_device*)arg;

	bool ackreq = 0;

	ret = xb_set_ackreq_default(xbdev, true);

	FAIL_IF_ERROR(ret);

	ret = xb_get_ackreq_default(xbdev, &ackreq);

	FAIL_IF_ERROR(ret);

	FAIL_IF_NOT_EQ(true, ackreq);

	TEST_SUCCESS();
}
void buffer_escape_exampe(void* arg, struct modtest_result* result) {
	char buf[] =		{ 0x7E, 0x00, 0x02, 0x23, 0x11, 0xCB, 0x00 };
	const char escbuf[] =	{ 0x7E, 0x00, 0x02, 0x23, 0x7D, 0x31, 0xCB };
	size_t esclen = 0;
	int err;

	//pr_debug("bufsize %lu", sizeof(buf) );

	esclen = buffer_escaped_len(buf, 5);
	err = buffer_escape(buf, 5, esclen);

	print_hex_dump_bytes("buf: ", DUMP_PREFIX_NONE, buf, 6);
	print_hex_dump_bytes("esc: ", DUMP_PREFIX_NONE, escbuf, 6);

	FAIL_IF_ERROR(err);
	FAIL_IF_NOT_EQ(0, memcmp(escbuf, buf, esclen) );

	TEST_SUCCESS();
}