1#include "block/sched/tests/test_internal.h"
2#include <mem/nofail.h>
3
4TEST_GROUP_DEFINE(bio_sched, .intensity_desc = {
5 .curve = SCALE_PIECEWISE_LOG,
6 .unit = "requests",
7 });
8
9#define EXT2_ROOT struct vfs_node *root = global.root_node
10
11static atomic_bool cb1d = false;
12
13static void bio_sch_callback1(struct bio_request *req) {
14 cc_ignore(req);
15
16 atomic_store(&cb1d, true);
17 test_info("cb 1 success");
18}
19
20TEST_DEFINE_INTEGRATION(bio_sched, coalesce, TEST_INTENSITY(1, 2, 16),
21 .required_fs = FS_EXT2) {
22 EXT2_ROOT;
23 struct ext2_fs *fs = root->fs_data;
24 struct block_device *d = fs->drive;
25 size_t reqs = ctx->intensity_val ? ctx->intensity_val : 2;
26
27 for (size_t i = 0; i < reqs; i++) {
28 struct bio_request *req = nofail_vnew(req);
29 *req = (struct bio_request){
30 .lba = i,
31 .disk = d,
32 .buffer = nofail(valloc_aligned(512, 4096)),
33 .size = 512,
34 .sector_count = 1,
35 .write = false,
36 .done = false,
37 .status = -1,
38 .on_complete = bio_sch_callback1,
39 .priority = BIO_RQ_MEDIUM,
40 .user_data = (void *) BIO_RQ_MEDIUM,
41 };
42 bio_sched_enqueue(disk: d, req);
43 }
44
45 char *name = valloc(100);
46 uint64_t t = time_get_us();
47 snprintf(name, 100, "enqueues took %lu us", time_get_us() - t);
48 test_info("%s", name);
49
50 bio_sched_dispatch_all(disk: d);
51
52 for (int i = 0; i < 5000; i++)
53 scheduler_yield();
54
55 return TEST_SUCCESS;
56}
57