grep: add tests for --threads=N and grep.threads
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 20 May 2017 21:42:12 +0000 (21:42 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 May 2017 23:25:37 +0000 (08:25 +0900)
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
89f09dd34e ("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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7810-grep.sh
index daa906b9b0eebd3824141dedcc39c38b7498632f..561709ef6aa1b8394317b3a9e722f5bddc391498 100755 (executable)
@@ -775,6 +775,22 @@ test_expect_success 'grep -W with userdiff' '
        test_cmp expected actual
 '
 
+for threads in $(test_seq 0 10)
+do
+       test_expect_success "grep --threads=$threads & -c grep.threads=$threads" "
+               git grep --threads=$threads . >actual.$threads &&
+               if test $threads -ge 1
+               then
+                       test_cmp actual.\$(($threads - 1)) actual.$threads
+               fi &&
+               git -c grep.threads=$threads grep . >actual.$threads &&
+               if test $threads -ge 1
+               then
+                       test_cmp actual.\$(($threads - 1)) actual.$threads
+               fi
+       "
+done
+
 test_expect_success 'grep from a subdirectory to search wider area (1)' '
        mkdir -p s &&
        (