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

[PATCH v2 2/3] perf-lib: add cleanup option

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Sep 23, 2013, 21:08 UTC
Message-ID
<1379970526-27997-3-git-send-email-t.gummerer@gmail.com>
In-Reply-To
<1379970526-27997-1-git-send-email-t.gummerer@gmail.com>

Add a --cleanup for the performance tests. This option can be used to clean up the tested repository after each time the performance tests are run. The option can be specified for normal tests too, although it will not do anything for them. Use test_when_finished for those tests.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 t/perf/README           | 11 ++++++++++-
 t/perf/perf-lib.sh      | 15 +++++++++++++++
 t/test-lib-functions.sh |  6 ++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/t/perf/README b/t/perf/README
index 21abbaf..73a1d1c 100644
--- a/t/perf/README
+++ b/t/perf/README
@@ -123,7 +123,7 @@ tests, use
 		command2
 	'
 
-	test_perf [--prereq <prereq>] [--] 'descriptive string' '
+	test_perf [--prereq <prereq>] [--cleanup <cleanup>] [--] 'descriptive string' '
 		command1 &&
 		command2
 	'
@@ -133,6 +133,15 @@ tests are only executed if the prerequisite is fulfilled.  The modern
 version also allows to distinguish the message from the description
 and test script with --, in case the message starts with --.
 
+cleanup is another optional parameter to test_perf, which is executed
+after every run of the performance test.  It can specify actions to
+bring the repository to the original state, in order to be able to
+execute the exact same test multiple times, e.g:
+
+	test_perf --cleanup 'git reset' 'test performance of git add' '
+		  git add $somefile
+	'
+
 test_perf spawns a subshell, for lack of better options.  This means
 that
 
diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
index 6477d38..8ace4a3 100644
--- a/t/perf/perf-lib.sh
+++ b/t/perf/perf-lib.sh
@@ -176,6 +176,21 @@ test_perf () {
 				test_failure_ "$@"
 				break
 			fi
+			if ! test -z "$cleanup_action"; then
+				say >&3 "cleaning up: $cleanup_action"
+				if test_run_ "$cleanup_action"
+				then
+					if test -z "$verbose"; then
+						printf " c%s" "$i"
+					else
+						echo "* cleaning up run $i/$GIT_PERF_REPEAT_COUNT:"
+					fi
+				else
+					test -z $verbose && echo
+					test_failure_ "$@"
+					break
+				fi
+			fi
 		done
 		if test -z "$verbose"; then
 			echo " ok"
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 473b21d..4bad14f 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -360,6 +360,12 @@ test_expect_parse () {
 			test_prereq=$2
 			shift
 			;;
+		--cleanup)
+			test $# -gt 1 ||
+			error "bug in the test script: --cleanup needs a parameter"
+			cleanup_action=$2
+			shift
+			;;
 		--)
 			shift
 			break
-- 
1.8.3.4.1241.g1ce9896
Previous: Thomas GummererNext: Thomas Gummerer
Message 11 of 12 in “perf-lib: split starting the test from the execution”
  1. 1/2 perf-lib: split starting the test from the executionThomas Gummerer, Sep 17, 2013
  2. 2/2 perf-lib: add test_perf_cleanup targetThomas Gummerer, Sep 17, 2013
  3. Junio C HamanoSep 17, 2013
  4. Thomas GummererSep 19, 2013
  5. Junio C HamanoSep 19, 2013
  6. Junio C HamanoSep 19, 2013
  7. Junio C HamanoSep 19, 2013
  8. Thomas GummererSep 20, 2013
  9. 0/3 Add cleanup action to perf-libThomas Gummerer, Sep 23, 2013
  10. 1/3 test-lib: introduce "modern" style testsThomas Gummerer, Sep 23, 2013
  11. 2/3 perf-lib: add cleanup optionThomas Gummerer, Sep 23, 2013
  12. 3/3 p0003-index.sh: add perf test for the index formatsThomas Gummerer, Sep 23, 2013

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.