[nginx-tests] Tests: explicit Valgrind support.
Maxim Dounin
mdounin at mdounin.ru
Fri May 31 03:25:38 UTC 2024
details: http://freenginx.org/hg/nginx-tests/rev/fb25cbe9d4ec
branches:
changeset: 1982:fb25cbe9d4ec
user: Maxim Dounin <mdounin at mdounin.ru>
date: Fri May 31 06:23:00 2024 +0300
description:
Tests: explicit Valgrind support.
Valgrind logging is done to a separate file, as it is not able to
follow stderr redirection within nginx or append to a file without
corrupting it. Further, Valgrind logging seems to interfere with
error suppression in tests, and catches various startup errors and
warnings, so the log is additionally filtered.
Since startup under Valgrind can be really slow, timeout in waitforfile()
was changed to 10 seconds.
Prodded by Robert Mueller.
diffstat:
README | 4 ++++
lib/Test/Nginx.pm | 18 +++++++++++++++---
2 files changed, 19 insertions(+), 3 deletions(-)
diffs (63 lines):
diff --git a/README b/README
--- a/README
+++ b/README
@@ -40,6 +40,10 @@ TEST_NGINX_UNSAFE
Run unsafe tests.
+TEST_NGINX_VALGRIND
+
+ Run nginx under Valgrind during tests.
+
TEST_NGINX_GLOBALS
Sets additional directives in main context.
diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm
--- a/lib/Test/Nginx.pm
+++ b/lib/Test/Nginx.pm
@@ -87,6 +87,12 @@ sub DESTROY {
Test::More::is($errors, '', 'no sanitizer errors');
}
+ if (Test::More->builder->expected_tests && $ENV{TEST_NGINX_VALGRIND}) {
+ my $errors = $self->read_file('valgrind.log');
+ $errors = join "\n", $errors =~ /^==\d+== .+/gm;
+ Test::More::is($errors, '', 'no valgrind errors');
+ }
+
if ($ENV{TEST_NGINX_CATLOG}) {
system("cat $self->{_testdir}/error.log");
}
@@ -365,7 +371,10 @@ sub try_run($$) {
sub plan($) {
my ($self, $plan) = @_;
- Test::More::plan(tests => $plan + 2);
+ $plan += 2;
+ $plan += 1 if $ENV{TEST_NGINX_VALGRIND};
+
+ Test::More::plan(tests => $plan);
return $self;
}
@@ -395,7 +404,10 @@ sub run(;$) {
my @globals = $self->{_test_globals} ?
() : ('-g', "pid $testdir/nginx.pid; "
. "error_log $testdir/error.log debug;");
- exec($NGINX, '-p', "$testdir/", '-c', 'nginx.conf',
+ my @valgrind = (not $ENV{TEST_NGINX_VALGRIND}) ?
+ () : ('valgrind', '-q',
+ "--log-file=$testdir/valgrind.log");
+ exec(@valgrind, $NGINX, '-p', "$testdir/", '-c', 'nginx.conf',
'-e', 'error.log', @globals)
or die "Unable to exec(): $!\n";
}
@@ -481,7 +493,7 @@ sub waitforfile($;$) {
# wait for file to appear
# or specified process to exit
- for (1 .. 50) {
+ for (1 .. 100) {
return 1 if -e $file;
return 0 if $exited;
$exited = waitpid($pid, WNOHANG) != 0 if $pid;
More information about the nginx-devel
mailing list