[LTP] [PATCH v2 12/31] testcases: sysfs: Add sys_ata01
Cyril Hrubis <[email protected]>
| Newsgroups | it.linux.lists.ltp |
|---|---|
| Message-ID | <[email protected]> |
A test for /sys/class/ata_device/*/* files. Signed-off-by: Cyril Hrubis <[email protected]> --- runtest/sysfs | 1 + testcases/kernel/sysfs/class/Makefile | 7 ++ .../kernel/sysfs/class/ata_device/.gitignore | 1 + .../kernel/sysfs/class/ata_device/Makefile | 7 ++ .../kernel/sysfs/class/ata_device/sys_ata01.c | 96 +++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 testcases/kernel/sysfs/class/Makefile create mode 100644 testcases/kernel/sysfs/class/ata_device/.gitignore create mode 100644 testcases/kernel/sysfs/class/ata_device/Makefile create mode 100644 testcases/kernel/sysfs/class/ata_device/sys_ata01.c diff --git a/runtest/sysfs b/runtest/sysfs index 3015c03f5..b5e644237 100644 --- a/runtest/sysfs +++ b/runtest/sysfs @@ -8,3 +8,4 @@ sys_cpu_vulnerabilities01 sys_cpu_vulnerabilities01 sys_cpu_smt01 sys_cpu_smt01 sys_cpu_cache01 sys_cpu_cache01 sys_clockevents01 sys_clockevents01 +sys_ata01 sys_ata01 diff --git a/testcases/kernel/sysfs/class/Makefile b/testcases/kernel/sysfs/class/Makefile new file mode 100644 index 000000000..5c8e7a249 --- /dev/null +++ b/testcases/kernel/sysfs/class/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2026 Cyril Hrubis <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk diff --git a/testcases/kernel/sysfs/class/ata_device/.gitignore b/testcases/kernel/sysfs/class/ata_device/.gitignore new file mode 100644 index 000000000..b5b1f8f4a --- /dev/null +++ b/testcases/kernel/sysfs/class/ata_device/.gitignore @@ -0,0 +1 @@ +/sys_ata01 diff --git a/testcases/kernel/sysfs/class/ata_device/Makefile b/testcases/kernel/sysfs/class/ata_device/Makefile new file mode 100644 index 000000000..034038061 --- /dev/null +++ b/testcases/kernel/sysfs/class/ata_device/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2026 Cyril Hrubis <[email protected]> + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/sysfs/class/ata_device/sys_ata01.c b/testcases/kernel/sysfs/class/ata_device/sys_ata01.c new file mode 100644 index 000000000..22e02a2c0 --- /dev/null +++ b/testcases/kernel/sysfs/class/ata_device/sys_ata01.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Cyril Hrubis <[email protected]> + */ + +/*\ + * Sanity checks for the ATA device attributes exported under + * /sys/class/ata_device/<dev>/. + * + * For every ATA device the test verifies that: + * + * - class is one of the known libata device classes (ata, atapi, pmp, semb, + * unknown) + * - dma_mode, pio_mode and xfer_mode, when non-empty, start with the "XFER_" + * prefix used by all libata transfer mode names + * - spdn_cnt (speed-down count) is non-negative + * + * dma_mode is legitimately empty for devices that only support PIO, so it is + * only checked when present. + * + * The test skips with TCONF when no ATA device is present. + */ + +#include <string.h> +#include <dirent.h> +#include "tst_test.h" +#include "tst_sysfs_assert.h" + +#define ATA_DEVICE "/sys/class/ata_device" + +static const char *const class_allowed[] = { + "ata", "atapi", "pmp", "semb", "unknown", NULL +}; + +static void check_mode(const char *dev, const char *attr) +{ + char mode[32]; + + if (!TST_SYSFS_READ_STR(mode, sizeof(mode), + ATA_DEVICE "/%s/%s", dev, attr)) { + tst_res(TCONF, "%s/%s does not exist", dev, attr); + return; + } + + if (mode[0] == '\0') { + tst_res(TCONF, "%s/%s is empty", dev, attr); + return; + } + + if (!strncmp(mode, "XFER_", 5)) + tst_res(TPASS, "%s/%s = '%s'", dev, attr, mode); + else + tst_res(TFAIL, "%s/%s = '%s' has no XFER_ prefix", + dev, attr, mode); +} + +static void check_device(const char *dev) +{ + tst_res(TINFO, "Checking ata device '%s'", dev); + + TST_SYSFS_ASSERT_ONEOF(class_allowed, ATA_DEVICE "/%s/class", dev); + check_mode(dev, "dma_mode"); + check_mode(dev, "pio_mode"); + check_mode(dev, "xfer_mode"); + + TST_SYSFS_ASSERT_RANGELL(0, LONG_MAX, ATA_DEVICE "/%s/spdn_cnt", dev); +} + +static void do_test(void) +{ + DIR *d; + struct dirent *ent; + int found = 0; + + if (!tst_sysfs_exists(ATA_DEVICE)) + tst_brk(TCONF, ATA_DEVICE ": not present"); + + d = SAFE_OPENDIR(ATA_DEVICE); + + while ((ent = SAFE_READDIR(d))) { + if (ent->d_name[0] == '.') + continue; + + found = 1; + check_device(ent->d_name); + } + + SAFE_CLOSEDIR(d); + + if (!found) + tst_res(TCONF, "No ATA device found"); +} + +static struct tst_test test = { + .test_all = do_test, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp