From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id CB7656ECED; Tue, 1 Dec 2026 17:33:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CB7656ECED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1796135615; bh=PgtuAkUrbSPg+30eIT744gTYvA56qHqDk6RkkUlPyqE=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yRrFq7WScee9rqp/LYWh8GoMxHHyz0wl/riXCQdDUrLGe18WvAX4qrabikGZiWkex 3mJUxil+i0A2FsIJthNCAZI9U1CFe7pmHjWufnpnWPW6BEyZh4cpFaVybWdCll3Eqa 7X+psUzI4skSVLDruBSMxCTa6yEtExAKk7QrvBUc= Received: from send82.i.mail.ru (send82.i.mail.ru [89.221.237.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1F6646ECED for ; Tue, 1 Dec 2026 17:33:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1F6646ECED Received: by exim-smtp-7cdd59bc4f-ldp9g with esmtpa (envelope-from ) id 1xYOvE-00000000FnR-1TrG; Tue, 01 Dec 2026 17:33:32 +0300 Message-ID: Date: Tue, 1 Dec 2026 17:33:32 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Evgeniy Temirgaleev , Sergey Bronnikov References: <4dd8dd2aecca35784e687f7920e6880ad0211f3c.1793624427.git.estetus@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD948BB5305717D37AFC59B0019E973B2F02F48BE00E26BB64C1313CFAB8367EF908E2BE116634AD74DFBDA425441B85E69411046492FDDF806F2007B30021CFCBD926F6C5B6D4AB9D0EB35CB8B4FE073DF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE771540F9ECFC94C4BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379BF04B24BEB7B2D58638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2AB2BA5A39855645B2E070BE324C7D3C49F0B640A7FA98B7FF6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C091DAD9F922AA71188941B15DA834481F9449624AB7ADAF37BA3038C0950A5D36D5E8D9A59859A8B6B85596BE9CDE5D2E76E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C5B09DCDDD98ABCD243847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A57AB3BAAE69698C315002B1117B3ED69696E485B524A0FBD4219207EC0A953D2C3610D81D389A125CDE35189EBF2DEA28FEA14CD2CD220BB99C5DF10A05D560A9880EC71AF561E0AAD9143641EC25BB398A5A4384F7FD2FD9 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659FADE325E4F08068D842D06635922D9D709A314A4F218D393B6EDE49E21F05333ED5646C190E4C3B5B8341EE9D5BE9A0A9C64B68D33EDE85AC5603451324496E11C6F68E07AA95E87C7CEAA0681F5848F4C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWKwhL9dEHQkpDLEd9SnCO68= X-Mailru-Sender: 520A125C2F17F0B17094CDC02B85F11B3D9707F185CF7C9D3DE06ABAFEAF6705F47C48AE319A0818B7CBEF92542CD7C8795FA72BAB74744FC77752E0C033A69EA16A481184E8BB1C9B38E6EA4F046BE03A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/3] test: add unit tests for the write buffer X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Evgeniy, thanks for review! Please see my comments below. Sergey On 11/11/26 18:24, Evgeniy Temirgaleev wrote: > Hi, Sergey! Thanks for the patch! > > LGTM with some comments. > > On 11/2/26 4:12 PM, Sergey Bronnikov wrote: >> From: Sergey Bronnikov >> >> The write buffer accumulates the profilers' output and passes it >> to the writer on flush. It has no unit tests, so cover writing of >> the data of all kinds, flushing of a full buffer, the explicit >> flush and the error reporting. >> >> Part of tarantool/tarantool#11620 >> --- >>   test/tarantool-c-tests/unit-wbuf.test.c | 388 ++++++++++++++++++++++++ >>   1 file changed, 388 insertions(+) >>   create mode 100644 test/tarantool-c-tests/unit-wbuf.test.c >> >> diff --git a/test/tarantool-c-tests/unit-wbuf.test.c >> b/test/tarantool-c-tests/unit-wbuf.test.c >> new file mode 100644 >> index 00000000..4bee6243 >> --- /dev/null >> +++ b/test/tarantool-c-tests/unit-wbuf.test.c >> @@ -0,0 +1,388 @@ >> +/* >> +** Testing of the write buffer. >> +** >> +** The write buffer accumulates the profilers' output and passes >> +** it to the writer on flush. The tests below cover writing of the >> +** data of all kinds, flushing on overflow, the explicit flush and >> +** the error reporting. >> +*/ >> + >> +#include >> + >> +#include >> +#include >> +#include >> + >> +#include "lj_wbuf.h" >> +#include "test.h" >> + >> +/* Size of the write buffer used in the tests. */ >> +#define BUFFER_SIZE 10 >> + >> +/* Size of the payload that does not fit into the write buffer. */ >> +#define PAYLOAD_SIZE (2 * BUFFER_SIZE + 5) >> + >> +/* What the writer does on flush. */ >> +enum writer_mode { >> +    /* Report all the data as written. */ >> +    WMODE_OK, >> +    /* Report a half of the data as written and keep the buffer. */ >> +    WMODE_PARTIAL, >> +    /* Imitate an unrecoverable write error, e.g. ENOSPC. */ >> +    WMODE_FAIL, >> +}; >> + >> +/* Writer context for simulating different write outcomes. */ >> +struct writer_ctx { >> +    /* What the writer does on flush. */ >> +    enum writer_mode mode; >> +    /* Number of performed flushes. */ >> +    size_t flushes; >> +    /* Number of bytes reported as written. */ >> +    size_t written; >> +    /* Everything reported as written, in order of writing. */ >> +    uint8_t out[2 * PAYLOAD_SIZE]; >> +}; >> + >> +static size_t test_writer(const void **buf_addr, size_t len, void *opt) >> +{ >> +    struct writer_ctx *ctx = opt; >> +    size_t n = len; >> + >> +    ctx->flushes++; >> +    if (ctx->mode == WMODE_FAIL) { >> +        errno = ENOSPC; >> +        *buf_addr = NULL; >> +        return 0; >> +    } >> +    if (ctx->mode == WMODE_PARTIAL) { >> +        errno = EIO; >> +        n = len / 2; >> +    } > Please, add an assertion to check "ctx->out[] have room for write" and > ctx->mode == WMODE_OK (or use switch-case with halt on default branch) > to handle possible tests misconfig. Updated: --- a/test/tarantool-c-tests/unit-wbuf.test.c +++ b/test/tarantool-c-tests/unit-wbuf.test.c @@ -53,15 +53,23 @@ static size_t test_writer(const void **buf_addr, size_t len, void *opt)         size_t n = len;         ctx->flushes++; -       if (ctx->mode == WMODE_FAIL) { +       switch (ctx->mode) { +       case WMODE_FAIL:                 errno = ENOSPC;                 *buf_addr = NULL;                 return 0; -       } -       else if (ctx->mode == WMODE_PARTIAL) { +       case WMODE_PARTIAL:                 errno = EIO;                 n = len / 2; +               break; +       case WMODE_OK: +               break; +       default: +               /* Unreachable: a test is misconfigured. */ +               assert_true(0); +               return 0;         } +       assert_true(ctx->written + n <= sizeof(ctx->out));         memcpy(ctx->out + ctx->written, *buf_addr, n);         /* The function is called only by lj_wbuf_flush(). */         ctx->written += n; > >> +    memcpy(ctx->out + ctx->written, *buf_addr, n); >> +    ctx->written += n; >> +    return n; >> +} >> + >> +static void writer_ctx_init(struct writer_ctx *ctx, enum writer_mode >> mode) >> +{ >> +    memset(ctx, 0, sizeof(*ctx)); >> +    ctx->mode = mode; >> +} >> + >> +static size_t buf_len(const struct lj_wbuf *buf) >> +{ >> +    return (size_t)(buf->pos - buf->buf); >> +} >> + > Please, rename to wbuf_len as in lj_wbuf.c. May be add a comment also: > a copy from... Updated: diff --git a/test/tarantool-c-tests/unit-wbuf.test.c b/test/tarantool-c-tests/unit-wbuf.test.c index 58454c49..7d53291f 100644 --- a/test/tarantool-c-tests/unit-wbuf.test.c +++ b/test/tarantool-c-tests/unit-wbuf.test.c @@ -82,7 +82,11 @@ static void writer_ctx_init(struct writer_ctx *ctx, enum writer_mode mode)      ctx->mode = mode;  } -static size_t buf_len(const struct lj_wbuf *buf) +/* + * A copy of wbuf_len() from src/lj_wbuf.c: the original is a + * static function and is not visible to the tests. + */ +static size_t wbuf_len(const struct lj_wbuf *buf)  {      return (size_t)(buf->pos - buf->buf);  } @@ -108,7 +112,7 @@ static int test_addbyte(void *state)      lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));      lj_wbuf_addbyte(&buf, 0x7f); -    assert_sizet_equal(buf_len(&buf), 1); +    assert_sizet_equal(wbuf_len(&buf), 1);      assert_int_equal(mem[0], 0x7f);      assert_sizet_equal(ctx.flushes, 0);      assert_int_equal(lj_wbuf_errno(&buf), 0); @@ -129,7 +133,7 @@ static int test_addu64(void *state)      /* 128 is encoded as two bytes. */      lj_wbuf_addu64(&buf, 128); -    assert_sizet_equal(buf_len(&buf), 2); +    assert_sizet_equal(wbuf_len(&buf), 2);      assert_int_equal(mem[0], 0x80);      assert_int_equal(mem[1], 0x01);      assert_sizet_equal(ctx.flushes, 0); @@ -149,7 +153,7 @@ static int test_addn(void *state)      lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));      lj_wbuf_addn(&buf, "xyz", 3); -    assert_sizet_equal(buf_len(&buf), 3); +    assert_sizet_equal(wbuf_len(&buf), 3);      assert_true(memcmp(mem, "xyz", 3) == 0);      assert_sizet_equal(ctx.flushes, 0); @@ -169,7 +173,7 @@ static int test_addstring(void *state)      /* A string is a ULEB128 length followed by the payload. */      lj_wbuf_addstring(&buf, "xyz"); -    assert_sizet_equal(buf_len(&buf), 4); +    assert_sizet_equal(wbuf_len(&buf), 4);      assert_int_equal(mem[0], 3);      assert_true(memcmp(mem + 1, "xyz", 3) == 0);      assert_sizet_equal(ctx.flushes, 0); @@ -201,7 +205,7 @@ static int test_addn_pumped_through_buffer(void *state)      assert_sizet_equal(ctx.written, 2 * BUFFER_SIZE);      assert_true(memcmp(ctx.out, payload, 2 * BUFFER_SIZE) == 0);      const int remains = PAYLOAD_SIZE - writes * BUFFER_SIZE; -    assert_sizet_equal(buf_len(&buf), remains); +    assert_sizet_equal(wbuf_len(&buf), remains);      assert_true(memcmp(mem, payload + 2 * BUFFER_SIZE, remains) == 0);      return TEST_EXIT_SUCCESS; @@ -222,28 +226,28 @@ static int test_flush_on_overflow(void *state)      /* A byte written to a full buffer is preceded by a flush. */      lj_wbuf_addn(&buf, payload, sizeof(payload)); -    assert_sizet_equal(buf_len(&buf), sizeof(mem)); +    assert_sizet_equal(wbuf_len(&buf), sizeof(mem));      lj_wbuf_addbyte(&buf, 0xaa);      assert_sizet_equal(ctx.flushes, 1);      assert_sizet_equal(ctx.written, sizeof(mem)); -    assert_sizet_equal(buf_len(&buf), 1); +    assert_sizet_equal(wbuf_len(&buf), 1);      assert_int_equal(mem[0], 0xaa);      /* The same for an ULEB128 value written to a full buffer. */      lj_wbuf_addn(&buf, payload, sizeof(payload) - 1); -    assert_sizet_equal(buf_len(&buf), sizeof(mem)); +    assert_sizet_equal(wbuf_len(&buf), sizeof(mem));      lj_wbuf_addu64(&buf, 0);      assert_sizet_equal(ctx.flushes, 2);      assert_sizet_equal(ctx.written, 2 * sizeof(mem)); -    assert_sizet_equal(buf_len(&buf), 1); +    assert_sizet_equal(wbuf_len(&buf), 1);      /* And for a data block written to a full buffer. */      lj_wbuf_addn(&buf, payload, sizeof(payload) - 1); -    assert_sizet_equal(buf_len(&buf), sizeof(mem)); +    assert_sizet_equal(wbuf_len(&buf), sizeof(mem));      lj_wbuf_addn(&buf, payload, 1);      assert_sizet_equal(ctx.flushes, 3);      assert_sizet_equal(ctx.written, 3 * sizeof(mem)); -    assert_sizet_equal(buf_len(&buf), 1); +    assert_sizet_equal(wbuf_len(&buf), 1);      return TEST_EXIT_SUCCESS;  } @@ -265,13 +269,13 @@ static int test_flush(void *state)      assert_sizet_equal(ctx.written, 3);      assert_true(memcmp(ctx.out, "xyz", 3) == 0);      /* The buffer is empty after a successful flush. */ -    assert_sizet_equal(buf_len(&buf), 0); +    assert_sizet_equal(wbuf_len(&buf), 0);      assert_false(lj_wbuf_test_flag(&buf,          STREAM_ERRIO | STREAM_STOP));      /* The buffer is usable after the flush. */      lj_wbuf_addbyte(&buf, 0x7f); -    assert_sizet_equal(buf_len(&buf), 1); +    assert_sizet_equal(wbuf_len(&buf), 1);      assert_int_equal(mem[0], 0x7f);      return TEST_EXIT_SUCCESS; @@ -300,7 +304,7 @@ static int test_flush_partial_write(void *state)      assert_false(lj_wbuf_test_flag(&buf, STREAM_STOP));      assert_ptr_equal(buf.buf, mem);      /* The unwritten data is dropped. */ -    assert_sizet_equal(buf_len(&buf), 0); +    assert_sizet_equal(wbuf_len(&buf), 0);      return TEST_EXIT_SUCCESS;  } @@ -401,7 +405,7 @@ static int test_addbyte_failed_flush(void *state)      for (i = 0; i < sizeof(mem); ++i)          lj_wbuf_addbyte(&buf, (uint8_t)i);      assert_sizet_equal(ctx.flushes, 0); -    assert_sizet_equal(buf_len(&buf), sizeof(mem)); +    assert_sizet_equal(wbuf_len(&buf), sizeof(mem));      /*       * The buffer is full, so the byte below triggers a failed @@ -427,7 +431,7 @@ static int test_addu64_failed_flush(void *state)      /* The maximal value takes exactly BUFFER_SIZE bytes. */      lj_wbuf_addu64(&buf, UINT64_MAX); -    assert_sizet_equal(buf_len(&buf), sizeof(mem)); +    assert_sizet_equal(wbuf_len(&buf), sizeof(mem));      /*       * There is no space left, so the next write triggers > >> +static void assert_stream_stopped_with_error(const struct lj_wbuf *buf) >> +{ >> +    assert_true(lj_wbuf_test_flag(buf, STREAM_STOP)); >> +    assert_true(lj_wbuf_test_flag(buf, STREAM_ERRIO)); >> +    assert_int_equal(lj_wbuf_errno(buf), ENOSPC); >> +    assert_ptr_equal(buf->buf, NULL); >> +    assert_ptr_equal(buf->pos, NULL); >> +} >> + >> +static int test_addbyte(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    lj_wbuf_addbyte(&buf, 0x7f); >> +    assert_sizet_equal(buf_len(&buf), 1); >> +    assert_int_equal(mem[0], 0x7f); >> +    assert_sizet_equal(ctx.flushes, 0); >> +    assert_int_equal(lj_wbuf_errno(&buf), 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_addu64(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    /* 128 is encoded as two bytes. */ > Please, add a check assert(2 < BUFFER_SIZE) to comment why ctx.flushes > must be zero. XXX > >> +    lj_wbuf_addu64(&buf, 128); >> +    assert_sizet_equal(buf_len(&buf), 2); >> +    assert_int_equal(mem[0], 0x80); >> +    assert_int_equal(mem[1], 0x01); >> +    assert_sizet_equal(ctx.flushes, 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_addn(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + > assert(3 < BUFFER_SIZE); Updated: diff --git a/test/tarantool-c-tests/unit-wbuf.test.c b/test/tarantool-c-tests/unit-wbuf.test.c index 7d53291f..c5097b89 100644 --- a/test/tarantool-c-tests/unit-wbuf.test.c +++ b/test/tarantool-c-tests/unit-wbuf.test.c @@ -13,6 +13,7 @@  #include  #include +#include "lj_utils.h"  #include "lj_wbuf.h"  #include "test.h" @@ -136,6 +137,12 @@ static int test_addu64(void *state)      assert_sizet_equal(wbuf_len(&buf), 2);      assert_int_equal(mem[0], 0x80);      assert_int_equal(mem[1], 0x01); +    /* +     * addu64() reserves LEB128_U64_MAXSIZE bytes regardless of +     * the actual encoded length, so the buffer must be large +     * enough to avoid a flush here. +     */ +    assert_true(LEB128_U64_MAXSIZE <= BUFFER_SIZE);      assert_sizet_equal(ctx.flushes, 0);      return TEST_EXIT_SUCCESS; > >> +    lj_wbuf_addn(&buf, "xyz", 3); >> +    assert_sizet_equal(buf_len(&buf), 3); >> +    assert_true(memcmp(mem, "xyz", 3) == 0); >> +    assert_sizet_equal(ctx.flushes, 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_addstring(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    /* A string is a ULEB128 length followed by the payload. */ > assert(4 < BUFFER_SIZE); Updated: diff --git a/test/tarantool-c-tests/unit-wbuf.test.c b/test/tarantool-c-tests/unit-wbuf.test.c index c5097b89..2a56e589 100644 --- a/test/tarantool-c-tests/unit-wbuf.test.c +++ b/test/tarantool-c-tests/unit-wbuf.test.c @@ -183,6 +183,12 @@ static int test_addstring(void *state)      assert_sizet_equal(wbuf_len(&buf), 4);      assert_int_equal(mem[0], 3);      assert_true(memcmp(mem + 1, "xyz", 3) == 0); +    /* +     * addstring() writes a ULEB128 length via addu64(), which +     * reserves LEB128_U64_MAXSIZE bytes, so the buffer must be +     * large enough to avoid a flush here. +     */ +    assert_true(LEB128_U64_MAXSIZE <= BUFFER_SIZE);      assert_sizet_equal(ctx.flushes, 0);      return TEST_EXIT_SUCCESS; > >> +    lj_wbuf_addstring(&buf, "xyz"); >> +    assert_sizet_equal(buf_len(&buf), 4); >> +    assert_int_equal(mem[0], 3); >> +    assert_true(memcmp(mem + 1, "xyz", 3) == 0); >> +    assert_sizet_equal(ctx.flushes, 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_addn_pumped_through_buffer(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    uint8_t payload[PAYLOAD_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    memset(payload, 'a', sizeof(payload)); >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    /* >> +     * The payload does not fit into the buffer, so it is >> +     * pumped through it. Two full buffers are flushed, the >> +     * rest stays in the buffer. >> +     */ >> +    lj_wbuf_addn(&buf, payload, sizeof(payload)); >> +    assert_sizet_equal(ctx.flushes, 2); >> +    assert_sizet_equal(ctx.written, 2 * BUFFER_SIZE); >> +    assert_true(memcmp(ctx.out, payload, 2 * BUFFER_SIZE) == 0); >> +    assert_sizet_equal(buf_len(&buf), PAYLOAD_SIZE - 2 * BUFFER_SIZE); >> +    assert_true(memcmp(mem, payload + 2 * BUFFER_SIZE, >> +               PAYLOAD_SIZE - 2 * BUFFER_SIZE) == 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} > A check for 'no error case' (implicit flush) after pumping as in the > flush test is needed. Updated: --- a/test/tarantool-c-tests/unit-wbuf.test.c +++ b/test/tarantool-c-tests/unit-wbuf.test.c @@ -220,6 +220,8 @@ static int test_addn_pumped_through_buffer(void *state)         const int remains = PAYLOAD_SIZE - writes * BUFFER_SIZE;         assert_sizet_equal(wbuf_len(&buf), remains);         assert_true(memcmp(mem, payload + 2 * BUFFER_SIZE, remains) == 0); +       /* The implicit flushes completed without an error. */ +       assert_false(lj_wbuf_test_flag(&buf, STREAM_ERRIO | STREAM_STOP));         return TEST_EXIT_SUCCESS;  } > >> + >> +static int test_flush_on_overflow(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    uint8_t payload[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    memset(payload, 'a', sizeof(payload)); >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); > Nit, may be add a macro with common header for all tests to reduce > text size and to simplify reading? Something like: > > #define TEST_INIT(mode) >     uint8_t mem[BUFFER_SIZE]; \ >     struct lj_wbuf buf; \ >     struct writer_ctx ctx; \ >     writer_ctx_init(&ctx, (mode)); \ >     lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); > > Added: diff --git a/test/tarantool-c-tests/unit-wbuf.test.c b/test/tarantool-c-tests/unit-wbuf.test.c index 798c71cd..d5e7912e 100644 --- a/test/tarantool-c-tests/unit-wbuf.test.c +++ b/test/tarantool-c-tests/unit-wbuf.test.c @@ -83,6 +83,18 @@ static void writer_ctx_init(struct writer_ctx *ctx, enum writer_mode mode)      ctx->mode = mode;  } +/* + * Declares and initializes the objects shared by all the tests. + * Tests that need extra local variables should declare them + * before the macro invocation. + */ +#define WBUF_TEST_SETUP(mode)                        \ +    uint8_t mem[BUFFER_SIZE];                    \ +    struct lj_wbuf buf;                        \ +    struct writer_ctx ctx;                        \ +    writer_ctx_init(&ctx, (mode));                    \ +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)) +  /*   * A copy of wbuf_len() from src/lj_wbuf.c: the original is a   * static function and is not visible to the tests. @@ -103,15 +115,10 @@ static void assert_stream_stopped_with_error(const struct lj_wbuf *buf)  static int test_addbyte(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_addbyte(&buf, 0x7f);      assert_sizet_equal(wbuf_len(&buf), 1);      assert_int_equal(mem[0], 0x7f); @@ -123,15 +130,10 @@ static int test_addbyte(void *state)  static int test_addu64(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      /* 128 is encoded as two bytes. */      lj_wbuf_addu64(&buf, 128);      assert_sizet_equal(wbuf_len(&buf), 2); @@ -150,15 +152,10 @@ static int test_addu64(void *state)  static int test_addn(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_addn(&buf, "xyz", 3);      assert_sizet_equal(wbuf_len(&buf), 3);      assert_true(memcmp(mem, "xyz", 3) == 0); @@ -169,15 +166,10 @@ static int test_addn(void *state)  static int test_addstring(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      /* A string is a ULEB128 length followed by the payload. */      lj_wbuf_addstring(&buf, "xyz");      assert_sizet_equal(wbuf_len(&buf), 4); @@ -196,16 +188,11 @@ static int test_addstring(void *state)  static int test_addn_pumped_through_buffer(void *state)  { -    uint8_t mem[BUFFER_SIZE];      uint8_t payload[PAYLOAD_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -      memset(payload, 'a', sizeof(payload)); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));      const int writes = PAYLOAD_SIZE / BUFFER_SIZE;      /* @@ -228,16 +215,11 @@ static int test_addn_pumped_through_buffer(void *state)  static int test_flush_on_overflow(void *state)  { -    uint8_t mem[BUFFER_SIZE];      uint8_t payload[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -      memset(payload, 'a', sizeof(payload)); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));      /* A byte written to a full buffer is preceded by a flush. */      lj_wbuf_addn(&buf, payload, sizeof(payload)); @@ -269,15 +251,10 @@ static int test_flush_on_overflow(void *state)  static int test_flush(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_addn(&buf, "xyz", 3);      lj_wbuf_flush(&buf);      assert_sizet_equal(ctx.flushes, 1); @@ -298,15 +275,10 @@ static int test_flush(void *state)  static int test_flush_partial_write(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_PARTIAL);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_PARTIAL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_addn(&buf, "xyz", 3);      lj_wbuf_flush(&buf);      /* A partial write is reported as an error. */ @@ -326,15 +298,10 @@ static int test_flush_partial_write(void *state)  static int test_flush_stopped_stream(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_FAIL);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_FAIL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_addn(&buf, "xyz", 3);      lj_wbuf_flush(&buf);      assert_stream_stopped_with_error(&buf); @@ -349,15 +316,10 @@ static int test_flush_stopped_stream(void *state)  static int test_write_to_stopped_stream(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_FAIL);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_FAIL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_addn(&buf, "xyz", 3);      lj_wbuf_flush(&buf);      assert_stream_stopped_with_error(&buf); @@ -376,15 +338,10 @@ static int test_write_to_stopped_stream(void *state)  static int test_terminate(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_OK);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_OK); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      lj_wbuf_terminate(&buf);      assert_true(buf.writer == NULL);      assert_ptr_equal(buf.ctx, NULL); @@ -406,16 +363,11 @@ static int test_terminate(void *state)   */  static int test_addbyte_failed_flush(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx;      size_t i; +    WBUF_TEST_SETUP(WMODE_FAIL);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_FAIL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      /* Fill the buffer without flushes. */      for (i = 0; i < sizeof(mem); ++i)          lj_wbuf_addbyte(&buf, (uint8_t)i); @@ -435,15 +387,10 @@ static int test_addbyte_failed_flush(void *state)  static int test_addu64_failed_flush(void *state)  { -    uint8_t mem[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_FAIL);      UNUSED(state); -    writer_ctx_init(&ctx, WMODE_FAIL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); -      /* The maximal value takes exactly BUFFER_SIZE bytes. */      lj_wbuf_addu64(&buf, UINT64_MAX);      assert_sizet_equal(wbuf_len(&buf), sizeof(mem)); @@ -461,16 +408,11 @@ static int test_addu64_failed_flush(void *state)  static int test_addn_failed_flush(void *state)  { -    uint8_t mem[BUFFER_SIZE];      uint8_t payload[BUFFER_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_FAIL);      UNUSED(state); -      memset(payload, 'a', sizeof(payload)); -    writer_ctx_init(&ctx, WMODE_FAIL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));      /* Fill the buffer without flushes. */      lj_wbuf_addn(&buf, payload, sizeof(payload)); @@ -489,16 +431,11 @@ static int test_addn_failed_flush(void *state)  static int test_addn_failed_flush_in_loop(void *state)  { -    uint8_t mem[BUFFER_SIZE];      uint8_t payload[PAYLOAD_SIZE]; -    struct lj_wbuf buf; -    struct writer_ctx ctx; +    WBUF_TEST_SETUP(WMODE_FAIL);      UNUSED(state); -      memset(payload, 'a', sizeof(payload)); -    writer_ctx_init(&ctx, WMODE_FAIL); -    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem));      /*       * The payload does not fit into the buffer, so it is >> + >> +    /* A byte written to a full buffer is preceded by a flush. */ >> +    lj_wbuf_addn(&buf, payload, sizeof(payload)); >> +    assert_sizet_equal(buf_len(&buf), sizeof(mem)); >> +    lj_wbuf_addbyte(&buf, 0xaa); >> +    assert_sizet_equal(ctx.flushes, 1); >> +    assert_sizet_equal(ctx.written, sizeof(mem)); >> +    assert_sizet_equal(buf_len(&buf), 1); >> +    assert_int_equal(mem[0], 0xaa); >> + >> +    /* The same for an ULEB128 value written to a full buffer. */ >> +    lj_wbuf_addn(&buf, payload, sizeof(payload) - 1); >> +    assert_sizet_equal(buf_len(&buf), sizeof(mem)); >> +    lj_wbuf_addu64(&buf, 0); >> +    assert_sizet_equal(ctx.flushes, 2); >> +    assert_sizet_equal(ctx.written, 2 * sizeof(mem)); >> +    assert_sizet_equal(buf_len(&buf), 1); >> + >> +    /* And for a data block written to a full buffer. */ >> +    lj_wbuf_addn(&buf, payload, sizeof(payload) - 1); >> +    assert_sizet_equal(buf_len(&buf), sizeof(mem)); >> +    lj_wbuf_addn(&buf, payload, 1); >> +    assert_sizet_equal(ctx.flushes, 3); >> +    assert_sizet_equal(ctx.written, 3 * sizeof(mem)); >> +    assert_sizet_equal(buf_len(&buf), 1); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_flush(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    lj_wbuf_addn(&buf, "xyz", 3); >> +    lj_wbuf_flush(&buf); >> +    assert_sizet_equal(ctx.flushes, 1); >> +    assert_sizet_equal(ctx.written, 3); >> +    assert_true(memcmp(ctx.out, "xyz", 3) == 0); >> +    /* The buffer is empty after a successful flush. */ >> +    assert_sizet_equal(buf_len(&buf), 0); >> +    assert_false(lj_wbuf_test_flag(&buf, STREAM_ERRIO | STREAM_STOP)); >> + >> +    /* The buffer is usable after the flush. */ >> +    lj_wbuf_addbyte(&buf, 0x7f); >> +    assert_sizet_equal(buf_len(&buf), 1); >> +    assert_int_equal(mem[0], 0x7f); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_flush_partial_write(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_PARTIAL); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    lj_wbuf_addn(&buf, "xyz", 3); >> +    lj_wbuf_flush(&buf); >> +    /* A partial write is reported as an error. */ >> +    assert_true(lj_wbuf_test_flag(&buf, STREAM_ERRIO)); >> +    assert_int_equal(lj_wbuf_errno(&buf), EIO); >> +    /* The writer keeps the buffer, so the stream is not stopped. */ >> +    assert_false(lj_wbuf_test_flag(&buf, STREAM_STOP)); >> +    assert_ptr_equal(buf.buf, mem); >> +    /* The unwritten data is dropped. */ >> +    assert_sizet_equal(buf_len(&buf), 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_flush_stopped_stream(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_FAIL); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    lj_wbuf_addn(&buf, "xyz", 3); >> +    lj_wbuf_flush(&buf); >> +    assert_stream_stopped_with_error(&buf); >> +    assert_sizet_equal(ctx.flushes, 1); >> + >> +    /* A stopped stream is not flushed again. */ >> +    lj_wbuf_flush(&buf); >> +    assert_sizet_equal(ctx.flushes, 1); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_write_to_stopped_stream(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_FAIL); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    lj_wbuf_addn(&buf, "xyz", 3); >> +    lj_wbuf_flush(&buf); >> +    assert_stream_stopped_with_error(&buf); >> + >> +    /* Writes to a stopped stream are ignored. */ >> +    lj_wbuf_addbyte(&buf, 0x7f); >> +    lj_wbuf_addu64(&buf, 128); >> +    lj_wbuf_addn(&buf, "xyz", 3); >> +    lj_wbuf_addstring(&buf, "xyz"); >> +    assert_stream_stopped_with_error(&buf); >> +    assert_sizet_equal(ctx.flushes, 1); >> +    assert_sizet_equal(ctx.written, 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +static int test_terminate(void *state) >> +{ >> +    uint8_t mem[BUFFER_SIZE]; >> +    struct lj_wbuf buf; >> +    struct writer_ctx ctx; >> + >> +    UNUSED(state); >> + >> +    writer_ctx_init(&ctx, WMODE_OK); >> +    lj_wbuf_init(&buf, test_writer, &ctx, mem, sizeof(mem)); >> + >> +    lj_wbuf_terminate(&buf); >> +    assert_true(buf.writer == NULL); >> +    assert_ptr_equal(buf.ctx, NULL); >> +    assert_ptr_equal(buf.buf, NULL); >> +    assert_ptr_equal(buf.pos, NULL); >> +    assert_sizet_equal(buf.size, 0); >> +    assert_false(lj_wbuf_test_flag(&buf, STREAM_ERRIO | STREAM_STOP)); >> +    assert_int_equal(lj_wbuf_errno(&buf), 0); >> + >> +    return TEST_EXIT_SUCCESS; >> +} >> + >> +/* >> +** A writer may release the buffer and set *data to NULL on an >> +** unrecoverable error (e.g. ENOSPC). The stream is stopped in >> +** this case, so the write functions must not touch the released >> +** buffer. >> +*/ > > It seems some code was omitted or added later? > This functions: > > static int test_addbyte_failed_flush(void *state) > static int test_addu64_failed_flush(void *state) > static int test_addn_failed_flush_in_loop(void *state) Yes, omitted. These functions added in the commit with fix. > > -- > A note about pumped write (addn) implementation: the pumping loop > doesn't stops if an IO error occurs, it may lose some content inside > src[n] as the flush discards unwritten data in some iterations. E.g. > if we write to socket and errno=EAGAIN occurs, there written < len is > valid case. > > It looks strange: what is the purpose of this behavior? The error in > any iteration corrupts the whole write. Client must check against > error flag always and terminate or repeat. (The LuaJIT code checks > against STREAM_ERRIO|STREAM_STOP always.) > > Its a questinon: Why the loop is not terminated as it continue with an > error is useless? > > I think it will be good to somehow put this information into the test > suite: make a test case with WMODE_PARTIAL for pumping addn() with > corresponding checks (have an error flag only and have not all data > written). The observation is correct. `lj_wbuf_flush()` distinguishes two failure modes: - `written < len` - a short write (e.g. `EAGAIN`). It sets `STREAM_ERRIO`, but the   buffer is still owned by us (`buf->buf != NULL`). It then resets   `buf->pos = buf->buf`, dropping the bytes that were not reported as written. - `buf->buf == NULL` - the writer released the buffer (e.g. `ENOSPC`). It sets   `STREAM_STOP`. The pumping loop in `lj_wbuf_addn()` breaks only on `STREAM_STOP` because that is the only case where `buf->buf` may be `NULL`; continuing after it could dereference `NULL`. With `STREAM_ERRIO` the buffer remains valid, so the loop keeps going - each iteration drops the unwritten part and pumps the next chunk. Is continuing useful? No, not really. The contract at the call sites is all-or-nothing: `lj_sysprof.c` and `lj_memprof.c` check `STREAM_ERRIO | STREAM_STOP` and abort the whole stream / return `PROFILE_ERRIO`. So once `STREAM_ERRIO` is set, the stream is going to be discarded anyway; the remaining pumping is wasted work, and the data has already been partially dropped by `lj_wbuf_flush()`. Stopping the loop on `STREAM_ERRIO` as well would be a reasonable cleanup, but that changes behaviour and is a separate change; the caller-visible semantics (the whole stream fails) would stay the same. I've added `test_addn_pumped_through_buffer_partial`. With `WMODE_PARTIAL` it pumps a payload larger than the buffer. This pins down the behaviour you described. If we later decide to break the loop on `STREAM_ERRIO`, the expectations in that test will be updated accordingly. @@ -226,18 +213,44 @@ static int test_addn_pumped_through_buffer(void *state)         return TEST_EXIT_SUCCESS;  } +static int test_addn_pumped_through_buffer_partial(void *state) +{ +       uint8_t payload[PAYLOAD_SIZE]; + +       WBUF_TEST_SETUP(WMODE_PARTIAL); +       UNUSED(state); +       memset(payload, 'a', sizeof(payload)); + +       const int writes = PAYLOAD_SIZE / BUFFER_SIZE; +       const int remains = PAYLOAD_SIZE - writes * BUFFER_SIZE; +       /* +        * The writer reports only a half of each flushed buffer as +        * written, so the pumping loop loses the unwritten halves, +        * but it does not stop on STREAM_ERRIO and keeps pumping +        * the rest of the payload. +        */ +       lj_wbuf_addn(&buf, payload, sizeof(payload)); +       assert_sizet_equal(ctx.flushes, writes); +       assert_sizet_equal(ctx.written, writes * (BUFFER_SIZE / 2)); +       /* Not all the data has been written. */ +       assert_true(ctx.written < sizeof(payload)); +       assert_true(lj_wbuf_test_flag(&buf, STREAM_ERRIO)); +       assert_false(lj_wbuf_test_flag(&buf, STREAM_STOP)); +       assert_int_equal(lj_wbuf_errno(&buf), EIO); +       /* The tail that did not fit into a full buffer is buffered. */ +       assert_sizet_equal(wbuf_len(&buf), remains); +       assert_true(memcmp(mem, payload + writes * BUFFER_SIZE, remains) == 0); + +       return TEST_EXIT_SUCCESS; +} +  static int test_flush_on_overflow(void *state) @@ -520,6 +488,7 @@ int main(void)                 test_unit_def(test_addn),                 test_unit_def(test_addstring),                 test_unit_def(test_addn_pumped_through_buffer), +  test_unit_def(test_addn_pumped_through_buffer_partial),                 test_unit_def(test_flush_on_overflow),                 test_unit_def(test_flush),                 test_unit_def(test_flush_partial_write), > > >> +int main(void) >> +{ >> +    const struct test_unit tgroup[] = { >> +        test_unit_def(test_addbyte), >> +        test_unit_def(test_addu64), >> +        test_unit_def(test_addn), >> +        test_unit_def(test_addstring), >> +        test_unit_def(test_addn_pumped_through_buffer), >> +        test_unit_def(test_flush_on_overflow), >> +        test_unit_def(test_flush), >> +        test_unit_def(test_flush_partial_write), >> +        test_unit_def(test_flush_stopped_stream), >> +        test_unit_def(test_write_to_stopped_stream), >> +        test_unit_def(test_terminate), >> +    }; >> +    const int test_result = test_run_group(tgroup, NULL); >> + >> +    return test_result; >> +} >