Commit 9f22f06b
9f22f06bc9b9Merged
Richard Ramsden <[email protected]> · 6 months ago · 10 files · +10 added
Description
test(ffi): add five regression tests for the FFI surface
Each test covers one feature so a future regression points at the
specific piece that broke. Tests use .rb.expected files (not the
CRuby-comparison path) since CRuby has no ffi_func.
ffi_libc_libm_basic cos / sqrt / pow / strlen / getpid ffi_const ffi_const inlined as Module::NAME ffi_buffer_reader ffi_buffer + ffi_read_u32/i32 round-trips ffi_ptr_nil :ptr == nil reads NULL correctly (BSS buffer) ffi_void_return :void calls in expression position
Details
- Commit
- 9f22f06bc9b9
- Parent
- e9eec312f2ab
test/ffi_buffer_reader.rbaddedView file
1+
module Buf2+
ffi_buffer :scratch, 163+
ffi_read_u32 :u32_at_0, 04+
ffi_read_u32 :u32_at_4, 45+
ffi_read_u32 :u32_at_8, 86+
ffi_read_i32 :i32_at_0, 07+
end8+
9+
# `ffi_buffer` lives in BSS so it's zero-initialised at load. Reading10+
# the buffer back through every reader kind at every offset proves the11+
# storage + read-pointer arithmetic line up.12+
puts Buf.u32_at_0(Buf.scratch)13+
puts Buf.u32_at_4(Buf.scratch)14+
puts Buf.u32_at_8(Buf.scratch)15+
puts Buf.i32_at_0(Buf.scratch)16+
17+
# A second buffer is laid out next to the first; each gets its own18+
# slot, so reading from one doesn't accidentally see the other's bytes.19+
module Other20+
ffi_buffer :scratch, 1621+
ffi_read_u32 :u32, 022+
end23+
puts Other.u32(Other.scratch)test/ffi_buffer_reader.rb.expectedaddedView file
Loading diff…
test/ffi_const.rbaddedView file
Loading diff…
test/ffi_const.rb.expectedaddedView file
Loading diff…
test/ffi_libc_libm_basic.rbaddedView file
Loading diff…
test/ffi_libc_libm_basic.rb.expectedaddedView file
Loading diff…
test/ffi_ptr_nil.rbaddedView file
Loading diff…
test/ffi_ptr_nil.rb.expectedaddedView file
Loading diff…
test/ffi_void_return.rbaddedView file
Loading diff…
test/ffi_void_return.rb.expectedaddedView file
Loading diff…