-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zdtm: add support for LD_PRELOAD tests
This commit adds a `--preload-libfault` option to ZDTM's run command. This option runs CRIU with LD_PRELOAD to intercept libc functions such as pread(). This method allows to simulate special cases, for example, when a successful call to pread() transfers fewer bytes than requested. Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
- Loading branch information
Showing
5 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CC = gcc | ||
CFLAGS = -c -fPIC -ldl | ||
|
||
SRC = libfault.c | ||
OBJ = $(SRC:.c=.o) | ||
|
||
LIB = libfault.so | ||
|
||
.PHONY: all clean run | ||
|
||
all: $(LIB) | ||
|
||
$(LIB): $(OBJ) | ||
$(CC) -shared -o $(LIB) $(OBJ) | ||
|
||
$(OBJ): $(SRC) | ||
$(CC) $(CFLAGS) $< | ||
|
||
clean: | ||
rm -f $(OBJ) $(LIB) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#define _GNU_SOURCE | ||
#include <unistd.h> | ||
#include <dlfcn.h> | ||
#include <errno.h> | ||
|
||
ssize_t (*original_pread)(int fd, void *buf, size_t count, off_t offset) = NULL; | ||
|
||
/** | ||
* This function is a wrapper around pread() that is used for testing CRIU's | ||
* handling of cases where pread() returns less data than requested. | ||
* | ||
* pmc_fill() in criu/pagemap.c is a good example of where this can happen. | ||
*/ | ||
ssize_t pread64(int fd, void *buf, size_t count, off_t offset) | ||
{ | ||
if (!original_pread) { | ||
original_pread = dlsym(RTLD_NEXT, "pread"); | ||
if (!original_pread) { | ||
errno = EIO; | ||
return -1; | ||
} | ||
} | ||
|
||
/* The following aims to simulate the case when pread() returns less | ||
* data than requested. We need to ensure that CRIU handles such cases. */ | ||
if (count > 2048) { | ||
count -= 1024; | ||
} | ||
|
||
return original_pread(fd, buf, count, offset); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters