2015-03-04 21:41:31 +11:00
# This mimics the top-level Makefile. We do it explicitly here so that this
# Makefile can operate with or without the kbuild infrastructure.
CC := $( CROSS_COMPILE) gcc
2017-03-01 15:15:07 -07:00
i f e q ( 0 , $( MAKELEVEL ) )
2019-04-15 15:51:42 -06:00
ifneq ( $( O) ,)
OUTPUT := $( O)
else
ifneq ( $( KBUILD_OUTPUT) ,)
OUTPUT := $( KBUILD_OUTPUT)
else
OUTPUT := $( shell pwd )
DEFAULT_INSTALL_HDR_PATH := 1
endif
endif
2017-03-01 15:15:07 -07:00
e n d i f
2017-09-11 13:06:33 -06:00
# The following are built by lib.mk common compile rules.
# TEST_CUSTOM_PROGS should be used by tests that require
# custom build rule and prevent common build rule use.
# TEST_PROGS are for test shell scripts.
# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
# and install targets. Common clean doesn't touch them.
2017-02-09 19:56:26 +11:00
TEST_GEN_PROGS := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_PROGS) )
2017-09-06 18:36:22 -06:00
TEST_GEN_PROGS_EXTENDED := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_PROGS_EXTENDED) )
2017-02-09 19:56:26 +11:00
TEST_GEN_FILES := $( patsubst %,$( OUTPUT) /%,$( TEST_GEN_FILES) )
2018-12-12 20:25:14 -07:00
i f d e f K S F T _ K H D R _ I N S T A L L
2018-09-04 12:47:21 +02:00
top_srcdir ?= ../../../..
i n c l u d e $( top_srcdir ) / s c r i p t s / s u b a r c h . i n c l u d e
ARCH ?= $( SUBARCH)
2019-04-15 15:51:42 -06:00
# set default goal to all, so make without a target runs all, even when
# all isn't the first target in the file.
.DEFAULT_GOAL := all
# Invoke headers install with --no-builtin-rules to avoid circular
# dependency in "make kselftest" case. In this case, second level
# make inherits builtin-rules which will use the rule generate
# Makefile.o and runs into
# "Circular Makefile.o <- prepare dependency dropped."
# and headers_install fails and test compile fails.
# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
# invokes them as sub-makes and --no-builtin-rules is not necessary,
# but doesn't cause any failures. Keep it simple and use the same
# flags in both cases.
# Note that the support to install headers from lib.mk is necessary
# when test Makefile is run directly with "make -C".
# When local build is done, headers are installed in the default
# INSTALL_HDR_PATH usr/include.
2018-09-04 12:47:21 +02:00
.PHONY : khdr
khdr :
2019-04-15 15:51:42 -06:00
i f n d e f K S F T _ K H D R _ I N S T A L L _ D O N E
i f e q ( 1 , $( DEFAULT_INSTALL_HDR_PATH ) )
make --no-builtin-rules ARCH = $( ARCH) -C $( top_srcdir) headers_install
e l s e
make --no-builtin-rules INSTALL_HDR_PATH = $$ OUTPUT/usr \
ARCH = $( ARCH) -C $( top_srcdir) headers_install
e n d i f
e n d i f
2018-09-04 12:47:21 +02:00
2018-12-12 20:25:14 -07:00
all : khdr $( TEST_GEN_PROGS ) $( TEST_GEN_PROGS_EXTENDED ) $( TEST_GEN_FILES )
e l s e
all : $( TEST_GEN_PROGS ) $( TEST_GEN_PROGS_EXTENDED ) $( TEST_GEN_FILES )
2018-09-04 12:47:21 +02:00
e n d i f
2017-08-23 18:46:00 -06:00
.ONESHELL :
2018-04-25 09:32:20 -06:00
d e f i n e R U N _ T E S T _ P R I N T _ R E S U L T
2018-04-25 17:45:48 -06:00
TEST_HDR_MSG = "selftests: " ` basename $$ PWD` :" $$ BASENAME_TEST " ; \
echo $$ TEST_HDR_MSG; \
2018-04-25 09:32:20 -06:00
echo "========================================" ; \
if [ ! -x $$ TEST ] ; then \
2018-04-25 17:45:48 -06:00
echo " $$ TEST_HDR_MSG: Warning: file $$ BASENAME_TEST is not executable, correct this. " ; \
echo " not ok 1.. $$ test_num $$ TEST_HDR_MSG [FAIL] " ; \
2018-04-25 09:32:20 -06:00
else \
cd ` dirname $$ TEST` > /dev/null; \
if [ " X $( summary) " != "X" ] ; then \
( ./$$ BASENAME_TEST > /tmp/$$ BASENAME_TEST 2>& 1 && \
2018-04-25 17:45:48 -06:00
echo " ok 1.. $$ test_num $$ TEST_HDR_MSG [PASS] " ) || \
2018-04-25 09:32:20 -06:00
( if [ $$ ? -eq $$ skip ] ; then \
2018-04-25 17:45:48 -06:00
echo " not ok 1.. $$ test_num $$ TEST_HDR_MSG [SKIP] " ; \
else echo " not ok 1.. $$ test_num $$ TEST_HDR_MSG [FAIL] " ; \
2018-04-25 09:32:20 -06:00
fi ; ) \
else \
( ./$$ BASENAME_TEST && \
2018-04-25 17:45:48 -06:00
echo " ok 1.. $$ test_num $$ TEST_HDR_MSG [PASS] " ) || \
2018-04-25 09:32:20 -06:00
( if [ $$ ? -eq $$ skip ] ; then \
2018-04-25 17:45:48 -06:00
echo " not ok 1.. $$ test_num $$ TEST_HDR_MSG [SKIP] " ; \
else echo " not ok 1.. $$ test_num $$ TEST_HDR_MSG [FAIL] " ; \
2018-04-25 09:32:20 -06:00
fi ; ) \
fi ; \
cd - > /dev/null; \
fi ;
e n d e f
2015-03-11 15:05:59 +11:00
d e f i n e R U N _ T E S T S
2018-04-27 17:55:41 -04:00
@export KSFT_TAP_LEVEL = ` echo 1` ; \
test_num = ` echo 0` ; \
2018-04-24 14:57:36 -06:00
skip = ` echo 4` ; \
2018-04-27 17:55:41 -04:00
echo "TAP version 13" ; \
for TEST in $( 1) ; do \
2016-11-29 19:55:52 +08:00
BASENAME_TEST = ` basename $$ TEST` ; \
2017-08-23 18:46:00 -06:00
test_num = ` echo $$ test_num+1 | bc` ; \
2018-04-25 09:32:20 -06:00
$( call RUN_TEST_PRINT_RESULT,$( TEST) ,$( BASENAME_TEST) ,$( test_num) ,$( skip) ) \
2015-03-11 15:05:59 +11:00
done ;
e n d e f
run_tests : all
2017-09-11 19:03:11 -06:00
i f n e q ( $( KBUILD_SRC ) , )
@if [ " X $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) " != "X" ] ; then
@rsync -aq $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) $( OUTPUT)
fi
@if [ " X $( TEST_PROGS) " != "X" ] ; then
$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( OUTPUT) /$( TEST_PROGS) )
else
$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) )
fi
e l s e
2017-09-11 13:06:33 -06:00
$( call RUN_TESTS, $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_PROGS) )
2017-09-11 19:03:11 -06:00
e n d i f
2015-03-11 15:05:59 +11:00
2015-03-11 15:06:00 +11:00
d e f i n e I N S T A L L _ R U L E
2015-09-09 21:06:28 +08:00
@if [ " X $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) " != "X" ] ; then \
mkdir -p ${ INSTALL_PATH } ; \
2016-11-29 19:55:48 +08:00
echo " rsync -a $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) $( INSTALL_PATH) / " ; \
rsync -a $( TEST_PROGS) $( TEST_PROGS_EXTENDED) $( TEST_FILES) $( INSTALL_PATH) /; \
2016-11-29 19:55:47 +08:00
fi
2017-09-11 13:06:33 -06:00
@if [ " X $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) " != "X" ] ; then \
2016-11-29 19:55:47 +08:00
mkdir -p ${ INSTALL_PATH } ; \
2017-09-11 13:06:33 -06:00
echo " rsync -a $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) $( INSTALL_PATH) / " ; \
rsync -a $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) $( INSTALL_PATH) /; \
2015-08-14 21:43:35 +08:00
fi
2015-03-11 15:06:00 +11:00
e n d e f
install : all
i f d e f I N S T A L L _ P A T H
$( INSTALL_RULE)
e l s e
$( error Error: set INSTALL_PATH to use install)
e n d i f
d e f i n e E M I T _ T E S T S
2018-05-01 12:15:34 -06:00
@test_num= ` echo 0` ; \
for TEST in $( TEST_GEN_PROGS) $( TEST_CUSTOM_PROGS) $( TEST_PROGS) ; do \
2016-11-29 19:55:52 +08:00
BASENAME_TEST = ` basename $$ TEST` ; \
2018-05-01 12:15:34 -06:00
test_num = ` echo $$ test_num+1 | bc` ; \
TEST_HDR_MSG = "selftests: " ` basename $$ PWD` :" $$ BASENAME_TEST " ; \
echo " echo $$ TEST_HDR_MSG " ; \
2018-05-01 14:38:47 -06:00
if [ ! -x $$ TEST ] ; then \
echo " echo \" $$ TEST_HDR_MSG: Warning: file $$ BASENAME_TEST is not executable, correct this.\" " ; \
echo " echo \"not ok 1.. $$ test_num $$ TEST_HDR_MSG [FAIL]\" " ; \
else
echo " (./ $$ BASENAME_TEST >> \$ $OUTPUT 2>&1 && echo \"ok 1.. $$ test_num $$ TEST_HDR_MSG [PASS]\") || (if [ \$ $? -eq \$ $skip ]; then echo \"not ok 1.. $$ test_num $$ TEST_HDR_MSG [SKIP]\"; else echo \"not ok 1.. $$ test_num $$ TEST_HDR_MSG [FAIL]\"; fi;) " ; \
fi ; \
2015-03-11 15:06:00 +11:00
done ;
e n d e f
emit_tests :
$( EMIT_TESTS)
2017-09-06 18:36:22 -06:00
# define if isn't already. It is undefined in make O= case.
i f e q ( $( RM ) , )
RM := rm -f
e n d i f
2017-04-21 16:07:51 -06:00
d e f i n e C L E A N
2016-11-29 19:55:51 +08:00
$( RM) -r $( TEST_GEN_PROGS) $( TEST_GEN_PROGS_EXTENDED) $( TEST_GEN_FILES) $( EXTRA_CLEAN)
2017-04-21 16:07:51 -06:00
e n d e f
clean :
$( CLEAN)
2016-11-29 19:55:47 +08:00
2017-09-06 18:36:22 -06:00
# When make O= with kselftest target from main level
# the following aren't defined.
#
i f n e q ( $( KBUILD_SRC ) , )
LINK.c = $( CC) $( CFLAGS) $( CPPFLAGS) $( LDFLAGS) $( TARGET_ARCH)
COMPILE.S = $( CC) $( ASFLAGS) $( CPPFLAGS) $( TARGET_ARCH) -c
LINK.S = $( CC) $( ASFLAGS) $( CPPFLAGS) $( LDFLAGS) $( TARGET_ARCH)
e n d i f
2018-06-02 08:44:03 -04:00
# Selftest makefiles can override those targets by setting
# OVERRIDE_TARGETS = 1.
i f e q ( $( OVERRIDE_TARGETS ) , )
2016-11-29 19:55:52 +08:00
$(OUTPUT)/% : %.c
2017-02-09 19:56:27 +11:00
$( LINK.c) $^ $( LDLIBS) -o $@
2016-11-29 19:55:52 +08:00
$(OUTPUT)/%.o : %.S
2017-02-09 19:56:28 +11:00
$( COMPILE.S) $^ -o $@
2016-11-29 19:55:52 +08:00
$(OUTPUT)/% : %.S
2017-02-09 19:56:28 +11:00
$( LINK.S) $^ $( LDLIBS) -o $@
2018-06-02 08:44:03 -04:00
e n d i f
2016-11-29 19:55:49 +08:00
2015-03-11 15:06:00 +11:00
.PHONY : run_tests all clean install emit_tests