koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 1 | import os.path |
| 2 | import unittest |
| 3 | |
| 4 | |
| 5 | from oktest import ok, main, test |
| 6 | |
| 7 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 8 | from wally.suits.io import fio_task_parser |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 9 | |
| 10 | code_test_defaults = """ |
| 11 | [defaults] |
| 12 | wait_for_previous |
| 13 | buffered=0 |
| 14 | iodepth=2 |
| 15 | RUNTIME=20 |
| 16 | |
| 17 | [sec1] |
| 18 | group_reporting |
| 19 | time_based |
| 20 | softrandommap=1 |
| 21 | filename=/tmp/xxx |
| 22 | size=5G |
| 23 | ramp_time=20 |
| 24 | runtime={RUNTIME} |
| 25 | blocksize=1m |
| 26 | rw=read |
| 27 | direct=1 |
| 28 | numjobs=1 |
| 29 | some_extra=1.2314 |
| 30 | |
| 31 | [sec2] |
| 32 | group_reporting |
| 33 | time_based |
| 34 | iodepth=1 |
| 35 | softrandommap=1 |
| 36 | filename=/tmp/xxx |
| 37 | size=5G |
| 38 | ramp_time=20 |
| 39 | runtime={RUNTIME} |
| 40 | blocksize=1m |
| 41 | rw=read |
| 42 | direct=1 |
| 43 | numjobs=1 |
| 44 | some_extra=1.2314 |
| 45 | """ |
| 46 | |
| 47 | defaults = """ |
| 48 | [defaults] |
| 49 | wait_for_previous |
| 50 | group_reporting |
| 51 | time_based |
| 52 | buffered=0 |
| 53 | iodepth=1 |
| 54 | softrandommap=1 |
| 55 | filename=/tmp/xxx |
| 56 | size=5G |
| 57 | ramp_time=20 |
| 58 | runtime=20 |
| 59 | blocksize=1m |
| 60 | rw=read |
| 61 | direct=1 |
| 62 | numjobs=1 |
| 63 | """ |
| 64 | |
| 65 | code_test_auto_params_1 = defaults + """ |
| 66 | [defaults] |
| 67 | RUNTIME=30 |
| 68 | |
| 69 | [sec1_{TEST_SUMM}] |
| 70 | ramp_time={% 20, 40 %} |
| 71 | runtime={RUNTIME} |
| 72 | blocksize={% 4k, 4m %} |
| 73 | """ |
| 74 | |
| 75 | |
| 76 | code_test_uniq = defaults + """ |
| 77 | [defaults] |
| 78 | REPCOUNT=2 |
| 79 | RUNTIME=30 |
| 80 | |
| 81 | [sec1_{TEST_SUMM}_{UNIQ} * 3] |
| 82 | |
| 83 | [sec2_{TEST_SUMM}_{UNIQ} * {REPCOUNT}] |
| 84 | """ |
| 85 | |
| 86 | code_test_cycles_default = defaults + """ |
| 87 | [defaults] |
| 88 | REPCOUNT=2 |
| 89 | RUNTIME={% 30, 60 %} |
| 90 | |
| 91 | [sec1_{TEST_SUMM}_{UNIQ} * 3] |
| 92 | runtime={RUNTIME} |
| 93 | blocksize={% 4k, 4m %} |
| 94 | """ |
| 95 | |
| 96 | |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 97 | class AgentTest(unittest.TestCase): |
| 98 | @test("test_parse_value") |
| 99 | def test_parse_value(self): |
| 100 | x = "asdfasd adsd d" |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 101 | ok(fio_task_parser.parse_value(x)) == x |
| 102 | ok(fio_task_parser.parse_value("10 2")) == "10 2" |
| 103 | ok(fio_task_parser.parse_value("None")).is_(None) |
| 104 | ok(fio_task_parser.parse_value("10")) == 10 |
| 105 | ok(fio_task_parser.parse_value("20")) == 20 |
| 106 | ok(fio_task_parser.parse_value("10.1") - 10.1) < 1E-7 |
| 107 | ok(fio_task_parser.parse_value("{% 10, 20 %}")) == [10, 20] |
| 108 | ok(fio_task_parser.parse_value("{% 10,20 %}")) == [10, 20] |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 109 | |
| 110 | code_test_compile_simplest = defaults + """ |
| 111 | [sec1] |
| 112 | some_extra=1.2314 |
| 113 | """ |
| 114 | |
| 115 | @test("test_compile_simplest") |
| 116 | def test_compile_simplest(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 117 | sections = fio_task_parser.parse_all_in_1(self.code_test_compile_simplest, {}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 118 | sections = list(sections) |
| 119 | |
| 120 | ok(len(sections)) == 1 |
| 121 | sec1 = sections[0] |
| 122 | ok(sec1.name) == "sec1" |
| 123 | vals = sec1.vals |
| 124 | ok(vals['wait_for_previous']).is_(None) |
| 125 | ok(vals['iodepth']) == 1 |
| 126 | ok(vals['some_extra'] - 1.2314) < 1E-7 |
| 127 | |
| 128 | code_test_params_in_defaults = defaults + """ |
| 129 | [defaults] |
| 130 | RUNTIME=20 |
| 131 | |
| 132 | [sec1] |
| 133 | runtime={RUNTIME} |
| 134 | """ |
| 135 | |
| 136 | @test("test_compile_defaults") |
| 137 | def test_compile_defaults(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 138 | sections = fio_task_parser.parse_all_in_1(self.code_test_params_in_defaults, {}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 139 | sections = list(sections) |
| 140 | |
| 141 | ok(len(sections)) == 1 |
| 142 | sec1 = sections[0] |
| 143 | ok(sec1.name) == "sec1" |
| 144 | vals = sec1.vals |
| 145 | ok(vals['wait_for_previous']).is_(None) |
| 146 | ok(vals['iodepth']) == 1 |
| 147 | ok(vals['runtime']) == 20 |
| 148 | |
| 149 | @test("test_defaults") |
| 150 | def test_defaults(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 151 | sections = fio_task_parser.parse_all_in_1(code_test_defaults, {}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 152 | sections = list(sections) |
| 153 | |
| 154 | ok(len(sections)) == 2 |
| 155 | sec1, sec2 = sections |
| 156 | |
| 157 | ok(sec1.name) == "sec1" |
| 158 | ok(sec2.name) == "sec2" |
| 159 | |
| 160 | ok(sec1.vals['wait_for_previous']).is_(None) |
| 161 | ok(sec2.vals['wait_for_previous']).is_(None) |
| 162 | |
| 163 | ok(sec1.vals['iodepth']) == 2 |
| 164 | ok(sec2.vals['iodepth']) == 1 |
| 165 | |
| 166 | ok(sec1.vals['buffered']) == 0 |
| 167 | ok(sec2.vals['buffered']) == 0 |
| 168 | |
| 169 | code_test_ext_params = defaults + """ |
| 170 | [sec1] |
| 171 | runtime={RUNTIME} |
| 172 | """ |
| 173 | |
| 174 | @test("test_external_params") |
| 175 | def test_external_params(self): |
| 176 | with self.assertRaises(KeyError): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 177 | sections = fio_task_parser.parse_all_in_1(self.code_test_ext_params, {}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 178 | list(sections) |
| 179 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 180 | sections = fio_task_parser.parse_all_in_1(self.code_test_ext_params, {'RUNTIME': 20}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 181 | sections = list(sections) |
| 182 | |
| 183 | code_test_cycle = defaults + """ |
| 184 | [sec1] |
| 185 | runtime={RUNTIME} |
| 186 | ramp_time={% 20, 40 %} |
| 187 | """ |
| 188 | |
| 189 | @test("test_cycle") |
| 190 | def test_cycle(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 191 | sections = fio_task_parser.parse_all_in_1(self.code_test_cycle, {'RUNTIME': 20}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 192 | sections = list(sections) |
| 193 | ok(len(sections)) == 2 |
| 194 | ok(sections[0].vals['ramp_time']) == 20 |
| 195 | ok(sections[1].vals['ramp_time']) == 40 |
| 196 | |
| 197 | code_test_cycles = defaults + """ |
| 198 | [sec1] |
| 199 | ramp_time={% 20, 40 %} |
| 200 | runtime={RUNTIME} |
| 201 | blocksize={% 4k, 4m %} |
| 202 | """ |
| 203 | |
| 204 | @test("test_cycles") |
| 205 | def test_cycles(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 206 | sections = fio_task_parser.parse_all_in_1(self.code_test_cycles, {'RUNTIME': 20}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 207 | sections = list(sections) |
| 208 | ok(len(sections)) == 4 |
| 209 | |
| 210 | combinations = [ |
| 211 | (section.vals['ramp_time'], section.vals['blocksize']) |
| 212 | for section in sections |
| 213 | ] |
| 214 | |
| 215 | combinations.sort() |
| 216 | |
| 217 | ok(combinations) == [(20, '4k'), (20, '4m'), (40, '4k'), (40, '4m')] |
| 218 | |
| 219 | @test("test_time_estimate") |
| 220 | def test_time_estimate(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 221 | sections = fio_task_parser.parse_all_in_1(self.code_test_cycles, {'RUNTIME': 20}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 222 | sections = list(sections) |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 223 | etime = fio_task_parser.calculate_execution_time(sections) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 224 | |
| 225 | ok(etime) == 20 * 4 + 20 * 2 + 40 * 2 |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 226 | ok(fio_task_parser.sec_to_str(etime)) == "0:03:20" |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 227 | |
| 228 | code_test_cycles2 = defaults + """ |
| 229 | [sec1 * 7] |
| 230 | ramp_time={% 20, 40 %} |
| 231 | runtime={RUNTIME} |
| 232 | blocksize={% 4k, 4m %} |
| 233 | """ |
| 234 | |
| 235 | @test("test_time_estimate") |
| 236 | def test_time_estimate_large(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 237 | sections = fio_task_parser.parse_all_in_1(self.code_test_cycles2, {'RUNTIME': 30}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 238 | sections = list(sections) |
| 239 | |
| 240 | ok(sections[0].name) == 'sec1' |
| 241 | ok(len(sections)) == 7 * 4 |
| 242 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 243 | etime = fio_task_parser.calculate_execution_time(sections) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 244 | # ramptime optimization |
| 245 | expected_time = (20 + 30 + 30 * 6) * 2 |
| 246 | expected_time += (40 + 30 + 30 * 6) * 2 |
| 247 | ok(etime) == expected_time |
| 248 | |
| 249 | code_test_cycles3 = defaults + """ |
| 250 | [sec1 * 7] |
| 251 | ramp_time={% 20, 40 %} |
| 252 | runtime={RUNTIME} |
| 253 | blocksize={% 4k, 4m %} |
| 254 | |
| 255 | [sec2 * 7] |
| 256 | ramp_time={% 20, 40 %} |
| 257 | runtime={RUNTIME} |
| 258 | blocksize={% 4k, 4m %} |
| 259 | """ |
| 260 | |
| 261 | @test("test_time_estimate2") |
| 262 | def test_time_estimate_large2(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 263 | sections = fio_task_parser.parse_all_in_1(self.code_test_cycles3, {'RUNTIME': 30}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 264 | sections = list(sections) |
| 265 | |
| 266 | ok(sections[0].name) == 'sec1' |
| 267 | ok(sections[1].name) == 'sec1' |
| 268 | ok(len(sections)) == 7 * 4 * 2 |
| 269 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 270 | etime = fio_task_parser.calculate_execution_time(sections) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 271 | # ramptime optimization |
| 272 | expected_time = (20 + 30 + 30 * 6) * 2 |
| 273 | expected_time += (40 + 30 + 30 * 6) * 2 |
| 274 | ok(etime) == expected_time * 2 |
| 275 | |
| 276 | code_test_repeats = defaults + """ |
| 277 | [defaults] |
| 278 | REPCOUNT=2 |
| 279 | [sec1 * 3] |
| 280 | [sec2 * {REPCOUNT}] |
| 281 | """ |
| 282 | |
| 283 | @test("test_repeat") |
| 284 | def test_repeat(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 285 | sections = fio_task_parser.parse_all_in_1(self.code_test_repeats, {}) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 286 | sections = list(sections) |
| 287 | ok(len(sections)) == 2 + 3 |
| 288 | ok(sections[0].name) == 'sec1' |
| 289 | ok(sections[1].name) == 'sec1' |
| 290 | ok(sections[2].name) == 'sec1' |
| 291 | ok(sections[3].name) == 'sec2' |
| 292 | ok(sections[4].name) == 'sec2' |
| 293 | |
| 294 | @test("test_real_tasks") |
| 295 | def test_real_tasks(self): |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 296 | tasks_dir = os.path.dirname(fio_task_parser.__file__) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 297 | fname = os.path.join(tasks_dir, 'io_scenario_ceph.cfg') |
| 298 | fc = open(fname).read() |
| 299 | |
| 300 | sections = P(fc, {'FILENAME': '/dev/null'}) |
| 301 | sections = list(sections) |
| 302 | |
| 303 | ok(len(sections)) == 7 * 9 * 4 + 7 |
| 304 | |
koder aka kdanilov | 39e449e | 2016-12-17 15:15:26 +0200 | [diff] [blame] | 305 | etime = fio_task_parser.calculate_execution_time(sections) |
koder aka kdanilov | 0c598a1 | 2015-04-21 03:01:40 +0300 | [diff] [blame] | 306 | # ramptime optimization |
| 307 | expected_time = (60 * 7 + 30) * 9 * 4 + (60 * 7 + 30) |
| 308 | ok(etime) == expected_time |
| 309 | |
| 310 | if __name__ == '__main__': |
| 311 | main() |
| 312 | |
| 313 | # def do_run_fio_fake(bconf): |
| 314 | # def estimate_iops(sz, bw, lat): |
| 315 | # return 1 / (lat + float(sz) / bw) |
| 316 | # global count |
| 317 | # count += 1 |
| 318 | # parsed_out = [] |
| 319 | |
| 320 | # BW = 120.0 * (1024 ** 2) |
| 321 | # LAT = 0.003 |
| 322 | |
| 323 | # for name, cfg in bconf: |
| 324 | # sz = to_bytes(cfg['blocksize']) |
| 325 | # curr_lat = LAT * ((random.random() - 0.5) * 0.1 + 1) |
| 326 | # curr_ulat = curr_lat * 1000000 |
| 327 | # curr_bw = BW * ((random.random() - 0.5) * 0.1 + 1) |
| 328 | # iops = estimate_iops(sz, curr_bw, curr_lat) |
| 329 | # bw = iops * sz |
| 330 | |
| 331 | # res = {'ctx': 10683, |
| 332 | # 'error': 0, |
| 333 | # 'groupid': 0, |
| 334 | # 'jobname': name, |
| 335 | # 'majf': 0, |
| 336 | # 'minf': 30, |
| 337 | # 'read': {'bw': 0, |
| 338 | # 'bw_agg': 0.0, |
| 339 | # 'bw_dev': 0.0, |
| 340 | # 'bw_max': 0, |
| 341 | # 'bw_mean': 0.0, |
| 342 | # 'bw_min': 0, |
| 343 | # 'clat': {'max': 0, |
| 344 | # 'mean': 0.0, |
| 345 | # 'min': 0, |
| 346 | # 'stddev': 0.0}, |
| 347 | # 'io_bytes': 0, |
| 348 | # 'iops': 0, |
| 349 | # 'lat': {'max': 0, 'mean': 0.0, |
| 350 | # 'min': 0, 'stddev': 0.0}, |
| 351 | # 'runtime': 0, |
| 352 | # 'slat': {'max': 0, 'mean': 0.0, |
| 353 | # 'min': 0, 'stddev': 0.0} |
| 354 | # }, |
| 355 | # 'sys_cpu': 0.64, |
| 356 | # 'trim': {'bw': 0, |
| 357 | # 'bw_agg': 0.0, |
| 358 | # 'bw_dev': 0.0, |
| 359 | # 'bw_max': 0, |
| 360 | # 'bw_mean': 0.0, |
| 361 | # 'bw_min': 0, |
| 362 | # 'clat': {'max': 0, |
| 363 | # 'mean': 0.0, |
| 364 | # 'min': 0, |
| 365 | # 'stddev': 0.0}, |
| 366 | # 'io_bytes': 0, |
| 367 | # 'iops': 0, |
| 368 | # 'lat': {'max': 0, 'mean': 0.0, |
| 369 | # 'min': 0, 'stddev': 0.0}, |
| 370 | # 'runtime': 0, |
| 371 | # 'slat': {'max': 0, 'mean': 0.0, |
| 372 | # 'min': 0, 'stddev': 0.0} |
| 373 | # }, |
| 374 | # 'usr_cpu': 0.23, |
| 375 | # 'write': {'bw': 0, |
| 376 | # 'bw_agg': 0, |
| 377 | # 'bw_dev': 0, |
| 378 | # 'bw_max': 0, |
| 379 | # 'bw_mean': 0, |
| 380 | # 'bw_min': 0, |
| 381 | # 'clat': {'max': 0, 'mean': 0, |
| 382 | # 'min': 0, 'stddev': 0}, |
| 383 | # 'io_bytes': 0, |
| 384 | # 'iops': 0, |
| 385 | # 'lat': {'max': 0, 'mean': 0, |
| 386 | # 'min': 0, 'stddev': 0}, |
| 387 | # 'runtime': 0, |
| 388 | # 'slat': {'max': 0, 'mean': 0.0, |
| 389 | # 'min': 0, 'stddev': 0.0} |
| 390 | # } |
| 391 | # } |
| 392 | |
| 393 | # if cfg['rw'] in ('read', 'randread'): |
| 394 | # key = 'read' |
| 395 | # elif cfg['rw'] in ('write', 'randwrite'): |
| 396 | # key = 'write' |
| 397 | # else: |
| 398 | # raise ValueError("Uknown op type {0}".format(key)) |
| 399 | |
| 400 | # res[key]['bw'] = bw |
| 401 | # res[key]['iops'] = iops |
| 402 | # res[key]['runtime'] = 30 |
| 403 | # res[key]['io_bytes'] = res[key]['runtime'] * bw |
| 404 | # res[key]['bw_agg'] = bw |
| 405 | # res[key]['bw_dev'] = bw / 30 |
| 406 | # res[key]['bw_max'] = bw * 1.5 |
| 407 | # res[key]['bw_min'] = bw / 1.5 |
| 408 | # res[key]['bw_mean'] = bw |
| 409 | # res[key]['clat'] = {'max': curr_ulat * 10, 'mean': curr_ulat, |
| 410 | # 'min': curr_ulat / 2, 'stddev': curr_ulat} |
| 411 | # res[key]['lat'] = res[key]['clat'].copy() |
| 412 | # res[key]['slat'] = res[key]['clat'].copy() |
| 413 | |
| 414 | # parsed_out.append(res) |
| 415 | |
| 416 | # return zip(parsed_out, bconf) |