diff options
Diffstat (limited to 'src/scvpp/tests')
-rw-r--r-- | src/scvpp/tests/CMakeLists.txt | 42 | ||||
-rw-r--r-- | src/scvpp/tests/scvpp_iface_test.c | 130 | ||||
-rw-r--r-- | src/scvpp/tests/scvpp_ip_test.c | 184 | ||||
-rw-r--r-- | src/scvpp/tests/scvpp_nat_test.c | 173 | ||||
-rw-r--r-- | src/scvpp/tests/scvpp_test.c | 109 | ||||
-rw-r--r-- | src/scvpp/tests/scvpp_test.h | 31 |
6 files changed, 0 insertions, 669 deletions
diff --git a/src/scvpp/tests/CMakeLists.txt b/src/scvpp/tests/CMakeLists.txt deleted file mode 100644 index 78e1861..0000000 --- a/src/scvpp/tests/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (c) 2018 Cisco and/or its affiliates. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_directories ("${PROJECT_SOURCE_DIR}/src") - -# check whether valgrind is installed -find_program(valgrind_FOUND valgrind) - -set(TEST_SRC - scvpp_test.h - scvpp_test.c - scvpp_iface_test.c - scvpp_ip_test.c - scvpp_nat_test.c -) - -add_executable(scvpp_test ${TEST_SRC}) -target_link_libraries(scvpp_test ${CMOCKA_LIBRARIES} scvpp_a) -target_include_directories(scvpp_test PRIVATE ../inc) -add_test(scvpp_test ./scvpp_test) -set_tests_properties(scvpp_test PROPERTIES TIMEOUT 60) - -if(valgrind_FOUND) - add_test(scvpp_valgrind valgrind - --error-exitcode=1 --read-var-info=yes - --leak-check=full --show-leak-kinds=all - ./scvpp_test - ) - set_tests_properties(scvpp_valgrind PROPERTIES TIMEOUT 60) -endif(valgrind_FOUND) diff --git a/src/scvpp/tests/scvpp_iface_test.c b/src/scvpp/tests/scvpp_iface_test.c deleted file mode 100644 index 6a96694..0000000 --- a/src/scvpp/tests/scvpp_iface_test.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <unistd.h> -#include <setjmp.h> -#include <stdarg.h> -#include <cmocka.h> - -#include "scvpp_test.h" - -#include <scvpp/interface.h> -#include <scvpp/v3po.h> - -static void test_enable_disable(void **state) -{ - UNUSED(state); - sw_interface_dump_t dump = {0}; - int rc; - - rc = interface_enable("tap0", 1); - assert_int_equal(rc, SCVPP_OK); - - rc = interface_dump_iface(&dump, "tap0"); - assert_int_equal(rc, SCVPP_OK); - - assert_int_equal(dump.admin_up_down, true); - - rc = interface_enable("tap0", 0); - assert_int_equal(rc, SCVPP_OK); -} - -static void test_create_tapv2(void **state) -{ - UNUSED(state); - tapv2_create_t query = {0}; - sw_interface_dump_t dump = {0}; - int rc; - - query.id = 1; - query.use_random_mac = 1; - - rc = create_tapv2(&query); - assert_int_equal(rc, SCVPP_OK); - - rc = interface_dump_iface(&dump, "tap1"); - assert_int_equal(rc, SCVPP_OK); -} - -static int teardown_tapv2(void **state) -{ - UNUSED(state); - return delete_tapv2("tap1"); -} - -static void test_dump_iface_all(void **state) -{ - UNUSED(state); - struct elt *stack = NULL; - sw_interface_dump_t *dump; - bool exist = false; - - stack = interface_dump_all(); - assert_non_null(stack); - foreach_stack_elt(stack) { - dump = (sw_interface_dump_t *) data; - if (!strncmp((char*) dump->interface_name, "tap0", VPP_INTFC_NAME_LEN)) - exist = true; - free(dump); - } - assert_true(exist); -} - -static void test_dump_iface_exist(void **state) -{ - UNUSED(state); - vapi_payload_sw_interface_details details = {0}; - int rc; - - rc = interface_dump_iface(&details, "local0"); - assert_int_equal(rc, SCVPP_OK); - - assert_string_equal(details.interface_name, "local0"); -} - -static void test_dump_iface_unexist(void **state) -{ - UNUSED(state); - vapi_payload_sw_interface_details details = {0}; - int rc; - - rc = interface_dump_iface(&details, "unexisting"); - assert_int_equal(rc, -SCVPP_NOT_FOUND); -} - -static void test_get_interface_name(void **state) -{ - UNUSED(state); - char interface_name[VPP_INTFC_NAME_LEN]; - uint32_t tap0_if_index; - int rc; - - rc = get_interface_id("tap0", &tap0_if_index); - assert_int_equal(rc, SCVPP_OK); - - rc = get_interface_name(interface_name, tap0_if_index); - assert_int_equal(rc, SCVPP_OK); - - assert_string_equal(interface_name, "tap0"); -} - -const struct CMUnitTest iface_tests[IFACE_TEST_SIZE] = { - cmocka_unit_test_teardown(test_create_tapv2, teardown_tapv2), - cmocka_unit_test(test_enable_disable), - cmocka_unit_test(test_dump_iface_all), - cmocka_unit_test(test_dump_iface_exist), - cmocka_unit_test(test_dump_iface_unexist), - cmocka_unit_test(test_get_interface_name), -}; diff --git a/src/scvpp/tests/scvpp_ip_test.c b/src/scvpp/tests/scvpp_ip_test.c deleted file mode 100644 index 5e28123..0000000 --- a/src/scvpp/tests/scvpp_ip_test.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2019 Cisco - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <unistd.h> -#include <setjmp.h> -#include <stdarg.h> -#include <cmocka.h> - -#include "scvpp_test.h" - -#include <scvpp/ip.h> -#include <scvpp/interface.h> -#include <scvpp/comm.h> - -static void test_add_remove_ipv4(void **state) -{ - UNUSED(state); - const char ip_q[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.144"; - char ip_r[VPP_IP4_ADDRESS_STRING_LEN]; - u8 prefix_q = 24; - u8 prefix_r; - int rc; - - //add ipv4 on tap0 - rc = ipv46_config_add_remove("tap0", ip_q, prefix_q, false, true); - assert_int_equal(rc, SCVPP_OK); - - //dump ipv4 on tap0 and check if it mach - rc = ipv46_address_dump("tap0", ip_r, &prefix_r, false); - assert_int_equal(rc, SCVPP_OK); - assert_string_equal(ip_q, ip_r); - assert_int_equal(prefix_q, prefix_r); - - //remove ipv4 on tap0 - rc = ipv46_config_add_remove("tap0", ip_q, prefix_q, false, false); - assert_int_equal(rc, SCVPP_OK); - - //dump ipv4 after removal and check if equals 0.0.0.0 - rc = ipv46_address_dump("tap0", ip_r, &prefix_r, false); - assert_int_equal(rc, SCVPP_OK); - assert_string_equal(ip_r, "0.0.0.0"); -} - -static void test_ipv4_add_del_route_no_iface(void **state) -{ - UNUSED(state); - int rc; - char dst_address[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.0"; - uint8_t prefix_len = 24; - char next_hop[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.100"; - uint32_t table_id = 0; - fib_dump_t *dump; - struct elt *stack; - bool route_found = false; - - /* Must fail, can not have both interface and next hop IP null */ - rc = ipv46_config_add_del_route(dst_address, prefix_len, NULL, true, - table_id, NULL); - assert_int_equal(rc, -SCVPP_EINVAL); - - rc = ipv46_config_add_del_route(dst_address, prefix_len, next_hop, true, - table_id, NULL); - assert_int_equal(rc, SCVPP_OK); - - /* Dump all FIB routes and check if we find ours */ - stack = ipv4_fib_dump_all(); - assert_non_null(stack); - foreach_stack_elt(stack) { - dump = (fib_dump_t *) data; - - if (strncmp(sc_ntoa(dump->address), dst_address, - VPP_IP4_ADDRESS_STRING_LEN) == 0 && - dump->address_length == prefix_len) { - route_found = true; - assert_int_equal(dump->table_id, table_id); - assert_int_equal(dump->count, 1); - assert_string_equal(sc_ntoa(dump->path[0].next_hop), next_hop); - } - free(dump); - } - assert_true(route_found); - - /* Delete previously set route */ - rc = ipv46_config_add_del_route(dst_address, prefix_len, next_hop, false, - table_id, NULL); - assert_int_equal(rc, SCVPP_OK); - - /* Check our route has been deleted */ - route_found = false; - stack = ipv4_fib_dump_all(); - assert_non_null(stack); - foreach_stack_elt(stack) { - dump = (fib_dump_t *) data; - if (strncmp(sc_ntoa(dump->address), dst_address, - VPP_IP4_ADDRESS_STRING_LEN) == 0 && - dump->address_length == prefix_len) { - route_found = true; - } - free(dump); - } - assert_false(route_found); -} - -static void test_ipv4_add_del_route_no_next_hop_ip(void **state) -{ - UNUSED(state); - int rc; - char dst_address[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.0"; - uint8_t prefix_len = 24; - char interface[VPP_IP4_ADDRESS_STRING_LEN] = "tap0"; - uint32_t table_id = 0; - uint32_t sw_if_index; - fib_dump_t *dump; - struct elt *stack; - bool route_found = false; - - //Add a new route - rc = ipv46_config_add_del_route(dst_address, prefix_len, NULL, true, - table_id, interface); - assert_int_equal(rc, SCVPP_OK); - - //Dump all FIB routes and check we find ours - stack = ipv4_fib_dump_all(); - assert_non_null(stack); - - rc = get_interface_id(interface, &sw_if_index); - assert_int_equal(rc, SCVPP_OK); - - foreach_stack_elt(stack) { - dump = (fib_dump_t *) data; - - if (strncmp(sc_ntoa(dump->address), dst_address, - VPP_IP4_ADDRESS_STRING_LEN) == 0 && - dump->address_length == prefix_len) { - route_found = true; - assert_int_equal(dump->table_id, table_id); - assert_int_equal(dump->count, 1); - assert_int_equal(dump->path[0].sw_if_index, sw_if_index); - } - free(dump); - } - assert_true(route_found); - - //Delete route - rc = ipv46_config_add_del_route(dst_address, prefix_len, NULL, false, - table_id, interface); - assert_int_equal(rc, SCVPP_OK); - - //Check our route has been deleted - route_found = false; - stack = ipv4_fib_dump_all(); - assert_non_null(stack); - - foreach_stack_elt(stack) { - dump = (fib_dump_t *) data; - if (strncmp(sc_ntoa(dump->address), dst_address, - VPP_IP4_ADDRESS_STRING_LEN) == 0 && - dump->address_length == prefix_len) { - route_found = true; - } - free(dump); - } - assert_false(route_found); -} - - -const struct CMUnitTest ip_tests[IP_TEST_SIZE] = { - cmocka_unit_test(test_add_remove_ipv4), - cmocka_unit_test(test_ipv4_add_del_route_no_next_hop_ip), - cmocka_unit_test(test_ipv4_add_del_route_no_iface), -}; diff --git a/src/scvpp/tests/scvpp_nat_test.c b/src/scvpp/tests/scvpp_nat_test.c deleted file mode 100644 index 93541e9..0000000 --- a/src/scvpp/tests/scvpp_nat_test.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <setjmp.h> -#include <cmocka.h> - -#include "scvpp_test.h" - -#include <scvpp/comm.h> -#include <scvpp/nat.h> - - -void test_nat44_static_mapping(void **state) -{ - UNUSED(state); - nat44_add_del_static_mapping_t map = {0}; - nat44_static_mapping_details_t dump = {0}; - u8 empty_ip[4] = {0}; - int rc; - - /*Configure the static mapping - Alternative to this CLI command: - nat44 add static mapping local 172.168.0.1 external 172.168.8.5 - */ - sc_aton("172.168.0.1", map.local_ip_address, - sizeof(map.local_ip_address)); - sc_aton("172.168.8.5", map.external_ip_address, - sizeof(map.external_ip_address)); - map.external_sw_if_index = ~0; - map.is_add = 1; - - rc = nat44_add_del_static_mapping(&map); - assert_int_equal(rc, SCVPP_OK); - - rc = nat44_static_mapping_dump(&dump); - assert_int_equal(rc, SCVPP_OK); - - assert_memory_equal(dump.local_ip_address, map.local_ip_address, - sizeof(dump.local_ip_address)); - - assert_memory_equal(dump.external_ip_address, map.external_ip_address, - sizeof(dump.external_ip_address)); - - /* Remove previous config*/ - map.is_add = 0; - - rc = nat44_add_del_static_mapping(&map); - assert_int_equal(rc, SCVPP_OK); - - memset(&dump, 0, sizeof(dump)); - - rc = nat44_static_mapping_dump(&dump); - assert_int_equal(rc, SCVPP_OK); - - assert_memory_equal(dump.local_ip_address, empty_ip, - sizeof(dump.local_ip_address)); - - assert_memory_equal(dump.external_ip_address, empty_ip, - sizeof(dump.external_ip_address)); -} - -void test_nat44_static_mapping_with_ports(void **state) -{ - UNUSED(state); - nat44_add_del_static_mapping_t map = {0}; - nat44_static_mapping_details_t dump = {0}; - nat44_add_del_address_range_t range = {0}; - u8 empty_ip[4] = {0}; - const u16 lport = 77; - const u16 eport = 88; - int rc; - - /*Configure address pool - Alternative to this CLI: - nat44 add address 5.4.4.4 - */ - sc_aton("5.4.4.4", range.first_ip_address, - sizeof(range.first_ip_address)); - - sc_aton("5.4.4.4", range.last_ip_address, - sizeof(range.last_ip_address)); - - range.is_add = 1; - - rc = nat44_add_del_addr_range(&range); - assert_int_equal(rc, SCVPP_OK); - - /*Configure NAT with ports - Alternative to this CLI: - nat44 add static mapping tcp local 172.168.0.1 77 external 5.4.4.4 88 - */ - - sc_aton("172.168.0.1", map.local_ip_address, - sizeof(map.local_ip_address)); - - sc_aton("5.4.4.4", map.external_ip_address, - sizeof(map.external_ip_address)); - - map.protocol = 6; - - map.external_sw_if_index = ~0; - - map.external_port = eport; - map.local_port = lport; - - map.is_add = 1; - - rc = nat44_add_del_static_mapping(&map); - assert_int_equal(rc, SCVPP_OK); - - rc = nat44_static_mapping_dump(&dump); - assert_int_equal(rc, SCVPP_OK); - - assert_memory_equal(dump.local_ip_address, map.local_ip_address, - sizeof(dump.local_ip_address)); - - assert_memory_equal(dump.external_ip_address, map.external_ip_address, - sizeof(dump.external_ip_address)); - - assert_int_equal(dump.local_port, lport); - - assert_int_equal(dump.external_port, eport); - - /* Remove all previous config*/ - - map.is_add = 0; - - rc = nat44_add_del_static_mapping(&map); - assert_int_equal(rc, SCVPP_OK); - - memset(&dump, 0, sizeof(dump)); - - rc = nat44_static_mapping_dump(&dump); - assert_int_equal(rc, SCVPP_OK); - - assert_memory_equal(dump.local_ip_address, empty_ip, - sizeof(dump.local_ip_address)); - - assert_memory_equal(dump.external_ip_address, empty_ip, - sizeof(dump.external_ip_address)); - - assert_int_equal(dump.local_port, 0); - - assert_int_equal(dump.external_port, 0); - - range.is_add = 0; - - rc = nat44_add_del_addr_range(&range); - assert_int_equal(rc, SCVPP_OK); -} - -const struct CMUnitTest nat_tests[] = { - cmocka_unit_test_setup_teardown(test_nat44_static_mapping, NULL, - NULL), - cmocka_unit_test_setup_teardown(test_nat44_static_mapping_with_ports, - NULL, NULL), - }; diff --git a/src/scvpp/tests/scvpp_test.c b/src/scvpp/tests/scvpp_test.c deleted file mode 100644 index f6e99a0..0000000 --- a/src/scvpp/tests/scvpp_test.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> -#include <setjmp.h> - -#include <scvpp/comm.h> -#include <scvpp/v3po.h> - -#include "scvpp_test.h" - -/* test "AAA.BBB.CCC.DDD" -> {A, B, C, D} */ -static void test_sc_ntoa(void **state) -{ - UNUSED(state); - u8 buf[4] = {192, 168, 100, 44}; - char *res; - - res = sc_ntoa(buf); - assert_string_equal(res, "192.168.100.44"); -} - -/* test {A, B, C, D} -> "AAA.BBB.CCC.DDD" */ -static void test_sc_aton(void **state) -{ - UNUSED(state); - char ip[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.44"; - uint8_t buf[4]; - int rc; - - rc = sc_aton(ip, buf, VPP_IP4_ADDRESS_LEN); - assert_int_equal(rc, 0); - - assert_int_equal(buf[0], 192); - assert_int_equal(buf[1], 168); - assert_int_equal(buf[2], 100); - assert_int_equal(buf[3], 44); -} - -static int setup(void **state) -{ - UNUSED(state); - tapv2_create_t query = {0}; - - if (sc_connect_vpp() != 0) { - fprintf(stderr, "Error connecting to VPP\n"); - return -1; - } - - /* Create interface tap0 to test several functions */ - query.id = 0; - query.use_random_mac = 1; - if (create_tapv2(&query) != 0) { - fprintf(stderr, "Error creating tap0\n"); - return -1; - } - - return 0; -} - -static int teardown(void **state) -{ - UNUSED(state); - /* Delete tap0 */ - if (delete_tapv2("tap0") != 0) { - fprintf(stderr, "Failed deleting tap0\n"); - return -1; - } - - sc_disconnect_vpp(); - - return 0; -} - -/* return code for scvpp-test binary is the number of failed test */ -int main() -{ - int rc = 0; - - const struct CMUnitTest common_tests[] = { - cmocka_unit_test(test_sc_ntoa), - cmocka_unit_test(test_sc_aton), - }; - - print_message("Common tests\n"); - rc |= cmocka_run_group_tests(common_tests, NULL, NULL); - print_message("Interface tests\n"); - rc |= cmocka_run_group_tests(iface_tests, setup, teardown); - print_message("IP tests\n"); - rc |= cmocka_run_group_tests(ip_tests, setup, teardown); - print_message("NAT tests\n"); - rc |= cmocka_run_group_tests(nat_tests, setup, teardown); - - return rc; -} diff --git a/src/scvpp/tests/scvpp_test.h b/src/scvpp/tests/scvpp_test.h deleted file mode 100644 index 28bd514..0000000 --- a/src/scvpp/tests/scvpp_test.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 Cisco - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __SCVPP_TEST_H -#define __SCVPP_TEST_H__ - -#include <cmocka.h> - -#define IFACE_TEST_SIZE 6 -extern const struct CMUnitTest iface_tests[IFACE_TEST_SIZE]; - -#define IP_TEST_SIZE 3 -extern const struct CMUnitTest ip_tests[IP_TEST_SIZE]; - -#define NAT_TEST_SIZE 2 -extern const struct CMUnitTest nat_tests[NAT_TEST_SIZE]; - -#endif /* __SCVPP_TEST_H__ */ |