git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 01/11] t: move reftable/record_test.c to the unit testing framework

From
CPChandra Pratap <chandrapratap3519@gmail.com>
Date
Jun 26, 2024, 12:57 UTC
Message-ID
<CA+J6zkSGyJ25dHSUgxF+-uEHBg13qaBwk_526QSqGN+FwRrMEQ@mail.gmail.com>
In-Reply-To
<CAOLa=ZQG4S6oJ_YTvc9LjV9C+THKcr_4xMsrOB2Mw6CZYfK9GA@mail.gmail.com>
On Wed, 26 Jun 2024 at 17:22, Karthik Nayak <karthik.188@gmail.com> wrote:
Show 137 quoted lines
>
> Chandra Pratap <chandrapratap3519@gmail.com> writes:
>
> > On Tue, 25 Jun 2024 at 13:56, Karthik Nayak <karthik.188@gmail.com> wrote:
> >>
> >> Chandra Pratap <chandrapratap3519@gmail.com> writes:
> >>
> >> > reftable/record_test.c exercises the functions defined in
> >> > reftable/record.{c, h}. Migrate reftable/record_test.c to the
> >> > unit testing framework. Migration involves refactoring the tests
> >> > to use the unit testing framework instead of reftable's test
> >> > framework.
> >> > While at it, change the type of index variable 'i' to 'size_t'
> >> > from 'int'. This is because 'i' is used in comparison against
> >> > 'ARRAY_SIZE(x)' which is of type 'size_t'.
> >> >
> >> > Also, use set_hash() which is defined locally in the test file
> >> > instead of set_test_hash() which is defined by
> >> > reftable/test_framework.{c, h}. This is fine to do as both these
> >> > functions are similarly implemented, and
> >> > reftable/test_framework.{c, h} is not #included in 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>
> >> > ---
> >> >  Makefile                                      |   2 +-
> >> >  t/helper/test-reftable.c                      |   1 -
> >> >  .../unit-tests/t-reftable-record.c            | 106 ++++++++----------
> >> >  3 files changed, 50 insertions(+), 59 deletions(-)
> >> >  rename reftable/record_test.c => t/unit-tests/t-reftable-record.c (77%)
> >> >
> >> > diff --git a/Makefile b/Makefile
> >> > index f25b2e80a1..def3700b4d 100644
> >> > --- a/Makefile
> >> > +++ b/Makefile
> >> > @@ -1338,6 +1338,7 @@ UNIT_TEST_PROGRAMS += t-hash
> >> >  UNIT_TEST_PROGRAMS += t-mem-pool
> >> >  UNIT_TEST_PROGRAMS += t-prio-queue
> >> >  UNIT_TEST_PROGRAMS += t-reftable-basics
> >> > +UNIT_TEST_PROGRAMS += t-reftable-record
> >> >  UNIT_TEST_PROGRAMS += t-strbuf
> >> >  UNIT_TEST_PROGRAMS += t-strcmp-offset
> >> >  UNIT_TEST_PROGRAMS += t-strvec
> >> > @@ -2678,7 +2679,6 @@ REFTABLE_TEST_OBJS += reftable/block_test.o
> >> >  REFTABLE_TEST_OBJS += reftable/dump.o
> >> >  REFTABLE_TEST_OBJS += reftable/merged_test.o
> >> >  REFTABLE_TEST_OBJS += reftable/pq_test.o
> >> > -REFTABLE_TEST_OBJS += reftable/record_test.o
> >> >  REFTABLE_TEST_OBJS += reftable/readwrite_test.o
> >> >  REFTABLE_TEST_OBJS += reftable/stack_test.o
> >> >  REFTABLE_TEST_OBJS += reftable/test_framework.o
> >> > diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c
> >> > index 9160bc5da6..aa6538a8da 100644
> >> > --- a/t/helper/test-reftable.c
> >> > +++ b/t/helper/test-reftable.c
> >> > @@ -5,7 +5,6 @@
> >> >  int cmd__reftable(int argc, const char **argv)
> >> >  {
> >> >       /* test from simple to complex. */
> >> > -     record_test_main(argc, argv);
> >> >       block_test_main(argc, argv);
> >> >       tree_test_main(argc, argv);
> >> >       pq_test_main(argc, argv);
> >> > diff --git a/reftable/record_test.c b/t/unit-tests/t-reftable-record.c
> >> > similarity index 77%
> >> > rename from reftable/record_test.c
> >> > rename to t/unit-tests/t-reftable-record.c
> >> > index 58290bdba3..1b357e6c7f 100644
> >> > --- a/reftable/record_test.c
> >> > +++ b/t/unit-tests/t-reftable-record.c
> >> > @@ -6,13 +6,9 @@
> >> >    https://developers.google.com/open-source/licenses/bsd
> >> >  */
> >> >
> >> > -#include "record.h"
> >> > -
> >> > -#include "system.h"
> >> > -#include "basics.h"
> >> > -#include "constants.h"
> >> > -#include "test_framework.h"
> >> > -#include "reftable-tests.h"
> >> > +#include "test-lib.h"
> >> > +#include "reftable/constants.h"
> >> > +#include "reftable/record.h"
> >> >
> >> >  static void test_copy(struct reftable_record *rec)
> >> >  {
> >> > @@ -24,9 +20,9 @@ static void test_copy(struct reftable_record *rec)
> >> >       reftable_record_copy_from(&copy, rec, GIT_SHA1_RAWSZ);
> >> >       /* do it twice to catch memory leaks */
> >>
> >> I'm curious why we do this, and if it is still needed. The original
> >> commit (e303bf22f reftable: (de)serialization for the polymorphic record
> >> type) doesn't mention any particular reasoning.
> >
> > Yeah, I was confused about this as well. I asked Patrick about it some time
> > ago and it seems like he had no clue about it either:
> > https://gitlab.slack.com/archives/C071PDKNCHM/p1717479205788209
> >
>
> Just to note, this is an internal GitLab link and not accessible to
> others on the list.
>
> But to summarize, seems like we're not sure why this was added. CC'ing
> Han-Wen here incase he remembers the intent.
>
> > Should we get rid of this after all?
>
> The best solution would be to understand its reasoning and incorporate
> that, but otherwise its best to remove it. We do have CI pipelines to
> capture leaks in a general sense.
>
> >> >       reftable_record_copy_from(&copy, rec, GIT_SHA1_RAWSZ);
> >> > -     EXPECT(reftable_record_equal(rec, &copy, GIT_SHA1_RAWSZ));
> >> > +     check(reftable_record_equal(rec, &copy, GIT_SHA1_RAWSZ));
> >> >
> >> > -     puts("testing print coverage:\n");
> >> > +     test_msg("testing print coverage:");
> >> >       reftable_record_print(&copy, GIT_SHA1_RAWSZ);
> >> >
> >>
> >> This prints for any test that uses this function. As I see from the
> >> current usage of the testing library, we only print debug information
> >> when we encounter something unexpected.
> >>
> >> This also clogs up the unit-test's output. So I would remove this from
> >> here.
> >
> > That's true, but that would also mean the print functions are no longer
> > exercised. Is that a fine tradeoff?
> >
>
> I don't see it this way. Just exercising the function doesn't test it in
> any way. Since the function just prints to stdout without an option to
> pick any other file descriptor, there is no way to test it currently
> either.

While that is true, it makes me wonder the reason behind adding it in the original test. Maybe we're supposed to manually verify the output?

> On the contrary if no one is using the function, perhaps we can even
> remove it.

The thing is, all the 'print' functions defined in reftable/ directory are meant to be used for debugging. So while they're not used anywhere in production, they still serve an important purpose during development.

Previous: Karthik NayakNext: Han-Wen Nienhuys
Message 19 of 74 in “t: port reftable/record_test.c to the unit testing framework”
  1. Chandra PratapJun 21, 2024
  2. 01/11 t: move reftable/record_test.c to the unit testing frameworkChandra Pratap, Jun 21, 2024
  3. 02/11 t-reftable-record: add reftable_record_cmp() tests for log recordsChandra Pratap, Jun 21, 2024
  4. 03/11 t-reftable-record: add comparison tests for ref recordsChandra Pratap, Jun 21, 2024
  5. 04/11 t-reftable-record: add comparison tests for index recordsChandra Pratap, Jun 21, 2024
  6. 05/11 t-reftable-record: add comparison tests for obj recordsChandra Pratap, Jun 21, 2024
  7. 06/11 t-reftable-record: add reftable_record_is_deletion() test for ref recordsChandra Pratap, Jun 21, 2024
  8. 07/11 t-reftable-record: add reftable_record_is_deletion() test for log recordsChandra Pratap, Jun 21, 2024
  9. 08/11 t-reftable-record: add reftable_record_is_deletion() test for obj recordsChandra Pratap, Jun 21, 2024
  10. 09/11 t-reftable-record: add reftable_record_is_deletion() test for index recordsChandra Pratap, Jun 21, 2024
  11. 10/11 t-reftable-record: add tests for reftable_ref_record_compare_name()Chandra Pratap, Jun 21, 2024
  12. 11/11 t-reftable-record: add tests for reftable_log_record_compare_key()Chandra Pratap, Jun 21, 2024
  13. Chandra PratapJun 21, 2024
  14. Chandra PratapJun 21, 2024
  15. 01/11 t: move reftable/record_test.c to the unit testing frameworkChandra Pratap, Jun 21, 2024
  16. Karthik NayakJun 25, 2024
  17. Chandra PratapJun 25, 2024
  18. Karthik NayakJun 26, 2024
  19. Chandra PratapJun 26, 2024
  20. Han-Wen NienhuysJun 26, 2024
  21. 02/11 t-reftable-record: add reftable_record_cmp() tests for log recordsChandra Pratap, Jun 21, 2024
  22. Karthik NayakJun 25, 2024
  23. 03/11 t-reftable-record: add comparison tests for ref recordsChandra Pratap, Jun 21, 2024
  24. 04/11 t-reftable-record: add comparison tests for index recordsChandra Pratap, Jun 21, 2024
  25. 05/11 t-reftable-record: add comparison tests for obj recordsChandra Pratap, Jun 21, 2024
  26. 06/11 t-reftable-record: add ref tests for reftable_record_is_deletion()Chandra Pratap, Jun 21, 2024
  27. Karthik NayakJun 25, 2024
  28. Eric SunshineJun 25, 2024
  29. Karthik NayakJun 26, 2024
  30. 07/11 t-reftable-record: add log tests for reftable_record_is_deletion()Chandra Pratap, Jun 21, 2024
  31. 08/11 t-reftable-record: add obj tests for reftable_record_is_deletion()Chandra Pratap, Jun 21, 2024
  32. 09/11 t-reftable-record: add index tests for reftable_record_is_deletion()Chandra Pratap, Jun 21, 2024
  33. Karthik NayakJun 25, 2024
  34. Chandra PratapJun 25, 2024
  35. Karthik NayakJun 26, 2024
  36. 10/11 t-reftable-record: add tests for reftable_ref_record_compare_name()Chandra Pratap, Jun 21, 2024
  37. Karthik NayakJun 25, 2024
  38. Chandra PratapJun 25, 2024
  39. 11/11 t-reftable-record: add tests for reftable_log_record_compare_key()Chandra Pratap, Jun 21, 2024
  40. Karthik NayakJun 25, 2024
  41. Karthik NayakJun 25, 2024
  42. [GSoC][PATCH v3 0/11] t: port reftable/record_test.c to the unit testing frameworkChandra Pratap, Jun 28, 2024
  43. 01/11 t: move reftable/record_test.c to the unit testing frameworkChandra Pratap, Jun 28, 2024
  44. Karthik NayakJun 30, 2024
  45. 02/11 t-reftable-record: add reftable_record_cmp() tests for log recordsChandra Pratap, Jun 28, 2024
  46. 03/11 t-reftable-record: add comparison tests for ref recordsChandra Pratap, Jun 28, 2024
  47. 04/11 t-reftable-record: add comparison tests for index recordsChandra Pratap, Jun 28, 2024
  48. 05/11 t-reftable-record: add comparison tests for obj recordsChandra Pratap, Jun 28, 2024
  49. 06/11 t-reftable-record: add ref tests for reftable_record_is_deletion()Chandra Pratap, Jun 28, 2024
  50. 07/11 t-reftable-record: add log tests for reftable_record_is_deletion()Chandra Pratap, Jun 28, 2024
  51. 08/11 t-reftable-record: add obj tests for reftable_record_is_deletion()Chandra Pratap, Jun 28, 2024
  52. 09/11 t-reftable-record: add index tests for reftable_record_is_deletion()Chandra Pratap, Jun 28, 2024
  53. 10/11 t-reftable-record: add tests for reftable_ref_record_compare_name()Chandra Pratap, Jun 28, 2024
  54. Karthik NayakJun 30, 2024
  55. Chandra PratapJul 1, 2024
  56. Karthik NayakJul 1, 2024
  57. Chandra PratapJul 1, 2024
  58. 11/11 t-reftable-record: add tests for reftable_log_record_compare_key()Chandra Pratap, Jun 28, 2024
  59. Karthik NayakJun 30, 2024
  60. Karthik NayakJun 30, 2024
  61. [GSoC][PATCH v4 0/11] t: port reftable/record_test.c to the unit testing framework frameworkChandra Pratap, Jul 2, 2024
  62. 01/11 t: move reftable/record_test.c to the unit testing frameworkChandra Pratap, Jul 2, 2024
  63. 02/11 t-reftable-record: add reftable_record_cmp() tests for log recordsChandra Pratap, Jul 2, 2024
  64. 03/11 t-reftable-record: add comparison tests for ref recordsChandra Pratap, Jul 2, 2024
  65. 04/11 t-reftable-record: add comparison tests for index recordsChandra Pratap, Jul 2, 2024
  66. 05/11 t-reftable-record: add comparison tests for obj recordsChandra Pratap, Jul 2, 2024
  67. 06/11 t-reftable-record: add ref tests for reftable_record_is_deletion()Chandra Pratap, Jul 2, 2024
  68. 07/11 t-reftable-record: add log tests for reftable_record_is_deletion()Chandra Pratap, Jul 2, 2024
  69. 08/11 t-reftable-record: add obj tests for reftable_record_is_deletion()Chandra Pratap, Jul 2, 2024
  70. 09/11 t-reftable-record: add index tests for reftable_record_is_deletion()Chandra Pratap, Jul 2, 2024
  71. 10/11 t-reftable-record: add tests for reftable_ref_record_compare_name()Chandra Pratap, Jul 2, 2024
  72. 11/11 t-reftable-record: add tests for reftable_log_record_compare_key()Chandra Pratap, Jul 2, 2024
  73. Karthik NayakJul 2, 2024
  74. Junio C HamanoJul 2, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.