From f5fbbdbef8ea445d8ca1561232315c823fae9b37 Mon Sep 17 00:00:00 2001 From: Clay Baenziger Date: Sat, 3 Aug 2019 05:58:18 -0400 Subject: [PATCH] testsuite: pgrep: Provide test for matching a more than 4k command line; beware as TCL does not seem to match on strings >4k --- testsuite/config/unix.exp | 17 ++++++++++++++--- testsuite/pgrep.test/pgrep.exp | 8 ++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp index bbee2333..61a329ed 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 9f935e60..c7fae1a4 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