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

Re: [PATCH v4] test-lib-functions: use test-tool for [de]packetize()

From
Taylor Blau <me@ttaylorr.com>
Date
Jul 16, 2021, 16:53 UTC
Message-ID
<YPG5few/PeStqe/2@nand.local>
In-Reply-To
<patch-1.1-546974eed59-20210716T153909Z-avarab@gmail.com>
On Fri, Jul 16, 2021 at 05:41:33PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 8 quoted lines
> I ejected changing/adding test code for this v4. This keeps the
> compatibility wrappers and just narrowly changes the things that need
> a packetize_raw() to use that new helper.
>
> I left the simpler packetize() case as a "printf", it could also use
> the test tool, but in case someone cares about process overhead on say
> Windows this entire change should be strictly better than the status
> quo.
Thanks, this version of the series looks much better to me.
Show 10 quoted lines
> +static void pack_raw_stdin(void)
> +{
> +	struct strbuf sb = STRBUF_INIT;
> +
> +	if (strbuf_read(&sb, 0, 0) < 0)
> +		die_errno("failed to read from stdin");
> +	packet_write(1, sb.buf, sb.len);
> +	strbuf_release(&sb);
> +}
> +
Looks good to me.
Show 7 quoted lines
> -# convert function arguments or stdin (if not arguments given) to pktline
> -# representation. If multiple arguments are given, they are separated by
> -# whitespace and put in a single packet. Note that data containing NULs must be
> -# given on stdin, and that empty input becomes an empty packet, not a flush
> -# packet (for that you can just print 0000 yourself).
> +# These functions are historical wrappers around "test-tool pkt-line"
> +# for older tests. Use "test-tool pkt-line" itself in new tests.

Nice. This keeps the diff relatively minimal. I don't really have a strong opinion on saying "packetize" or "test-tool pkt-line pack" in the future. Arguably the latter is more direct, but it's also more of a mouthful.

I'm fine to take the approach you have here, and adjust the guidance in the future depending on if people really do start preferring one over the other in new tests.

Show 13 quoted lines
>  packetize () {
>  	if test $# -gt 0
>  	then
>  		packet="$*"
>  		printf '%04x%s' "$((4 + ${#packet}))" "$packet"
>  	else
> -		perl -e '
> -			my $packet = do { local $/; <STDIN> };
> -			printf "%04x%s", 4 + length($packet), $packet;
> -		'
> +		test-tool pkt-line pack
>  	fi
>  }

For what it's worth, I would be happy to remove the printf shortcut entirely. Some quick grepping indicates only 22 uses of the word "packetize" in our whole test suite (one of them being the function declaration itself). And of the 21 callers, only 10 pass at least one argument:

    git grep -Ew 'packetize [^()&]+' -- t

So I would be fine with adding 10 more new processes to the test suite in the name of simplifying this declaration. I don't feel strongly, though, since the conditional here does not really add that much complexity.

Thanks, Taylor

Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 30 of 33 in “tests: migrate to "test-tool pkt-line"”
  1. 0/5 tests: migrate to "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 7, 2021
  2. 1/5 serve tests: add missing "extra delim" testÆvar Arnfjörð Bjarmason, Jul 7, 2021
  3. 2/5 serve tests: use test_cmp in "protocol violations" testÆvar Arnfjörð Bjarmason, Jul 7, 2021
  4. 3/5 tests: replace [de]packetize() shell+perl test-tool pkt-lineÆvar Arnfjörð Bjarmason, Jul 7, 2021
  5. 4/5 tests: replace remaining packetize() with "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 7, 2021
  6. 5/5 test-lib-functions.sh: remove unused [de]packetize() functionsÆvar Arnfjörð Bjarmason, Jul 7, 2021
  7. 0/5 tests: migrate to "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 12, 2021
  8. 1/5 serve tests: add missing "extra delim" testÆvar Arnfjörð Bjarmason, Jul 12, 2021
  9. 2/5 serve tests: use test_cmp in "protocol violations" testÆvar Arnfjörð Bjarmason, Jul 12, 2021
  10. 3/5 tests: replace [de]packetize() shell+perl test-tool pkt-lineÆvar Arnfjörð Bjarmason, Jul 12, 2021
  11. Jeff KingJul 13, 2021
  12. Ævar Arnfjörð BjarmasonJul 13, 2021
  13. Jeff KingJul 14, 2021
  14. 4/5 tests: replace remaining packetize() with "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 12, 2021
  15. Jeff KingJul 13, 2021
  16. Ævar Arnfjörð BjarmasonJul 13, 2021
  17. Jeff KingJul 14, 2021
  18. 5/5 test-lib-functions.sh: remove unused [de]packetize() functionsÆvar Arnfjörð Bjarmason, Jul 12, 2021
  19. Junio C HamanoJul 12, 2021
  20. Jeff KingJul 13, 2021
  21. 0/5 tests: migrate to "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 14, 2021
  22. 1/5 serve tests: add missing "extra delim" testÆvar Arnfjörð Bjarmason, Jul 14, 2021
  23. 3/5 tests: replace [de]packetize() shell+perl test-tool pkt-lineÆvar Arnfjörð Bjarmason, Jul 14, 2021
  24. Taylor BlauJul 14, 2021
  25. Junio C HamanoJul 14, 2021
  26. 2/5 serve tests: use test_cmp in "protocol violations" testÆvar Arnfjörð Bjarmason, Jul 14, 2021
  27. 4/5 tests: replace remaining packetize() with "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 14, 2021
  28. 5/5 test-lib-functions.sh: remove unused [de]packetize() functionsÆvar Arnfjörð Bjarmason, Jul 14, 2021
  29. test-lib-functions: use test-tool for [de]packetize()Ævar Arnfjörð Bjarmason, Jul 16, 2021
  30. Taylor BlauJul 16, 2021
  31. Jeff KingJul 16, 2021
  32. Jeff KingJul 16, 2021
  33. Junio C HamanoJul 19, 2021

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.