summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClay Baenziger <cwb@clayb.net>2019-08-03 05:58:18 -0400
committerCraig Small <csmall@dropbear.xyz>2019-09-21 17:00:53 +1000
commite516cf4a1809a4f9e5dfb6d2b8a396e0ccbdef67 (patch)
tree766c431f24a3195f63337139358c000013e9d537
parent61b627d53c9f025b8718b0f335ea38fa49358d9b (diff)
downloadprocps-ng-e516cf4a1809a4f9e5dfb6d2b8a396e0ccbdef67.tar.gz
testsuite: pgrep: Provide test for matching a more than 4k command line; beware as TCL does not seem to match on strings >4k
-rw-r--r--testsuite/config/unix.exp17
-rw-r--r--testsuite/pgrep.test/pgrep.exp8
2 files changed, 18 insertions, 7 deletions
diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp
index bbee233..61a329e 100644
--- a/testsuite/config/unix.exp
+++ b/testsuite/config/unix.exp
@@ -118,7 +118,7 @@ proc expect_table_dsc { test match_header match_item } {
}
proc make_testproc { } {
- global testproc_path testproc_comm testproc1_pid testproc2_pid topdir
+ global testproc_path testproc_comm testproc_arg_str testproc1_pid testproc2_pid topdir
set testproc_realpath "${topdir}/lib/test_process"
set testproc_comm "spcorp"
@@ -133,8 +133,19 @@ proc make_testproc { } {
eof { perror "test proc does not link to test process" }
}
-
- set testproc1_pid [ exec $testproc_path & ]
+ # make a process with the argument set to a fraction of ARG_MAX length
+ # but small enough we do not run TCL out of memory for regular expressions
+ # nor do we get argument list too long (104857 was found to work on Ubuntu 18.04)
+ set max_arg_len [ expr min([ exec /usr/bin/getconf ARG_MAX ], 104857) ]
+ # ensure we have enough slack to launch the test prog and pgrep
+ set reserved_space [expr max([ string length $testproc_path ], [ string length $topdir ] + 10)]
+ set testproc_arg_str "a"
+ set i $reserved_space
+ while {$i<$max_arg_len} {
+ incr i
+ append testproc_arg_str "a"
+ }
+ set testproc1_pid [ exec $testproc_path $testproc_arg_str & ]
set testproc2_pid [ exec $testproc_path & ]
}
diff --git a/testsuite/pgrep.test/pgrep.exp b/testsuite/pgrep.test/pgrep.exp
index 66dd4c7..3a3e1e1 100644
--- a/testsuite/pgrep.test/pgrep.exp
+++ b/testsuite/pgrep.test/pgrep.exp
@@ -34,9 +34,9 @@ set test "pgrep with : delimiter"
spawn $pgrep -d : $testproc_comm
expect_pass "$test" "^${testproc1_pid}:${testproc2_pid}\\s*$"
-# FIXME - Need to test against -f flag
set test "pgrep match against full process name"
-untested $test
+spawn $pgrep -f "$testproc_path\\s+$testproc_arg_str"
+expect_pass "$test" "^$testproc1_pid\\s*$"
set test "pgrep with matching gid"
spawn $pgrep -G $gid $testproc_comm
@@ -51,8 +51,8 @@ spawn $pgrep -l $testproc_comm
expect_pass "$test" "^$testproc1_pid\\s+$testproc_comm\\s+$testproc2_pid\\s+$testproc_comm\\s*$"
set test "pgrep with full command line"
-spawn $pgrep -a $testproc_comm
-expect_pass "$test" "^$testproc1_pid\\s+$testproc_path\\s+$testproc2_pid\\s+$testproc_path\\s*$"
+spawn $pgrep -af "$testproc_path$"
+expect_pass "$test" "^$testproc2_pid\\s+$testproc_path\\s*$"
set test "pgrep find newest test pid"
spawn $pgrep -n $testproc_comm