[GSoC][PATCH v6 0/6] t: port reftable/stack_test.c to the unit testing framework

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/stack_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@xxxxxx>
Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx>

---
Changes in v6:
- Fix the Makefile changes in patch 7 of the previous series that
  broke the OSX CI.
- Squash patch 7 of the previous series into patch 1.

CI/PR: https://github.com/gitgitgadget/git/pull/1762

Chandra Pratap(6):
t: move reftable/stack_test.c to the unit testing framework
t: harmonize t-reftable-stack.c with coding guidelines
t-reftable-stack: use Git's tempfile API instead of mkstemp()
t-reftable-stack: use reftable_ref_record_equal() to compare ref records
t-reftable-stack: add test for non-default compaction factor
t-reftable-stack: add test for stack iterators

Makefile                                           |  12 +-
reftable/reftable-tests.h                          |  14 -
reftable/test_framework.c                          |  27 -
reftable/test_framework.h                          |  61 --
t/helper/test-reftable.c                           |   8 -
t/helper/test-tool.c                               |   3 +-
t/helper/test-tool.h                               |   1 -
t/t0032-reftable-unittest.sh                       |  16 -
.../unit-tests/t-reftable-stack.c                  | 665 ++++++++++++---------
9 files changed, 392 insertions(+), 415 deletions(-)

Range-diff against v5:
1:  e9af30d14a ! 1:  fa549a875a t: move reftable/stack_test.c to the unit testing framework
    @@ Commit message
         '#included' in the test file, copy this function in the
         ported test file.

    +    With the migration of stack test to the unit-tests framework,
    +    "test-tool reftable" becomes a no-op. Hence, get rid of everything
    +    that uses "test-tool reftable" alongside everything that is used
    +    to implement it.
    +
    +    While at it, alphabetically sort the cmds[] list in
    +    helper/test-tool.c by moving the entry for "dump-reftable".
    +
         Mentored-by: Patrick Steinhardt <ps@xxxxxx>
         Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
         Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx>

      ## Makefile ##
    +@@ Makefile: TEST_SHELL_PATH = $(SHELL_PATH)
    + LIB_FILE = libgit.a
    + XDIFF_LIB = xdiff/lib.a
    + REFTABLE_LIB = reftable/libreftable.a
    +-REFTABLE_TEST_LIB = reftable/libreftable_test.a
    +
    + GENERATED_H += command-list.h
    + GENERATED_H += config-list.h
     @@ Makefile: UNIT_TEST_PROGRAMS += t-reftable-merged
      UNIT_TEST_PROGRAMS += t-reftable-pq
      UNIT_TEST_PROGRAMS += t-reftable-readwrite
    @@ Makefile: REFTABLE_OBJS += reftable/stack.o
      REFTABLE_OBJS += reftable/writer.o

     -REFTABLE_TEST_OBJS += reftable/stack_test.o
    - REFTABLE_TEST_OBJS += reftable/test_framework.o
    -
    +-REFTABLE_TEST_OBJS += reftable/test_framework.o
    +-
      TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
    -
    - ## reftable/reftable-tests.h ##
    -@@ reftable/reftable-tests.h: license that can be found in the LICENSE file or at
    - #ifndef REFTABLE_TESTS_H
    - #define REFTABLE_TESTS_H

    --int stack_test_main(int argc, const char **argv);
    + .PHONY: test-objs
    +@@ Makefile: $(XDIFF_LIB): $(XDIFF_OBJS)
    + $(REFTABLE_LIB): $(REFTABLE_OBJS)
    + 	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^

    - #endif
    +-$(REFTABLE_TEST_LIB): $(REFTABLE_TEST_OBJS)
    +-	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
    +-
    + export DEFAULT_EDITOR DEFAULT_PAGER
    +
    + Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
    +@@ Makefile: perf: all
    +
    + t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
    +
    +-t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
    ++t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
    + 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
    +
    + check-sha1:: t/helper/test-tool$X
    +@@ Makefile: clean: profile-clean coverage-clean cocciclean
    + 	$(RM) git.res
    + 	$(RM) $(OBJECTS)
    + 	$(RM) headless-git.o
    +-	$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
    ++	$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
    + 	$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)
    + 	$(RM) $(TEST_PROGRAMS)
    + 	$(RM) $(FUZZ_PROGRAMS)
    +
    + ## reftable/reftable-tests.h (deleted) ##
    +@@
    +-/*
    +-Copyright 2020 Google LLC
    +-
    +-Use of this source code is governed by a BSD-style
    +-license that can be found in the LICENSE file or at
    +-https://developers.google.com/open-source/licenses/bsd
    +-*/
    +-
    +-#ifndef REFTABLE_TESTS_H
    +-#define REFTABLE_TESTS_H
    +-
    +-int stack_test_main(int argc, const char **argv);
    +-
    +-#endif
    +
    + ## reftable/test_framework.c (deleted) ##
    +@@
    +-/*
    +-Copyright 2020 Google LLC
    +-
    +-Use of this source code is governed by a BSD-style
    +-license that can be found in the LICENSE file or at
    +-https://developers.google.com/open-source/licenses/bsd
    +-*/
    +-
    +-#include "system.h"
    +-#include "test_framework.h"
    +-
    +-
    +-void set_test_hash(uint8_t *p, int i)
    +-{
    +-	memset(p, (uint8_t)i, hash_size(GIT_SHA1_FORMAT_ID));
    +-}
    +-
    +-ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
    +-{
    +-	strbuf_add(b, data, sz);
    +-	return sz;
    +-}
    +-
    +-int noop_flush(void *arg UNUSED)
    +-{
    +-	return 0;
    +-}
    +
    + ## reftable/test_framework.h (deleted) ##
    +@@
    +-/*
    +-Copyright 2020 Google LLC
    +-
    +-Use of this source code is governed by a BSD-style
    +-license that can be found in the LICENSE file or at
    +-https://developers.google.com/open-source/licenses/bsd
    +-*/
    +-
    +-#ifndef TEST_FRAMEWORK_H
    +-#define TEST_FRAMEWORK_H
    +-
    +-#include "system.h"
    +-#include "reftable-error.h"
    +-
    +-#define EXPECT_ERR(c)                                                          \
    +-	do {                                                                   \
    +-		if (c != 0) {                                                  \
    +-			fflush(stderr);                                        \
    +-			fflush(stdout);                                        \
    +-			fprintf(stderr, "%s: %d: error == %d (%s), want 0\n",  \
    +-				__FILE__, __LINE__, c, reftable_error_str(c)); \
    +-			abort();                                               \
    +-		}                                                              \
    +-	} while (0)
    +-
    +-#define EXPECT_STREQ(a, b)                                                       \
    +-	do {                                                                     \
    +-		if (strcmp(a, b)) {                                              \
    +-			fflush(stderr);                                          \
    +-			fflush(stdout);                                          \
    +-			fprintf(stderr, "%s:%d: %s (%s) != %s (%s)\n", __FILE__, \
    +-				__LINE__, #a, a, #b, b);                         \
    +-			abort();                                                 \
    +-		}                                                                \
    +-	} while (0)
    +-
    +-#define EXPECT(c)                                                                  \
    +-	do {                                                                       \
    +-		if (!(c)) {                                                        \
    +-			fflush(stderr);                                            \
    +-			fflush(stdout);                                            \
    +-			fprintf(stderr, "%s: %d: failed assertion %s\n", __FILE__, \
    +-				__LINE__, #c);                                     \
    +-			abort();                                                   \
    +-		}                                                                  \
    +-	} while (0)
    +-
    +-#define RUN_TEST(f)                          \
    +-	fprintf(stderr, "running %s\n", #f); \
    +-	fflush(stderr);                      \
    +-	f();
    +-
    +-void set_test_hash(uint8_t *p, int i);
    +-
    +-/* Like strbuf_add, but suitable for passing to reftable_new_writer
    +- */
    +-ssize_t strbuf_add_void(void *b, const void *data, size_t sz);
    +-
    +-int noop_flush(void *);
    +-
    +-#endif

      ## t/helper/test-reftable.c ##
     @@
    - int cmd__reftable(int argc, const char **argv)
    - {
    - 	/* test from simple to complex. */
    + #include "reftable/reftable-merged.h"
    + #include "reftable/reftable-reader.h"
    + #include "reftable/reftable-stack.h"
    +-#include "reftable/reftable-tests.h"
    + #include "test-tool.h"
    +
    +-int cmd__reftable(int argc, const char **argv)
    +-{
    +-	/* test from simple to complex. */
     -	stack_test_main(argc, argv);
    - 	return 0;
    - }
    -
    +-	return 0;
    +-}
    +-
    + static void print_help(void)
    + {
    + 	printf("usage: dump [-st] arg\n\n"
    +
    + ## t/helper/test-tool.c ##
    +@@ t/helper/test-tool.c: static struct test_cmd cmds[] = {
    + 	{ "drop-caches", cmd__drop_caches },
    + 	{ "dump-cache-tree", cmd__dump_cache_tree },
    + 	{ "dump-fsmonitor", cmd__dump_fsmonitor },
    ++	{ "dump-reftable", cmd__dump_reftable },
    + 	{ "dump-split-index", cmd__dump_split_index },
    + 	{ "dump-untracked-cache", cmd__dump_untracked_cache },
    + 	{ "env-helper", cmd__env_helper },
    +@@ t/helper/test-tool.c: static struct test_cmd cmds[] = {
    + 	{ "read-graph", cmd__read_graph },
    + 	{ "read-midx", cmd__read_midx },
    + 	{ "ref-store", cmd__ref_store },
    +-	{ "reftable", cmd__reftable },
    + 	{ "rot13-filter", cmd__rot13_filter },
    +-	{ "dump-reftable", cmd__dump_reftable },
    + 	{ "regex", cmd__regex },
    + 	{ "repository", cmd__repository },
    + 	{ "revision-walking", cmd__revision_walking },
    +
    + ## t/helper/test-tool.h ##
    +@@ t/helper/test-tool.h: int cmd__read_graph(int argc, const char **argv);
    + int cmd__read_midx(int argc, const char **argv);
    + int cmd__ref_store(int argc, const char **argv);
    + int cmd__rot13_filter(int argc, const char **argv);
    +-int cmd__reftable(int argc, const char **argv);
    + int cmd__regex(int argc, const char **argv);
    + int cmd__repository(int argc, const char **argv);
    + int cmd__revision_walking(int argc, const char **argv);
    +
    + ## t/t0032-reftable-unittest.sh (deleted) ##
    +@@
    +-#!/bin/sh
    +-#
    +-# Copyright (c) 2020 Google LLC
    +-#
    +-
    +-test_description='reftable unittests'
    +-
    +-TEST_PASSES_SANITIZE_LEAK=true
    +-. ./test-lib.sh
    +-
    +-test_expect_success 'unittests' '
    +-	TMPDIR=$(pwd) && export TMPDIR &&
    +-	test-tool reftable
    +-'
    +-
    +-test_done

      ## reftable/stack_test.c => t/unit-tests/t-reftable-stack.c ##
     @@ t/unit-tests/t-reftable-stack.c: license that can be found in the LICENSE file or at
2:  8e8e09bd5b = 2:  1fd91e7a12 t: harmonize t-reftable-stack.c with coding guidelines
3:  ca4b00feef = 3:  8a7132500a t-reftable-stack: use Git's tempfile API instead of mkstemp()
4:  3e723667dd = 4:  786f7c2874 t-reftable-stack: use reftable_ref_record_equal() to compare ref records
5:  7526550c92 = 5:  388f1129d8 t-reftable-stack: add test for non-default compaction factor
6:  05e4b7e715 = 6:  5468c9853f t-reftable-stack: add test for stack iterators
7:  560d3c76e0 < -:  ---------- t: clean up leftover reftable test cruft





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux