-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fixes module build on 5.18 and newer where genhd.h was merged into blkdev.h. Signed-off-by: Ricardo B. Marliere <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
- Loading branch information
Showing
2 changed files
with
39 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]>"); | ||
MODULE_AUTHOR("Copyright (c) 2013 Oracle and/or its affiliates"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it would be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* Author: Alexey Kodanev <[email protected]> | ||
*/ | ||
|
||
/*\ | ||
* [Description] | ||
* | ||
* Test checks block device kernel API. | ||
*/ | ||
|
@@ -26,74 +17,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}, | ||
{NULL, NULL, 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)"}, | ||
{} | ||
}; | ||
|
||
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"); | ||
tst_module_unload(MODULE_NAME_KO); | ||
} | ||
|
||
void setup(int argc, char *argv[]) | ||
static void run(unsigned int n) | ||
{ | ||
tst_parse_opts(argc, argv, options, help); | ||
|
||
tst_require_root(); | ||
|
||
tst_sig(FORK, DEF_HANDLER, cleanup); | ||
} | ||
|
||
static void test_run(void) | ||
{ | ||
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, | ||
}; |