blob: bcf7e1fef116622d7bba6834806e78958c18f63d [file] [log] [blame]
Mike Frysinger7c830582013-02-02 19:49:00 -05001# Copyright 2018, Google Inc. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met:
6#
7# * Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9# * Redistributions in binary form must reproduce the above
10# copyright notice, this list of conditions and the following disclaimer
11# in the documentation and/or other materials provided with the
12# distribution.
13# * Neither the name of Google Inc. nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29top_srcdir ?= ..
30
31DEF_FLAGS = -g -pipe
32DEF_WFLAGS = -Wall
33CFLAGS ?= $(DEF_FLAGS)
34CXXFLAGS ?= $(DEF_FLAGS)
35CFLAGS += $(DEF_WFLAGS) -Wstrict-prototypes
36CXXFLAGS += $(DEF_WFLAGS)
37CPPFLAGS += -I$(top_srcdir)
38# We use static linking here so that if people run through qemu/etc... by hand,
39# it's a lot easier to run/debug. Same for strace output.
40LDFLAGS += -static
41
42TESTS = \
Joshua Peraza7bde79c2019-12-05 11:36:48 -080043 fallocate \
Joshua Perazabe2d5a82020-04-15 14:36:21 -070044 sigaction \
Joshua Peraza726d71e2019-11-13 12:21:13 -080045 sigtimedwait \
Mike Frysinger7c830582013-02-02 19:49:00 -050046 unlink \
47
48all: check
49
50%_test: %.c test_skel.h $(top_srcdir)/linux_syscall_support.h
51 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $<
52
53%_test: %.cc test_skel.h $(top_srcdir)/linux_syscall_support.h
54 $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $<
55
56%_run: %_test
57 @t=$(@:_run=_test); \
58 echo "./$$t"; \
59 if ! env -i ./$$t; then \
60 env -i strace -f -v ./$$t; \
61 echo "TRY: gdb -q -ex r -ex bt ./$$t"; \
62 exit 1; \
63 fi
64
65ALL_TEST_TARGETS = $(TESTS:=_test)
66compile_tests: $(ALL_TEST_TARGETS)
67
68ALL_RUN_TARGETS = $(TESTS:=_run)
69check: $(ALL_RUN_TARGETS)
70
71# The "tempfile" targets are the names we use with temp files.
72# Clean them out in case some tests crashed in the middle.
73clean:
74 rm -f *~ *.o tempfile.* a.out core $(ALL_TEST_TARGETS)
75
76.SUFFIXES:
77.PHONY: all check clean compile_tests
78.SECONDARY: $(ALL_TEST_TARGETS)
79
80# Try to cross-compile the tests for all our supported arches. We test with
81# both gcc and clang. We don't support execution (yet?), but just compiling
82# & linking helps catch common bugs.
83.PHONY: cross compile_cross
84cross_compile:
85 @echo "Running: $(MAKE) $@ CC='$(CC)' CXX='$(CXX)'"; \
86 if (echo '#include <stdio.h>' | $(CC) -x c -c -o /dev/null -) 2>/dev/null; then \
87 $(MAKE) -s clean; \
88 $(MAKE) -k --no-print-directory compile_tests; \
89 else \
90 echo "Skipping $(CC) test: not installed"; \
91 fi; \
92 echo
93
94# The names here are a best effort. Not easy to probe for.
95cross:
96 @for cc in \
97 "x86_64-pc-linux-gnu-gcc" \
98 "i686-pc-linux-gnu-gcc" \
99 "x86_64-pc-linux-gnu-gcc -mx32" \
100 "armv7a-unknown-linux-gnueabi-gcc -marm -mhard-float" \
101 "armv7a-unknown-linux-gnueabi-gcc -mthumb -mhard-float" \
102 "powerpc-unknown-linux-gnu-gcc" \
103 "aarch64-unknown-linux-gnu-gcc" \
104 "mips64-unknown-linux-gnu-gcc -mabi=64" \
105 "mips64-unknown-linux-gnu-gcc -mabi=32" \
106 "mips64-unknown-linux-gnu-gcc -mabi=n32" \
107 "s390-ibm-linux-gnu-gcc" \
108 "s390x-ibm-linux-gnu-gcc" \
109 ; do \
110 cxx=`echo "$$cc" | sed 's:-gcc:-g++:'`; \
111 $(MAKE) --no-print-directory CC="$$cc" CXX="$$cxx" cross_compile; \
112 \
113 sysroot=`$$cc --print-sysroot 2>/dev/null`; \
114 gccdir=`$$cc -print-file-name=libgcc.a 2>/dev/null`; \
115 gccdir=`dirname "$$gccdir"`; \
116 : Skip building for clang for mips/o32 and s390/31-bit until it works.; \
117 case $$cc in \
118 mips64*-mabi=32) continue;; \
119 s390-*) continue;; \
120 esac; \
121 set -- $$cc; \
122 tuple=$${1%-gcc}; \
123 shift; \
124 cc="clang -target $$tuple $$*"; \
125 : Assume the build system is x86_64 based, so ignore the sysroot.; \
126 case $$tuple in \
127 x86_64*) ;; \
128 *) cc="$$cc --sysroot $$sysroot -B$$gccdir -L$$gccdir";; \
129 esac; \
130 cxx=`echo "$$cc" | sed 's:^clang:clang++:'`; \
131 $(MAKE) --no-print-directory CC="$$cc" CXX="$$cxx" cross_compile; \
132 done