From: "Ricardo B. Marliere via ltp" <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] block_dev: Convert to new API
Date: Mon, 21 Oct 2024 19:05:07 -0300 [thread overview]
Message-ID: <20241021-block_dev-v2-1-339a95c89fe0@suse.com> (raw)
Signed-off-by: Ricardo B. Marliere <rbm@suse.com>
---
v1->v2:
- Added ifdef for including genhd.h in older kernels
- Removed unused pointer
- Fixed `make check` linter warnings
- Link to v1: https://lore.kernel.org/r/20241018-block_dev-v1-1-f1f98dfebb6d@suse.com
v1:
- Tested against v6.11
---
.../block/block_dev_kernel/ltp_block_dev.c | 4 +-
.../block/block_dev_user/block_dev.c | 77 +++++++++-------------
2 files changed, 34 insertions(+), 47 deletions(-)
diff --git a/testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c b/testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c
index 17047c0d5ae3f6556f3fa4b0eb2a17a86e5f05a6..5ce145c9f87d1c8a13c32505595990145d24a928 100644
--- a/testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c
+++ b/testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c
@@ -12,8 +12,10 @@
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
-#include <linux/genhd.h>
#include <linux/blkdev.h>
+#ifndef DISK_NAME_LEN
+#include <linux/genhd.h>
+#endif
MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>");
MODULE_AUTHOR("Copyright (c) 2013 Oracle and/or its affiliates");
diff --git a/testcases/kernel/device-drivers/block/block_dev_user/block_dev.c b/testcases/kernel/device-drivers/block/block_dev_user/block_dev.c
index 543c36795cc3b2776c59141023e03ff2c58bd36a..9f87a88c9f9150ed1771616821d26e4982c55708 100644
--- a/testcases/kernel/device-drivers/block/block_dev_user/block_dev.c
+++ b/testcases/kernel/device-drivers/block/block_dev_user/block_dev.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
*
@@ -26,74 +27,58 @@
#include <unistd.h>
#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "old_module.h"
+#include "tst_test.h"
+#include "tst_module.h"
-char *TCID = "block_dev";
-int TST_TOTAL = 9;
+#define MODULE_NAME "ltp_block_dev"
+#define MODULE_NAME_KO MODULE_NAME ".ko"
-static const char module_name[] = "ltp_block_dev.ko";
static const char dev_result[] = "/sys/devices/ltp_block_dev/result";
static const char dev_tcase[] = "/sys/devices/ltp_block_dev/tcase";
-static int module_loaded;
-static int run_all_testcases;
-static const option_t options[] = {
- {"a", &run_all_testcases, NULL},
+static int module_loaded;
+static char *run_all_testcases;
+static struct tst_option options[] = {
+ {"a", &run_all_testcases, "-a\tRun all test-cases (can crash the kernel)"},
{NULL, NULL, NULL}
};
static void cleanup(void)
{
if (module_loaded)
- tst_module_unload(NULL, module_name);
-}
-
-static void help(void)
-{
- printf(" -a Run all test-cases (can crash the kernel)\n");
-}
-
-void setup(int argc, char *argv[])
-{
- tst_parse_opts(argc, argv, options, help);
-
- tst_require_root();
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
+ tst_module_unload(MODULE_NAME_KO);
}
-static void test_run(void)
+static void run(unsigned int n)
{
- int off = 0;
/*
* test-cases #8 and #9 can crash the kernel.
* We have to wait for kernel fix where register_blkdev() &
* unregister_blkdev() checks the input device name parameter
* against NULL pointer.
*/
- if (!run_all_testcases)
- off = 2;
-
- tst_module_load(cleanup, module_name, NULL);
- module_loaded = 1;
-
- int i, pass = 0;
- for (i = 0; i < TST_TOTAL - off; ++i) {
- SAFE_FILE_PRINTF(cleanup, dev_tcase, "%d", i + 1);
- SAFE_FILE_SCANF(cleanup, dev_result, "%d", &pass);
- tst_resm((pass) ? TPASS : TFAIL, "Test-case '%d'", i + 1);
+ n++;
+ if (!run_all_testcases && (n == 8 || n == 9)) {
+ tst_res(TCONF, "Skipped n = %d", n);
+ return;
}
-}
-int main(int argc, char *argv[])
-{
- setup(argc, argv);
-
- test_run();
+ if (!module_loaded) {
+ tst_module_load(MODULE_NAME_KO, NULL);
+ module_loaded = 1;
+ }
- cleanup();
+ int pass = 0;
- tst_exit();
+ SAFE_FILE_PRINTF(dev_tcase, "%d", n);
+ SAFE_FILE_SCANF(dev_result, "%d", &pass);
+ tst_res((pass) ? TPASS : TFAIL, "Test-case '%d'", n);
}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .cleanup = cleanup,
+ .test = run,
+ .tcnt = 9,
+ .options = options,
+};
---
base-commit: 47aff4decc81ac837fd745278def6883fc2f197b
change-id: 20241018-block_dev-c322152e03ad
Best regards,
--
Ricardo B. Marliere <rbm@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-10-21 22:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 22:05 Ricardo B. Marliere via ltp [this message]
2024-10-22 11:48 ` [LTP] [PATCH v2] block_dev: Convert to new API Cyril Hrubis
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=20241021-block_dev-v2-1-339a95c89fe0@suse.com \
--to=ltp@lists.linux.it \
--cc=rbm@suse.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox