Пример #1
0
int init_module(void)
{
	START_TESTS("Addr");

	CALL_TEST(addr_count_test(), "Addr count");
	CALL_TEST(contains_test(), "Prefix contains");

	END_TESTS;
}
Пример #2
0
int init_module(void)
{
	START_TESTS("IPv6 header iterator");

	CALL_TEST(test_no_subheaders(), "No subheaders");
	CALL_TEST(test_subheaders(), "Subheaders");

	END_TESTS;
}
int init_module(void)
{
	START_TESTS("Determine incoming tuple");

	CALL_TEST(test_determine_in_tuple_ipv4(), "3 fragments IPv4 packet.");
	CALL_TEST(test_determine_in_tuple_ipv6(), "3 fragments IPv6 packet.");

	END_TESTS;
}
Пример #4
0
int init_module(void)
{
	START_TESTS("Hash table");

	CALL_TEST(test(), "Everything, except for_each");
	CALL_TEST(test_for_each_function(), "for_each function");

	END_TESTS;
}
Пример #5
0
int init_module(void)
{
	START_TESTS("Determine incoming tuple");

	if (is_error(pktmod_init()))
		return -EINVAL;

	CALL_TEST(test_determine_in_tuple_ipv4(), "3 fragments IPv4 packet.");
	CALL_TEST(test_determine_in_tuple_ipv6(), "3 fragments IPv6 packet.");

	pktmod_destroy();

	END_TESTS;
}
Пример #6
0
int init_module(void)
{
    int i;
    START_TESTS("nf_nat64_rfc6052.c");

    // test the extract function.
    for (i = 0; i < 6; i++) {
        CALL_TEST(test_extract_ipv4(arr_ipv6[i], pref[i]), arr_ipv6[i]);
    }

    // Test the append function.
    for (i = 0; i < 6; i++) {
        CALL_TEST(test_append_ipv4(arr_ipv6[i], prefix[i], pref[i]), arr_ipv6[i]);
    }

    END_TESTS;
}
Пример #7
0
int init_module(void)
{
	START_TESTS("Packet");
	if (str_to_addr6("1::1", &dummies6[0]) != 0)
		return -EINVAL;
	if (str_to_addr6("2::2", &dummies6[1]) != 0)
		return -EINVAL;
	if (str_to_addr4("1.1.1.1", &dummies4[0]) != 0)
		return -EINVAL;
	if (str_to_addr4("2.2.2.2", &dummies4[1]) != 0)
		return -EINVAL;

	CALL_TEST(test_function_is_dont_fragment_set(), "Dont fragment getter");
	CALL_TEST(test_function_is_more_fragments_set(), "More fragments getter");
	CALL_TEST(test_function_build_ipv4_frag_off_field(), "Generate frag offset + flags function");

	CALL_TEST(test_inner_packet_validation4(), "Inner packet IPv4 Validation");
	CALL_TEST(test_inner_packet_validation6(), "Inner packet IPv6 Validation");

	END_TESTS;
}
Пример #8
0
static int init_test_module(void)
{
	START_TESTS("Handling Hairpinning");

	if (!init())
		return -EINVAL;

	/*
	 * Well, the only thing not being tested here, I think, is hairpinning not getting in the way
	 * when there's no need for it.
	 * But that's handled in every other test, ever.
	 */

	CALL_TEST(test_hairpin(L4PROTO_UDP, create_skb6_udp), "UDP");
	CALL_TEST(test_hairpin(L4PROTO_TCP, create_skb6_tcp), "TCP");
	CALL_TEST(test_icmp(), "ICMP");

	deinit();

	END_TESTS;
}
Пример #9
0
int init_module(void)
{
	START_TESTS("IPv6 header iterator");

	CALL_TEST(test_next_no_subheaders(), "next function, no subheaders");
	CALL_TEST(test_next_subheaders(), "next function, subheaders");
	CALL_TEST(test_next_unsupported(), "next function, unsupported hdrs");

	CALL_TEST(test_last_no_subheaders(), "last function, no subheaders");
	CALL_TEST(test_last_subheaders(), "last function, subheaders");
	CALL_TEST(test_last_unsupported(), "last function, unsupported hdrs");

	CALL_TEST(test_find_no_subheaders(), "find function, no subheaders");
	CALL_TEST(test_find_subheaders(), "find function, subheaders");
	CALL_TEST(test_find_unsupported(), "find function, unsupported hdrs");

	END_TESTS;
}
Пример #10
0
int init_module(void)
{
	int i;
	START_TESTS("rfc6052.c");

	if (!init())
		return -EINVAL;

	// test the extract function.
	for (i = 0; i < 6; i++) {
		CALL_TEST(test_addr_6to4(&ipv6_addr[i], &prefixes[i], &ipv4_addr), "Extract-%pI6c",
				&ipv6_addr[i]);
	}

	// Test the append function.
	for (i = 0; i < 6; i++) {
		CALL_TEST(test_addr_4to6(&ipv4_addr, &prefixes[i], &ipv6_addr[i]), "Append-%pI6c",
				&ipv6_addr[i]);
	}

	END_TESTS;
}
Пример #11
0
int init_module(void)
{
	START_TESTS("Translating the Packet");

	if (config_init(&config))
		return false;

	/* Misc single function tests */
	CALL_TEST(test_function_has_unexpired_src_route(), "Unexpired source route querier");
	CALL_TEST(test_function_build_id_field(), "Identification builder");
	CALL_TEST(test_function_icmp6_minimum_mtu(), "ICMP6 Minimum MTU function");
	CALL_TEST(test_function_icmp4_to_icmp6_param_prob(), "Param problem function");

	CALL_TEST(test_function_generate_ipv4_id(), "Generate id function");
	CALL_TEST(test_function_generate_df_flag(), "Generate DF flag function");
	CALL_TEST(test_function_build_protocol_field(), "Build protocol function");
	CALL_TEST(test_function_has_nonzero_segments_left(), "Segments left indicator function");
	CALL_TEST(test_function_icmp4_minimum_mtu(), "ICMP4 Minimum MTU function");

	config_put(config);

	END_TESTS;
}
Пример #12
0
int init_module(void)
{
	START_TESTS("Outgoing");

	if (!init())
		return -EINVAL;

	CALL_TEST(test_6to4(tuple5, IPPROTO_UDP, IPPROTO_UDP), "Tuple-5, 6 to 4, UDP");
	CALL_TEST(test_4to6(tuple5, IPPROTO_UDP, IPPROTO_UDP), "Tuple-5, 4 to 6, UDP");
	CALL_TEST(test_6to4(tuple5, IPPROTO_TCP, IPPROTO_TCP), "Tuple-5, 6 to 4, TCP");
	CALL_TEST(test_4to6(tuple5, IPPROTO_TCP, IPPROTO_TCP), "Tuple-5, 4 to 6, TCP");
	CALL_TEST(test_6to4(tuple5, NEXTHDR_ICMP, IPPROTO_ICMP), "Tuple-5, 6 to 4, ICMP");
	CALL_TEST(test_4to6(tuple5, IPPROTO_ICMP, NEXTHDR_ICMP), "Tuple-5, 4 to 6, ICMP");

	CALL_TEST(test_6to4(tuple3, NEXTHDR_ICMP, IPPROTO_ICMP), "Tuple-3, 6 to 4, ICMP");
	CALL_TEST(test_4to6(tuple3, IPPROTO_ICMP, NEXTHDR_ICMP), "Tuple-3, 4 to 6, ICMP");

	cleanup();

	END_TESTS;
}
int main(int argc, char* argv[])
{
  TRY_ENTRY();
  string_tools::set_module_name_and_folder(argv[0]);

  //set up logging options
  log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3);
  log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_3);
  
  log_space::log_singletone::add_logger(LOGGER_FILE, 
    log_space::log_singletone::get_default_log_file().c_str(), 
    log_space::log_singletone::get_default_log_folder().c_str());

  po::options_description desc_options("Allowed options");
  command_line::add_arg(desc_options, command_line::arg_help);
  command_line::add_arg(desc_options, arg_test_data_path);
  command_line::add_arg(desc_options, arg_generate_test_data);
  command_line::add_arg(desc_options, arg_play_test_data);
  command_line::add_arg(desc_options, arg_generate_and_play_test_data);
  command_line::add_arg(desc_options, arg_test_transactions);

  po::variables_map vm;
  bool r = command_line::handle_error_helper(desc_options, [&]()
  {
    po::store(po::parse_command_line(argc, argv, desc_options), vm);
    po::notify(vm);
    return true;
  });
  if (!r)
    return 1;

  if (command_line::get_arg(vm, command_line::arg_help))
  {
    std::cout << desc_options << std::endl;
    return 0;
  }

  size_t tests_count = 0;
  std::vector<std::string> failed_tests;
  std::string tests_folder = command_line::get_arg(vm, arg_test_data_path);
  if (command_line::get_arg(vm, arg_generate_test_data))
  {
    GENERATE("chain001.dat", gen_simple_chain_001);
  }
  else if (command_line::get_arg(vm, arg_play_test_data))
  {
    PLAY("chain001.dat", gen_simple_chain_001);
  }
  else if (command_line::get_arg(vm, arg_test_transactions))
  {
    CALL_TEST("TRANSACTIONS TESTS", test_transactions);
  }
  else //if (command_line::get_arg(vm, arg_generate_and_play_test_data))
  {    
     // crypto::random_prng_initialize_with_seed(0);
//     GENERATE_AND_PLAY(mix_attr_tests);

    GENERATE_AND_PLAY(prun_ring_signatures);
    GENERATE_AND_PLAY(get_random_outs_test);
    GENERATE_AND_PLAY(mix_attr_tests);
    GENERATE_AND_PLAY(gen_simple_chain_001);
    GENERATE_AND_PLAY(gen_simple_chain_split_1);
    GENERATE_AND_PLAY(one_block);
    GENERATE_AND_PLAY(gen_chain_switch_1);
    GENERATE_AND_PLAY(gen_ring_signature_1);
    GENERATE_AND_PLAY(gen_ring_signature_2);
    //GENERATE_AND_PLAY(gen_ring_signature_big); // Takes up to XXX hours (if CURRENCY_MINED_MONEY_UNLOCK_WINDOW == 10)

    // Block verification tests
    GENERATE_AND_PLAY(gen_block_big_major_version);
    GENERATE_AND_PLAY(gen_block_big_minor_version);
    GENERATE_AND_PLAY(gen_block_ts_not_checked);
    GENERATE_AND_PLAY(gen_block_ts_in_past);
    GENERATE_AND_PLAY(gen_block_ts_in_future);
    //GENERATE_AND_PLAY(gen_block_invalid_prev_id); disabled becouse impossible to generate text chain with wrong prev_id - pow hash not works without chaining
    GENERATE_AND_PLAY(gen_block_invalid_nonce);
    GENERATE_AND_PLAY(gen_block_no_miner_tx);
    GENERATE_AND_PLAY(gen_block_unlock_time_is_low);
    GENERATE_AND_PLAY(gen_block_unlock_time_is_high);
    GENERATE_AND_PLAY(gen_block_unlock_time_is_timestamp_in_past);
    GENERATE_AND_PLAY(gen_block_unlock_time_is_timestamp_in_future);
    GENERATE_AND_PLAY(gen_block_height_is_low);
    GENERATE_AND_PLAY(gen_block_height_is_high);
    GENERATE_AND_PLAY(gen_block_miner_tx_has_2_tx_gen_in);
    GENERATE_AND_PLAY(gen_block_miner_tx_has_2_in);
    GENERATE_AND_PLAY(gen_block_miner_tx_with_txin_to_key);
    GENERATE_AND_PLAY(gen_block_miner_tx_out_is_small);
    GENERATE_AND_PLAY(gen_block_miner_tx_out_is_big);
    GENERATE_AND_PLAY(gen_block_miner_tx_has_no_out);
    GENERATE_AND_PLAY(gen_block_miner_tx_has_out_to_alice);
    GENERATE_AND_PLAY(gen_block_has_invalid_tx);
    GENERATE_AND_PLAY(gen_block_is_too_big);
    GENERATE_AND_PLAY(gen_block_invalid_binary_format); // Takes up to 3 hours, if CURRENCY_MINED_MONEY_UNLOCK_WINDOW == 500, up to 30 minutes, if CURRENCY_MINED_MONEY_UNLOCK_WINDOW == 10
    GENERATE_AND_PLAY(gen_alias_tests); 

    
    // Transaction verification tests
    GENERATE_AND_PLAY(gen_tx_big_version);
    GENERATE_AND_PLAY(gen_tx_unlock_time);
    GENERATE_AND_PLAY(gen_tx_input_is_not_txin_to_key);
    GENERATE_AND_PLAY(gen_tx_no_inputs_no_outputs);
    GENERATE_AND_PLAY(gen_tx_no_inputs_has_outputs);
    GENERATE_AND_PLAY(gen_tx_has_inputs_no_outputs);
    GENERATE_AND_PLAY(gen_tx_invalid_input_amount);
    GENERATE_AND_PLAY(gen_tx_input_wo_key_offsets);
    GENERATE_AND_PLAY(gen_tx_sender_key_offest_not_exist);
    GENERATE_AND_PLAY(gen_tx_key_offest_points_to_foreign_key);
    GENERATE_AND_PLAY(gen_tx_mixed_key_offest_not_exist);
    GENERATE_AND_PLAY(gen_tx_key_image_not_derive_from_tx_key);
    GENERATE_AND_PLAY(gen_tx_key_image_is_invalid);
    GENERATE_AND_PLAY(gen_tx_check_input_unlock_time);
    GENERATE_AND_PLAY(gen_tx_txout_to_key_has_invalid_key);
    GENERATE_AND_PLAY(gen_tx_output_with_zero_amount);
    GENERATE_AND_PLAY(gen_tx_output_is_not_txout_to_key);
    GENERATE_AND_PLAY(gen_tx_signatures_are_invalid);

    // Double spend
    GENERATE_AND_PLAY(gen_double_spend_in_tx<false>);
    GENERATE_AND_PLAY(gen_double_spend_in_tx<true>);
    GENERATE_AND_PLAY(gen_double_spend_in_the_same_block<false>);
    GENERATE_AND_PLAY(gen_double_spend_in_the_same_block<true>);
    GENERATE_AND_PLAY(gen_double_spend_in_different_blocks<false>);
    GENERATE_AND_PLAY(gen_double_spend_in_different_blocks<true>);
    GENERATE_AND_PLAY(gen_double_spend_in_different_chains);
    GENERATE_AND_PLAY(gen_double_spend_in_alt_chain_in_the_same_block<false>);
    GENERATE_AND_PLAY(gen_double_spend_in_alt_chain_in_the_same_block<true>);
    GENERATE_AND_PLAY(gen_double_spend_in_alt_chain_in_different_blocks<false>);
    GENERATE_AND_PLAY(gen_double_spend_in_alt_chain_in_different_blocks<true>);

    GENERATE_AND_PLAY(gen_uint_overflow_1);
    GENERATE_AND_PLAY(gen_uint_overflow_2);

    //GENERATE_AND_PLAY(gen_block_reward);
    std::stringstream ss;
    ss << (failed_tests.empty() ? concolor::green : concolor::magenta);
    ss << "\nREPORT:\n";
    ss << "  Test run: " << tests_count << '\n';
    ss << "  Failures: " << failed_tests.size() << '\n';
    if (!failed_tests.empty())
    {
      std::cout << "FAILED TESTS:\n";
      BOOST_FOREACH(auto test_name, failed_tests)
      {
        std::cout << "  " << test_name << '\n';
      }
    }
Пример #14
0
int __init filtering_test_init(void)
{
    START_TESTS("Filtering and Updating");
    
    log_debug("\n\n\n");
    log_debug("\n\nNAT64 %s TEST module inserted!", "filtering_test");

    /*      UDP & ICMP      */
    CALL_TEST(test_transport_address_ipv4(), "test_transport_address_ipv4");
    CALL_TEST(test_transport_address_ipv6(), "test_transport_address_ipv6");
    CALL_TEST(test_extract_ipv4_from_ipv6(), "test_extract_ipv4_from_ipv6");
    CALL_TEST(test_embed_ipv4_in_ipv6(), "test_embed_ipv4_in_ipv6");
    INIT_CALL_END(init_full(), test_allocate_ipv4_transport_address(), end_full(), "test_allocate_ipv4_transport_address");
    INIT_CALL_END(init_full(), test_allocate_ipv4_transport_address_digger(), end_full(), "test_allocate_ipv4_transport_address_digger");
    INIT_CALL_END(init_full(), test_ipv6_udp(), end_full(), "test_ipv6_udp");
    INIT_CALL_END(init_full(), test_ipv4_udp(), end_full(), "test_ipv4_udp");
    INIT_CALL_END(init_full(), test_ipv6_icmp6(), end_full(), "test_ipv6_icmp6");
    INIT_CALL_END(init_full(), test_ipv4_icmp4(), end_full(), "test_ipv4_icmp4");
    /* CALL_TEST(test_send_icmp_error_message(), "test_send_icmp_error_message"); Not implemented yet! */
    INIT_CALL_END(init_full(), test_filtering_and_updating(), end_full(), "test_filtering_and_updating");

    /*      TCP      */
    CALL_TEST(test_packet_is_ipv4(), "test_packet_is_ipv4");
    CALL_TEST(test_packet_is_ipv6(), "test_packet_is_ipv6");
    CALL_TEST(test_packet_is_v4_syn(), "test_packet_is_v4_syn");
    CALL_TEST(test_packet_is_v6_syn(), "test_packet_is_v6_syn");
    CALL_TEST(test_packet_is_v4_fin(), "test_packet_is_v4_fin");
    CALL_TEST(test_packet_is_v6_fin(), "test_packet_is_v6_fin");
    CALL_TEST(test_packet_is_v4_rst(), "test_packet_is_v4_rst");
    CALL_TEST(test_packet_is_v6_rst(), "test_packet_is_v6_rst");
    CALL_TEST(test_send_probe_packet(), "test_send_probe_packet");
    INIT_CALL_END(init_full(), test_tcp_closed_state_handle_6(), end_full(), "test_tcp_closed_state_handle_6");
    /* INIT_CALL_END(init_full(), test_tcp_closed_state_handle_4(), end_full(), "test_tcp_closed_state_handle_4"); Not implemented yet! */
    CALL_TEST(test_tcp_v4_init_state_handle(), "test_tcp_v4_init_state_handle");
    CALL_TEST(test_tcp_v6_init_state_handle(), "test_tcp_v6_init_state_handle");
    CALL_TEST(test_tcp_established_state_handle(), "test_tcp_established_state_handle");
    CALL_TEST(test_tcp_v4_fin_rcv_state_handle(), "test_tcp_v4_fin_rcv_state_handle");
    CALL_TEST(test_tcp_v6_fin_rcv_state_handle(), "test_tcp_v6_fin_rcv_state_handle");
    CALL_TEST(test_tcp_trans_state_handle(), "test_tcp_trans_state_handle");
    /* INIT_CALL_END(init_full(), test_tcp(), end_full(), "test_tcp"); */

    /* A non 0 return means a test failed; module can't be loaded. */
    END_TESTS;
}
Пример #15
0
	TESTCASE() {
		CALL_TEST(SearchInFunc);
	}
Пример #16
0
int init_module(void)
{
	START_TESTS("Translating the Packet");

	if (is_error(translate_packet_init()))
		return -EINVAL;

	/* Misc single function tests */
	CALL_TEST(test_function_has_unexpired_src_route(), "Unexpired source route querier");
	CALL_TEST(test_function_build_id_field(), "Identification builder");
	CALL_TEST(test_function_icmp6_minimum_mtu(), "ICMP6 Minimum MTU function");
	CALL_TEST(test_function_icmp4_to_icmp6_param_prob(), "Param problem function");

	CALL_TEST(test_function_generate_ipv4_id_nofrag(), "Generate id function (no frag)");
	CALL_TEST(test_function_generate_df_flag(), "Generate DF flag function");
	CALL_TEST(test_function_build_protocol_field(), "Build protocol function");
	CALL_TEST(test_function_has_nonzero_segments_left(), "Segments left indicator function");
	CALL_TEST(test_function_generate_ipv4_id_dofrag(), "Generate id function (frag)");
	CALL_TEST(test_function_icmp4_minimum_mtu(), "ICMP4 Minimum MTU function");

	/* Full packet translation tests */
	CALL_TEST(test_4to6_udp(), "Full translation, 4->6 UDP");
	CALL_TEST(test_4to6_tcp(), "Full translation, 4->6 TCP");
	CALL_TEST(test_4to6_icmp_info(), "Full translation, 4->6 ICMP info");
	CALL_TEST(test_4to6_icmp_error(), "Full translation, 4->6 ICMP error");
	CALL_TEST(test_4to6frag_tcp(), "Full Fragments, 4->6 TCP");
	CALL_TEST(test_4to6frag_udp(), "Full Fragments, 4->6 UDP");
	CALL_TEST(test_4to6frag_icmp(), "Full Fragments, 4->6 ICMP");

	CALL_TEST(test_6to4_udp(), "Full translation, 6->4 UDP");
	CALL_TEST(test_6to4_tcp(), "Full translation, 6->4 TCP");
	CALL_TEST(test_6to4_icmp_info(), "Full translation, 6->4 ICMP info");
	CALL_TEST(test_6to4_icmp_error(), "Full translation, 6->4 ICMP error");
	CALL_TEST(test_6to4frag_tcp(), "Full Fragments, 6->4 TCP");
	CALL_TEST(test_6to4frag_udp(), "Full Fragments, 6->4 UDP");
	CALL_TEST(test_6to4frag_icmp(), "Full Fragments, 6->4 ICMP");

	/* TODO (test) still need to test zero IPv4-UDP checksums. I think that's all. */

	translate_packet_destroy();

	END_TESTS;
}
Пример #17
0
int init_module(void)
{
	START_TESTS("IPv6 header iterator");

	CALL_TEST(test_next_function_no_subheaders(), "next function, no subheaders");
	CALL_TEST(test_next_function_subheaders(), "next function, subheaders");
	CALL_TEST(test_next_function_unsupported(), "next function, unsupported headers");
	CALL_TEST(test_next_function_overflow(), "next function, corrupted packet");

	CALL_TEST(test_last_function_no_subheaders(), "last function, no subheaders");
	CALL_TEST(test_last_function_subheaders(), "last function, subheaders");
	CALL_TEST(test_last_function_unsupported(), "last function, unsupported headers");
	CALL_TEST(test_last_function_overflow(), "last function, corrupted packet");

	CALL_TEST(test_get_ext_function_no_subheaders(), "get ext function, no subheaders");
	CALL_TEST(test_get_ext_function_subheaders(), "get ext function, subheaders");
	CALL_TEST(test_get_ext_function_unsupported(), "get ext function, unsupported headers");
	CALL_TEST(test_get_ext_function_overflow(), "get ext function, corrupted packet");

	END_TESTS;
}