Makefile 5.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# Wendelin.core | Instructions to build & test
# Copyright (C) 2014-2015  Nexedi SA and Contributors.
#                     	   Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Open Source Initiative approved licenses and Convey
# the resulting work. Corresponding source of such a combination shall include
# the source code for all other software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
all	:

PYTHON	?= python
21
PYTEST	?= $(PYTHON) -m pytest
22
PYBENCH ?= $(PYTHON) t/py.bench
23
VALGRIND?= valgrind
24 25 26 27 28 29 30 31 32 33 34 35 36

# use the same C compiler as python
# (for example it could be `gcc -m64` on a 32bit userspace)
CC	:= $(shell $(PYTHON) -c "from __future__ import print_function;	\
		import sysconfig as _;	\
		print(_.get_config_vars()['CC'])")
ifeq ($(CC),)
$(error "Cannot defermine py-CC")
endif

all	: bigfile/_bigfile.so


37 38 39
ccan_config := 3rdparty/ccan/config.h

bigfile/_bigfile.so : $(ccan_config) FORCE
40 41 42 43 44 45 46
	$(PYTHON) setup.py ll_build_ext --inplace


FORCE	:


# TODO add FORCE?
47
$(ccan_config): 3rdparty/ccan/Makefile
48 49 50 51 52 53 54 55
	$(MAKE) -C $(@D) $(@F)

# if there is no ccan/Makefile - ccan submodule has not been initialized
# if there is - it is ok, as that Makefile does not need to be rebuilt
3rdparty/ccan/Makefile:
	@echo 'E: 3rdparty/ccan submodule not initialized'
	@echo 'E: please do `git submodule update --init`'
	@false
56 57 58 59 60 61


# -*- testing -*-

# XXX dup with setup.py
CPPFLAGS:= -Iinclude -I3rdparty/ccan -I3rdparty/include
62 63 64
CFLAGS	:= -g -Wall -D_GNU_SOURCE -std=gnu99 -fplan9-extensions	\
	   -Wno-declaration-after-statement	\
	   -Wno-error=declaration-after-statement	\
65 66 67 68

# XXX hack ugly
LOADLIBES=lib/bug.c lib/utils.c 3rdparty/ccan/ccan/tap/tap.c
TESTS	:= $(patsubst %.c,%,$(wildcard bigfile/tests/test_*.c))
69
test	: test.t test.py test.fault test.asan test.tsan test.vgmem test.vghel test.vgdrd
70

71 72 73 74 75 76 77 78 79 80 81 82 83
# TODO move XFAIL markers into *.c

# TSAN fails on test_virtmem (http://code.google.com/p/thread-sanitizer/issues/detail?id=75)
# NOTE the bug was fixed in compiler-rt 20140917 (6afe775d)
#      -> we can remove this xfail when the fix propagates to gcc/clang release
XFAIL_bigfile/tests/test_virtmem.tsanrun	:= y

# Before calling our SIGSEGV handler, Memcheck first reports "invalid read|write" error.
# A solution could be to tell memcheck via VALGRIND_MAKE_MEM_DEFINED that VMA
# address space is ok to access _before_ handling pagefault.
# http://valgrind.org/docs/manual/mc-manual.html#mc-manual.clientreqs
XFAIL_bigfile/tests/test_virtmem.vgmemrun	:= y

84 85 86 87 88 89 90 91 92

# extract what goes after RUNWITH: marker from command source, or empty if no marker
runwith = $(shell grep -oP '(?<=^// RUNWITH: ).*' $(basename $1).c)

# run a test, not failing if failure is expected
xrun	= $1 $(if $(XFAIL_$@),|| echo "($@ - expected failure)")
XRUN<	= $(call xrun,$(call runwith,$<) $<)


93
LINKC	= $(LINK.c) $< $(LOADLIBES) $(LDLIBS) -o $@
94 95 96 97 98 99

# tests without instrumentation
test.t	: $(TESTS:%=%.trun)
%.trun	: %.t
	$(XRUN<)

100
%.t	: %.c $(ccan_config)
101 102 103 104 105 106 107 108
	$(LINKC)

# test with AddressSanitizer
test.asan: $(TESTS:%=%.asanrun)
%.asanrun: %.asan
	$(XRUN<)

%.asan	: CFLAGS += -fsanitize=address
109
%.asan	: %.c $(ccan_config)
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
	$(LINKC)


# test with ThreadSanitizer

# TSAN works only on x86_64
# (can't rely on `uname -m` - could have 32bit userspace on 64bit kernel)
ifneq ($(shell $(CPP) -dM - </dev/null | grep __x86_64__),)
test.tsan: $(TESTS:%=%.tsanrun)
%.tsanrun: %.tsan
	$(XRUN<)
else
test.tsan:
	@echo "Skip $@	# ThreadSanitizer does not support \"`$(CC) -v 2>&1 | grep '^Target:'`\""
endif



%.tsan	: CFLAGS += -fsanitize=thread -pie -fPIC
129
%.tsan	: %.c $(ccan_config)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	$(LINKC)


# run valgrind so errors affect exit code
# TODO stop on first error
# (http://stackoverflow.com/questions/16345555/is-there-a-way-to-stop-valgrind-on-the-first-error-it-finds
#  but it still asks interactively, whether to "run debugger")
VALGRINDRUN  = $(VALGRIND) --error-exitcode=1

# to track memory access on each instruction (e.g. without this reads from NULL are ignored)
# XXX why =allregs-at-mem-access is not sufficient?
#     see "Handling of Signals" in http://valgrind.org/docs/manual/manual-core.html
#     without this option our SIGSEGV handler is not always called
#     see also: https://bugs.kde.org/show_bug.cgi?id=124035
VALGRINDRUN += --vex-iropt-register-updates=allregs-at-each-insn


# like XRUN< for valgrind
vgxrun	= $(call xrun,$(call runwith,$2) $(VALGRINDRUN) $1 $2)

# test with valgrind/memcheck
test.vgmem: $(TESTS:%=%.vgmemrun)
%.vgmemrun: %.t
	$(call vgxrun,--tool=memcheck, $<)


# test with valgrind/helgrind
test.vghel: $(TESTS:%=%.vghelrun)
%.vghelrun: %.t
	$(call vgxrun,--tool=helgrind, $<)


# test with valgrind/drd
test.vgdrd: $(TESTS:%=%.vgdrdrun)
%.vgdrdrun: %.t
	$(call vgxrun,--tool=drd, $<)
166 167


168 169 170 171 172
# run python tests
PYTEST_IGNORE	:=  --ignore=3rdparty --ignore=build --ignore=t
test.py	: bigfile/_bigfile.so
	$(PYTEST) $(PYTEST_IGNORE)

173 174 175 176 177 178 179 180
# test.py via Valgrind (very slow)
test.py.vghel: bigfile/_bigfile.so
	$(call vgxrun,--tool=helgrind, $(PYTEST) $(PYTEST_IGNORE))

test.py.drd: bigfile/_bigfile.so
	$(call vgxrun,--tool=drd, $(PYTEST) $(PYTEST_IGNORE))


181

182 183 184 185 186 187 188 189
# test pagefault for double/real faults - it should crash
tfault	:= bigfile/tests/tfault
# XXX FAULTS extraction fragile
FAULTS	:= $(shell grep '{"fault.*"' $(tfault).c | sed 's/"/ /g' |awk '{print $$2}')
test.fault : $(FAULTS:%=%.tfault)

%.tfault : $(tfault).t
	t/tfault-run $< $* $(shell grep '{"$*"' $(tfault).c | awk '{print $$NF}')
190 191 192 193 194


# -*- benchmarking -*-
bench	: bigfile/_bigfile.so
	$(PYBENCH) $(PYTEST_IGNORE)