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

[PATCH 2/4] test-tools: migrate read-cache-perf to parse_options()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 7, 2021, 11:58 UTC
Message-ID
<patch-2.4-07f392e087-20210607T115454Z-avarab@gmail.com>
In-Reply-To
<cover-0.4-0000000000-20210607T115454Z-avarab@gmail.com>

Change the newly added (but then mostly copy/pasted) read-cache-perf to use the parse_options() API. This will make things easier as we add new options.

Since we check the "cnt = < 1" case now via more idiomatic post-parse_options() assertions we can move from the for-loop to a while-loop and ditch the "i" variable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-read-cache-perf.c | 26 ++++++++++++++++++++------
 t/perf/p0002-read-cache.sh      |  2 +-
 2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/t/helper/test-read-cache-perf.c b/t/helper/test-read-cache-perf.c
index 90176c010a..54ad0c3135 100644
--- a/t/helper/test-read-cache-perf.c
+++ b/t/helper/test-read-cache-perf.c
@@ -1,18 +1,32 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "parse-options.h"
+
+static const char *read_cache_perf_usage[] = {
+	"test-tool read-cache-perf [<options>...]",
+	NULL
+};
 
 int cmd__read_cache_perf(int argc, const char **argv)
 {
 	struct repository *r = the_repository;
-	int i, cnt = 1;
+	int cnt = -1;
+	struct option options[] = {
+		OPT_INTEGER(0, "count", &cnt, "number of passes"),
+		OPT_END()
+	};
 
-	if (argc == 2)
-		cnt = strtol(argv[1], NULL, 0);
-	else
-		die("usage: test-tool read-cache-perf [<count>]");
+	argc = parse_options(argc, argv, "test-tools", options,
+			     read_cache_perf_usage, 0);
+	if (argc > 0)
+		usage_msg_opt("Too many arguments.", read_cache_perf_usage,
+			      options);
+	if (cnt < 1)
+		usage_msg_opt("Need at least one pass.", read_cache_perf_usage,
+			      options);
 
 	setup_git_directory();
-	for (i = 0; i < cnt; i++) {
+	while (cnt--) {
 		repo_read_index(r);
 		discard_index(r->index);
 	}
diff --git a/t/perf/p0002-read-cache.sh b/t/perf/p0002-read-cache.sh
index d0ba5173fb..1762b64865 100755
--- a/t/perf/p0002-read-cache.sh
+++ b/t/perf/p0002-read-cache.sh
@@ -8,7 +8,7 @@ test_perf_default_repo
 
 count=1000
 test_perf "read_cache/discard_cache $count times" "
-	test-tool read-cache-perf $count
+	test-tool read-cache-perf --count=$count
 "
 
 test_done
-- 
2.32.0.rc3.434.gd8aed1f08a7
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 4 of 18 in “test-tool: split up "read-cache" tool”
  1. 0/4 test-tool: split up "read-cache" toolÆvar Arnfjörð Bjarmason, Jun 7, 2021
  2. 4/4 read-cache perf: add a perf test for refresh_index()Ævar Arnfjörð Bjarmason, Jun 7, 2021
  3. 3/4 test-tools: migrate read-cache-again to parse_options()Ævar Arnfjörð Bjarmason, Jun 7, 2021
  4. 2/4 test-tools: migrate read-cache-perf to parse_options()Ævar Arnfjörð Bjarmason, Jun 7, 2021
  5. 1/4 test-tool: split up test-tool read-cacheÆvar Arnfjörð Bjarmason, Jun 7, 2021
  6. Junio C HamanoJun 7, 2021
  7. Ævar Arnfjörð BjarmasonJun 8, 2021
  8. Junio C HamanoJun 8, 2021
  9. Emily ShafferJun 30, 2021
  10. Ævar Arnfjörð BjarmasonJun 30, 2021
  11. 0/4 test-tool: split up "read-cache" toolÆvar Arnfjörð Bjarmason, Aug 24, 2021
  12. 1/4 test-tool: split up test-tool read-cacheÆvar Arnfjörð Bjarmason, Aug 24, 2021
  13. 2/4 test-tool: migrate read-cache-perf to parse_options()Ævar Arnfjörð Bjarmason, Aug 24, 2021
  14. 3/4 test-tool: migrate read-cache-again to parse_options()Ævar Arnfjörð Bjarmason, Aug 24, 2021
  15. 4/4 read-cache perf: add a perf test for refresh_index()Ævar Arnfjörð Bjarmason, Aug 24, 2021
  16. Taylor BlauAug 24, 2021
  17. Junio C HamanoAug 25, 2021
  18. Ævar Arnfjörð BjarmasonAug 27, 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.