git: f50d338974f2 - stable/13 - lib/libsbuf/tests: reformat with `clang-format`
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 26 Mar 2025 21:12:26 UTC
The branch stable/13 has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=f50d338974f27fcf075ec041c68753ffd4366c80 commit f50d338974f27fcf075ec041c68753ffd4366c80 Author: Enji Cooper <ngie@FreeBSD.org> AuthorDate: 2024-12-02 04:39:52 +0000 Commit: Enji Cooper <ngie@FreeBSD.org> CommitDate: 2025-03-26 21:10:48 +0000 lib/libsbuf/tests: reformat with `clang-format` This change is being done first so any functional changes from the tests will be clearer to reviewers. No functional change intended. MFC after: 2 weeks Ref: https://reviews.freebsd.org/D47826 (cherry picked from commit 991bd461625a2c521d5be4fd6938deed57f60972) --- lib/libsbuf/tests/sbuf_core_test.c | 32 +++++++++---------- lib/libsbuf/tests/sbuf_stdio_test.c | 21 ++++++------- lib/libsbuf/tests/sbuf_string_test.c | 60 +++++++++++++++++++----------------- 3 files changed, 58 insertions(+), 55 deletions(-) diff --git a/lib/libsbuf/tests/sbuf_core_test.c b/lib/libsbuf/tests/sbuf_core_test.c index 1ed320316510..b01a43e12c5c 100644 --- a/lib/libsbuf/tests/sbuf_core_test.c +++ b/lib/libsbuf/tests/sbuf_core_test.c @@ -26,6 +26,8 @@ #include <sys/cdefs.h> #include <sys/param.h> #include <sys/sbuf.h> + +#include <atf-c.h> #include <errno.h> #include <stdarg.h> #include <stdio.h> @@ -33,12 +35,10 @@ #include <string.h> #include <unistd.h> -#include <atf-c.h> - #include "sbuf_test_common.h" -static char test_string[] = "this is a test string"; -#define TEST_STRING_CHOP_COUNT 5 +static char test_string[] = "this is a test string"; +#define TEST_STRING_CHOP_COUNT 5 _Static_assert(nitems(test_string) > TEST_STRING_CHOP_COUNT, "test_string is too short"); @@ -76,8 +76,8 @@ ATF_TC_BODY(sbuf_clear_test, tc) buf_len = sbuf_len(sb); ATF_REQUIRE_MSG(buf_len == 0, "sbuf_len (%zd) != 0", buf_len); - ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), "", - "sbuf (\"%s\") was not empty", sbuf_data(sb)); + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), "", "sbuf (\"%s\") was not empty", + sbuf_data(sb)); sbuf_delete(sb); } @@ -104,7 +104,6 @@ ATF_TC_BODY(sbuf_done_and_sbuf_finish_test, tc) static int drain_ret0(void *arg, const char *data, int len) { - (void)arg; (void)data; (void)len; @@ -145,10 +144,11 @@ ATF_TC_BODY(sbuf_len_test, tc) buf_len = sbuf_len(sb); ATF_REQUIRE_MSG(buf_len == (ssize_t)(i * test_string_len), "sbuf_len (%zd) != %zu", buf_len, i * test_string_len); - ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, + "sbuf_cat failed"); } -#ifdef HAVE_SBUF_SET_FLAGS +#ifdef HAVE_SBUF_SET_FLAGS sbuf_set_flags(sb, SBUF_INCLUDENUL); ATF_REQUIRE_MSG((ssize_t)(i * test_string_len + 1) == sbuf_len(sb), "sbuf_len(..) didn't report the NUL char"); @@ -173,8 +173,8 @@ ATF_TC_BODY(sbuf_new_fixedlen, tc) child_proc = atf_utils_fork(); if (child_proc == 0) { - ATF_REQUIRE_EQ_MSG(0, sbuf_finish(&sb), "sbuf_finish failed: %s", - strerror(errno)); + ATF_REQUIRE_EQ_MSG(0, sbuf_finish(&sb), + "sbuf_finish failed: %s", strerror(errno)); sbuf_putbuf(&sb); exit(0); @@ -183,7 +183,8 @@ ATF_TC_BODY(sbuf_new_fixedlen, tc) sbuf_putc(&sb, ' '); - ATF_CHECK_EQ_MSG(-1, sbuf_finish(&sb), "failed to return error on overflow"); + ATF_CHECK_EQ_MSG(-1, sbuf_finish(&sb), + "failed to return error on overflow"); sbuf_delete(&sb); } @@ -244,7 +245,6 @@ ATF_TC_BODY(sbuf_setpos_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, sbuf_clear_test); ATF_TP_ADD_TC(tp, sbuf_done_and_sbuf_finish_test); ATF_TP_ADD_TC(tp, sbuf_drain_ret0_test); @@ -252,15 +252,15 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, sbuf_new_fixedlen); #if 0 /* TODO */ -#ifdef HAVE_SBUF_CLEAR_FLAGS +#ifdef HAVE_SBUF_CLEAR_FLAGS ATF_TP_ADD_TC(tp, sbuf_clear_flags_test); #endif -#ifdef HAVE_SBUF_GET_FLAGS +#ifdef HAVE_SBUF_GET_FLAGS ATF_TP_ADD_TC(tp, sbuf_get_flags_test); #endif ATF_TP_ADD_TC(tp, sbuf_new_positive_test); ATF_TP_ADD_TC(tp, sbuf_new_negative_test); -#ifdef HAVE_SBUF_SET_FLAGS +#ifdef HAVE_SBUF_SET_FLAGS ATF_TP_ADD_TC(tp, sbuf_set_flags_test); #endif #endif diff --git a/lib/libsbuf/tests/sbuf_stdio_test.c b/lib/libsbuf/tests/sbuf_stdio_test.c index 5bf32c674901..4987c1409723 100644 --- a/lib/libsbuf/tests/sbuf_stdio_test.c +++ b/lib/libsbuf/tests/sbuf_stdio_test.c @@ -26,6 +26,8 @@ #include <sys/cdefs.h> #include <sys/param.h> #include <sys/sbuf.h> + +#include <atf-c.h> #include <errno.h> #include <stdarg.h> #include <stdio.h> @@ -33,17 +35,15 @@ #include <string.h> #include <unistd.h> -#include <atf-c.h> - #include "sbuf_test_common.h" -static char test_string[] = "this is a test string"; +static char test_string[] = "this is a test string"; -#define MESSAGE_FORMAT "message: %s\n" -#define MESSAGE_SEPARATOR ';' +#define MESSAGE_FORMAT "message: %s\n" +#define MESSAGE_SEPARATOR ';' static int -sbuf_vprintf_helper(struct sbuf *sb, const char * restrict format, ...) +sbuf_vprintf_helper(struct sbuf *sb, const char *restrict format, ...) { va_list ap; int rc; @@ -117,8 +117,8 @@ ATF_TC_BODY(sbuf_printf_test, tc) struct sbuf *sb; char *test_string_tmp; - asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, - test_string, MESSAGE_SEPARATOR, test_string); + asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, test_string, + MESSAGE_SEPARATOR, test_string); ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed"); sb = sbuf_new_auto(); @@ -177,8 +177,8 @@ ATF_TC_BODY(sbuf_vprintf_test, tc) char *test_string_tmp; int rc; - asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, - test_string, MESSAGE_SEPARATOR, test_string); + asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, test_string, + MESSAGE_SEPARATOR, test_string); ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed"); sb = sbuf_new_auto(); @@ -204,7 +204,6 @@ ATF_TC_BODY(sbuf_vprintf_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, sbuf_printf_drain_null_test); ATF_TP_ADD_TC(tp, sbuf_printf_drain_test); ATF_TP_ADD_TC(tp, sbuf_printf_test); diff --git a/lib/libsbuf/tests/sbuf_string_test.c b/lib/libsbuf/tests/sbuf_string_test.c index 9deccc572692..9ff3dde0cab3 100644 --- a/lib/libsbuf/tests/sbuf_string_test.c +++ b/lib/libsbuf/tests/sbuf_string_test.c @@ -26,28 +26,33 @@ #include <sys/cdefs.h> #include <sys/param.h> #include <sys/sbuf.h> + +#include <atf-c.h> #include <errno.h> #include <libutil.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <atf-c.h> - #include "sbuf_test_common.h" -static char test_string[] = "this is a test string"; -static char test_whitespace_string[] = " \f\n\r\t\v "; -static int test_buffer[] = { 0, 1, 2, 3, 4, 5, }; +static char test_string[] = "this is a test string"; +static char test_whitespace_string[] = " \f\n\r\t\v "; +static int test_buffer[] = { + 0, + 1, + 2, + 3, + 4, + 5, +}; static void check_buffers_equal(const void *sb_buf, const void *test_buf, size_t len) { - if (memcmp(sb_buf, test_buf, len) != 0) { printf("sbuf:\n"); - hexdump(sb_buf, len, NULL, 0), - printf("test_buf:\n"); + hexdump(sb_buf, len, NULL, 0), printf("test_buf:\n"); hexdump(test_buf, len, NULL, 0); atf_tc_fail("contents of sbuf didn't match test_buf contents"); } @@ -76,16 +81,16 @@ ATF_TC_BODY(sbuf_bcat_test, tc) test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, sizeof(test_buffer)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + sizeof(test_buffer)); ATF_CHECK_MSG(sbuf_bcat(sb, test_buffer, sizeof(test_buffer)) == 0, "sbuf_bcat failed"); test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)(2 * sizeof(test_buffer)), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, 2 * sizeof(test_buffer)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + 2 * sizeof(test_buffer)); ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", strerror(errno)); @@ -113,16 +118,16 @@ ATF_TC_BODY(sbuf_bcpy_test, tc) test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, sizeof(test_buffer)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + sizeof(test_buffer)); ATF_CHECK_MSG(sbuf_bcpy(sb, test_buffer, sizeof(test_buffer)) == 0, "sbuf_bcpy failed"); test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, sizeof(test_buffer)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + sizeof(test_buffer)); ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", strerror(errno)); @@ -150,15 +155,15 @@ ATF_TC_BODY(sbuf_cat_test, tc) test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, sizeof(test_string)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + sizeof(test_string)); ATF_CHECK_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string_tmp), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, strlen(test_string_tmp)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + strlen(test_string_tmp)); ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", strerror(errno)); @@ -186,15 +191,15 @@ ATF_TC_BODY(sbuf_cpy_test, tc) test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, strlen(test_string)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + strlen(test_string)); ATF_CHECK_MSG(sbuf_cpy(sb, test_string) == 0, "sbuf_cpy failed"); test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string), - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, strlen(test_string)); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + strlen(test_string)); ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", strerror(errno)); @@ -217,7 +222,7 @@ ATF_TC_BODY(sbuf_putc_test, tc) ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", strerror(errno)); - for (i = 0; i <= strlen(test_string); i++) { /* Include the NUL */ + for (i = 0; i <= strlen(test_string); i++) { /* Include the NUL */ ATF_REQUIRE_MSG(sbuf_putc(sb, test_string[i]) == 0, "sbuf_putc failed"); @@ -257,8 +262,8 @@ ATF_TC_BODY(sbuf_trim_test, tc) strlen(test_whitespace_string)); test_sbuf_len = sbuf_len(sb); ATF_REQUIRE_MSG(exp_sbuf_len == test_sbuf_len, - "sbuf_len(..) => %zd (actual) != %zu (expected)", - test_sbuf_len, exp_sbuf_len); + "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len, + exp_sbuf_len); ATF_REQUIRE_MSG(sbuf_trim(sb) == 0, "sbuf_trim failed"); @@ -274,7 +279,6 @@ ATF_TC_BODY(sbuf_trim_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, sbuf_bcat_test); ATF_TP_ADD_TC(tp, sbuf_bcpy_test); ATF_TP_ADD_TC(tp, sbuf_cat_test);