Skip to contentSkip to conversation

Uncrustify the tests/unit_tests/ part of our tree.

PATCH In review Gert Doering 2 participants 4 messages Apr 26, 2020 – Apr 27, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Uncrustify the tests/unit_tests/ part of our tree.

Apply uncrustify 0.70.1 (FreeBSD port) with our rules to that part of the tree, which followed a more compact coding style so far.

---
 tests/unit_tests/example_test/test.c       |  18 ++-
 tests/unit_tests/example_test/test2.c      |   6 +-
 tests/unit_tests/openvpn/test_argv.c       |   5 +-
 tests/unit_tests/openvpn/test_buffer.c     |   6 +-
 tests/unit_tests/openvpn/test_crypto.c     |   6 +-
 tests/unit_tests/openvpn/test_ncp.c        |   6 +-
 tests/unit_tests/openvpn/test_networking.c |  40 +++++
 tests/unit_tests/openvpn/test_packet_id.c  |  35 +++--
 tests/unit_tests/openvpn/test_tls_crypt.c  | 161 ++++++++++++---------
 9 files changed, 180 insertions(+), 103 deletions(-)
tests/unit_tests/example_test/test.c +12 -6
index d48e5f55..bc3fdc17 100644
@@ -7,7 +7,8 @@
 #include <cmocka.h>
 
 static int
-setup(void **state) {
+setup(void **state)
+{
     int *answer  = malloc(sizeof(int));
 
     *answer = 42;
@@ -17,31 +18,36 @@ setup(void **state) {
 }
 
 static int
-teardown(void **state) {
+teardown(void **state)
+{
     free(*state);
 
     return 0;
 }
 
 static void
-null_test_success(void **state) {
+null_test_success(void **state)
+{
     (void) state;
 }
 
 static void
-int_test_success(void **state) {
+int_test_success(void **state)
+{
     int *answer = *state;
     assert_int_equal(*answer, 42);
 }
 
 static void
-failing_test(void **state) {
+failing_test(void **state)
+{
     /* This tests fails to test that make check fails */
     assert_int_equal(0, 42);
 }
 
 int
-main(void) {
+main(void)
+{
     const struct CMUnitTest tests[] = {
         cmocka_unit_test(null_test_success),
         cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
tests/unit_tests/example_test/test2.c +4 -2
index b5d4fa60..5a186d5d 100644
@@ -8,13 +8,15 @@
 
 
 static void
-test_true(void **state) {
+test_true(void **state)
+{
     (void) state;
 }
 
 
 int
-main(void) {
+main(void)
+{
     const struct CMUnitTest tests[] = {
         cmocka_unit_test(test_true),
     };
tests/unit_tests/openvpn/test_argv.c +3 -2
index 25e80c1c..3dc470a5 100644
@@ -204,7 +204,7 @@ argv_str__multiple_argv__correct_output(void **state)
     argv_printf_cat(&a, "%lu", 1L );
     output = argv_str(&a, &gc, PA_BRACKET);
     assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"
-				" [-1] [4294967295] [1]");
+                        " [-1] [4294967295] [1]");
 
     argv_free(&a);
     gc_free(&gc);
@@ -234,7 +234,8 @@ argv_insert_head__non_empty_argv__head_added(void **state)
     argv_printf(&a, "%s", PATH2);
     b = argv_insert_head(&a, PATH1);
     assert_int_equal(b.argc, a.argc + 1);
-    for (i = 0; i < b.argc; i++) {
+    for (i = 0; i < b.argc; i++)
+    {
         if (i == 0)
         {
             assert_string_equal(b.argv[i], PATH1);
tests/unit_tests/openvpn/test_buffer.c +4 -2
index 7c9a9e2f..d2188b02 100644
@@ -63,7 +63,8 @@ struct test_buffer_list_aggregate_ctx {
     struct buffer_list *empty_buffers;
 };
 
-static int test_buffer_list_setup(void **state)
+static int
+test_buffer_list_setup(void **state)
 {
     struct test_buffer_list_aggregate_ctx *ctx  = calloc(1, sizeof(*ctx));
     ctx->empty = buffer_list_new(0);
@@ -86,7 +87,8 @@ static int test_buffer_list_setup(void **state)
     return 0;
 }
 
-static int test_buffer_list_teardown(void **state)
+static int
+test_buffer_list_teardown(void **state)
 {
     struct test_buffer_list_aggregate_ctx *ctx = *state;
 
tests/unit_tests/openvpn/test_crypto.c +4 -2
index 7027d3da..fdf814de 100644
@@ -44,7 +44,8 @@
 static const char testtext[] = "Dummy text to test PEM encoding";
 
 static void
-crypto_pem_encode_decode_loopback(void **state) {
+crypto_pem_encode_decode_loopback(void **state)
+{
     struct gc_arena gc = gc_new();
     struct buffer src_buf;
     buf_set_read(&src_buf, (void *)testtext, sizeof(testtext));
@@ -69,7 +70,8 @@ crypto_pem_encode_decode_loopback(void **state) {
 }
 
 int
-main(void) {
+main(void)
+{
     const struct CMUnitTest tests[] = {
         cmocka_unit_test(crypto_pem_encode_decode_loopback),
     };
tests/unit_tests/openvpn/test_ncp.c +3 -3
index f8d03b35..19432410 100644
@@ -66,12 +66,12 @@ test_check_ncp_ciphers_list(void **state)
     }
 
     /* For testing that with OpenSSL 1.1.0+ that also accepts ciphers in
-       a different spelling the normalised cipher output is the same */
+     * a different spelling the normalised cipher output is the same */
     bool have_chacha_mixed_case = cipher_kt_get("ChaCha20-Poly1305");
     if (have_chacha_mixed_case)
     {
-      assert_string_equal(mutate_ncp_cipher_list("BF-CBC:ChaCha20-Poly1305", &gc),
-			  bf_chacha);
+        assert_string_equal(mutate_ncp_cipher_list("BF-CBC:ChaCha20-Poly1305", &gc),
+                            bf_chacha);
     }
 
     assert_ptr_equal(mutate_ncp_cipher_list("vollbit", &gc), NULL);
tests/unit_tests/openvpn/test_networking.c +40 -0
index 2d37d6e1..e7c148f0 100644
@@ -29,7 +29,9 @@ net__addr_v4_add(const char *addr_str, int prefixlen)
 
     ret = inet_pton(AF_INET, addr_str, &addr);
     if (ret != 1)
+    {
         return -1;
+    }
 
     addr = ntohl(addr);
 
@@ -46,7 +48,9 @@ net__addr_v6_add(const char *addr_str, int prefixlen)
 
     ret = inet_pton(AF_INET6, addr_str, &addr);
     if (ret != 1)
+    {
         return -1;
+    }
 
     printf("CMD: ip -6 addr add %s/%d dev %s\n", addr_str, prefixlen, iface);
 
@@ -60,17 +64,23 @@ net__route_v4_add(const char *dst_str, int prefixlen, int metric)
     int ret;
 
     if (!dst_str)
+    {
         return -1;
+    }
 
     ret = inet_pton(AF_INET, dst_str, &dst);
     if (ret != 1)
+    {
         return -1;
+    }
 
     dst = ntohl(dst);
 
     printf("CMD: ip route add %s/%d dev %s", dst_str, prefixlen, iface);
     if (metric > 0)
+    {
         printf(" metric %d", metric);
+    }
     printf("\n");
 
     return net_route_v4_add(NULL, &dst, prefixlen, NULL, iface, 0, metric);
@@ -85,15 +95,21 @@ net__route_v4_add_gw(const char *dst_str, int prefixlen, const char *gw_str,
     int ret;
 
     if (!dst_str || !gw_str)
+    {
         return -1;
+    }
 
     ret = inet_pton(AF_INET, dst_str, &dst);
     if (ret != 1)
+    {
         return -1;
+    }
 
     ret = inet_pton(AF_INET, gw_str, &gw);
     if (ret != 1)
+    {
         return -1;
+    }
 
     dst = ntohl(dst);
     gw = ntohl(gw);
@@ -101,7 +117,9 @@ net__route_v4_add_gw(const char *dst_str, int prefixlen, const char *gw_str,
     printf("CMD: ip route add %s/%d dev %s via %s", dst_str, prefixlen, iface,
            gw_str);
     if (metric > 0)
+    {
         printf(" metric %d", metric);
+    }
     printf("\n");
 
     return net_route_v4_add(NULL, &dst, prefixlen, &gw, iface, 0, metric);
@@ -114,15 +132,21 @@ net__route_v6_add(const char *dst_str, int prefixlen, int metric)
     int ret;
 
     if (!dst_str)
+    {
         return -1;
+    }
 
     ret = inet_pton(AF_INET6, dst_str, &dst);
     if (ret != 1)
+    {
         return -1;
+    }
 
     printf("CMD: ip -6 route add %s/%d dev %s", dst_str, prefixlen, iface);
     if (metric > 0)
+    {
         printf(" metric %d", metric);
+    }
     printf("\n");
 
     return net_route_v6_add(NULL, &dst, prefixlen, NULL, iface, 0, metric);
@@ -137,20 +161,28 @@ net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_str,
     int ret;
 
     if (!dst_str || !gw_str)
+    {
         return -1;
+    }
 
     ret = inet_pton(AF_INET6, dst_str, &dst);
     if (ret != 1)
+    {
         return -1;
+    }
 
     ret = inet_pton(AF_INET6, gw_str, &gw);
     if (ret != 1)
+    {
         return -1;
+    }
 
     printf("CMD: ip -6 route add %s/%d dev %s via %s", dst_str, prefixlen,
            iface, gw_str);
     if (metric > 0)
+    {
         printf(" metric %d", metric);
+    }
     printf("\n");
 
     return net_route_v6_add(NULL, &dst, prefixlen, &gw, iface, 0, metric);
@@ -189,20 +221,28 @@ main(int argc, char *argv[])
     {
         case 0:
             return net__iface_up(true);
+
         case 1:
             return net__iface_mtu_set(1281);
+
         case 2:
             return net__addr_v4_add("10.255.255.1", 24);
+
         case 3:
             return net__addr_v6_add("2001::1", 64);
+
         case 4:
             return net__route_v4_add("11.11.11.0", 24, 0);
+
         case 5:
             return net__route_v4_add_gw("11.11.12.0", 24, "10.255.255.2", 0);
+
         case 6:
             return net__route_v6_add("2001:babe:cafe:babe::", 64, 600);
+
         case 7:
             return net__route_v6_add_gw("2001:cafe:babe::", 48, "2001::2", 600);
+
         default:
             printf("invalid test: %d\n", test);
             break;
tests/unit_tests/openvpn/test_packet_id.c +19 -16
index ba420c49..a12b8b0f 100644
@@ -49,9 +49,10 @@ struct test_packet_id_write_data {
 };
 
 static int
-test_packet_id_write_setup(void **state) {
+test_packet_id_write_setup(void **state)
+{
     struct test_packet_id_write_data *data =
-            calloc(1, sizeof(struct test_packet_id_write_data));
+        calloc(1, sizeof(struct test_packet_id_write_data));
 
     if (!data)
     {
@@ -66,7 +67,8 @@ test_packet_id_write_setup(void **state) {
 }
 
 static int
-test_packet_id_write_teardown(void **state) {
+test_packet_id_write_teardown(void **state)
+{
     free(*state);
     return 0;
 }
@@ -155,20 +157,21 @@ test_packet_id_write_long_wrap(void **state)
 }
 
 int
-main(void) {
+main(void)
+{
     const struct CMUnitTest tests[] = {
-            cmocka_unit_test_setup_teardown(test_packet_id_write_short,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_long,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_short_prepend,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_long_prepend,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_short_wrap,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_short,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_long,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_short_prepend,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_long_prepend,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_short_wrap,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
     };
 
     return cmocka_run_group_tests_name("packet_id tests", tests, NULL, NULL);
tests/unit_tests/openvpn/test_tls_crypt.c +91 -70

322 lines not on this page · raw message

Signature · 1 line
2.25.2
#1 lore raw

Hi,

Quoted 2 lines · Gert Doering

Apply uncrustify 0.70.1 (FreeBSD port) with our rules to that part of the tree, which followed a more compact coding style so far.

Just as a remark: the coding style in tests/unit_tests is fairly consistent, just *different*.

We can apply the same rules, or we can define a "more compact" ruleset, which is sometimes more important for tests ("I want to see what the test is doing, not stare at pages of { } lines").

So this is more out for discussion than for "please apply this patch".

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw
In reply to Gert Doering

Hi,

Quoted 27 lines · Gert Doering

Apply uncrustify 0.70.1 (FreeBSD port) with our rules to that part of the tree, which followed a more compact coding style so far.
---

tests/unit_tests/openvpn/test_packet_id.c +5 -13
@@ -155,20 +157,21 @@ test_packet_id_write_long_wrap(void **state)
 }
 
 int
-main(void) {
+main(void)
+{
     const struct CMUnitTest tests[] = {
-            cmocka_unit_test_setup_teardown(test_packet_id_write_short,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_long,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_short_prepend,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_long_prepend,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_short_wrap,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
-            cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap,
-                    test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_short,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_long,

tests/unit_tests/openvpn/test_packet_id.c test_packet_id_write_long_wrap(void **state) · line 175

Quoted 10 lines
tests/unit_tests/openvpn/test_packet_id.c +9 -0
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_short_prepend,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_long_prepend,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_short_wrap,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
+        cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap,
+                                        test_packet_id_write_setup, test_packet_id_write_teardown),
     };

This now exceeds 80 chars by a fair amount. Perhaps rewrap?

Otherwise this looks good to me. I think having consistent style over the code base, including tests, would be good.

-Steffan

#3 lore raw
In reply to Gert Doering

Patch has been applied to the master branch.

I've rewrapped test_packet_id.c as proposed - indeed, much nicer :-)

commit da1574ef7826d73f01e120cbd1ba40ce39a305b7 (master)

Author: Gert Doering
Date:   Sun Apr 26 11:54:02 2020 +0200
     Uncrustify the tests/unit_tests/ part of our tree.

     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19823.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering