Skip to content

Commit c581365

Browse files
avargitster
authored andcommitted
grep: add tests for --threads=N and grep.threads
Add tests for --threads=N being supplied on the command-line, or when grep.threads=N being supplied in the configuration. When the threading support was made run-time configurable in commit 89f09dd ("grep: add --threads=<num> option and grep.threads configuration", 2015-12-15) no tests were added for it. In developing a change to the grep code I was able to make '--threads=1 <pat>` segfault, while the test suite still passed. This change fixes that blind spot in the tests. In addition to asserting that asking for N threads shouldn't segfault, test that the grep output given any N is the same. The choice to test only 1..10 as opposed to 1..8 or 1..16 or whatever is arbitrary. Testing 1..1024 works locally for me (but gets noticeably slower as more threads are spawned). Given the structure of the code there's no reason to test an arbitrary number of threads, only 0, 1 and >=2 are special modes of operation. A later patch introduces a PTHREADS test prerequisite which is true under NO_PTHREADS=UnfortunatelyYes, but even under NO_PTHREADS it's fine to test --threads=N, we'll just ignore it and not use threading. So these tests also make sense under that mode to assert that --threads=N without pthreads still returns expected results. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e01b4da commit c581365

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

t/t7810-grep.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,22 @@ test_expect_success 'grep -W with userdiff' '
775775
test_cmp expected actual
776776
'
777777

778+
for threads in $(test_seq 0 10)
779+
do
780+
test_expect_success "grep --threads=$threads & -c grep.threads=$threads" "
781+
git grep --threads=$threads . >actual.$threads &&
782+
if test $threads -ge 1
783+
then
784+
test_cmp actual.\$(($threads - 1)) actual.$threads
785+
fi &&
786+
git -c grep.threads=$threads grep . >actual.$threads &&
787+
if test $threads -ge 1
788+
then
789+
test_cmp actual.\$(($threads - 1)) actual.$threads
790+
fi
791+
"
792+
done
793+
778794
test_expect_success 'grep from a subdirectory to search wider area (1)' '
779795
mkdir -p s &&
780796
(

0 commit comments

Comments
 (0)