Maya Erez | 6018155 | 2012-06-27 11:25:26 +0300 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * The test scheduler allows to test the block device by dispatching |
| 13 | * specific requests according to the test case and declare PASS/FAIL |
| 14 | * according to the requests completion error code. |
| 15 | * Each test is exposed via debugfs and can be triggered by writing to |
| 16 | * the debugfs file. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef _LINUX_TEST_IOSCHED_H |
| 21 | #define _LINUX_TEST_IOSCHED_H |
| 22 | |
| 23 | /* |
| 24 | * Patterns definitions for read/write requests data |
| 25 | */ |
| 26 | #define TEST_PATTERN_SEQUENTIAL -1 |
| 27 | #define TEST_PATTERN_5A 0x5A5A5A5A |
| 28 | #define TEST_PATTERN_FF 0xFFFFFFFF |
| 29 | #define TEST_NO_PATTERN 0xDEADBEEF |
| 30 | #define BIO_U32_SIZE 1024 |
| 31 | |
| 32 | struct test_data; |
| 33 | |
| 34 | typedef int (prepare_test_fn) (struct test_data *); |
| 35 | typedef int (run_test_fn) (struct test_data *); |
| 36 | typedef int (check_test_result_fn) (struct test_data *); |
| 37 | typedef int (post_test_fn) (struct test_data *); |
| 38 | typedef char* (get_test_case_str_fn) (struct test_data *); |
| 39 | typedef void (blk_dev_test_init_fn) (void); |
| 40 | typedef void (blk_dev_test_exit_fn) (void); |
| 41 | |
| 42 | /** |
| 43 | * enum test_state - defines the state of the test |
| 44 | */ |
| 45 | enum test_state { |
| 46 | TEST_IDLE, |
| 47 | TEST_RUNNING, |
| 48 | TEST_COMPLETED, |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * enum test_results - defines the success orfailure of the test |
| 53 | */ |
| 54 | enum test_results { |
| 55 | TEST_NO_RESULT, |
| 56 | TEST_FAILED, |
| 57 | TEST_PASSED, |
| 58 | TEST_NOT_SUPPORTED, |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * enum req_unique_type - defines a unique request type |
| 63 | */ |
| 64 | enum req_unique_type { |
| 65 | REQ_UNIQUE_NONE, |
| 66 | REQ_UNIQUE_DISCARD, |
| 67 | REQ_UNIQUE_FLUSH, |
Maya Erez | 22f7abf | 2012-07-18 21:52:33 +0300 | [diff] [blame] | 68 | REQ_UNIQUE_SANITIZE, |
Maya Erez | 6018155 | 2012-06-27 11:25:26 +0300 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /** |
| 72 | * struct test_debug - debugfs directories |
| 73 | * @debug_root: The test-iosched debugfs root directory |
| 74 | * @debug_utils_root: test-iosched debugfs utils root |
| 75 | * directory |
| 76 | * @debug_tests_root: test-iosched debugfs tests root |
| 77 | * directory |
| 78 | * @debug_test_result: Exposes the test result to the user |
| 79 | * space |
| 80 | * @start_sector: The start sector for read/write requests |
| 81 | */ |
| 82 | struct test_debug { |
| 83 | struct dentry *debug_root; |
| 84 | struct dentry *debug_utils_root; |
| 85 | struct dentry *debug_tests_root; |
| 86 | struct dentry *debug_test_result; |
| 87 | struct dentry *start_sector; |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * struct test_request - defines a test request |
| 92 | * @queuelist: The test requests list |
| 93 | * @bios_buffer: Write/read requests data buffer |
| 94 | * @buf_size: Write/read requests data buffer size (in |
| 95 | * bytes) |
| 96 | * @rq: A block request, to be dispatched |
| 97 | * @req_completed: A flag to indicate if the request was |
| 98 | * completed |
| 99 | * @req_result: Keeps the error code received in the |
| 100 | * request completion callback |
| 101 | * @is_err_expected: A flag to indicate if the request should |
| 102 | * fail |
| 103 | * @wr_rd_data_pattern: A pattern written to the write data |
| 104 | * buffer. Can be used in read requests to |
| 105 | * verify the data |
| 106 | * @req_id: A unique ID to identify a test request |
| 107 | * to ease the debugging of the test cases |
| 108 | */ |
| 109 | struct test_request { |
| 110 | struct list_head queuelist; |
| 111 | unsigned int *bios_buffer; |
| 112 | int buf_size; |
| 113 | struct request *rq; |
| 114 | bool req_completed; |
| 115 | int req_result; |
| 116 | int is_err_expected; |
| 117 | int wr_rd_data_pattern; |
| 118 | int req_id; |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * struct test_info - specific test information |
| 123 | * @testcase: The current running test case |
| 124 | * @timeout_msec: Test specific test timeout |
| 125 | * @buf_size: Write/read requests data buffer size (in |
| 126 | * bytes) |
| 127 | * @prepare_test_fn: Test specific test preparation callback |
| 128 | * @run_test_fn: Test specific test running callback |
| 129 | * @check_test_result_fn: Test specific test result checking |
| 130 | * callback |
| 131 | * @get_test_case_str_fn: Test specific function to get the test name |
Lee Susman | f18263a | 2012-10-24 14:14:37 +0200 | [diff] [blame] | 132 | * @test_duration: A jiffies value saved for timing |
| 133 | * calculations |
Maya Erez | 6018155 | 2012-06-27 11:25:26 +0300 | [diff] [blame] | 134 | * @data: Test specific private data |
| 135 | */ |
| 136 | struct test_info { |
| 137 | int testcase; |
| 138 | unsigned timeout_msec; |
| 139 | prepare_test_fn *prepare_test_fn; |
| 140 | run_test_fn *run_test_fn; |
| 141 | check_test_result_fn *check_test_result_fn; |
| 142 | post_test_fn *post_test_fn; |
| 143 | get_test_case_str_fn *get_test_case_str_fn; |
Lee Susman | f18263a | 2012-10-24 14:14:37 +0200 | [diff] [blame] | 144 | unsigned long test_duration; |
Maya Erez | 6018155 | 2012-06-27 11:25:26 +0300 | [diff] [blame] | 145 | void *data; |
| 146 | }; |
| 147 | |
| 148 | /** |
| 149 | * struct blk_dev_test_type - identifies block device test |
| 150 | * @list: list head pointer |
| 151 | * @init_fn: block device test init callback |
| 152 | * @exit_fn: block device test exit callback |
| 153 | */ |
| 154 | struct blk_dev_test_type { |
| 155 | struct list_head list; |
| 156 | blk_dev_test_init_fn *init_fn; |
| 157 | blk_dev_test_exit_fn *exit_fn; |
| 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * struct test_data - global test iosched data |
| 162 | * @queue: The test IO scheduler requests list |
| 163 | * @test_queue: The test requests list |
| 164 | * @next_req: Points to the next request to be |
| 165 | * dispatched from the test requests list |
| 166 | * @wait_q: A wait queue for waiting for the test |
| 167 | * requests completion |
| 168 | * @test_state: Indicates if there is a running test. |
| 169 | * Used for dispatch function |
| 170 | * @test_result: Indicates if the test passed or failed |
| 171 | * @debug: The test debugfs entries |
| 172 | * @req_q: The block layer request queue |
| 173 | * @num_of_write_bios: The number of write BIOs added to the test requests. |
| 174 | * Used to calcualte the sector number of |
| 175 | * new BIOs. |
| 176 | * @start_sector: The address of the first sector that can |
| 177 | * be accessed by the test |
| 178 | * @timeout_timer: A timer to verify test completion in |
| 179 | * case of non-completed requests |
| 180 | * @wr_rd_next_req_id: A unique ID to identify WRITE/READ |
| 181 | * request to ease the debugging of the |
| 182 | * test cases |
| 183 | * @unique_next_req_id: A unique ID to identify |
| 184 | * FLUSH/DISCARD/SANITIZE request to ease |
| 185 | * the debugging of the test cases |
| 186 | * @lock: A lock to verify running a single test |
| 187 | * at a time |
| 188 | * @test_info: A specific test data to be set by the |
| 189 | * test invokation function |
| 190 | * @ignore_round: A boolean variable indicating that a |
| 191 | * test round was disturbed by an external |
| 192 | * flush request, therefore disqualifying |
| 193 | * the results |
| 194 | */ |
| 195 | struct test_data { |
| 196 | struct list_head queue; |
| 197 | struct list_head test_queue; |
| 198 | struct test_request *next_req; |
| 199 | wait_queue_head_t wait_q; |
| 200 | enum test_state test_state; |
| 201 | enum test_results test_result; |
| 202 | struct test_debug debug; |
| 203 | struct request_queue *req_q; |
| 204 | int num_of_write_bios; |
| 205 | u32 start_sector; |
| 206 | struct timer_list timeout_timer; |
| 207 | int wr_rd_next_req_id; |
| 208 | int unique_next_req_id; |
| 209 | spinlock_t lock; |
| 210 | struct test_info test_info; |
| 211 | bool fs_wr_reqs_during_test; |
| 212 | bool ignore_round; |
| 213 | }; |
| 214 | |
| 215 | extern int test_iosched_start_test(struct test_info *t_info); |
| 216 | extern void test_iosched_mark_test_completion(void); |
| 217 | extern int test_iosched_add_unique_test_req(int is_err_expcted, |
| 218 | enum req_unique_type req_unique, |
| 219 | int start_sec, int nr_sects, rq_end_io_fn *end_req_io); |
| 220 | extern int test_iosched_add_wr_rd_test_req(int is_err_expcted, |
| 221 | int direction, int start_sec, |
| 222 | int num_bios, int pattern, rq_end_io_fn *end_req_io); |
| 223 | |
| 224 | extern struct dentry *test_iosched_get_debugfs_tests_root(void); |
| 225 | extern struct dentry *test_iosched_get_debugfs_utils_root(void); |
| 226 | |
| 227 | extern struct request_queue *test_iosched_get_req_queue(void); |
| 228 | |
| 229 | extern void test_iosched_set_test_result(int); |
| 230 | |
| 231 | void test_iosched_set_ignore_round(bool ignore_round); |
| 232 | |
| 233 | void test_iosched_register(struct blk_dev_test_type *bdt); |
| 234 | |
| 235 | void test_iosched_unregister(struct blk_dev_test_type *bdt); |
| 236 | |
| 237 | #endif /* _LINUX_TEST_IOSCHED_H */ |