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