blob: 805440958b034d858b03eaa7bf13414deaade440 [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,
68};
69
70/**
71 * struct test_debug - debugfs directories
72 * @debug_root: The test-iosched debugfs root directory
73 * @debug_utils_root: test-iosched debugfs utils root
74 * directory
75 * @debug_tests_root: test-iosched debugfs tests root
76 * directory
77 * @debug_test_result: Exposes the test result to the user
78 * space
79 * @start_sector: The start sector for read/write requests
80 */
81struct test_debug {
82 struct dentry *debug_root;
83 struct dentry *debug_utils_root;
84 struct dentry *debug_tests_root;
85 struct dentry *debug_test_result;
86 struct dentry *start_sector;
87};
88
89/**
90 * struct test_request - defines a test request
91 * @queuelist: The test requests list
92 * @bios_buffer: Write/read requests data buffer
93 * @buf_size: Write/read requests data buffer size (in
94 * bytes)
95 * @rq: A block request, to be dispatched
96 * @req_completed: A flag to indicate if the request was
97 * completed
98 * @req_result: Keeps the error code received in the
99 * request completion callback
100 * @is_err_expected: A flag to indicate if the request should
101 * fail
102 * @wr_rd_data_pattern: A pattern written to the write data
103 * buffer. Can be used in read requests to
104 * verify the data
105 * @req_id: A unique ID to identify a test request
106 * to ease the debugging of the test cases
107 */
108struct test_request {
109 struct list_head queuelist;
110 unsigned int *bios_buffer;
111 int buf_size;
112 struct request *rq;
113 bool req_completed;
114 int req_result;
115 int is_err_expected;
116 int wr_rd_data_pattern;
117 int req_id;
118};
119
120/**
121 * struct test_info - specific test information
122 * @testcase: The current running test case
123 * @timeout_msec: Test specific test timeout
124 * @buf_size: Write/read requests data buffer size (in
125 * bytes)
126 * @prepare_test_fn: Test specific test preparation callback
127 * @run_test_fn: Test specific test running callback
128 * @check_test_result_fn: Test specific test result checking
129 * callback
130 * @get_test_case_str_fn: Test specific function to get the test name
131 * @data: Test specific private data
132 */
133struct test_info {
134 int testcase;
135 unsigned timeout_msec;
136 prepare_test_fn *prepare_test_fn;
137 run_test_fn *run_test_fn;
138 check_test_result_fn *check_test_result_fn;
139 post_test_fn *post_test_fn;
140 get_test_case_str_fn *get_test_case_str_fn;
141 void *data;
142};
143
144/**
145 * struct blk_dev_test_type - identifies block device test
146 * @list: list head pointer
147 * @init_fn: block device test init callback
148 * @exit_fn: block device test exit callback
149 */
150struct blk_dev_test_type {
151 struct list_head list;
152 blk_dev_test_init_fn *init_fn;
153 blk_dev_test_exit_fn *exit_fn;
154};
155
156/**
157 * struct test_data - global test iosched data
158 * @queue: The test IO scheduler requests list
159 * @test_queue: The test requests list
160 * @next_req: Points to the next request to be
161 * dispatched from the test requests list
162 * @wait_q: A wait queue for waiting for the test
163 * requests completion
164 * @test_state: Indicates if there is a running test.
165 * Used for dispatch function
166 * @test_result: Indicates if the test passed or failed
167 * @debug: The test debugfs entries
168 * @req_q: The block layer request queue
169 * @num_of_write_bios: The number of write BIOs added to the test requests.
170 * Used to calcualte the sector number of
171 * new BIOs.
172 * @start_sector: The address of the first sector that can
173 * be accessed by the test
174 * @timeout_timer: A timer to verify test completion in
175 * case of non-completed requests
176 * @wr_rd_next_req_id: A unique ID to identify WRITE/READ
177 * request to ease the debugging of the
178 * test cases
179 * @unique_next_req_id: A unique ID to identify
180 * FLUSH/DISCARD/SANITIZE request to ease
181 * the debugging of the test cases
182 * @lock: A lock to verify running a single test
183 * at a time
184 * @test_info: A specific test data to be set by the
185 * test invokation function
186 * @ignore_round: A boolean variable indicating that a
187 * test round was disturbed by an external
188 * flush request, therefore disqualifying
189 * the results
190 */
191struct test_data {
192 struct list_head queue;
193 struct list_head test_queue;
194 struct test_request *next_req;
195 wait_queue_head_t wait_q;
196 enum test_state test_state;
197 enum test_results test_result;
198 struct test_debug debug;
199 struct request_queue *req_q;
200 int num_of_write_bios;
201 u32 start_sector;
202 struct timer_list timeout_timer;
203 int wr_rd_next_req_id;
204 int unique_next_req_id;
205 spinlock_t lock;
206 struct test_info test_info;
207 bool fs_wr_reqs_during_test;
208 bool ignore_round;
209};
210
211extern int test_iosched_start_test(struct test_info *t_info);
212extern void test_iosched_mark_test_completion(void);
213extern int test_iosched_add_unique_test_req(int is_err_expcted,
214 enum req_unique_type req_unique,
215 int start_sec, int nr_sects, rq_end_io_fn *end_req_io);
216extern int test_iosched_add_wr_rd_test_req(int is_err_expcted,
217 int direction, int start_sec,
218 int num_bios, int pattern, rq_end_io_fn *end_req_io);
219
220extern struct dentry *test_iosched_get_debugfs_tests_root(void);
221extern struct dentry *test_iosched_get_debugfs_utils_root(void);
222
223extern struct request_queue *test_iosched_get_req_queue(void);
224
225extern void test_iosched_set_test_result(int);
226
227void test_iosched_set_ignore_round(bool ignore_round);
228
229void test_iosched_register(struct blk_dev_test_type *bdt);
230
231void test_iosched_unregister(struct blk_dev_test_type *bdt);
232
233#endif /* _LINUX_TEST_IOSCHED_H */