blob: 1e428c587f29b576c8c8952448ded8c9ba0ad2dd [file] [log] [blame]
Maya Erez60181552012-06-27 11:25:26 +03001/* 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
32struct test_data;
33
34typedef int (prepare_test_fn) (struct test_data *);
35typedef int (run_test_fn) (struct test_data *);
36typedef int (check_test_result_fn) (struct test_data *);
37typedef int (post_test_fn) (struct test_data *);
38typedef char* (get_test_case_str_fn) (struct test_data *);
39typedef void (blk_dev_test_init_fn) (void);
40typedef void (blk_dev_test_exit_fn) (void);
41
42/**
43 * enum test_state - defines the state of the test
44 */
45enum 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 */
54enum 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 */
64enum req_unique_type {
65 REQ_UNIQUE_NONE,
66 REQ_UNIQUE_DISCARD,
67 REQ_UNIQUE_FLUSH,
Maya Erez22f7abf2012-07-18 21:52:33 +030068 REQ_UNIQUE_SANITIZE,
Maya Erez60181552012-06-27 11:25:26 +030069};
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 */
82struct 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 */
109struct 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
132 * @data: Test specific private data
133 */
134struct test_info {
135 int testcase;
136 unsigned timeout_msec;
137 prepare_test_fn *prepare_test_fn;
138 run_test_fn *run_test_fn;
139 check_test_result_fn *check_test_result_fn;
140 post_test_fn *post_test_fn;
141 get_test_case_str_fn *get_test_case_str_fn;
142 void *data;
143};
144
145/**
146 * struct blk_dev_test_type - identifies block device test
147 * @list: list head pointer
148 * @init_fn: block device test init callback
149 * @exit_fn: block device test exit callback
150 */
151struct blk_dev_test_type {
152 struct list_head list;
153 blk_dev_test_init_fn *init_fn;
154 blk_dev_test_exit_fn *exit_fn;
155};
156
157/**
158 * struct test_data - global test iosched data
159 * @queue: The test IO scheduler requests list
160 * @test_queue: The test requests list
161 * @next_req: Points to the next request to be
162 * dispatched from the test requests list
163 * @wait_q: A wait queue for waiting for the test
164 * requests completion
165 * @test_state: Indicates if there is a running test.
166 * Used for dispatch function
167 * @test_result: Indicates if the test passed or failed
168 * @debug: The test debugfs entries
169 * @req_q: The block layer request queue
170 * @num_of_write_bios: The number of write BIOs added to the test requests.
171 * Used to calcualte the sector number of
172 * new BIOs.
173 * @start_sector: The address of the first sector that can
174 * be accessed by the test
175 * @timeout_timer: A timer to verify test completion in
176 * case of non-completed requests
177 * @wr_rd_next_req_id: A unique ID to identify WRITE/READ
178 * request to ease the debugging of the
179 * test cases
180 * @unique_next_req_id: A unique ID to identify
181 * FLUSH/DISCARD/SANITIZE request to ease
182 * the debugging of the test cases
183 * @lock: A lock to verify running a single test
184 * at a time
185 * @test_info: A specific test data to be set by the
186 * test invokation function
187 * @ignore_round: A boolean variable indicating that a
188 * test round was disturbed by an external
189 * flush request, therefore disqualifying
190 * the results
191 */
192struct test_data {
193 struct list_head queue;
194 struct list_head test_queue;
195 struct test_request *next_req;
196 wait_queue_head_t wait_q;
197 enum test_state test_state;
198 enum test_results test_result;
199 struct test_debug debug;
200 struct request_queue *req_q;
201 int num_of_write_bios;
202 u32 start_sector;
203 struct timer_list timeout_timer;
204 int wr_rd_next_req_id;
205 int unique_next_req_id;
206 spinlock_t lock;
207 struct test_info test_info;
208 bool fs_wr_reqs_during_test;
209 bool ignore_round;
210};
211
212extern int test_iosched_start_test(struct test_info *t_info);
213extern void test_iosched_mark_test_completion(void);
214extern int test_iosched_add_unique_test_req(int is_err_expcted,
215 enum req_unique_type req_unique,
216 int start_sec, int nr_sects, rq_end_io_fn *end_req_io);
217extern int test_iosched_add_wr_rd_test_req(int is_err_expcted,
218 int direction, int start_sec,
219 int num_bios, int pattern, rq_end_io_fn *end_req_io);
220
221extern struct dentry *test_iosched_get_debugfs_tests_root(void);
222extern struct dentry *test_iosched_get_debugfs_utils_root(void);
223
224extern struct request_queue *test_iosched_get_req_queue(void);
225
226extern void test_iosched_set_test_result(int);
227
228void test_iosched_set_ignore_round(bool ignore_round);
229
230void test_iosched_register(struct blk_dev_test_type *bdt);
231
232void test_iosched_unregister(struct blk_dev_test_type *bdt);
233
234#endif /* _LINUX_TEST_IOSCHED_H */