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

Re: [PATCH v2 1/2] t: add "test-tool genbytes" to avoid slow tr(1) on macOS

From
Kristofer Karlsson <krka@spotify.com>
Date
Nov 9, 2026, 07:10 UTC
Message-ID
<CAL71e4PkS0dRvqSkL81hSPO3M3K2n5ZTumFNvCx9MsBsFKbnmw@mail.gmail.com>
In-Reply-To
<xmqqeccu3hqq.fsf@gitster.g>
On Mon, 9 Nov 2026 at 02:39, Junio C Hamano <gitster@pobox.com> wrote:
Show 40 quoted lines
>
> "Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > diff --git a/t/helper/test-genbytes.c b/t/helper/test-genbytes.c
> > new file mode 100644
> > index 0000000000..b760326b24
> > --- /dev/null
> > +++ b/t/helper/test-genbytes.c
> > @@ -0,0 +1,61 @@
> > +#define DISABLE_SIGN_COMPARE_WARNINGS
> > +
> > +#include "test-tool.h"
> > +#include "git-compat-util.h"
> > +#include "hex-ll.h"
> > +
> > +/*
> > + * Write "count" copies of "byte" to stdout, or an endless stream of them if
> > + * "count" is negative.
> > + */
> > +static int generate_bytes(char byte, intmax_t count)
> > +{
> > +     char buf[256 * 1024];
>
> Allocating 256kB on stack may not be a great practice, but this may
> sufficiently work on most reasonable systems, as this is an internal
> of a "run once and exit" test helper function.
>
> Still, the stack memory for the primary thread of a process is
> limited to 8MB or so on modern Linux systems, and I hear macOS also
> uses 8MB.  I am not familiar with Windows, but some documentation
> found on the Web seems to say that their linker gives 1MB to their
> product by default, and among 1MB, 256kB is not an insignificant
> fraction.
>
> Again, this is an internal of a "run once and exit" test helper, so
> declaring this as "static char buf[]" should not pose an issue; it is
> not like you would need to have multiple simultaneous invocations of
> this function, each of which needs to fill this buffer with
> different values.
Yes, I think we have a few options to choose between:
  1. keep the previous static.  Technically this means that we
     should also document it as not being thread-safe.
     Currently it does not matter, since it's never called from
     anywhere else, but there is a slight code smell to it
     since the buffer no longer hosts a constant value.
  2. remove static and keep the size.  Since the stack is not
     complex or deep here it should be safe.  It would break
     on platforms with a very small stack, but since it's only
     use by CI and developers any breakage would be immediately
     obvious and easy to fix.
  3. remove static and shrink the buffer size.  From my (limited)
     local experiment, it seems the buffer is larger than needed.
     We could shrink it without losing performance.

I don't have a strong opinion here; I went with (2) because it seemed like the smallest change but I'd be happy to change it.

If we go with static, I'd prefer to have a small comment above the function definition:

  /* not thread-safe (due to the mutable static 'buf') */

Thanks, Kristofer

Previous: Junio C HamanoNext: Junio C Hamano
Message 28 of 39 in “t: add "test-tool genbytes" to avoid slow tr(1) on macOS”
  1. 0/3 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 7, 2026
  2. 1/3 t/helper: rename test-genzeros.c to test-genbytes.cKristofer Karlsson via GitGitGadget, Nov 7, 2026
  3. Junio C HamanoNov 7, 2026
  4. Junio C HamanoNov 8, 2026
  5. Kristofer KarlssonNov 8, 2026
  6. Junio C HamanoNov 8, 2026
  7. Kristofer KarlssonNov 8, 2026
  8. 2/3 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 7, 2026
  9. Johannes SixtNov 8, 2026
  10. Kristofer KarlssonNov 8, 2026
  11. Johannes SixtNov 8, 2026
  12. Kristofer KarlssonNov 8, 2026
  13. Johannes SixtNov 8, 2026
  14. Johannes SixtNov 9, 2026
  15. Kristofer KarlssonNov 9, 2026
  16. Johannes SixtNov 9, 2026
  17. Collin FunkNov 10, 2026
  18. Kristofer KarlssonNov 10, 2026
  19. Junio C HamanoNov 8, 2026
  20. 3/3 t: replace "test-tool genzeros" with "genbytes NUL"Kristofer Karlsson via GitGitGadget, Nov 7, 2026
  21. Junio C HamanoNov 7, 2026
  22. Kristofer KarlssonNov 8, 2026
  23. Junio C HamanoNov 7, 2026
  24. Kristofer KarlssonNov 8, 2026
  25. 0/2 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 8, 2026
  26. 1/2 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 8, 2026
  27. Junio C HamanoNov 9, 2026
  28. Kristofer KarlssonNov 9, 2026
  29. Junio C HamanoNov 9, 2026
  30. Patrick SteinhardtNov 9, 2026
  31. Kristofer KarlssonNov 9, 2026
  32. 2/2 t: replace "test-tool genzeros" with "genbytes 00"Kristofer Karlsson via GitGitGadget, Nov 8, 2026
  33. t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 10, 2026
  34. Junio C HamanoNov 10, 2026
  35. Patrick SteinhardtNov 11, 2026
  36. Junio C HamanoNov 11, 2026
  37. Kristofer KarlssonNov 11, 2026
  38. Junio C HamanoNov 11, 2026
  39. t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 11, 2026

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.