Mercurial > hg > nginx-tests
comparison lib/Test/Nginx.pm @ 1982:fb25cbe9d4ec default tip
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 31 May 2024 06:23:00 +0300 |
parents | 0e2b14c75232 |
children |
comparison
equal
deleted
inserted
replaced
1981:0e2b14c75232 | 1982:fb25cbe9d4ec |
---|---|
83 | 83 |
84 if (Test::More->builder->expected_tests) { | 84 if (Test::More->builder->expected_tests) { |
85 my $errors = $self->read_file('error.log'); | 85 my $errors = $self->read_file('error.log'); |
86 $errors = join "\n", $errors =~ /.+Sanitizer.+/gm; | 86 $errors = join "\n", $errors =~ /.+Sanitizer.+/gm; |
87 Test::More::is($errors, '', 'no sanitizer errors'); | 87 Test::More::is($errors, '', 'no sanitizer errors'); |
88 } | |
89 | |
90 if (Test::More->builder->expected_tests && $ENV{TEST_NGINX_VALGRIND}) { | |
91 my $errors = $self->read_file('valgrind.log'); | |
92 $errors = join "\n", $errors =~ /^==\d+== .+/gm; | |
93 Test::More::is($errors, '', 'no valgrind errors'); | |
88 } | 94 } |
89 | 95 |
90 if ($ENV{TEST_NGINX_CATLOG}) { | 96 if ($ENV{TEST_NGINX_CATLOG}) { |
91 system("cat $self->{_testdir}/error.log"); | 97 system("cat $self->{_testdir}/error.log"); |
92 } | 98 } |
363 } | 369 } |
364 | 370 |
365 sub plan($) { | 371 sub plan($) { |
366 my ($self, $plan) = @_; | 372 my ($self, $plan) = @_; |
367 | 373 |
368 Test::More::plan(tests => $plan + 2); | 374 $plan += 2; |
375 $plan += 1 if $ENV{TEST_NGINX_VALGRIND}; | |
376 | |
377 Test::More::plan(tests => $plan); | |
369 | 378 |
370 return $self; | 379 return $self; |
371 } | 380 } |
372 | 381 |
373 sub todo_alerts() { | 382 sub todo_alerts() { |
393 | 402 |
394 if ($pid == 0) { | 403 if ($pid == 0) { |
395 my @globals = $self->{_test_globals} ? | 404 my @globals = $self->{_test_globals} ? |
396 () : ('-g', "pid $testdir/nginx.pid; " | 405 () : ('-g', "pid $testdir/nginx.pid; " |
397 . "error_log $testdir/error.log debug;"); | 406 . "error_log $testdir/error.log debug;"); |
398 exec($NGINX, '-p', "$testdir/", '-c', 'nginx.conf', | 407 my @valgrind = (not $ENV{TEST_NGINX_VALGRIND}) ? |
408 () : ('valgrind', '-q', | |
409 "--log-file=$testdir/valgrind.log"); | |
410 exec(@valgrind, $NGINX, '-p', "$testdir/", '-c', 'nginx.conf', | |
399 '-e', 'error.log', @globals) | 411 '-e', 'error.log', @globals) |
400 or die "Unable to exec(): $!\n"; | 412 or die "Unable to exec(): $!\n"; |
401 } | 413 } |
402 | 414 |
403 # wait for nginx to start | 415 # wait for nginx to start |
479 my $exited; | 491 my $exited; |
480 | 492 |
481 # wait for file to appear | 493 # wait for file to appear |
482 # or specified process to exit | 494 # or specified process to exit |
483 | 495 |
484 for (1 .. 50) { | 496 for (1 .. 100) { |
485 return 1 if -e $file; | 497 return 1 if -e $file; |
486 return 0 if $exited; | 498 return 0 if $exited; |
487 $exited = waitpid($pid, WNOHANG) != 0 if $pid; | 499 $exited = waitpid($pid, WNOHANG) != 0 if $pid; |
488 select undef, undef, undef, 0.1; | 500 select undef, undef, undef, 0.1; |
489 } | 501 } |