[LTP] [PATCH 1/2] tst_test: Add $LTP_SINGLE_ITERATION to limit variant

Petr Vorel pvorel@suse.cz
Mon Feb 24 11:00:14 CET 2025


Allow to test only single struct tst_test->test_variants.
This is a similar feature to $LTP_SINGLE_FS_TYPE.

Value is ignored when test does not specify test_variants.
When value is higher than test_variants value lastest variant is used.

	# LTP_SINGLE_VARIANT=0 LTP_SINGLE_FS_TYPE=ext4 ./getdents02
	..
	tst_test.c:1918: TINFO: WARNING: testing only variant 0 of 3
	tst_supported_fs_types.c:161: TINFO: WARNING: testing only ext4
	tst_supported_fs_types.c:97: TINFO: Kernel supports ext4
	tst_supported_fs_types.c:62: TINFO: mkfs.ext4 does exist
	tst_test.c:1834: TINFO: === Testing on ext4 ===
	tst_test.c:1171: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
	mke2fs 1.47.2 (1-Jan-2025)
	tst_test.c:1183: TINFO: Mounting /dev/loop0 to /tmp/LTP_getx2HrGH/mntpoint fstyp=ext4 flags=0
	getdents.h:148: TINFO: Testing the SYS_getdents syscall
	tst_buffers.c:57: TINFO: Test is using guarded buffers
	getdents02.c:77: TPASS: fd=-5 dirp=0x7f0587803ee9 size=279 : EBADF (9)
	getdents02.c:77: TPASS: fd=3 dirp=0x5641617a31e8 size=1 : EINVAL (22)
	getdents02.c:77: TPASS: fd=4 dirp=0x7f0587803ee9 size=279 : ENOTDIR (20)
	getdents02.c:77: TPASS: fd=5 dirp=0x7f0587803ee9 size=279 : ENOENT (2)
	getdents02.c:77: TPASS: fd=3 dirp=0x7f0587802000 size=279 : EFAULT (14)

	# LTP_SINGLE_VARIANT=2 LTP_SINGLE_FS_TYPE=ext4 ./getdents02
	...
	tst_test.c:1918: TINFO: WARNING: testing only variant 2 of 3
	tst_supported_fs_types.c:161: TINFO: WARNING: testing only ext4
	tst_supported_fs_types.c:97: TINFO: Kernel supports ext4
	tst_supported_fs_types.c:62: TINFO: mkfs.ext4 does exist
	tst_test.c:1834: TINFO: === Testing on ext4 ===
	tst_test.c:1171: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
	mke2fs 1.47.2 (1-Jan-2025)
	tst_test.c:1183: TINFO: Mounting /dev/loop0 to /tmp/LTP_getWtBnGE/mntpoint fstyp=ext4 flags=0
	getdents.h:157: TCONF: libc getdents() is not implemented

	# LTP_SINGLE_VARIANT=99 LTP_SINGLE_FS_TYPE=ext4 ./getdents02 # higher value is max value
	tst_test.c:1918: TINFO: WARNING: testing only variant 3 of 3
	tst_supported_fs_types.c:161: TINFO: WARNING: testing only ext4
	tst_supported_fs_types.c:97: TINFO: Kernel supports ext4
	tst_supported_fs_types.c:62: TINFO: mkfs.ext4 does exist
	tst_test.c:1834: TINFO: === Testing on ext4 ===
	tst_test.c:1171: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
	mke2fs 1.47.2 (1-Jan-2025)
	tst_test.c:1183: TINFO: Mounting /dev/loop0 to /tmp/LTP_get1fX70n/mntpoint fstyp=ext4 flags=0
	getdents.h:162: TINFO: Testing libc getdents64()
	tst_buffers.c:57: TINFO: Test is using guarded buffers
	getdents02.c:77: TPASS: fd=-5 dirp=0x7fcf140f3ee8 size=280 : EBADF (9)
	getdents02.c:77: TPASS: fd=3 dirp=0x55a76e4531e8 size=1 : EINVAL (22)
	getdents02.c:77: TPASS: fd=4 dirp=0x7fcf140f3ee8 size=280 : ENOTDIR (20)
	getdents02.c:77: TPASS: fd=5 dirp=0x7fcf140f3ee8 size=280 : ENOENT (2)
	getdents02.c:77: TPASS: fd=3 dirp=0x7fcf140f2000 size=280 : EFAULT (14)

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi all,

Andrea wanted to run only single variant.

Kind regards,
Petr

 lib/tst_test.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 3823ea109e..6edc310209 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -581,6 +581,7 @@ static void print_help(void)
 	fprintf(stderr, "LTP_DEV              Path to the block device to be used (for .needs_device)\n");
 	fprintf(stderr, "LTP_DEV_FS_TYPE      Filesystem used for testing (default: %s)\n", DEFAULT_FS_TYPE);
 	fprintf(stderr, "LTP_SINGLE_FS_TYPE   Testing only - specifies filesystem instead all supported (for .all_filesystems)\n");
+	fprintf(stderr, "LTP_SINGLE_VARIANT   Testing only - specifies tst_variant to be run\n");
 	fprintf(stderr, "LTP_TIMEOUT_MUL      Timeout multiplier (must be a number >=1)\n");
 	fprintf(stderr, "LTP_RUNTIME_MUL      Runtime multiplier (must be a number >=1)\n");
 	fprintf(stderr, "LTP_VIRT_OVERRIDE    Overrides virtual machine detection (values: \"\"|kvm|microsoft|xen|zvm)\n");
@@ -1887,6 +1888,7 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	int ret = 0;
 	unsigned int test_variants = 1;
 	struct utsname uval;
+	const char *only_variant;
 
 	lib_pid = getpid();
 	tst_test = self;
@@ -1899,7 +1901,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	tst_res(TINFO, "LTP version: "LTP_VERSION);
 
-
 	uname(&uval);
 	tst_res(TINFO, "Tested kernel: %s %s %s", uval.release, uval.version, uval.machine);
 
@@ -1908,10 +1909,20 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	set_overall_timeout();
 
-	if (tst_test->test_variants)
+	if (tst_test->test_variants) {
 		test_variants = tst_test->test_variants;
+		only_variant = getenv("LTP_SINGLE_VARIANT");
+		if (only_variant && only_variant[0] != '\0') {
+			tst_variant = MIN(SAFE_STRTOL((char *)only_variant, 0, INT_MAX),
+							  test_variants - 1);
+			tst_res(TINFO, "WARNING: testing only variant %d of %d",
+					tst_variant, test_variants - 1);
+			test_variants = tst_variant + 1;
+		}
+	}
+
+	for (; tst_variant < test_variants; tst_variant++) {
 
-	for (tst_variant = 0; tst_variant < test_variants; tst_variant++) {
 		if (tst_test->all_filesystems || count_fs_descs() > 1)
 			ret |= run_tcases_per_fs();
 		else
-- 
2.47.2



More information about the ltp mailing list