Added LD_PRELOAD library to monitor msync calls in testing
This commit is contained in:
4
Makefile
4
Makefile
@@ -85,7 +85,8 @@ check: $(OBJS) $(CHECK_BINS)
|
|||||||
r=true ; for bin in $(CHECK_BINS); do $$bin || r=false; done ; $$r
|
r=true ; for bin in $(CHECK_BINS); do $$bin || r=false; done ; $$r
|
||||||
|
|
||||||
acceptance: build
|
acceptance: build
|
||||||
cd tests/acceptance && RUBYOPT='-I.' ruby nbd_scenarios -v
|
$(MAKE) -C tests/acceptance/ld_preloads all
|
||||||
|
cd tests/acceptance && LD_PRELOADS=$$(echo ld_preloads/*.o) RUBYOPT='-I.' ruby nbd_scenarios -v
|
||||||
|
|
||||||
test: check acceptance
|
test: check acceptance
|
||||||
|
|
||||||
@@ -108,6 +109,7 @@ install:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build/*
|
rm -rf build/*
|
||||||
|
$(RM) $(LD_PRELOAD_OBJ)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean objs check_objs all server proxy check_bins check doc build test acceptance
|
.PHONY: clean objs check_objs all server proxy check_bins check doc build test acceptance
|
||||||
|
13
tests/acceptance/ld_preloads/Makefile
Normal file
13
tests/acceptance/ld_preloads/Makefile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
SRC := $(wildcard *.c)
|
||||||
|
OBJS := $(SRC:%.c=%.o)
|
||||||
|
|
||||||
|
all: $(OBJS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(OBJS)
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
gcc -shared -fPIC -ldl -o $@ $<
|
||||||
|
|
||||||
|
.PHONY: all clean
|
33
tests/acceptance/ld_preloads/msync_catcher.c
Normal file
33
tests/acceptance/ld_preloads/msync_catcher.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
typedef int (*real_msync_t)(void *addr, size_t length, int flags);
|
||||||
|
|
||||||
|
int real_msync(void *addr, size_t length, int flags) {
|
||||||
|
return ((real_msync_t)dlsym(RTLD_NEXT, "msync"))(addr, length, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Noddy LD_PRELOAD wrapper to catch msync calls, and log them to a file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int msync(void *addr, size_t length, int flags) {
|
||||||
|
FILE *fd;
|
||||||
|
char *fn;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
retval = real_msync(addr, length, flags);
|
||||||
|
|
||||||
|
fn = getenv("MSYNC_CATCHER_OUTPUT");
|
||||||
|
if ( fn != NULL ) {
|
||||||
|
fd = fopen(fn,"a");
|
||||||
|
fprintf(fd,"msync:%d:%i:%i:%i\n", addr, length, flags, retval);
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'environment'
|
require 'environment'
|
||||||
require 'flexnbd/fake_source'
|
require 'flexnbd/fake_source'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
class TestServeMode < Test::Unit::TestCase
|
class TestServeMode < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
@@ -11,6 +12,7 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@env.cleanup
|
@env.cleanup
|
||||||
|
teardown_msync_catcher
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,6 +39,26 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup_msync_catcher
|
||||||
|
@msync_catcher = Tempfile.new('msync')
|
||||||
|
ENV['MSYNC_CATCHER_OUTPUT'] = @msync_catcher.path
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_msync_output
|
||||||
|
op = []
|
||||||
|
until @msync_catcher.eof?
|
||||||
|
op << @msync_catcher.readline.chomp.split(':').map do |e|
|
||||||
|
e =~ /^\d+$/ ? e.to_i : e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
op
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown_msync_catcher
|
||||||
|
@msync_catcher.close if @msync_catcher
|
||||||
|
ENV.delete 'MSYNC_CATCHER_OUTPUT'
|
||||||
|
end
|
||||||
|
|
||||||
def test_bad_request_magic_receives_error_response
|
def test_bad_request_magic_receives_error_response
|
||||||
connect_to_server do |client|
|
connect_to_server do |client|
|
||||||
# replace REQUEST_MAGIC with all 0s to make it look bad
|
# replace REQUEST_MAGIC with all 0s to make it look bad
|
||||||
@@ -109,15 +131,21 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_flush_is_accepted
|
def test_flush_is_accepted
|
||||||
|
setup_msync_catcher
|
||||||
connect_to_server do |client|
|
connect_to_server do |client|
|
||||||
client.flush
|
client.flush
|
||||||
rsp = client.read_response
|
rsp = client.read_response
|
||||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||||
assert_equal 0, rsp[:error]
|
assert_equal 0, rsp[:error]
|
||||||
end
|
end
|
||||||
|
op = parse_msync_output
|
||||||
|
assert_equal 1, op.count, 'Only one msync expected'
|
||||||
|
assert_equal @env.blocksize, op.first[2], 'msync length wrong'
|
||||||
|
assert_equal 6, op.first[3], 'msync called with incorrect flags'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_write_with_fua_is_accepted
|
def test_write_with_fua_is_accepted
|
||||||
|
setup_msync_catcher
|
||||||
page_size = Integer(`getconf PAGESIZE`)
|
page_size = Integer(`getconf PAGESIZE`)
|
||||||
@env.blocksize = page_size * 10
|
@env.blocksize = page_size * 10
|
||||||
connect_to_server do |client|
|
connect_to_server do |client|
|
||||||
@@ -127,13 +155,15 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
rsp = client.read_response
|
rsp = client.read_response
|
||||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||||
assert_equal 0, rsp[:error]
|
assert_equal 0, rsp[:error]
|
||||||
# TODO: test offset and length
|
|
||||||
# Should be rounded to the third page
|
|
||||||
# assert_equal(msync_offset, page_size *3)
|
|
||||||
|
|
||||||
# Should be 100 + 33, as we've started writing 100 bytes into a page, for
|
|
||||||
# 33 bytes
|
|
||||||
# assert_equal(msync_length, 133)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
op = parse_msync_output
|
||||||
|
assert_equal 1, op.count, 'Only one msync expected'
|
||||||
|
|
||||||
|
# Should be 100 + 33, as we've started writing 100 bytes into a page, for
|
||||||
|
# 33 bytes
|
||||||
|
assert_equal 133, op.first[2], 'msync length wrong'
|
||||||
|
assert_equal 6, op.first[3], 'msync called with incorrect flags'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user