Skip to content

Commit a94dbda

Browse files
committed
Add UringMachine.kernel_version, skip read_each tests on early kernel
1 parent 5e69510 commit a94dbda

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

ext/um/extconf.rb

+19-16
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ def get_config
2222
raise "UringMachine requires kernel version 6.4 or newer!" if combined_version < 604
2323

2424
{
25-
kernel_version: combined_version,
26-
submit_all_flag: combined_version >= 518,
27-
coop_taskrun_flag: combined_version >= 519,
28-
single_issuer_flag: combined_version >= 600,
29-
prep_bind: combined_version >= 611,
30-
prep_listen: combined_version >= 611,
31-
prep_cmd_sock: combined_version >= 607,
32-
prep_futex: combined_version >= 607,
33-
prep_waitid: combined_version >= 607
25+
kernel_version: combined_version,
26+
submit_all_flag: combined_version >= 518,
27+
coop_taskrun_flag: combined_version >= 519,
28+
single_issuer_flag: combined_version >= 600,
29+
prep_bind: combined_version >= 611,
30+
prep_listen: combined_version >= 611,
31+
prep_cmd_sock: combined_version >= 607,
32+
prep_futex: combined_version >= 607,
33+
prep_waitid: combined_version >= 607,
34+
prep_read_multishot: combined_version >= 607
3435
}
3536
end
3637

@@ -55,13 +56,15 @@ def get_config
5556
raise "Couldn't find liburing.a"
5657
end
5758

58-
$defs << '-DHAVE_IORING_SETUP_SUBMIT_ALL' if config[:submit_all_flag]
59-
$defs << '-DHAVE_IORING_SETUP_COOP_TASKRUN' if config[:coop_taskrun_flag]
60-
$defs << '-DHAVE_IO_URING_PREP_BIND' if config[:prep_bind]
61-
$defs << '-DHAVE_IO_URING_PREP_LISTEN' if config[:prep_listen]
62-
$defs << '-DHAVE_IO_URING_PREP_CMD_SOCK' if config[:prep_cmd_sock]
63-
$defs << '-DHAVE_IO_URING_PREP_FUTEX' if config[:prep_futex]
64-
$defs << '-DHAVE_IO_URING_PREP_WAITID' if config[:prep_waitid]
59+
$defs << "-DUM_KERNEL_VERSION=#{config[:kernel_version]}"
60+
$defs << '-DHAVE_IORING_SETUP_SUBMIT_ALL' if config[:submit_all_flag]
61+
$defs << '-DHAVE_IORING_SETUP_COOP_TASKRUN' if config[:coop_taskrun_flag]
62+
$defs << '-DHAVE_IO_URING_PREP_BIND' if config[:prep_bind]
63+
$defs << '-DHAVE_IO_URING_PREP_LISTEN' if config[:prep_listen]
64+
$defs << '-DHAVE_IO_URING_PREP_CMD_SOCK' if config[:prep_cmd_sock]
65+
$defs << '-DHAVE_IO_URING_PREP_FUTEX' if config[:prep_futex]
66+
$defs << '-DHAVE_IO_URING_PREP_WAITID' if config[:prep_waitid]
67+
$defs << '-DHAVE_IO_URING_PREP_READ_MULTISHOT' if config[:prep_read_multishot]
6568
$CFLAGS << ' -Wno-pointer-arith'
6669

6770
CONFIG['optflags'] << ' -fno-strict-aliasing'

ext/um/um_class.c

+10
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ VALUE UM_read(int argc, VALUE *argv, VALUE self) {
107107
}
108108

109109
VALUE UM_read_each(VALUE self, VALUE fd, VALUE bgid) {
110+
#ifdef HAVE_IO_URING_PREP_READ_MULTISHOT
110111
struct um *machine = get_machine(self);
111112
return um_read_each(machine, NUM2INT(fd), NUM2INT(bgid));
113+
#else
114+
rb_raise(rb_eRuntimeError, "Not supported by kernel");
115+
#endif
112116
}
113117

114118
VALUE UM_write(int argc, VALUE *argv, VALUE self) {
@@ -254,6 +258,10 @@ VALUE UM_queue_shift(VALUE self, VALUE queue) {
254258

255259
#endif
256260

261+
VALUE UM_kernel_version(VALUE self) {
262+
return INT2NUM(UM_KERNEL_VERSION);
263+
}
264+
257265
void Init_UM(void) {
258266
rb_ext_ractor_safe(true);
259267

@@ -295,5 +303,7 @@ void Init_UM(void) {
295303
rb_define_method(cUM, "shift", UM_queue_shift, 1);
296304
#endif
297305

306+
rb_define_singleton_method(cUM, "kernel_version", UM_kernel_version, 0);
307+
298308
um_define_net_constants(cUM);
299309
}

test/test_um.rb

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
require_relative 'helper'
44
require 'socket'
55

6+
class UringMachineTest < Minitest::Test
7+
def test_kernel_version
8+
v = UringMachine.kernel_version
9+
assert_kind_of Integer, v
10+
assert_in_range 600..700, v
11+
end
12+
end
13+
614
class SchedulingTest < UMBaseTest
715
def test_schedule_and_yield
816
buf = []
@@ -254,9 +262,10 @@ def test_read_with_negative_buffer_offset
254262

255263
class ReadEachTest < UMBaseTest
256264
def test_read_each
265+
skip if UringMachine.kernel_version < 607
266+
257267
r, w = IO.pipe
258268
bufs = []
259-
260269
bgid = machine.setup_buffer_ring(4096, 1024)
261270
assert_equal 0, bgid
262271

@@ -283,8 +292,9 @@ def test_read_each
283292

284293
# send once and close write fd
285294
def test_read_each_raising_1
286-
r, w = IO.pipe
295+
skip if UringMachine.kernel_version < 607
287296

297+
r, w = IO.pipe
288298
bgid = machine.setup_buffer_ring(4096, 1024)
289299
assert_equal 0, bgid
290300

@@ -306,8 +316,9 @@ def test_read_each_raising_1
306316

307317
# send once and leave write fd open
308318
def test_read_each_raising_2
309-
r, w = IO.pipe
319+
skip if UringMachine.kernel_version < 607
310320

321+
r, w = IO.pipe
311322
bgid = machine.setup_buffer_ring(4096, 1024)
312323
assert_equal 0, bgid
313324

@@ -330,8 +341,9 @@ def test_read_each_raising_2
330341

331342
# send twice
332343
def test_read_each_raising_3
333-
r, w = IO.pipe
344+
skip if UringMachine.kernel_version < 607
334345

346+
r, w = IO.pipe
335347
bgid = machine.setup_buffer_ring(4096, 1024)
336348
assert_equal 0, bgid
337349

@@ -354,8 +366,9 @@ def test_read_each_raising_3
354366
end
355367

356368
def test_read_each_break
357-
r, w = IO.pipe
369+
skip if UringMachine.kernel_version < 607
358370

371+
r, w = IO.pipe
359372
bgid = machine.setup_buffer_ring(4096, 1024)
360373

361374
t = Thread.new do
@@ -379,6 +392,8 @@ def test_read_each_break
379392
end
380393

381394
def test_read_each_bad_file
395+
skip if UringMachine.kernel_version < 607
396+
382397
_r, w = IO.pipe
383398
bgid = machine.setup_buffer_ring(4096, 1024)
384399

0 commit comments

Comments
 (0)