tests: Migrate to new cmocka API
authorAndreas Schneider <asn@samba.org>
Thu, 6 Aug 2015 14:08:32 +0000 (16:08 +0200)
committerAndreas Schneider <asn@samba.org>
Tue, 11 Aug 2015 11:58:22 +0000 (13:58 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
12 files changed:
tests/test_echo_tcp_bind.c
tests/test_echo_tcp_connect.c
tests/test_echo_tcp_get_peer_sock_name.c
tests/test_echo_tcp_socket.c
tests/test_echo_tcp_socket_options.c
tests/test_echo_tcp_write_read.c
tests/test_echo_tcp_writev_readv.c
tests/test_echo_udp_send_recv.c
tests/test_echo_udp_sendmsg_recvmsg.c
tests/test_echo_udp_sendto_recvfrom.c
tests/test_ioctl.c
tests/test_sendmsg_recvmsg_fd.c

index b95724d9d1e446632a1f52714e49c1f242126f77..0baf0bd9bece3047235e21bb949b59a935da07a7 100644 (file)
 #include <rpc/rpc.h>
 #endif
 
-static void setup_echo_srv_tcp_ipv4(void **state)
+static int setup_echo_srv_tcp_ipv4(void **state)
 {
        torture_setup_echo_srv_tcp_ipv4(state);
+
+       return 0;
 }
 
-static void setup_echo_srv_tcp_ipv6(void **state)
+static int setup_echo_srv_tcp_ipv6(void **state)
 {
        torture_setup_echo_srv_tcp_ipv6(state);
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_bind_ipv4(void **state)
@@ -492,39 +498,39 @@ static void test_bindresvport_on_ipv6_sock_null(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_bind_ipv4,
+       const struct CMUnitTest tcp_bind_tests[] = {
+               cmocka_unit_test_setup_teardown(test_bind_ipv4,
                                         setup_echo_srv_tcp_ipv4,
                                         teardown),
 #if 0 /* TODO */
-               unit_test_setup_teardown(test_bind_ipv4_addr_in_use,
+               cmocka_unit_test_setup_teardown(test_bind_ipv4_addr_in_use,
                                         setup_echo_srv_tcp_ipv4,
                                         teardown),
 #endif
 #ifdef HAVE_BINDRESVPORT
-               unit_test_setup_teardown(test_bindresvport_ipv4,
+               cmocka_unit_test_setup_teardown(test_bindresvport_ipv4,
                                         setup_echo_srv_tcp_ipv4,
                                         teardown),
-               unit_test_setup_teardown(test_bindresvport_ipv4_null,
+               cmocka_unit_test_setup_teardown(test_bindresvport_ipv4_null,
                                         setup_echo_srv_tcp_ipv4,
                                         teardown),
 #endif /* HAVE_BINDRESVPORT */
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_bind_on_ipv6_sock,
+               cmocka_unit_test_setup_teardown(test_bind_on_ipv6_sock,
                                         setup_echo_srv_tcp_ipv6,
                                         teardown),
 #ifdef HAVE_BINDRESVPORT
-               unit_test_setup_teardown(test_bindresvport_on_ipv6_sock,
+               cmocka_unit_test_setup_teardown(test_bindresvport_on_ipv6_sock,
                                         setup_echo_srv_tcp_ipv6,
                                         teardown),
-               unit_test_setup_teardown(test_bindresvport_on_ipv6_sock_null,
+               cmocka_unit_test_setup_teardown(test_bindresvport_on_ipv6_sock_null,
                                         setup_echo_srv_tcp_ipv6,
                                         teardown),
 #endif /* HAVE_BINDRESVPORT */
 #endif /* HAVE_IPV6 */
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(tcp_bind_tests, NULL, NULL);
 
        return rc;
 }
index 0697e1314debf50b8c2be8da3ae19ada79ee2b18..f97b5ace08d2d7004add1876f5cff9f36d963b9a 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_tcp_ipv4(void **state)
+static int setup_echo_srv_tcp_ipv4(void **state)
 {
        torture_setup_echo_srv_tcp_ipv4(state);
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_connect_broadcast_ipv4(void **state)
@@ -82,14 +86,16 @@ static void test_connect_downgrade_ipv6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_connect_broadcast_ipv4, setup_echo_srv_tcp_ipv4, teardown),
+       const struct CMUnitTest tcp_connect_tests[] = {
+               cmocka_unit_test(test_connect_broadcast_ipv4),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_connect_downgrade_ipv6, setup_echo_srv_tcp_ipv4, teardown),
+               cmocka_unit_test(test_connect_downgrade_ipv6),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(tcp_connect_tests,
+                                   setup_echo_srv_tcp_ipv4,
+                                   teardown);
 
        return rc;
 }
index 4be729c5c00b6e36acb20f917db83c4916a9fab8..9a002552182186f0b6f41ba6e4b506a93d3a87b0 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_tcp_ipv4(void **state)
+static int setup_echo_srv_tcp_ipv4(void **state)
 {
        torture_setup_echo_srv_tcp_ipv4(state);
        setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "20", 1);
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void _assert_sockaddr_equal(struct torture_address *addr, const char *a,
@@ -446,25 +450,27 @@ static void test_connect_getsockname_getpeername_len(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_connect_getsockname_getpeername,
-                                        setup_echo_srv_tcp_ipv4,
-                                        teardown),
-               unit_test_setup_teardown(test_connect_getsockname_getpeername_port,
-                                        setup_echo_srv_tcp_ipv4,
-                                        teardown),
-               unit_test_setup_teardown(test_connect_getsockname_getpeername_any,
-                                        setup_echo_srv_tcp_ipv4,
-                                        teardown),
-               unit_test_setup_teardown(test_connect_getsockname_getpeername_any_port,
-                                        setup_echo_srv_tcp_ipv4,
-                                        teardown),
-               unit_test_setup_teardown(test_connect_getsockname_getpeername_len,
-                                        setup_echo_srv_tcp_ipv4,
-                                        teardown),
+       const struct CMUnitTest sock_name_tests[] = {
+               cmocka_unit_test_setup_teardown(test_connect_getsockname_getpeername,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_connect_getsockname_getpeername_port,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_connect_getsockname_getpeername_any,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_connect_getsockname_getpeername_any_port,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_connect_getsockname_getpeername_len,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(sock_name_tests,
+                                   NULL,
+                                   NULL);
 
        return rc;
 }
index a4b2f8927e5964202aaffa8aa1b879a8193ddc51..1bd4710b30c2ad889c2db12dc5a983fe955603d2 100644 (file)
@@ -56,14 +56,14 @@ static void test_socket_getsockname6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test(test_socket_getsockname),
+       const struct CMUnitTest getsockname_tests[] = {
+               cmocka_unit_test(test_socket_getsockname),
 #ifdef HAVE_IPV6
-               unit_test(test_socket_getsockname6),
+               cmocka_unit_test(test_socket_getsockname6),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(getsockname_tests, NULL, NULL);
 
        return rc;
 }
index dbad41d570945b99c76b21394dbfffe3e062b4a8..f068fb842374f5e86f825695640b85d66a833446 100644 (file)
 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
 #endif
 
-static void setup_echo_srv_tcp_ipv4(void **state)
+static int setup_echo_srv_tcp_ipv4(void **state)
 {
        torture_setup_echo_srv_tcp_ipv4(state);
+
+       return 0;
 }
 
 #ifdef HAVE_IPV6
-static void setup_echo_srv_tcp_ipv6(void **state)
+static int setup_echo_srv_tcp_ipv6(void **state)
 {
        torture_setup_echo_srv_tcp_ipv6(state);
+
+       return 0;
 }
 
-static void setup_ipv6(void **state)
+static int setup_ipv6(void **state)
 {
        torture_setup_socket_dir(state);
+
+       return 0;
 }
 #endif
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_sockopt_sndbuf(void **state)
@@ -288,20 +296,24 @@ static void test_bind_ipv6_only(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_sockopt_sndbuf, setup_echo_srv_tcp_ipv4, teardown),
-               unit_test_setup_teardown(test_sockopt_so,
-                                        setup_echo_srv_tcp_ipv4,
-                                        teardown),
+       const struct CMUnitTest sockopt_tests[] = {
+               cmocka_unit_test_setup_teardown(test_sockopt_sndbuf,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_sockopt_so,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_sockopt_so6,
-                                        setup_echo_srv_tcp_ipv6,
-                                        teardown),
-               unit_test_setup_teardown(test_bind_ipv6_only, setup_ipv6, teardown),
+               cmocka_unit_test_setup_teardown(test_sockopt_so6,
+                                               setup_echo_srv_tcp_ipv6,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_bind_ipv6_only,
+                                               setup_ipv6,
+                                               teardown),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(sockopt_tests, NULL, NULL);
 
        return rc;
 }
index 80200ad04175af5618458edc858f3506b3af3174..9129022a7b8d47cf74853e0f0f839a7969ac2fa5 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_tcp_ipv4(void **state)
+static int setup_echo_srv_tcp_ipv4(void **state)
 {
        torture_setup_echo_srv_tcp_ipv4(state);
+
+       return 0;
 }
 
 #ifdef HAVE_IPV6
-static void setup_echo_srv_tcp_ipv6(void **state)
+static int setup_echo_srv_tcp_ipv6(void **state)
 {
        torture_setup_echo_srv_tcp_ipv6(state);
+
+       return 0;
 }
 #endif
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_write_read_ipv4(void **state)
@@ -133,14 +139,18 @@ static void test_write_read_ipv6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_write_read_ipv4, setup_echo_srv_tcp_ipv4, teardown),
+       const struct CMUnitTest tcp_write_tests[] = {
+               cmocka_unit_test_setup_teardown(test_write_read_ipv4,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_write_read_ipv6, setup_echo_srv_tcp_ipv6, teardown),
+               cmocka_unit_test_setup_teardown(test_write_read_ipv6,
+                                               setup_echo_srv_tcp_ipv6,
+                                               teardown),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(tcp_write_tests, NULL, NULL);
 
        return rc;
 }
index 7a8b43681acf1f441509aedf1dfc400379ea9a56..e01123661f2e940895b40535f37973f30d7530ed 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_tcp_ipv4(void **state)
+static int setup_echo_srv_tcp_ipv4(void **state)
 {
        torture_setup_echo_srv_tcp_ipv4(state);
+
+       return 0;
 }
 
 #ifdef HAVE_IPV6
-static void setup_echo_srv_tcp_ipv6(void **state)
+static int setup_echo_srv_tcp_ipv6(void **state)
 {
        torture_setup_echo_srv_tcp_ipv6(state);
+
+       return 0;
 }
 #endif
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_writev_readv_ipv4(void **state)
@@ -166,14 +172,18 @@ static void test_writev_readv_ipv6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_writev_readv_ipv4, setup_echo_srv_tcp_ipv4, teardown),
+       const struct CMUnitTest tcp_writev_tests[] = {
+               cmocka_unit_test_setup_teardown(test_writev_readv_ipv4,
+                                               setup_echo_srv_tcp_ipv4,
+                                               teardown),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_writev_readv_ipv6, setup_echo_srv_tcp_ipv6, teardown),
+               cmocka_unit_test_setup_teardown(test_writev_readv_ipv6,
+                                               setup_echo_srv_tcp_ipv6,
+                                               teardown),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(tcp_writev_tests, NULL, NULL);
 
        return rc;
 }
index 435d1b930165f3d22e41e603ea4d1fb2e74feb20..cf4e84833fe6d963955250e5302ca9085b222e13 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_udp_ipv4(void **state)
+static int setup_echo_srv_udp_ipv4(void **state)
 {
        torture_setup_echo_srv_udp_ipv4(state);
+
+       return 0;
 }
 
 #ifdef HAVE_IPV6
-static void setup_echo_srv_udp_ipv6(void **state)
+static int setup_echo_srv_udp_ipv6(void **state)
 {
        torture_setup_echo_srv_udp_ipv6(state);
+
+       return 0;
 }
 #endif
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_send_recv_ipv4(void **state)
@@ -137,14 +143,18 @@ static void test_send_recv_ipv6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_send_recv_ipv4, setup_echo_srv_udp_ipv4, teardown),
+       const struct CMUnitTest send_tests[] = {
+               cmocka_unit_test_setup_teardown(test_send_recv_ipv4,
+                                               setup_echo_srv_udp_ipv4,
+                                               teardown),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_send_recv_ipv6, setup_echo_srv_udp_ipv6, teardown),
+               cmocka_unit_test_setup_teardown(test_send_recv_ipv6,
+                                               setup_echo_srv_udp_ipv6,
+                                               teardown),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(send_tests, NULL, NULL);
 
        return rc;
 }
index 111a9ae16e53b8432dce279a36daa08a8d7adfad..aa9caea97ceb237d11d57420014ce5cce45ce274 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_udp_ipv4(void **state)
+static int setup_echo_srv_udp_ipv4(void **state)
 {
        torture_setup_echo_srv_udp_ipv4(state);
+
+       return 0;
 }
 
 #ifdef HAVE_IPV6
-static void setup_echo_srv_udp_ipv6(void **state)
+static int setup_echo_srv_udp_ipv6(void **state)
 {
        torture_setup_echo_srv_udp_ipv6(state);
+
+       return 0;
 }
 #endif
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_sendto_recvfrom_ipv4(void **state)
@@ -188,14 +194,18 @@ static void test_sendto_recvfrom_ipv6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_sendto_recvfrom_ipv4, setup_echo_srv_udp_ipv4, teardown),
+       const struct CMUnitTest sendmsg_tests[] = {
+               cmocka_unit_test_setup_teardown(test_sendto_recvfrom_ipv4,
+                                               setup_echo_srv_udp_ipv4,
+                                               teardown),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_sendto_recvfrom_ipv6, setup_echo_srv_udp_ipv6, teardown),
+               cmocka_unit_test_setup_teardown(test_sendto_recvfrom_ipv6,
+                                               setup_echo_srv_udp_ipv6,
+                                               teardown),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(sendmsg_tests, NULL, NULL);
 
        return rc;
 }
index 88f877371f79019b8844908a110bef0624c629eb..79948ced4718668cec037a0d2efb3a72704f08ac 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-static void setup_echo_srv_udp_ipv4(void **state)
+static int setup_echo_srv_udp_ipv4(void **state)
 {
        torture_setup_echo_srv_udp_ipv4(state);
+
+       return 0;
 }
 
 #ifdef HAVE_IPV6
-static void setup_echo_srv_udp_ipv6(void **state)
+static int setup_echo_srv_udp_ipv6(void **state)
 {
        torture_setup_echo_srv_udp_ipv6(state);
+
+       return 0;
 }
 #endif
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_echo_srv(state);
+
+       return 0;
 }
 
 static void test_sendto_recvfrom_ipv4(void **state)
@@ -189,14 +195,18 @@ static void test_sendto_recvfrom_ipv6(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_sendto_recvfrom_ipv4, setup_echo_srv_udp_ipv4, teardown),
+       const struct CMUnitTest sendto_tests[] = {
+               cmocka_unit_test_setup_teardown(test_sendto_recvfrom_ipv4,
+                                               setup_echo_srv_udp_ipv4,
+                                               teardown),
 #ifdef HAVE_IPV6
-               unit_test_setup_teardown(test_sendto_recvfrom_ipv6, setup_echo_srv_udp_ipv6, teardown),
+               cmocka_unit_test_setup_teardown(test_sendto_recvfrom_ipv6,
+                                               setup_echo_srv_udp_ipv6,
+                                               teardown),
 #endif
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(sendto_tests, NULL, NULL);
 
        return rc;
 }
index 47ef838c5302c73531c46d4e9b52eeb72966dfbb..aebff9121721505f556dfae75c84e3c21eba692d 100644 (file)
@@ -14,7 +14,7 @@
 #include <limits.h>
 #include <unistd.h>
 
-static void setup(void **state)
+static int setup(void **state)
 {
        char test_tmpdir[256];
        const char *p;
@@ -29,16 +29,18 @@ static void setup(void **state)
        *state = strdup(p);
        setenv("SOCKET_WRAPPER_DIR", p, 1);
        setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "11", 1);
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        char remove_cmd[PATH_MAX] = {0};
        char *s = (char *)*state;
        int rc;
 
        if (s == NULL) {
-               return;
+               return -1;
        }
 
        snprintf(remove_cmd, sizeof(remove_cmd), "rm -rf %s", s);
@@ -48,6 +50,8 @@ static void teardown(void **state)
        if (rc < 0) {
                fprintf(stderr, "%s failed: %s", remove_cmd, strerror(errno));
        }
+
+       return rc;
 }
 
 static void test_swrap_socket(void **state)
@@ -95,12 +99,12 @@ static void test_swrap_ioctl_sock(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_swrap_socket, setup, teardown),
-               unit_test_setup_teardown(test_swrap_ioctl_sock, setup, teardown),
+       const struct CMUnitTest ioctl_tests[] = {
+               cmocka_unit_test_setup_teardown(test_swrap_socket, setup, teardown),
+               cmocka_unit_test_setup_teardown(test_swrap_ioctl_sock, setup, teardown),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(ioctl_tests, NULL, NULL);
 
        return rc;
 }
index 78b42355866c98de5630f22c76dad282e9a73bbe..30c98610c29b9cf8283afcb2e2ec85258fac2af6 100644 (file)
@@ -106,11 +106,11 @@ static void test_sendmsg_recvmsg_fd(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test(test_sendmsg_recvmsg_fd),
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test(test_sendmsg_recvmsg_fd),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(tests, NULL, NULL);
 
        return rc;
 }