mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 1 | /* |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. |
mridge | 3889d93 | 2006-01-09 19:17:16 +0000 | [diff] [blame] | 4 | * |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
mridge | 3889d93 | 2006-01-09 19:17:16 +0000 | [diff] [blame] | 9 | * |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 10 | * This program is distributed in the hope that it would be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
mridge | 3889d93 | 2006-01-09 19:17:16 +0000 | [diff] [blame] | 14 | * |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
mridge | 3889d93 | 2006-01-09 19:17:16 +0000 | [diff] [blame] | 18 | * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 19 | * This is the main of your user space test program, |
| 20 | * which will open the correct kernel bioule, find the |
| 21 | * file descriptor value and use that value to make |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 22 | * ioctl calls to the system |
| 23 | * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * Use the ki_generic and other ki_testname functions |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 25 | * to abstract the calls from the main |
| 26 | * |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 27 | * FILE : user_tbio.c |
| 28 | * USAGE : kernel_space:./load_tbio.sh |
| 29 | * user_space :./test_bio |
| 30 | * |
| 31 | * DESCRIPTION : The bioule will test block i/o layer for kernel 2.5 |
| 32 | * REQUIREMENTS: |
| 33 | * 1) glibc 2.1.91 or above. |
| 34 | * |
| 35 | * HISTORY : |
| 36 | * 11/19/2003 Kai Zhao (ltcd3@cn.ibm.com) |
| 37 | * |
| 38 | * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) |
| 39 | * |
| 40 | */ |
| 41 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 42 | #define _GNU_SOURCE |
| 43 | #include <stdio.h> |
| 44 | #include <stdlib.h> |
| 45 | #include <sys/stat.h> |
| 46 | #include <sys/ioctl.h> |
| 47 | #include <fcntl.h> |
| 48 | #include <errno.h> |
| 49 | #include <sys/types.h> |
| 50 | #include <linux/kernel.h> |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 51 | #include <unistd.h> |
| 52 | #include <string.h> |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 53 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 54 | #include "test.h" |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 55 | #include "safe_macros.h" |
| 56 | #include "tst_module.h" |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 57 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 58 | #include "../tbio_kernel/tbio.h" |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 59 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 60 | char *TCID = TBIO_DEVICE_NAME; |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 61 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 62 | static const char module_name[] = "ltp_tbio.ko"; |
| 63 | static int module_loaded; |
| 64 | static int tbio_fd = -1; |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 65 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 66 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 67 | { |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 68 | |
| 69 | if (tbio_fd != -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 70 | close(tbio_fd); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 71 | tbio_fd = -1; |
| 72 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 73 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 74 | if (module_loaded) |
| 75 | tst_module_unload(NULL, module_name); |
| 76 | |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 77 | if (unlink(DEVICE_NAME) && (errno != ENOENT)) |
| 78 | tst_brkm(TBROK | TERRNO, NULL, "unlink failed"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 81 | |
| 82 | void setup(void) |
| 83 | { |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 84 | dev_t devt; |
| 85 | struct stat st; |
| 86 | unsigned int i, valid_node_created; |
| 87 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 88 | tst_require_root(NULL); |
| 89 | |
| 90 | if (tst_kvercmp(2, 6, 0) < 0) { |
| 91 | tst_brkm(TCONF, NULL, |
| 92 | "Test must be run with kernel 2.6 or newer"); |
| 93 | } |
| 94 | |
| 95 | tst_module_load(cleanup, module_name, NULL); |
| 96 | module_loaded = 1; |
| 97 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 98 | SAFE_FILE_SCANF(cleanup, "/sys/class/block/tbio/dev", |
| 99 | "%d:0", &TBIO_MAJOR); |
| 100 | |
| 101 | devt = makedev(TBIO_MAJOR, 0); |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 102 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 103 | /* |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 104 | * Wait until udev creates the device node. |
| 105 | * If the node is not created or invalid, create it manually. |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 106 | */ |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 107 | valid_node_created = 0; |
| 108 | for (i = 0; i < 50; i++) { |
| 109 | if (stat(DEVICE_NAME, &st)) { |
| 110 | if (errno != ENOENT) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 111 | tst_brkm(TBROK | TERRNO, cleanup, |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 112 | "stat() failed"); |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 113 | } else { |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 114 | if ((st.st_mode & S_IFBLK) && (st.st_rdev == devt)) { |
| 115 | valid_node_created = 1; |
| 116 | break; |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 117 | } |
| 118 | } |
Stanislav Kholmanskikh | 5e61dbe | 2015-01-15 13:39:44 +0300 | [diff] [blame] | 119 | |
| 120 | usleep(100000); |
| 121 | } |
| 122 | |
| 123 | if (!valid_node_created) { |
| 124 | tst_resm(TINFO, |
| 125 | "The device file was not created by udev, " |
| 126 | "proceeding with manual creation"); |
| 127 | |
| 128 | if (unlink(DEVICE_NAME) && (errno != ENOENT)) |
| 129 | tst_brkm(TBROK | TERRNO, cleanup, "unlink() failed"); |
| 130 | if (mknod(DEVICE_NAME, S_IFBLK | S_IRUSR | S_IWUSR | |
| 131 | S_IRGRP | S_IWGRP, devt)) |
| 132 | tst_brkm(TBROK | TERRNO, cleanup, "mknod() failed"); |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | tbio_fd = open(DEVICE_NAME, O_RDWR); |
| 136 | if (tbio_fd < 0) { |
| 137 | tst_brkm(TBROK | TERRNO, cleanup, "open of %s failed", |
| 138 | DEVICE_NAME); |
| 139 | } |
| 140 | |
| 141 | tst_resm(TINFO, "Device opened successfully "); |
| 142 | } |
| 143 | |
| 144 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | int tbio_to_dev(int fd, int flag) |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 146 | { |
| 147 | int rc; |
| 148 | tbio_interface_t bif; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 149 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 150 | memset(&bif, 0, sizeof(tbio_interface_t)); |
| 151 | rc = posix_memalign(&bif.data, 512, 1024); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 152 | if (rc) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 153 | tst_resm(TINFO, "posix_memalign failed"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 154 | return -1; |
| 155 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 156 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 157 | strcpy(bif.data, "User space data"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 158 | bif.data_len = 1024; |
| 159 | bif.direction = TBIO_TO_DEV; |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 160 | bif.cmd = SAFE_MALLOC(cleanup, 6); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 161 | if (bif.cmd == NULL) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 162 | tst_resm(TINFO, "malloc cmd space failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 163 | free(bif.data); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 164 | return -1; |
| 165 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 166 | strcpy(bif.cmd, "WRITE"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 167 | bif.cmd_len = 6; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 168 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 169 | rc = ioctl(fd, flag, &bif); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 170 | if (rc) { |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 171 | free(bif.data); |
| 172 | free(bif.cmd); |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 173 | tst_resm(TINFO, "Ioctl error for TBIO_TO_DEV"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 174 | return rc; |
| 175 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 176 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 177 | free(bif.data); |
| 178 | free(bif.cmd); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 179 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 180 | return 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 181 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 184 | int tbio_from_dev(int fd, int flag) |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 185 | { |
| 186 | int rc; |
| 187 | tbio_interface_t bif; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 188 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 189 | memset(&bif, 0, sizeof(tbio_interface_t)); |
| 190 | rc = posix_memalign(&bif.data, 512, 1024); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 191 | if (rc) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 192 | tst_resm(TINFO, "posix_memalign failed"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 193 | return -1; |
| 194 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 195 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 196 | memset(bif.data, 0, 1024); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 197 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 198 | bif.data_len = 1024; |
| 199 | bif.direction = TBIO_FROM_DEV; |
Stanislav Kholmanskikh | 49a41ae | 2014-12-19 15:49:01 +0300 | [diff] [blame] | 200 | bif.cmd = SAFE_MALLOC(cleanup, 5); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 201 | if (bif.cmd == NULL) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 202 | tst_resm(TINFO, "malloc cmd space failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 203 | free(bif.data); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 204 | return -1; |
| 205 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 206 | strcpy(bif.cmd, "READ"); |
Stanislav Kholmanskikh | 49a41ae | 2014-12-19 15:49:01 +0300 | [diff] [blame] | 207 | bif.cmd_len = 5; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 208 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 209 | rc = ioctl(fd, flag, &bif); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 210 | if (rc) { |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 211 | free(bif.data); |
| 212 | free(bif.cmd); |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 213 | tst_resm(TINFO, "Ioctl error for TBIO_TO_DEV"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 214 | return rc; |
| 215 | } |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 216 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 217 | if (strcmp(bif.data, "User space data")) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 218 | tst_resm(TINFO, "TBIO_FROM_DEV failed"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 219 | free(bif.data); |
| 220 | free(bif.cmd); |
| 221 | return -1; |
| 222 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 223 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 224 | free(bif.data); |
| 225 | free(bif.cmd); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 226 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 227 | return 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 228 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 231 | int tbio_split_to_dev(int fd, int flag) |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 232 | { |
| 233 | int rc; |
| 234 | tbio_interface_t bif; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 235 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 236 | memset(&bif, 0, sizeof(tbio_interface_t)); |
| 237 | rc = posix_memalign(&bif.data, 512, 2048); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 238 | if (rc) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 239 | tst_resm(TINFO, "posix_memalign failed"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 240 | return -1; |
| 241 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 242 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 243 | strcpy(bif.data, "User space data"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 244 | bif.data_len = 2048; |
| 245 | bif.direction = TBIO_TO_DEV; |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 246 | bif.cmd = SAFE_MALLOC(cleanup, 6); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 247 | if (bif.cmd == NULL) { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 248 | tst_resm(TINFO, "malloc cmd space failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 249 | free(bif.data); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 250 | return -1; |
| 251 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 252 | strcpy(bif.cmd, "WRITE"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 253 | bif.cmd_len = 6; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 254 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 255 | rc = ioctl(fd, flag, &bif); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 256 | if (rc) { |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 257 | free(bif.data); |
| 258 | free(bif.cmd); |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 259 | tst_resm(TINFO, "Ioctl error for TBIO_TO_DEV"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 260 | return rc; |
| 261 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 262 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 263 | free(bif.data); |
| 264 | free(bif.cmd); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 265 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 266 | return 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 267 | |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 270 | int ki_generic(int fd, int flag) |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 271 | { |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 272 | tbio_interface_t bif; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 273 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 274 | int rc = ioctl(fd, flag, &bif); |
| 275 | if (rc) |
| 276 | tst_resm(TINFO | TERRNO, "ioctl error"); |
| 277 | |
| 278 | return rc; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | int main(void) |
| 283 | { |
| 284 | setup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 285 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 286 | if (ki_generic(tbio_fd, LTP_TBIO_ALLOC)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 287 | tst_resm(TFAIL, "failed on LTP_TBIO_ALLOC test"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 288 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 289 | tst_resm(TPASS, "success on LTP_TBIO_ALLOC test"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 290 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 291 | if (ki_generic(tbio_fd, LTP_TBIO_CLONE)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 292 | tst_resm(TFAIL, "failed on LTP_TBIO_CLONE test"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 293 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 294 | tst_resm(TPASS, "success on LTP_TBIO_CLONE test"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 295 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 296 | if (ki_generic(tbio_fd, LTP_TBIO_GET_NR_VECS)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 297 | tst_resm(TFAIL, "failed on LTP_TBIO_GET_NR_VECS test"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 298 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 299 | tst_resm(TPASS, "success on LTP_TBIO_GET_NR_VECS test"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 300 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 301 | if (ki_generic(tbio_fd, LTP_TBIO_ADD_PAGE)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 302 | tst_resm(TFAIL, "failed on LTP_TBIO_ADD_PAGE test"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 303 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 304 | tst_resm(TPASS, "success on LTP_TBIO_ADD_PAGE test"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 305 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 306 | if (tbio_split_to_dev(tbio_fd, LTP_TBIO_SPLIT)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 307 | tst_resm(TFAIL, "failed on LTP_TBIO_SPLIT:write to dev"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 308 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 309 | tst_resm(TPASS, "success on LTP_TBIO_SPLIT:write to dev"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 310 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 311 | if (tbio_to_dev(tbio_fd, LTP_TBIO_DO_IO)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 312 | tst_resm(TFAIL, "failed on LTP_TBIO_DO_IO:write to dev"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 313 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 314 | tst_resm(TPASS, "success on LTP_TBIO_DO_IO:write to dev"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 315 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 316 | if (tbio_from_dev(tbio_fd, LTP_TBIO_DO_IO)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 317 | tst_resm(TFAIL, "failed on LTP_TBIO_DO_IO:read from dev"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 318 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 319 | tst_resm(TPASS, "success on LTP_TBIO_DO_IO:read from dev"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 320 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 321 | if (ki_generic(tbio_fd, LTP_TBIO_PUT)) |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 322 | tst_resm(TFAIL, "failed on LTP_TBIO_PUT test"); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 323 | else |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 324 | tst_resm(TPASS, "success on LTP_TBIO_PUT test"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 325 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 326 | cleanup(); |
mridge | 061ba16 | 2003-12-03 17:06:14 +0000 | [diff] [blame] | 327 | |
Alexey Kodanev | 69d3b32 | 2013-10-22 16:16:42 +0400 | [diff] [blame] | 328 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 329 | } |