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

Petr Vorel pvorel@suse.cz
Tue Feb 25 12:44:17 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.
Variant counting starts with 0, latest value is test_variants - 1
(C array like counting).
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:1904: TINFO: WARNING: testing only variant 0 of 3
    tst_test.c:1937: TINFO: ===== Testing tst_variant: 0 =====
    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_getrQ7dbE/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=0x7fdf76897ee9 size=279 : EBADF (9)
    getdents02.c:77: TPASS: fd=3 dirp=0x557a810581e8 size=1 : EINVAL (22)
    getdents02.c:77: TPASS: fd=4 dirp=0x7fdf76897ee9 size=279 : ENOTDIR (20)
    getdents02.c:77: TPASS: fd=5 dirp=0x7fdf76897ee9 size=279 : ENOENT (2)
    getdents02.c:77: TPASS: fd=3 dirp=0x7fdf76896000 size=279 : EFAULT (14)

    # LTP_SINGLE_VARIANT=2 LTP_SINGLE_FS_TYPE=ext4 ./getdents02
    ...
    tst_test.c:1904: TINFO: WARNING: testing only variant 2 of 3
    tst_test.c:1937: TINFO: ===== Testing tst_variant: 2 =====
    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_gethBuDHc/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:1904: TINFO: WARNING: testing only variant 3 of 3
    tst_test.c:1937: TINFO: ===== Testing tst_variant: 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_getnfis4f/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=0x7f1b029b2ee8 size=280 : EBADF (9)
    getdents02.c:77: TPASS: fd=3 dirp=0x55fbc55661e8 size=1 : EINVAL (22)
    getdents02.c:77: TPASS: fd=4 dirp=0x7f1b029b2ee8 size=280 : ENOTDIR (20)
    getdents02.c:77: TPASS: fd=5 dirp=0x7f1b029b2ee8 size=280 : ENOENT (2)
    getdents02.c:77: TPASS: fd=3 dirp=0x7f1b029b1000 size=280 : EFAULT (14)

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v1->v2:
* Add a function that would set two integer variables, first_variant and
last variant (Cyril). NOTE: I'm not sure if the implementation is really
better than the previous one.
* Add documentation into setup_tests.rst.

 doc/users/setup_tests.rst |  3 +++
 lib/tst_test.c            | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/doc/users/setup_tests.rst b/doc/users/setup_tests.rst
index 2766ed719c..78e1098917 100644
--- a/doc/users/setup_tests.rst
+++ b/doc/users/setup_tests.rst
@@ -46,6 +46,9 @@ users.
      - Testing only - specifies filesystem instead all supported
        (for tests with ``.all_filesystems``).
 
+   * - LTP_SINGLE_VARIANT
+     - Testing only - specifies tst_variant to be run.
+
    * - LTP_DEV_FS_TYPE
      - Filesystem used for testing (default: ``ext2``).
 
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 3823ea109e..ddeacfb228 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");
@@ -1882,10 +1883,33 @@ static int run_tcases_per_fs(void)
 
 unsigned int tst_variant;
 
+static void setup_variants(unsigned int *first_variant, unsigned int *last_variant)
+{
+	const char *only_variant;
+	*first_variant = 0;
+	*last_variant = 1;
+
+	if (!tst_test->test_variants)
+		return;
+
+	*last_variant = tst_test->test_variants;
+
+	only_variant = getenv("LTP_SINGLE_VARIANT");
+	if (!only_variant || only_variant[0] == '\0')
+		return;
+
+	*first_variant = MIN(SAFE_STRTOL((char *)only_variant, 0, INT_MAX),
+					  *last_variant - 1);
+
+	tst_res(TINFO, "WARNING: testing only variant %d of %d",
+			*first_variant, *last_variant - 1);
+	*last_variant = *first_variant + 1;
+}
+
 void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 {
 	int ret = 0;
-	unsigned int test_variants = 1;
+	unsigned int first_variant, last_variant;
 	struct utsname uval;
 
 	lib_pid = getpid();
@@ -1899,7 +1923,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 +1931,10 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	set_overall_timeout();
 
-	if (tst_test->test_variants)
-		test_variants = tst_test->test_variants;
+	setup_variants(&first_variant, &last_variant);
 
-	for (tst_variant = 0; tst_variant < test_variants; tst_variant++) {
+	for (tst_variant = first_variant; tst_variant < last_variant; tst_variant++) {
+		tst_res(TINFO, "===== Testing tst_variant: %d =====", 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