blob: c4835449200ad602cf75e53802e8098bf1f847f2 [file] [log] [blame]
Alexey Kodanev4970a2f2013-10-02 13:23:50 +04001/*
2 * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
19 *
20 * Test checks block device kernel API.
21 */
22
23#define _GNU_SOURCE
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include <string.h>
28
29#include "test.h"
Alexey Kodanev4970a2f2013-10-02 13:23:50 +040030#include "safe_macros.h"
31#include "tst_module.h"
32
33char *TCID = "block_dev";
34int TST_TOTAL = 9;
35
36static const char module_name[] = "ltp_block_dev.ko";
37static const char dev_result[] = "/sys/devices/ltp_block_dev/result";
38static const char dev_tcase[] = "/sys/devices/ltp_block_dev/tcase";
39static int module_loaded;
40
41static int run_all_testcases;
42static const option_t options[] = {
43 {"a", &run_all_testcases, NULL},
44 {NULL, NULL, NULL}
45};
46
47static void cleanup(void)
48{
49 if (module_loaded)
50 tst_module_unload(NULL, module_name);
Alexey Kodanev4970a2f2013-10-02 13:23:50 +040051}
52
53static void help(void)
54{
55 printf(" -a Run all test-cases (can crash the kernel)\n");
56}
57
58void setup(int argc, char *argv[])
59{
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020060 const char *msg;
Alexey Kodanev4970a2f2013-10-02 13:23:50 +040061 msg = parse_opts(argc, argv, options, help);
62 if (msg != NULL)
63 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
64
65 tst_require_root(NULL);
66
67 if (tst_kvercmp(2, 6, 0) < 0) {
68 tst_brkm(TCONF, NULL,
69 "Test must be run with kernel 2.6 or newer");
70 }
71
72 tst_sig(FORK, DEF_HANDLER, cleanup);
73}
74
75static void test_run(void)
76{
77 int off = 0;
78 /*
79 * test-cases #8 and #9 can crash the kernel.
80 * We have to wait for kernel fix where register_blkdev() &
81 * unregister_blkdev() checks the input device name parameter
82 * against NULL pointer.
83 */
84 if (!run_all_testcases)
85 off = 2;
86
87 tst_module_load(cleanup, module_name, NULL);
88 module_loaded = 1;
89
90 int i, pass = 0;
91 for (i = 0; i < TST_TOTAL - off; ++i) {
92 SAFE_FILE_PRINTF(cleanup, dev_tcase, "%d", i + 1);
93 SAFE_FILE_SCANF(cleanup, dev_result, "%d", &pass);
94 tst_resm((pass) ? TPASS : TFAIL, "Test-case '%d'", i + 1);
95 }
96}
97
98int main(int argc, char *argv[])
99{
100 setup(argc, argv);
101
102 test_run();
103
104 cleanup();
105
106 tst_exit();
107}