Commit e42bc2dc authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

portability. addresses #1789

git-svn-id: file:///svn/toku/tokudb@12523 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3e95f194
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include "toku_portability.h"
int main(void) {
int fd = toku_os_lock_file(__FILE__);
assert(fd != -1);
pid_t pid = fork();
assert(pid != -1);
if (pid == 0) {
int fd2 = toku_os_lock_file(__FILE__);
assert(fd2 == -1);
return 0;
} else {
int status;
pid_t wpid = waitpid(-1, &status, 0);
assert(wpid == pid);
assert(status == 0);
}
int r = toku_os_unlock_file(fd);
assert(r == 0);
return 0;
}
../linux/file.c
\ No newline at end of file
# -*- Mode: Makefile -*-
CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
CPPFLAGS += -DTOKU_ALLOW_DEPRECATED
CPPFLAGS += -I../../toku_include -I.. -I.
CFLAGS = -Wall -Werror -g -O0 -std=c99
LDFLAGS = ../libtokuportability.a -lpthread
SRCS = $(wildcard test-*.c)
TARGETS = $(patsubst %.c,%,$(SRCS))
RUNTARGETS = $(patsubst %,%.tdbrun,$(TARGETS))
VGRIND = valgrind
ifeq ($(CC),icc)
CFLAGS += -diag-disable 981
endif
HERE=linux/tests
ifeq ($(SUMMARIZE),1)
SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sPASS\n" $(HERE)/$@; else printf "%-60sFAIL\n" $(HERE)/$@ ; test 0 = 1; fi
SUMMARIZE_SHOULD_FAIL= ;if test $$? = 0; then printf "%-60sXFAIL\n" $(HERE)/$@; else printf "%-60sXPASS\n" $(HERE)/$@ ; test 0 = 1; fi
INVERTER=;test $$? -ne 0
else
SUMMARIZE_CMD =
endif
all: $(TARGETS)
%: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS)
test-gettime: test-gettime.c
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) -lrt
.PHONY: check
check: $(TARGETS) $(RUNTARGETS);
%.tdbrun: %
ifeq ($(VGRIND),)
./$< $(SUMMARIZE_CMD)
else
$(VGRIND) --log-file=$<.valgrind ./$<; \
if [ $$? = 0 ] ; then \
grep "LEAK SUMMARY" $<.valgrind >/dev/null 2>&1; \
if [ $$? = 0 ] ; then cat $<.valgrind; test 0 = 1; fi \
fi \
$(SUMMARIZE_CMD)
endif
clean:
rm -rf $(TARGETS) *.valgrind pwrite4g.data testdir
../../linux/tests/test-flock.c
\ No newline at end of file
../../linux/tests/test-max-data.c
\ No newline at end of file
../../linux/tests/test-pwrite4g.c
\ No newline at end of file
../../linux/tests/test.h
\ No newline at end of file
......@@ -2,6 +2,15 @@
#include <fcntl.h>
#include <test.h>
#include <assert.h>
#include <string.h>
static int iszero(char *cp, size_t n) {
size_t i;
for (i=0; i<n; i++)
if (cp[i] != 0)
return 0;
return 1;
}
int test_main(int argc, char *argv[]) {
char fname[] = "pwrite4g.data";
......@@ -11,8 +20,15 @@ int test_main(int argc, char *argv[]) {
assert(fd>=0);
char buf[] = "hello";
int64_t offset = (1LL<<32) + 100;
r = toku_os_pwrite(fd, buf, sizeof(buf), offset);
assert(r==sizeof(buf));
r = toku_os_pwrite(fd, buf, sizeof buf, offset);
assert(r==sizeof buf);
char newbuf[sizeof buf];
r = pread(fd, newbuf, sizeof newbuf, 100);
assert(r==sizeof newbuf);
assert(iszero(newbuf, sizeof newbuf));
r = pread(fd, newbuf, sizeof newbuf, offset);
assert(r==sizeof newbuf);
assert(memcmp(newbuf, buf, sizeof newbuf) == 0);
int64_t fsize;
r = toku_os_get_file_size(fd, &fsize);
assert(r == 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment