Example #1
0
/**
 * Inserts a single entry, validates it, removes it, validates again.
 * Does not touch the session tables.
 */
static bool simple_bib(void)
{
	struct ipv4_transport_addr addr = addr4[0];
	struct bib_entry *bib;
	bool success = true;

	if (is_error(pool4_get_any_port(L4PROTO_TCP, &addr.l3, &addr.l4)))
		return false;

	bib = bib_create(&addr, &addr6[0], false, L4PROTO_TCP);
	if (!assert_not_null(bib, "Allocation of test BIB entry"))
		return false;

	success &= assert_equals_int(0, bibdb_add(bib), "BIB insertion call");
	success &= assert_bib("BIB insertion state", bib, false, true, false);
	if (!success)
		return false;

	success &= assert_equals_int(0, bibdb_remove(bib, false), "BIB removal call");
	success &= assert_bib("BIB removal state", bib, false, false, false);
	if (!success)
		return false;

	bib_kfree(bib);
	return success;
}
Example #2
0
static void
check_on_demand_playlist (const gchar * data)
{
  GstM3U8Client *client;
  GstM3U8 *pl;
  GstM3U8MediaFile *file;

  client = load_playlist (data);
  pl = client->current;

  /* Sequence should be 0 as it's an ondemand playlist */
  assert_equals_int (client->sequence, 0);
  /* Check that we are not live */
  assert_equals_int (gst_m3u8_client_is_live (client), FALSE);
  /* Check number of entries */
  assert_equals_int (g_list_length (pl->files), 4);
  /* Check first media segments */
  file = GST_M3U8_MEDIA_FILE (g_list_first (pl->files)->data);
  assert_equals_string (file->uri, "http://media.example.com/001.ts");
  assert_equals_int (file->sequence, 0);
  /* Check last media segments */
  file = GST_M3U8_MEDIA_FILE (g_list_last (pl->files)->data);
  assert_equals_string (file->uri, "http://media.example.com/004.ts");
  assert_equals_int (file->sequence, 3);

  gst_m3u8_client_free (client);
}
Example #3
0
/**
 * Asserts the "bib" entry was correctly inserted into the tables.
 * -> if udp_table_has_it, will test the entry exists and is correctly indexed by the UDP table.
 *    Else it will assert the bib is not indexed by the UDP table.
 * -> if tcp_table_has_it, will test the entry exists and is correctly indexed by the TCP table.
 *    Else it will assert the bib is not indexed by the TCP table.
 * -> if icmp_table_has_it, will test the entry exists and is correctly indexed by the ICMP table.
 *    Else it will assert the bib is not indexed by the ICMP table.
 */
static bool assert_bib(char* test_name, struct bib_entry* bib,
		bool udp_table_has_it, bool tcp_table_has_it, bool icmp_table_has_it)
{
	l4_protocol l4_protos[] = { L4PROTO_UDP, L4PROTO_TCP, L4PROTO_ICMP };
	bool table_has_it[3];
	int i;

	table_has_it[0] = udp_table_has_it;
	table_has_it[1] = tcp_table_has_it;
	table_has_it[2] = icmp_table_has_it;

	for (i = 0; i < 3; i++) {
		struct bib_entry *expected_bib = table_has_it[i] ? bib : NULL;
		struct bib_entry *retrieved_bib;
		int success = true;

		success &= assert_equals_int(table_has_it[i] ? 0 : -ESRCH,
				bibdb_get_by_ipv4(&bib->ipv4, l4_protos[i], &retrieved_bib),
				test_name);
		success &= assert_bib_entry_equals(expected_bib, retrieved_bib, test_name);

		success &= assert_equals_int(table_has_it[i] ? 0 : -ESRCH,
				bibdb_get_by_ipv6(&bib->ipv6, l4_protos[i], &retrieved_bib),
				test_name);
		success &= assert_bib_entry_equals(expected_bib, retrieved_bib, test_name);

		if (!success)
			return false;
	}

	return true;
}
Example #4
0
/*
 * A V6 RST packet arrives.
 */
static bool test_tcp_established_state_handle_v6rst(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct sk_buff *skb;
	unsigned long timeout;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			ESTABLISHED);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV6, false, true, false)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_established_state_handle(skb, session, &expirer), "result");
	success &= assert_equals_u8(TRANS, session->state, "V6 rst-state");
	success &= assert_equals_int(0, sessiondb_get_timeout(session, &timeout), "V6 rst-toresult");
	success &= assert_equals_ulong(TCPTRANS_TIMEOUT, timeout, "V6 rst-lifetime");

	kfree_skb(skb);
	return success;
}
static void
_test_flow_aggregation (GstFlowReturn flow, GstFlowReturn flow1,
    GstFlowReturn flow2, GstFlowReturn demux_flow, gboolean should_fail)
{
  GstPad *srcpad;
  GstValidateReport *report;
  GstValidatePadMonitor *pmonitor, *pmonitor1, *pmonitor2;
  GstElement *demuxer = fake_demuxer_new ();
  GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline"));
  GList *reports;
  GstValidateRunner *runner;
  GstValidateMonitor *monitor;

  fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE));
  runner = gst_validate_runner_new ();
  monitor = gst_validate_monitor_factory_create (GST_OBJECT (pipeline),
      runner, NULL);
  gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));

  gst_bin_add (pipeline, demuxer);
  fake_demuxer_prepare_pads (pipeline, demuxer, runner);

  srcpad = gst_pad_new ("srcpad1", GST_PAD_SRC);
  gst_pad_link (srcpad, demuxer->sinkpads->data);
  fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE));
  gst_check_setup_events_with_stream_id (srcpad, demuxer, NULL,
      GST_FORMAT_TIME, "the-stream");

  pmonitor = _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->data));
  pmonitor1 =
      _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->next->data));
  pmonitor2 =
      _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->next->next->data));

  pmonitor->last_flow_return = flow;
  pmonitor1->last_flow_return = flow1;
  pmonitor2->last_flow_return = flow2;
  FAKE_DEMUXER (demuxer)->return_value = demux_flow;

  fail_unless_equals_int (gst_pad_push (srcpad, gst_buffer_new ()), demux_flow);

  reports = gst_validate_runner_get_reports (runner);
  if (should_fail) {
    assert_equals_int (g_list_length (reports), 1);
    report = reports->data;
    fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_CRITICAL);
    fail_unless_equals_int (report->issue->issue_id, WRONG_FLOW_RETURN);
  } else {
    assert_equals_int (g_list_length (reports), 0);

  }

  g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref);
  clean_bus (GST_ELEMENT (pipeline));

  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
  ASSERT_OBJECT_REFCOUNT (pipeline, "ours", 1);
  check_destroyed (pipeline, demuxer, NULL);
  check_destroyed (monitor, pmonitor, NULL);
}
Example #6
0
static bool test_get_any_port_aux(enum l4_protocol proto, int id_count,
		char *test_name)
{
	int a, p; /* address counter, port counter */
	__u16 result;
	bool success = true;

	for (a = 0; a < ARRAY_SIZE(expected_ips); a++) {
		for (p = 0; p < id_count; p++) {
			success &= assert_equals_int(0, pool4_get_any_port(proto, &expected_ips[a], &result),
					test_name);
			success &= assert_false(ports[a][result], test_name);
			ports[a][result] = true;

			if (!success)
				return success;
		}

		if (!assert_equals_int(-ESRCH, pool4_get_any_port(proto, &expected_ips[a], &result),
				test_name))
			return false;
	}

	return true;
}
Example #7
0
/*
 * A V6 FIN packet arrives.
 */
static bool test_tcp_v4_fin_rcv_state_handle_v6fin(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct packet pkt;
	struct sk_buff *skb;
	unsigned long timeout = 0;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			V4_FIN_RCV);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV6, false, false, true)))
		return false;
	if (is_error(pkt_init_ipv6(&pkt, skb)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_v4_fin_rcv_state_handle(&pkt, session, &expirer), "V6 fin-result");
	success &= assert_equals_u8(V4_FIN_V6_FIN_RCV, session->state, "V6 fin-state");
	success &= assert_equals_int(0, sessiondb_get_timeout(session, &timeout), "V6 fin-toresult");
	success &= assert_equals_ulong(TCPTRANS_TIMEOUT, timeout, "V6 fin-lifetime");

	kfree_skb(skb);
	return success;
}
Example #8
0
static bool test_for_each_function(void)
{
	struct test_table table;
	struct loop_summary summary = {
			.values = { 0, 0, 0 },
			.array_size = 0
	};
	int i;
	bool success;

	struct table_key keys[] = { { 2 }, { 3 }, { 12 } };
	struct table_value values[] = { { 6623 }, { 784 }, { 736 } };

	/* Init. */
	test_table_init(&table, &equals_function, &hash_code_function);
	for (i = 0; i < ARRAY_SIZE(values); i++) {
		if (test_table_put(&table, &keys[i], &values[i]) != 0) {
			log_warning("Put operation failed on value %d.", i);
			test_table_empty(&table, NULL);
			return false;
		}
	}

	success &= assert_equals_int(0, test_table_for_each(&table, for_each_func, &summary), "");
	success &= assert_equals_int(3, summary.array_size, "");
	for (i = 0; i < ARRAY_SIZE(values); i++) {
		success &= assert_true(summary.values[0] == values[i].value
				|| summary.values[1] == values[i].value
				|| summary.values[2] == values[i].value, "");
	}

	test_table_empty(&table, NULL);
	return true;
}
bool test_tcp_trans_state_handle( void )
{
    struct sk_buff *skb;
    struct session_entry session;
    bool success = true;

    /* A V4 RST packet arrives. */
    if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V4_RST, TRANS, 10))
        return false;

    success &= assert_true(tcp_trans_state_handle( skb, &session ), "V4 rst-result");
    success &= assert_equals_u8(TRANS, session.state, "V4 rst-state");
    success &= assert_equals_int(10, session.dying_time, "V4 rst-lifetime");
    kfree_skb(skb);

    /* A V6 RST packet arrives. */
    if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V6_RST, TRANS, 10))
        return false;

    success &= assert_true(tcp_trans_state_handle( skb, &session ), "V6 rst-result");
    success &= assert_equals_u8(TRANS, session.state, "V6 rst-state");
    success &= assert_equals_int(10, session.dying_time, "V6 rst-lifetime");
    kfree_skb(skb);

    /* Something else arrives. */
    if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V4_SYN, TRANS, 10))
        return false;

    success &= assert_true(tcp_trans_state_handle(skb, &session), "else-result");
    success &= assert_equals_u8(ESTABLISHED, session.state, "else-state");
    success &= assert_not_equals_int(10, session.dying_time, "else-lifetime");
    kfree_skb(skb);

    return success;
}
Example #10
0
/*
 * Something else arrives.
 */
static bool test_tcp_trans_state_handle_else(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct packet pkt;
	struct sk_buff *skb;
	unsigned long timeout = 0;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			TRANS);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV4, true, false, false)))
		return false;
	if (is_error(pkt_init_ipv4(&pkt, skb)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_trans_state_handle(&pkt, session, &expirer), "else-result");
	success &= assert_equals_u8(ESTABLISHED, session->state, "else-state");
	success &= assert_equals_int(0, sessiondb_get_timeout(session, &timeout), "else-toresult");
	success &= assert_equals_ulong(TCPEST_TIMEOUT, timeout, "else-lifetime");

	kfree_skb(skb);
	return success;
}
Example #11
0
static bool compare_skbs(struct sk_buff *expected, struct sk_buff *actual)
{
	unsigned char *expected_ptr, *actual_ptr;
	unsigned int i, s, min_len;
	int errors = 0;

	if (!assert_equals_int(count_frags(expected), count_frags(actual), "Fragment count"))
		return false;

	s = 0;
	while (expected && !errors) {
		log_debug("Reviewing packet %u.", s);

		if (!assert_equals_int(expected->len, actual->len, "skb length"))
			errors++;

		expected_ptr = (unsigned char *) skb_network_header(expected);
		actual_ptr = (unsigned char *) skb_network_header(actual);
		min_len = (expected->len < actual->len) ? expected->len : actual->len;

		for (i = 0; i < min_len && errors < 6; i++) {
			if (expected_ptr[i] != actual_ptr[i]) {
				log_err("Packets differ at byte %u. Expected: 0x%x; actual: 0x%x.",
						i, expected_ptr[i], actual_ptr[i]);
				errors++;
			}
		}

		expected = expected->next;
		actual = actual->next;
		s++;
	}

	return !errors;
}
Example #12
0
/**
 * "ars" means add, remove, send
 */
static bool test_pkt_queue_ars(void)
{
	struct session_entry *session;
	struct sk_buff *skb;
	struct tuple tuple4;
	struct tcphdr *hdr_tcp;
	bool success = true;

	/* Prepare */
	if (is_error(init_ipv4_tuple(&tuple4, "5.6.7.8", 5678, "192.168.2.1", 8765, L4PROTO_TCP)))
		return false;
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "192.168.2.1", 8765, "5.6.7.8", 5678,
			V4_INIT); /* The session entry that is supposed to be created in "tcp_close_state_handle". */
	if (!session)
		return false;

	if (is_error(create_skb4_tcp(&tuple4, &skb, 100, 32))) {
		session_return(session);
		return false;
	}
	hdr_tcp = tcp_hdr(skb);
	hdr_tcp->syn = true;
	hdr_tcp->rst = false;
	hdr_tcp->fin = false;

	success &= assert_equals_int(0, pktqueue_add(session, skb), "pktqueue_add 1");
	success &= assert_equals_int(0, pktqueue_remove(session), "pktqueue_remove 1");
	success &= assert_equals_int(-ENOENT, pktqueue_send(session), "pktqueue_send 1");
	success &= assert_equals_int(0, icmp64_pop(), "pktqueue not sent an icmp error");


	session_return(session);
	/* kfree_skb(skb); "skb" kfreed when pktqueue_remove is executed */
	return success;
}
bool test_ipv4_icmp4( void )
{
    u_int8_t protocol;
    struct tuple tuple;
    struct sk_buff* skb = NULL;
    bool success = true;

    protocol = IPPROTO_ICMP;
    success &= init_tuple_for_test_ipv4( &tuple , protocol );
    skb = init_skb_for_test( &tuple, protocol );
    success &= assert_not_null(skb, "init_skb_for_test");
    success &= assert_equals_int(NF_DROP, ipv4_icmp4( skb, &tuple ), 
		"See if we discard an IPv4 ICMP packet, which tries to start a communication.");
    kfree_skb(skb);

    protocol = IPPROTO_ICMP;
    success &= init_tuple_for_test_ipv6( &tuple , protocol );
    skb = init_skb_for_test( &tuple, protocol );
    success &= assert_not_null(skb, "init_skb_for_test");        
    success &= assert_equals_int(NF_ACCEPT, ipv6_icmp6(skb, &tuple ), 
		"See if we can process correctly an IPv6 ICMP packet.");
    kfree_skb(skb);

    protocol = IPPROTO_ICMP;
    success &= init_tuple_for_test_ipv4( &tuple , protocol );
    skb = init_skb_for_test( &tuple, protocol );
    success &= assert_not_null(skb, "init_skb_for_test");        
    success &= assert_equals_int(NF_ACCEPT, ipv4_icmp4( skb, &tuple ), 
		"See if we can process correctly an expected IPv4 ICMP packet.");
    kfree_skb(skb);

    return success;
}
bool test_ipv4_udp( void )
{
    u_int8_t protocol = IPPROTO_UDP;
    struct tuple tuple;
    struct sk_buff* skb;
    bool success = true;

    skb = init_skb_for_test( &tuple, protocol );
    if (!skb)
    	return false;

    success &= init_tuple_for_test_ipv4( &tuple , protocol );
    success &= assert_equals_int(NF_DROP, ipv4_udp( skb, &tuple ), 
		"See if we discard an IPv4 UDP packet, which tries to start a communication.");

    success &= init_tuple_for_test_ipv6( &tuple , protocol );
    success &= assert_equals_int(NF_ACCEPT, ipv6_udp( skb, &tuple ), 
		"See if we can process correctly an IPv6 UDP packet.");

    success &= init_tuple_for_test_ipv4( &tuple , protocol  );
    success &= assert_equals_int(NF_ACCEPT, ipv4_udp( skb, &tuple ), 
		"See if we can process correctly an expected IPv4 UDP packet.");

    kfree_skb(skb);

    return success;
}
Example #15
0
static bool test_get_match_aux(enum l4_protocol proto, int port_min, int port_max, int step,
		char *test_name)
{
	int a, p; /* address counter, port counter */
	struct ipv4_transport_addr base;
	__u16 result;
	bool success = true;

	for (a = 0; a < ARRAY_SIZE(expected_ips); a++) {
		base.l3 = expected_ips[a];

		for (p = port_min; p <= port_max; p += step) {
			base.l4 = p;
			success &= assert_equals_int(0, pool4_get_match(proto, &base, &result), test_name);
			success &= assert_false(ports[a][result], test_name);
			ports[a][result] = true;

			if (!success)
				return false;
		}

		if (!assert_equals_int(-ESRCH, pool4_get_match(proto, &base, &result), test_name))
			return false;
	}

	return true;
}
static bool test_4to6(l4_protocol l4_proto)
{
	struct tuple incoming, outgoing;
	bool success = true;

	incoming.src.addr.ipv4 = remote_ipv4;
	incoming.dst.addr.ipv4 = local_ipv4;
	incoming.src.l4_id = 123; /* Whatever */
	incoming.dst.l4_id = 80; /* Lookup will use this. */
	incoming.l3_proto = L3PROTO_IPV4;
	incoming.l4_proto = l4_proto;

	if (l4_proto != L4PROTO_ICMP) {
		success &= assert_equals_int(VER_CONTINUE, tuple5(&incoming, &outgoing), "Function5 call");
		success &= assert_equals_u16(123, outgoing.src.l4_id, "Source port");
		success &= assert_equals_u16(1500, outgoing.dst.l4_id, "Destination port");
	} else {
		success &= assert_equals_int(VER_CONTINUE, tuple3(&incoming, &outgoing), "Function3 call");
		success &= assert_equals_u16(1500, outgoing.icmp_id, "ICMP ID");
	}
	success &= assert_equals_ipv6(&local_ipv6, &outgoing.src.addr.ipv6, "Source address");
	success &= assert_equals_ipv6(&remote_ipv6, &outgoing.dst.addr.ipv6, "Destination address");
	success &= assert_equals_u16(L3PROTO_IPV6, outgoing.l3_proto, "Layer-3 protocol");
	success &= assert_equals_u8(l4_proto, outgoing.l4_proto, "Layer-4 protocol");

	return success;
}
Example #17
0
static bool test_next_function_subheaders(void)
{
	bool success = true;
	struct hdr_iterator iterator;

	/* Init */
	struct ipv6hdr *ip6_header;
	struct frag_hdr *fragment_hdr;
	struct ipv6_opt_hdr *hop_by_hop_hdr;
	struct ipv6_opt_hdr *routing_hdr;
	unsigned char *payload;

	ip6_header = kmalloc_packet(FRAG_HDR_LEN + OPT_HDR_LEN + ROUTING_HDR_LEN + 4, NEXTHDR_FRAGMENT);
	if (!ip6_header)
		return false;
	fragment_hdr = add_frag_hdr(ip6_header, sizeof(struct ipv6hdr), NEXTHDR_HOP);
	hop_by_hop_hdr = add_opt_hdr(fragment_hdr, FRAG_HDR_LEN, NEXTHDR_ROUTING);
	routing_hdr = add_routing_hdr(hop_by_hop_hdr, OPT_HDR_LEN, NEXTHDR_UDP);
	payload = add_payload(routing_hdr, ROUTING_HDR_LEN);

	/* Test */
	hdr_iterator_init(&iterator, ip6_header);
	success &= assert_equals_ptr(fragment_hdr, iterator.data, "Frag hdr, data");
	success &= assert_equals_u8(NEXTHDR_FRAGMENT, iterator.hdr_type, "Frag hdr, type");
	if (!success)
		goto end;

	success &= assert_equals_int(HDR_ITERATOR_SUCCESS, hdr_iterator_next(&iterator), "Next 1");
	success &= assert_equals_ptr(hop_by_hop_hdr, iterator.data, "Hop-by-hop hdr, data");
	success &= assert_equals_u8(NEXTHDR_HOP, iterator.hdr_type, "Hop-by-hop hdr, type");
	if (!success)
		goto end;

	success &= assert_equals_int(HDR_ITERATOR_SUCCESS, hdr_iterator_next(&iterator), "Next 2");
	success &= assert_equals_ptr(routing_hdr, iterator.data, "Routing hdr, data");
	success &= assert_equals_u8(NEXTHDR_ROUTING, iterator.hdr_type, "Routing hdr, type");
	if (!success)
		goto end;

	success &= assert_equals_int(HDR_ITERATOR_SUCCESS, hdr_iterator_next(&iterator), "Next 3");
	success &= assert_equals_ptr(payload, iterator.data, "Payload 1, data");
	success &= assert_equals_u8(NEXTHDR_UDP, iterator.hdr_type, "Payload 1, type");
	if (!success)
		goto end;

	success &= assert_equals_int(HDR_ITERATOR_END, hdr_iterator_next(&iterator), "Next 4");
	success &= assert_equals_ptr(payload, iterator.data, "Payload 2, data");
	success &= assert_equals_u8(NEXTHDR_UDP, iterator.hdr_type, "Payload 2, type");
	/* Fall through. */

end:
	kfree(ip6_header);
	return success;
}
Example #18
0
void test_assertions ()
{
        char *c;

        assert(1+1 == 2);
        assert(1+1 == 3);

        assert_true(1+1 == 2);
        assert_true(1+1 == 3);

        assert_false(1+1 == 3);
        assert_false(1+1 == 2);
        
        assert_equals_int(1, 1);
        assert_equals_int(1, 2);

        assert_not_equals_int(1, 2);
        assert_not_equals_int(1, 1);
        
        assert_equals_int(1, 1);
        assert_equals_int(1, 2);

        assert_not_equals_int(1, 2);
        assert_not_equals_int(1, 1);

        assert_equals_str("abc", "abc");
        assert_equals_str("abc", "def");

        assert_not_equals_str("abc", "def");
        assert_not_equals_str("abc", "abc");

        c = NULL;
        assert_null(c);
        c = malloc(sizeof(char));
        assert_null(c);

        c = malloc(sizeof(char));
        assert_not_null(c);
        c = NULL;
        assert_not_null(c);

        assert_equals_float(2.0, 2.0);
        assert_equals_float(2.0, 2.1);

        assert_not_equals_float(2.0, 2.1);
        assert_not_equals_float(2.0, 2.0);

        assert_equals_double(2.0, 2.0);
        assert_equals_double(2.0, 2.1);

        assert_not_equals_double(2.0, 2.1);
        assert_not_equals_double(2.0, 2.0);
}
Example #19
0
static bool test_get_any_addr_aux(l4_protocol proto, int min_range, int max_range, int range_step,
		int range_outside)
{
	struct ipv4_transport_addr tuple_addr;
	int p;
	bool success = true;

	for (p = min_range; p <= max_range; p += range_step) {
		success &= assert_equals_int(0, pool4_get_any_addr(proto, p, &tuple_addr),
				"Matched borrow 1-result");
		success &= assert_equals_ipv4(&expected_ips[0], &tuple_addr.l3,
				"Matched borrow 1-address");
		success &= assert_false(ports[0][tuple_addr.l4], "Matched borrow 1-port");
		ports[0][tuple_addr.l4] = true;

		success &= assert_equals_int(0, pool4_get_any_addr(proto, p, &tuple_addr),
				"Matched borrow 2-result");
		success &= assert_equals_ipv4(&expected_ips[1], &tuple_addr.l3,
				"Matched borrow 2-address");
		success &= assert_false(ports[1][tuple_addr.l4], "Matched borrow 2-port");
		ports[1][tuple_addr.l4] = true;

		if (!success)
			return success;
	}

	/* At this point, the pool should not have low even ports, so it should lend random data. */
	for (p = 0; p < range_outside; p += 1) {
		success &= assert_equals_int(0, pool4_get_any_addr(proto, 10, &tuple_addr),
				"Mismatched borrow 1-result");
		success &= assert_equals_ipv4(&expected_ips[0], &tuple_addr.l3,
				"Mismatched borrow 1-address");
		success &= assert_false(ports[0][tuple_addr.l4], "Mismatched borrow 1-port");
		ports[0][tuple_addr.l4] = true;

		success &= assert_equals_int(0, pool4_get_any_addr(proto, 10, &tuple_addr),
				"Mismatched borrow 2-result");
		success &= assert_equals_ipv4(&expected_ips[1], &tuple_addr.l3,
				"Mismatched borrow 2-address");
		success &= assert_false(ports[1][tuple_addr.l4], "Mismatched borrow 2-port");
		ports[1][tuple_addr.l4] = true;

		if (!success)
			return success;
	}

	/* The pool ran out of ports. */
	success &= assert_equals_int(-ESRCH, pool4_get_any_addr(proto, 10, &tuple_addr),
			"Exhausted pool");

	return success;
}
Example #20
0
static void
do_test_seek (GstM3U8Client * client, guint seek_pos, gint pos)
{
  GstClockTime cur_pos;
  gboolean ret;

  ret = gst_m3u8_client_seek (client, seek_pos * GST_SECOND);
  if (pos == -1) {
    assert_equals_int (ret, FALSE);
    return;
  }
  assert_equals_int (ret, TRUE);
  gst_m3u8_client_get_current_position (client, &cur_pos, NULL);
  assert_equals_uint64 (cur_pos, pos * GST_SECOND);
}
Example #21
0
static bool test_last_function_unsupported(void)
{
	bool success = true;
	struct hdr_iterator iterator;

	/* Init */
	struct ipv6hdr *ip6_header;
	struct frag_hdr *fragment_hdr;
	struct ipv6_opt_hdr *esp_hdr;
	struct ipv6_opt_hdr *routing_hdr;
	unsigned char *payload;

	ip6_header = kmalloc_packet(FRAG_HDR_LEN + OPT_HDR_LEN + ROUTING_HDR_LEN + 4, NEXTHDR_FRAGMENT);
	if (!ip6_header)
		return false;
	fragment_hdr = add_frag_hdr(ip6_header, sizeof(struct ipv6hdr), NEXTHDR_ESP);
	esp_hdr = add_opt_hdr(fragment_hdr, FRAG_HDR_LEN, FRAG_HDR_LEN);
	routing_hdr = add_routing_hdr(esp_hdr, OPT_HDR_LEN, NEXTHDR_UDP);
	payload = add_payload(routing_hdr, ROUTING_HDR_LEN);

	/* Test */
	hdr_iterator_init(&iterator, ip6_header);
	success &= assert_equals_int(HDR_ITERATOR_UNSUPPORTED, hdr_iterator_last(&iterator), "Result");
	success &= assert_equals_ptr(esp_hdr, iterator.data, "Last function, data");
	success &= assert_equals_u8(NEXTHDR_ESP, iterator.hdr_type, "Last function, type");

	/* End */
	kfree(ip6_header);
	return success;
}
Example #22
0
/**
 * Inserts a single entry, validates it, removes it, validates again.
 * Does not touch the session tables.
 */
bool simple_bib(void)
{
	struct bib_entry *bib;
	bool success = true;

	bib = create_bib_entry(0, 0);
	if (!assert_not_null(bib, "Allocation of test BIB entry"))
		return false;

	success &= assert_equals_int(0, bib_add(bib, IPPROTO_TCP), "BIB insertion call");
	success &= assert_bib("BIB insertion state", bib, false, true, false);
	if (!success)
		/*
		 * Rather have a slight memory leak than corrupted memory. Because of the error, the table
		 * might or might not have a reference to the entry, and if it does, it will try to kfree
		 * it during bib_destroy(). Hence, better not free it here.
		 */
		return false;

	success &= assert_true(bib_remove(bib, IPPROTO_TCP), "BIB removal call");
	success &= assert_bib("BIB removal state", bib, false, false, false);
	if (!success)
		return false;

	kfree(bib);
	return success;
}
Example #23
0
/*
 * A V4 FIN packet arrives.
 */
static bool test_tcp_established_state_handle_v4fin(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct packet pkt;
	struct sk_buff *skb;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			ESTABLISHED);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV4, false, false, true)))
		return false;
	if (is_error(pkt_init_ipv4(&pkt, skb)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_established_state_handle(&pkt, session, &expirer), "result");
	success &= assert_equals_u8(V4_FIN_RCV, session->state, "V4 fin-state");
	success &= assert_null(session->expirer, "null expirer");

	kfree_skb(skb);
	return success;
}
Example #24
0
/*
* A V6 RST packet arrives.
*/
static bool test_tcp_trans_state_handle_v6rst(void)
{
	struct session_entry *session;
	struct expire_timer *expirer;
	struct packet pkt;
	struct sk_buff *skb;
	bool success = true;

	/* Prepare */
	session = session_create_str_tcp("1::2", 1212, "3::4", 3434, "5.6.7.8", 5678, "8.7.6.5", 8765,
			TRANS);
	if (!session)
		return false;
	if (is_error(create_tcp_packet(&skb, L3PROTO_IPV6, false, true, false)))
		return false;
	if (is_error(pkt_init_ipv6(&pkt, skb)))
		return false;

	/* Evaluate */
	success &= assert_equals_int(0, tcp_trans_state_handle(&pkt, session, &expirer), "V6 rst-result");
	success &= assert_equals_u8(TRANS, session->state, "V6 rst-state");
	success &= assert_null(session->expirer, "null expirer");

	kfree_skb(skb);
	return success;
}
Example #25
0
/**
 * For every key (from the "keys" array), extracts its corresponding value from "table", and asserts
 * it equals its corresponding expected value (from the "expected_values" array).
 *
 * Assumes "keys" and "expected_values" have the same length.
 */
static bool assert_table_content(struct test_table *table,
		struct table_key *keys, struct table_value *expected_values,
		char *test_name)
{
	int i;
	bool success = true;

	for (i = 0; i < 4; i++) {
		struct table_value *current_val = test_table_get(table, &keys[i]);

		if (expected_values[i].value == -1) {
			success &= assert_null(current_val, test_name);
		} else {
			bool local = true;

			local &= assert_not_null(current_val, test_name);
			if (local)
				local &= assert_equals_int(expected_values[i].value, current_val->value, test_name);

			success &= local;
		}
	}

	return success;
}
Example #26
0
static bool test_allocate_aux(struct tuple *tuple6, struct in_addr *same_addr,
		struct in_addr *out_addr, bool test_port)
{
	struct ipv4_transport_addr result;
	bool success = true;
	struct host6_node *host6;

	if (host6_node_get_or_create(&tuple6->src.addr6.l3, &host6))
		return false;

	success &= assert_equals_int(0, allocate_transport_address(host6, tuple6, &result),
			"function result");

	/* BTW: Because in_addrs are __be32s, "1.1.1.1" is the same as "0x1010101U" */
	success &= assert_true(result.l3.s_addr == htonl(0x1010101U)
			|| result.l3.s_addr == htonl(0x2020202U), "Result address is in pool");
	if (same_addr)
		success &= assert_equals_ipv4(same_addr, &result.l3, "Result address was recycled");
	if (test_port) {
		success &= assert_true(is_same_range(tuple6->src.addr6.l4, result.l4),
				"Result port is in the requested range");
		success &= assert_true(is_same_parity(tuple6->src.addr6.l4, result.l4),
				"Result port has the same parity as requested");
	}

	success &= bib_inject(&tuple6->src.addr6.l3, tuple6->src.addr6.l4, &result.l3, result.l4,
			L4PROTO_UDP) != NULL;

	if (out_addr)
		*out_addr = result.l3;

	host6_node_return(host6);

	return success;
}
bool test_tcp_v6_init_state_handle( void )
{
    struct sk_buff *skb;
    struct session_entry session;
    bool success = true;

    // A V4 SYN packet arrives.
    if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V4_SYN, V6_INIT, 10))
        return false;

    success &= assert_true(tcp_v6_init_state_handle(skb, &session), "V4 syn-result");
    success &= assert_equals_u8(ESTABLISHED, session.state, "V4 syn-state");
    success &= assert_not_equals_int(10, session.dying_time, "V4 syn-lifetime");
    kfree_skb(skb);

    // A V6 SYN packet arrives.
    if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V6_SYN, V6_INIT, 10))
        return false;

    success &= assert_true(tcp_v6_init_state_handle(skb, &session), "V6 syn-result");
    success &= assert_equals_u8(V6_INIT, session.state, "V6 syn-state");
    success &= assert_not_equals_int(10, session.dying_time, "V6 syn-lifetime");
    kfree_skb(skb);

    // Something else arrives.
    if (!init_skb_and_session(&skb, &session, PACKET_TYPE_V6_RST, V6_INIT, 10))
        return false;

    success &= assert_true(tcp_v6_init_state_handle(skb, &session), "else-result");
    success &= assert_equals_u8(V6_INIT, session.state, "else-state");
    success &= assert_equals_int(10, session.dying_time, "else-lifetime");
    kfree_skb(skb);

    return success;
}
Example #28
0
static bool test_sessiondb_timeouts_aux(struct expire_timer *expirer,
		unsigned int expirer_seconds, char *test_name)
{
	unsigned long mssec = msecs_to_jiffies(1000 * expirer_seconds);
	unsigned long timeout = get_timeout(expirer);

	return assert_equals_int(mssec, timeout, test_name);
}
Example #29
0
/**
 * Same as assert_bib(), except asserting session entries on the session table.
 */
static bool assert_session(char* test_name, struct session_entry* session,
		bool udp_table_has_it, bool tcp_table_has_it, bool icmp_table_has_it)
{
	struct session_entry *retrieved_session, *expected_session;
	struct tuple tuple6, tuple4;
	l4_protocol l4_protos[] = { L4PROTO_UDP, L4PROTO_TCP, L4PROTO_ICMP };
	bool table_has_it[3];
	bool success;
	int i;

	table_has_it[0] = udp_table_has_it;
	table_has_it[1] = tcp_table_has_it;
	table_has_it[2] = icmp_table_has_it;

	for (i = 0; i < 3; i++) {
		tuple4.dst.addr4 = session->local4;
		tuple4.src.addr4 = session->remote4;
		tuple4.l3_proto = L3PROTO_IPV4;
		tuple4.l4_proto = l4_protos[i];

		tuple6.dst.addr6 = session->local6;
		tuple6.src.addr6 = session->remote6;
		tuple6.l3_proto = L3PROTO_IPV6;
		tuple6.l4_proto = l4_protos[i];

		expected_session = table_has_it[i] ? session : NULL;
		success = true;

		retrieved_session = NULL;
		success &= assert_equals_int(table_has_it[i] ? 0 : -ESRCH,
				sessiondb_get(&tuple4, &retrieved_session),
				test_name);
		success &= assert_session_entry_equals(expected_session, retrieved_session, test_name);

		retrieved_session = NULL;
		success &= assert_equals_int(table_has_it[i] ? 0 : -ESRCH,
				sessiondb_get(&tuple6, &retrieved_session),
				test_name);
		success &= assert_session_entry_equals(expected_session, retrieved_session, test_name);

		if (!success)
			return false;
	}

	return true;
}
Example #30
0
static bool test_function_icmp4_to_icmp6_param_prob(void)
{
	struct icmphdr hdr4;
	struct icmp6hdr hdr6;
	bool success = true;

	hdr4.type = ICMP_PARAMETERPROB;
	hdr4.code = ICMP_PTR_INDICATES_ERROR;
	hdr4.icmp4_unused = cpu_to_be32(0x08000000);
	success &= assert_equals_int(0, icmp4_to_icmp6_param_prob(&hdr4, &hdr6), "func result 1");
	success &= assert_equals_u8(ICMPV6_HDR_FIELD, hdr6.icmp6_code, "code");
	success &= assert_equals_u8(7, be32_to_cpu(hdr6.icmp6_pointer), "pointer");

	hdr4.icmp4_unused = cpu_to_be32(0x05000000);
	success &= assert_equals_int(-EINVAL, icmp4_to_icmp6_param_prob(&hdr4, &hdr6), "func result 2");

	return success;
}