Skip to contentSkip to conversation

t/perf: do not run tests in user's $SHELL

PATCH RESEND In review René Scharfe 4 participants 6 messages Dec 20, 2021 – Dec 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 t/perf: do not run tests in user's $SHELL

From: Johannes Altmanninger <[email protected]>

The environment variable $SHELL is usually set to the user's interactive shell. We never use that shell for build and test scripts because it might not be a POSIX shell.

Perf tests are run inside $SHELL via a wrapper defined in t/perf/perf-lib.sh. Use $TEST_SHELL_PATH like elsewhere.

---
Original submission:
https://lore.kernel.org/git/[email protected]/

 t/perf/perf-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/perf/perf-lib.sh +1 -1
index 780a7402d5..407252bac7 100644
@@ -161,7 +161,7 @@ test_run_perf_ () {
 	test_cleanup=:
 	test_export_="test_cleanup"
 	export test_cleanup test_export_
-	"$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+	"$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
 	test_export_="$test_export_ $*"

--
2.34.0

#1 lore raw
Quoted 6 lines · René Scharfe

From: Johannes Altmanninger <[email protected]>

The environment variable $SHELL is usually set to the user's interactive shell. We never use that shell for build and test scripts because it might not be a POSIX shell.

Quoted 8 lines

Perf tests are run inside $SHELL via a wrapper defined in t/perf/perf-lib.sh. Use $TEST_SHELL_PATH like elsewhere.

---
Original submission:
https://lore.kernel.org/git/[email protected]/

This LGTM & I think it could be picked up as-is.

Just a nit in case af a re-roll. I think it would help to summarize the history a bit per
https://lore.kernel.org/git/YV+1%[email protected]/. I.e. something like:

In 342e9ef2d9e (Introduce a performance testing framework, 2012-02-17) when t/perf was introduced the TEST_SHELL_PATH was not part of GIT-BUILD-OPTIONS. That was added later in 3f824e91c84 (t/Makefile:
introduce TEST_SHELL_PATH, 2017-12-08). We will always have that available in perf-lib.sh since test-lib.sh will load it before this code is executed.

Quoted 16 lines
 t/perf/perf-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/perf/perf-lib.sh +1 -1
index 780a7402d5..407252bac7 100644
@@ -161,7 +161,7 @@ test_run_perf_ () {
 	test_cleanup=:
 	test_export_="test_cleanup"
 	export test_cleanup test_export_
-	"$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+	"$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
 	test_export_="$test_export_ $*"
#2 lore raw
Quoted 20 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · René Scharfe

From: Johannes Altmanninger <[email protected]>

The environment variable $SHELL is usually set to the user's interactive shell. We never use that shell for build and test scripts because it might not be a POSIX shell.

Quoted 8 lines

Perf tests are run inside $SHELL via a wrapper defined in t/perf/perf-lib.sh. Use $TEST_SHELL_PATH like elsewhere.

---
Original submission:
https://lore.kernel.org/git/[email protected]/

This LGTM & I think it could be picked up as-is.

Quoted 8 lines

Just a nit in case af a re-roll. I think it would help to summarize the history a bit per
https://lore.kernel.org/git/YV+1%[email protected]/. I.e. something like:

In 342e9ef2d9e (Introduce a performance testing framework, 2012-02-17) when t/perf was introduced the TEST_SHELL_PATH was not part of GIT-BUILD-OPTIONS.

(but SHELL_PATH was, which is what we should have used back then)

Quoted 4 lines

That was added later in 3f824e91c84 (t/Makefile:
introduce TEST_SHELL_PATH, 2017-12-08). We will always have that available in perf-lib.sh since test-lib.sh will load it before this code is executed.

yes that's a good thing to point out

Quoted 18 lines
Quoted 17 lines
 t/perf/perf-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/perf/perf-lib.sh +1 -1
index 780a7402d5..407252bac7 100644
@@ -161,7 +161,7 @@ test_run_perf_ () {
 	test_cleanup=:
 	test_export_="test_cleanup"
 	export test_cleanup test_export_
-	"$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+	"$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
 	test_export_="$test_export_ $*"
#3 lore raw
Quoted 30 lines · Johannes Altmanninger
Quoted 20 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · René Scharfe

From: Johannes Altmanninger <[email protected]>

The environment variable $SHELL is usually set to the user's interactive shell. We never use that shell for build and test scripts because it might not be a POSIX shell.

Quoted 8 lines

Perf tests are run inside $SHELL via a wrapper defined in t/perf/perf-lib.sh. Use $TEST_SHELL_PATH like elsewhere.

---
Original submission:
https://lore.kernel.org/git/[email protected]/

This LGTM & I think it could be picked up as-is.

Quoted 8 lines

Just a nit in case af a re-roll. I think it would help to summarize the history a bit per
https://lore.kernel.org/git/YV+1%[email protected]/. I.e. something like:

In 342e9ef2d9e (Introduce a performance testing framework, 2012-02-17) when t/perf was introduced the TEST_SHELL_PATH was not part of GIT-BUILD-OPTIONS.

Quoted 8 lines

(but SHELL_PATH was, which is what we should have used back then)

Quoted 4 lines

That was added later in 3f824e91c84 (t/Makefile:
introduce TEST_SHELL_PATH, 2017-12-08). We will always have that available in perf-lib.sh since test-lib.sh will load it before this code is executed.

yes that's a good thing to point out

Care to redo the patch in a final form, then?

Thanks.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

 t/perf/perf-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/perf/perf-lib.sh +1 -1
index 780a7402d5..407252bac7 100644
@@ -161,7 +161,7 @@ test_run_perf_ () {
 	test_cleanup=:
 	test_export_="test_cleanup"
 	export test_cleanup test_export_
-	"$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+	"$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
 	test_export_="$test_export_ $*"
#4 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 7 lines · Johannes Altmanninger
Quoted 4 lines · Ævar Arnfjörð Bjarmason

That was added later in 3f824e91c84 (t/Makefile:
introduce TEST_SHELL_PATH, 2017-12-08). We will always have that available in perf-lib.sh since test-lib.sh will load it before this code is executed.

yes that's a good thing to point out

Care to redo the patch in a final form, then?

Of course. I should have acked that earlier, sorry. I waited until I could send my updated version but didn't find a quiet moment until today. Anyway, sending the updated patch now.

#5 lore raw

PATCH v2 1/1 t/perf: do not run tests in user's $SHELL

In reply to Junio C Hamano

The environment variable $SHELL is usually set to the user's interactive shell. Our build and test scripts never use $SHELL because there are no guarantees about its input language. Instead, we use /bin/sh which should be a POSIX shell.

For systems with a broken /bin/sh, we allow to override that path via SHELL_PATH. To run tests in yet another shell we allow to override SHELL_PATH with TEST_SHELL_PATH.

Perf tests run in $SHELL via a wrapper defined in t/perf/perf-lib.sh, so they break with e.g. SHELL=python. Use TEST_SHELL_PATH like in other tests. TEST_SHELL_PATH is always defined because t/perf/perf-lib.sh includes t/test-lib.sh, which includes GIT-BUILD-OPTIONS.

---
 t/perf/perf-lib.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I extended the commit message because in hindsight it was overly terse (judging from both re-reading it and from review comments).

We could add more Acked-bys but one seems enough here.

range-diff to the first version:

@@ Commit message
t/perf: do not run tests in user's $SHELL

The environment variable $SHELL is usually set to the user's
- interactive shell. We never use that shell for build and test scripts
- because it might not be a POSIX shell.
+ interactive shell. Our build and test scripts never use $SHELL because
+ there are no guarantees about its input language. Instead, we use
+ /bin/sh which should be a POSIX shell.

- Perf tests are run inside $SHELL via a wrapper defined in
- t/perf/perf-lib.sh. Use $TEST_SHELL_PATH like elsewhere.
+ For systems with a broken /bin/sh, we allow to override that path via
+ SHELL_PATH. To run tests in yet another shell we allow to override
+ SHELL_PATH with TEST_SHELL_PATH.
+
+ Perf tests run in $SHELL via a wrapper defined in t/perf/perf-lib.sh,
+ so they break with e.g. SHELL=python. Use TEST_SHELL_PATH like
+ in other tests. TEST_SHELL_PATH is always defined because
+ t/perf/perf-lib.sh includes t/test-lib.sh, which includes
+ GIT-BUILD-OPTIONS.
+
+ Acked-by: Jeff King <[email protected]>

t/perf/perf-lib.sh +1 -1
index 780a7402d5..407252bac7 100644
@@ -161,7 +161,7 @@ test_run_perf_ () {
 	test_cleanup=:
 	test_export_="test_cleanup"
 	export test_cleanup test_export_
-	"$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+	"$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
 	test_export_="$test_export_ $*"
Signature · 1 line
2.34.1