Message ID | 20240821124150.4463-1-chandrapratap3519@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | t: port reftable/block_test.c to the unit testing framework | expand |
On Wed, Aug 21, 2024 at 06:00:50PM +0530, Chandra Pratap wrote: > The reftable library comes with self tests, which are exercised > as part of the usual end-to-end tests and are designed to > observe the end-user visible effects of Git commands. What it > exercises, however, is a better match for the unit-testing > framework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests', > 2023-12-09), which is designed to observe how low level > implementation details, at the level of sequences of individual > function calls, behave. > > Hence, port reftable/block_test.c to the unit testing framework and > improve upon the ported test. The first patch in the series moves > the test to the unit testing framework, and the rest of the patches > improve upon the ported test. > > Mentored-by: Patrick Steinhardt <ps@pks.im> > Mentored-by: Christian Couder <chriscool@tuxfamily.org> > Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> > > --- > Changes in v3: > - Use block_source_from_strbuf() instead of malloc_block_source() > in log, obj, and index block tests (patches 9, 10, 11). > - Remove a line that causes a memory leak in obj test (patch 10). This addresses all comments I had on the preceding version and plugs the memory leak. So this looks good to me, thanks! Patrick
Patrick Steinhardt <ps@pks.im> writes: >> - Use block_source_from_strbuf() instead of malloc_block_source() >> in log, obj, and index block tests (patches 9, 10, 11). >> - Remove a line that causes a memory leak in obj test (patch 10). > > This addresses all comments I had on the preceding version and > plugs the memory leak. So this looks good to me, thanks! Thanks, both. Let me mark it for 'next', then.
The reftable library comes with self tests, which are exercised as part of the usual end-to-end tests and are designed to observe the end-user visible effects of Git commands. What it exercises, however, is a better match for the unit-testing framework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests', 2023-12-09), which is designed to observe how low level implementation details, at the level of sequences of individual function calls, behave. Hence, port reftable/block_test.c to the unit testing framework and improve upon the ported test. The first patch in the series moves the test to the unit testing framework, and the rest of the patches improve upon the ported test. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> --- Changes in v3: - Use block_source_from_strbuf() instead of malloc_block_source() in log, obj, and index block tests (patches 9, 10, 11). - Remove a line that causes a memory leak in obj test (patch 10). CI/PR: https://github.com/gitgitgadget/git/pull/1749 Chandra Pratap(11): t: move reftable/block_test.c to the unit testing framework t: harmonize t-reftable-block.c with coding guidelines t-reftable-block: release used block reader t-reftable-block: use reftable_record_equal() instead of check_str() t-reftable-block: use reftable_record_key() instead of strbuf_addstr() t-reftable-block: use block_iter_reset() instead of block_iter_close() t-reftable-block: use xstrfmt() instead of xstrdup() t-reftable-block: remove unnecessary variable 'j' t-reftable-block: add tests for log blocks t-reftable-block: add tests for obj blocks t-reftable-block: add tests for index blocks Makefile | 2 +- reftable/block_test.c | 123 ------------------------------ reftable/reftable-tests.h | 1 - t/helper/test-reftable.c | 1 - t/unit-tests/t-reftable-block.c | 370 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 371 insertions(+), 126 deletions(-) Range-diff against v2: 1: 502fcc1374 ! 1: 4cd1981016 t-reftable-block: add tests for log blocks @@ t/unit-tests/t-reftable-block.c: static void t_block_read_write(void) + int ret; + struct block_reader br = { 0 }; + struct block_iter it = BLOCK_ITER_INIT; -+ struct strbuf want = STRBUF_INIT; ++ struct strbuf want = STRBUF_INIT, buf = STRBUF_INIT; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; -+ block.source = malloc_block_source(); ++ block_source_from_strbuf(&block.source ,&buf); + block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size, + header_off, hash_size(GIT_SHA1_FORMAT_ID)); + @@ t/unit-tests/t-reftable-block.c: static void t_block_read_write(void) + reftable_record_release(&rec); + reftable_block_done(&br.block); + strbuf_release(&want); ++ strbuf_release(&buf); + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); +} 2: e3cefa7e3d ! 2: 4e9752e72a t-reftable-block: add tests for obj blocks @@ t/unit-tests/t-reftable-block.c: static void t_log_block_read_write(void) + int ret; + struct block_reader br = { 0 }; + struct block_iter it = BLOCK_ITER_INIT; -+ struct strbuf want = STRBUF_INIT; ++ struct strbuf want = STRBUF_INIT, buf = STRBUF_INIT; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; -+ block.source = malloc_block_source(); ++ block_source_from_strbuf(&block.source, &buf); + block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size, + header_off, hash_size(GIT_SHA1_FORMAT_ID)); + + for (i = 0; i < N; i++) { + uint8_t bytes[] = { i, i + 1, i + 2, i + 3, i + 5 }, *allocated; -+ allocated = reftable_malloc(ARRAY_SIZE(bytes)); + DUP_ARRAY(allocated, bytes, ARRAY_SIZE(bytes)); + + rec.u.obj.hash_prefix = allocated; @@ t/unit-tests/t-reftable-block.c: static void t_log_block_read_write(void) + reftable_record_release(&rec); + reftable_block_done(&br.block); + strbuf_release(&want); ++ strbuf_release(&buf); + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); +} 3: 4be7749c4b ! 3: db62f23594 t-reftable-block: add tests for index blocks @@ t/unit-tests/t-reftable-block.c: static void t_obj_block_read_write(void) + int ret; + struct block_reader br = { 0 }; + struct block_iter it = BLOCK_ITER_INIT; -+ struct strbuf want = STRBUF_INIT; ++ struct strbuf want = STRBUF_INIT, buf = STRBUF_INIT; + + REFTABLE_CALLOC_ARRAY(block.data, block_size); + block.len = block_size; -+ block.source = malloc_block_source(); ++ block_source_from_strbuf(&block.source, &buf); + block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size, + header_off, hash_size(GIT_SHA1_FORMAT_ID)); + @@ t/unit-tests/t-reftable-block.c: static void t_obj_block_read_write(void) + reftable_record_release(&rec); + reftable_block_done(&br.block); + strbuf_release(&want); ++ strbuf_release(&buf); + for (i = 0; i < N; i++) + reftable_record_release(&recs[i]); +}