user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] Makefile: add `check-debris' target
Date: Sat, 16 Sep 2023 03:21:21 +0000	[thread overview]
Message-ID: <20230916032121.2204877-1-e@80x24.org> (raw)

This non-parallelized target is useful for noticing core dumps
and preventing them from being clobbered as we run the test
suite.  It will also notice leftover temporary files and
directories.

This make target was used on OpenBSD 7.3 to develop at least two
recent fixes:

e281363ba937 (lei: ensure we run DESTROY|END at daemon exit w/ kqueue)
759885e60e59 (lei: ensure --stdin sets %ENV and $current_lei)

I considered using a per-test TMPDIR for this to enable
parallelization, but on-filesystem UNIX sockets won't work
with excessively long path names.
---
 MANIFEST                      |  1 +
 Makefile.PL                   |  6 ++++--
 lib/PublicInbox/TestCommon.pm | 29 ++++++++++++++++++++++++++++-
 t/lei-externals.t             |  2 ++
 xt/check-debris.t             | 30 ++++++++++++++++++++++++++++++
 5 files changed, 65 insertions(+), 3 deletions(-)
 create mode 100644 xt/check-debris.t

diff --git a/MANIFEST b/MANIFEST
index 21f718ec..2fe5dd17 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -620,6 +620,7 @@ t/x-unknown-alpine.eml
 t/xap_helper.t
 t/xcpdb-reshard.t
 version-gen.perl
+xt/check-debris.t
 xt/cmp-msgstr.t
 xt/create-many-inboxes.t
 xt/eml_check_limits.t
diff --git a/Makefile.PL b/Makefile.PL
index a04a3b75..5b7914dc 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -235,12 +235,14 @@ check-each :: pure_all
 	\$(EATMYDATA) \$(PROVE) --state=save -bvw -j\$(N)
 	-@\$(check_manifest)
 
-# lightly-tested way to run tests, relies "--state=save" in check-each
-# for best performance
+# this relies "--state=save" in check-each for best performance
 check-run :: pure_all check-man
 	\$(EATMYDATA) \$(PROVE) -bvw t/run.perl :: -j\$(N)
 	-@\$(check_manifest)
 
+check-debris :: pure_all
+	PERL5LIB="\$\$PWD"/blib/lib \$(PROVE) -bvw xt/\$@.t
+
 check :: check-each
 
 lib/PublicInbox/UserContent.pm :: contrib/css/216dark.css
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 4c819a4f..ae67a0ae 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -11,6 +11,7 @@ use POSIX qw(dup2);
 use IO::Socket::INET;
 use File::Spec;
 use Scalar::Util qw(isvstring);
+use Carp ();
 our @EXPORT;
 my $lei_loud = $ENV{TEST_LEI_ERR_LOUD};
 my $tail_cmd = $ENV{TAIL};
@@ -25,7 +26,7 @@ BEGIN {
 		create_coderepo no_scm_rights
 		tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
 		test_httpd xbail require_cmd is_xdeeply tail_f
-		ignore_inline_c_missing no_pollerfd);
+		ignore_inline_c_missing no_pollerfd no_coredump);
 	require Test::More;
 	my @methods = grep(!/\W/, @Test::More::EXPORT);
 	eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -298,8 +299,31 @@ sub _run_sub ($$$) {
 	}
 }
 
+sub no_coredump (@) {
+	my @dirs = @_;
+	my $cwdfh;
+	if (@dirs) { opendir($cwdfh, '.') or die "opendir(.): $!" }
+	my @found;
+	for (@dirs, '.') {
+		chdir $_;
+		my @cores = glob('core.* *.core');
+		push @cores, 'core' if -d 'core';
+		push(@found, "@cores found in $_") if @cores;
+		chdir $cwdfh if $cwdfh;
+	}
+	return if !@found; # keep it quiet.
+	is(scalar(@found), 0, 'no core dumps found');
+	diag(join("\n", @found) . Carp::longmess());
+	if (-t STDIN) {
+		diag 'press ENTER to continue, (q) to quit';
+		chomp(my $line = <STDIN>);
+		xbail 'user quit' if $line =~ /\Aq/;
+	}
+}
+
 sub run_script ($;$$) {
 	my ($cmd, $env, $opt) = @_;
+	no_coredump($opt->{-C} ? ($opt->{-C}) : ());
 	my ($key, @argv) = @$cmd;
 	my $run_mode = $ENV{TEST_RUN_MODE} // $opt->{run_mode} // 1;
 	my $sub = $run_mode == 0 ? undef : key2sub($key);
@@ -383,6 +407,7 @@ sub run_script ($;$$) {
 		local $/;
 		$$redir = <$fh>;
 	}
+	no_coredump($opt->{-C} ? ($opt->{-C}) : ());
 	$? == 0;
 }
 
@@ -656,6 +681,7 @@ SKIP: {
 			File::Path::rmtree([glob("$home/*")]);
 			File::Path::rmtree("$home/.config");
 		} else {
+			no_coredump $tmpdir;
 			lei_ok(qw(daemon-pid), \"daemon-pid after $t");
 			chomp($daemon_pid = $lei_out);
 			if (!$daemon_pid) {
@@ -672,6 +698,7 @@ SKIP: {
 			tick;
 		}
 		ok(!kill(0, $daemon_pid), "$t daemon stopped");
+		no_coredump $tmpdir;
 		my $f = "$daemon_xrd/lei/errors.log";
 		open my $fh, '<', $f or BAIL_OUT "$f: $!";
 		my @l = <$fh>;
diff --git a/t/lei-externals.t b/t/lei-externals.t
index aeaf8ee4..4f2dd6ba 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -48,6 +48,7 @@ SKIP: {
 		$tp->join;
 		ok(WIFSIGNALED($?), "signaled @$out");
 		is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
+		no_coredump;
 		seek($err, 0, 0);
 		my @err = <$err>;
 		is_deeply(\@err, [], "no errors @$out");
@@ -66,6 +67,7 @@ SKIP: {
 			tick();
 		}
 		ok(!$alive, 'daemon-kill worked');
+		no_coredump;
 	}
 } # /SKIP
 }; # /sub
diff --git a/xt/check-debris.t b/xt/check-debris.t
new file mode 100644
index 00000000..0bb5091d
--- /dev/null
+++ b/xt/check-debris.t
@@ -0,0 +1,30 @@
+#!perl -w
+use v5.12;
+use autodie qw(open);
+use PublicInbox::TestCommon;
+use File::Spec;
+my $tmpdir = File::Spec->tmpdir;
+
+diag "note: writes to `$tmpdir' by others results in false-positives";
+
+my %cur = map { $_ => 1 } glob("$tmpdir/*");
+for my $t (@ARGV ? @ARGV : glob('t/*.t')) {
+	open my $fh, '-|', $^X, '-w', $t;
+	my @out;
+	while (<$fh>) {
+		chomp;
+		push @out, $_;
+		next if /^ok / || /\A[0-9]+\.\.[0-9]+\z/;
+		diag $_;
+	}
+	ok(close($fh), $t) or diag(explain(\@out));
+
+	no_coredump($tmpdir);
+
+	my @remain = grep { !$cur{$_}++ } glob("$tmpdir/*");
+	next if !@remain;
+	is_deeply(\@remain, [], "$t has no leftovers") or
+		diag "$t added: ",explain(\@remain);
+}
+
+done_testing;

                 reply	other threads:[~2023-09-16  3:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230916032121.2204877-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).