All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: oliver.yang@linux.alibaba.com, Vansh Choudhary <ch@vnsh.in>,
	Gao Xiang <xiang@kernel.org>
Subject: [PATCH v2] erofs-utils: tests: add test for negative GNU tar mtimes
Date: Wed,  8 Apr 2026 11:33:16 +0800	[thread overview]
Message-ID: <20260408033316.273626-1-hsiangkao@linux.alibaba.com> (raw)
In-Reply-To: <20260407181313.89203-1-ch@vnsh.in>

From: Vansh Choudhary <ch@vnsh.in>

Add a regression test for negative GNU tar mtimes.

It creates a tarball with a file whose mtime is -1, checks that the
mtime field is encoded in GNU base-256 format, and verifies that the
timestamp is preserved after building and extracting the image.

Signed-off-by: Vansh Choudhary <ch@vnsh.in>
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
v2:
 - use dump.erofs instead of fsck.erofs;
 - switch to MIT license.

 tests/Makefile.am   |  3 +++
 tests/erofs/030     | 55 +++++++++++++++++++++++++++++++++++++++++++++
 tests/erofs/030.out |  2 ++
 3 files changed, 60 insertions(+)
 create mode 100755 tests/erofs/030
 create mode 100644 tests/erofs/030.out

diff --git a/tests/Makefile.am b/tests/Makefile.am
index d8ac067805e8..28edc0d744d1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -126,6 +126,9 @@ TESTS += erofs/028
 # 029 - test FUSE daemon and kernel error handling on corrupted inodes
 TESTS += erofs/029
 
+# 030 - regression test for negative GNU tar mtimes
+TESTS += erofs/030
+
 # NEW TEST CASE HERE
 # TESTS += erofs/999
 
diff --git a/tests/erofs/030 b/tests/erofs/030
new file mode 100755
index 000000000000..72765cb19aee
--- /dev/null
+++ b/tests/erofs/030
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: MIT
+#
+# 030 - regression test for negative GNU tar mtimes
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$(echo $0 | awk '{print $((NF-1))"/"$NF}' FS="/")
+
+# get standard environment, filters and checks
+. "${srcdir}/common/rc"
+
+cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+}
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+echo "QA output created by $seq"
+
+if [ -z "$SCRATCH_DEV" ]; then
+	SCRATCH_DEV=$tmp/erofs_$seq.img
+	rm -f $SCRATCH_DEV
+fi
+
+localdir="$tmp/$seq"
+rm -rf $localdir
+mkdir -p $localdir/src
+
+touch -d @-1 $localdir/src/testfile >> $seqres.full 2>&1 || \
+	_notrun "touch -d @-1 is not supported"
+tar --format=gnu -C $localdir/src -cf $localdir/foo.tar testfile >> $seqres.full 2>&1 || \
+	_fail "failed to create tarball"
+
+mtime=$(od -An -t x1 -j 136 -N 12 $localdir/foo.tar | tr -d '[:space:]')
+[ "$mtime" = "ffffffffffffffffffffffff" ] || \
+	_notrun "tar did not encode a negative GNU mtime"
+
+$MKFS_EROFS_PROG --tar=f $SCRATCH_DEV $localdir/foo.tar \
+	>> $seqres.full 2>&1 || _fail "failed to mkfs tarball"
+
+output=$($DUMP_EROFS_PROG --path=/testfile $SCRATCH_DEV 2>&1)
+[ $? -eq 0 ] || _fail "failed to dump testfile"
+echo "$output" >> $seqres.full
+
+mtime=$(grep '^Timestamp:' <<< $output | sed 's/^.*: //')
+[ "x$mtime" = "x1970-01-01 07:59:59.000000000" ] || \
+	_fail "negative GNU mtime was not preserved"
+
+echo Silence is golden
+status=0
+exit 0
diff --git a/tests/erofs/030.out b/tests/erofs/030.out
new file mode 100644
index 000000000000..06a1c8fe02bb
--- /dev/null
+++ b/tests/erofs/030.out
@@ -0,0 +1,2 @@
+QA output created by 030
+Silence is golden
-- 
2.43.5



  reply	other threads:[~2026-04-08  3:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-05 10:18 [PATCH] erofs-utils: tar: fix negative GNU base-256 number parsing Vansh Choudhary
2026-04-07  9:35 ` Gao Xiang
2026-04-07 18:13   ` [PATCH] erofs-utils: tests: add test for negative GNU tar mtimes Vansh Choudhary
2026-04-08  3:33     ` Gao Xiang [this message]
2026-04-08  3:36 ` [PATCH] erofs-utils: tar: fix negative GNU base-256 number parsing Gao Xiang
2026-04-08  4:41   ` Vansh Choudhary

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

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

  git send-email \
    --in-reply-to=20260408033316.273626-1-hsiangkao@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=ch@vnsh.in \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=oliver.yang@linux.alibaba.com \
    --cc=xiang@kernel.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.