TestMakeBase.gmk revision 2333:5a206e2ff241
133965Sjdp# 2218822Sdim# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3130561Sobrien# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 433965Sjdp# 533965Sjdp# This code is free software; you can redistribute it and/or modify it 633965Sjdp# under the terms of the GNU General Public License version 2 only, as 733965Sjdp# published by the Free Software Foundation. Oracle designates this 833965Sjdp# particular file as subject to the "Classpath" exception as provided 933965Sjdp# by Oracle in the LICENSE file that accompanied this code. 1033965Sjdp# 1133965Sjdp# This code is distributed in the hope that it will be useful, but WITHOUT 1233965Sjdp# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1333965Sjdp# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1433965Sjdp# version 2 for more details (a copy is included in the LICENSE file that 1533965Sjdp# accompanied this code). 1633965Sjdp# 1733965Sjdp# You should have received a copy of the GNU General Public License version 1833965Sjdp# 2 along with this work; if not, write to the Free Software Foundation, 1933965Sjdp# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20218822Sdim# 21218822Sdim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2233965Sjdp# or visit www.oracle.com if you need additional information or have any 2333965Sjdp# questions. 2433965Sjdp# 2533965Sjdp 26218822Sdimdefault: all 2733965Sjdp 2833965Sjdpinclude $(SPEC) 2933965Sjdpinclude MakeBase.gmk 3089857Sobrien 31218822SdimTHIS_FILE := $(SRC_ROOT)/test/make/TestMakeBase.gmk 3233965SjdpDEPS := $(THIS_FILE) \ 3333965Sjdp $(SRC_ROOT)/make/common/MakeBase.gmk \ 3433965Sjdp # 3533965Sjdp 3633965Sjdp# Assert two strings are equal 3733965Sjdp# 1 - Tested value 3833965Sjdp# 2 - Exepected value 3933965Sjdp# 3 - Error message 4033965Sjdpdefine assert-equals 4133965Sjdp ifneq ($$(strip $1),$$(strip $2)) 4233965Sjdp $$(error $3 - Expected >$$(strip $2)< - Got >$$(strip $1)<) 4333965Sjdp endif 4433965Sjdpendef 4533965Sjdp 4633965Sjdp# On macosx, file system timestamps only have 1 second resultion so must add 4733965Sjdp# sleeps to properly test dependencies. 4833965Sjdpifeq ($(OPENJDK_BUILD_OS), macosx) 4933965Sjdp SLEEP_ON_MAC := sleep 1 5033965Sjdpendif 5133965Sjdp 5233965SjdpOUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/make-base 5333965Sjdp$(call MakeDir, $(OUTPUT_DIR)) 5433965Sjdp 5533965Sjdp################################################################################ 5633965Sjdp# Escape $ 5733965Sjdpifneq ($(call EscapeDollar, foo$$bar), foo\$$bar) 5833965Sjdp $(error EscapeDollar failed $(call EscapeDollar, foo$$bar) foo\$$bar) 5933965Sjdpendif 6033965Sjdp 6133965SjdpESCAPE_DOLLAR_DIR := $(OUTPUT_DIR)/escape-dollar 6233965Sjdp 6333965Sjdp$(ESCAPE_DOLLAR_DIR)/_escape_dollar: $(DEPS) 6433965Sjdp $(RM) -r $(@D) 6533965Sjdp $(MKDIR) -p $(@D) 6633965Sjdp $(ECHO) foo\$$bar > $(@D)/file1 6733965Sjdp $(ECHO) $(call EscapeDollar, foo$$bar) > $(@D)/file2 6833965Sjdp $(ECHO) $(call EscapeDollar, foo\$$bar) > $(@D)/file3 6933965Sjdp $(DIFF) $(@D)/file1 $(@D)/file2 7033965Sjdp $(DIFF) $(@D)/file1 $(@D)/file3 7133965Sjdp $(TOUCH) $@ 7233965Sjdp 7333965SjdpTEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar 74130561Sobrien 7533965Sjdp################################################################################ 7633965Sjdp# Test containing and not-containing 7733965Sjdp 7833965SjdpCONT_LIST := foo bar baz foobar foobaz 7933965Sjdp 8033965Sjdp# Param 1 - string to look for 8133965Sjdp# Param 2 - expected result 8233965Sjdpdefine TestContaining 8333965Sjdp value := $$(call containing, $1, $(CONT_LIST)) 8433965Sjdp ifneq ($$(value), $2) 8533965Sjdp $$(info (call containing, $1, $(CONT_LIST))) 8633965Sjdp $$(error result >$$(value)<, expected >$2<) 8733965Sjdp endif 8833965Sjdpendef 8933965Sjdp 9033965Sjdp$(eval $(call TestContaining,bar,bar foobar)) 9133965Sjdp$(eval $(call TestContaining,foo bar,foo bar foobar foobaz)) 9233965Sjdp 9333965Sjdp# Param 1 - string to look for 9433965Sjdp# Param 2 - expected result 9533965Sjdpdefine TestNotContaining 9633965Sjdp value := $$(call not-containing, $1, $(CONT_LIST)) 9733965Sjdp ifneq ($$(value), $2) 9833965Sjdp $$(info (call not-containing, $1, $(CONT_LIST))) 9933965Sjdp $$(error result >$$(value)<, expected >$2<) 10033965Sjdp endif 10133965Sjdpendef 10233965Sjdp 10333965Sjdp$(eval $(call TestNotContaining,bar,foo baz foobaz)) 10433965Sjdp$(eval $(call TestNotContaining,foo bar,baz)) 10533965Sjdp 10633965Sjdp################################################################################ 10733965Sjdp# Test Equals 10833965Sjdp 10933965SjdpEQUALS_VALUE1 := value1$(SPACE) 11033965SjdpEQUALS_VALUE2 := value2 11133965Sjdp 11233965Sjdpifneq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE2)), ) 11333965Sjdp $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE2)< are equal) 11433965Sjdpendif 11533965Sjdp 11633965Sjdpifeq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE1)), ) 11733965Sjdp $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE1)< are not equal) 11833965Sjdpendif 11933965Sjdp 12033965Sjdp################################################################################ 12133965Sjdp# Test remove-prefixes 12233965Sjdp 12333965Sjdp$(eval $(call assert-equals, \ 12433965Sjdp $(call remove-prefixes, pre, prefix postfix), fix postfix, \ 12533965Sjdp Prefixes not properly removed)) 12633965Sjdp 12733965Sjdp$(eval $(call assert-equals, \ 12833965Sjdp $(call remove-prefixes, pre post, prefix postfix), fix fix, \ 12933965Sjdp Prefixes not properly removed)) 13033965Sjdp 13133965Sjdp################################################################################ 13233965Sjdp# Test ShellQuote 13333965Sjdp 13433965SjdpSHELL_QUOTE_VALUE := foo '""' "''" bar 13533965SjdpSHELL_QUOTE_RESULT := $(shell $(ECHO) $(call ShellQuote, \ 13633965Sjdp $(SHELL_QUOTE_VALUE))) 13733965Sjdp 13833965Sjdpifneq ($(SHELL_QUOTE_VALUE), $(SHELL_QUOTE_RESULT)) 13933965Sjdp $(error Expected: >$(SHELL_QUOTE_VALUE)< - Result: >$(SHELL_QUOTE_RESULT)<) 14033965Sjdpendif 14133965Sjdp 14233965Sjdp################################################################################ 14333965Sjdp# Test read and write to file 14433965Sjdp 14533965SjdpREAD_WRITE_FILE := $(OUTPUT_DIR)/read-write 14633965SjdpREAD_WRITE_VALUE := foo '""' "''" \t\n\\ bar 14733965Sjdp$(call WriteFile, $(READ_WRITE_VALUE), $(READ_WRITE_FILE)) 14833965SjdpREAD_WRITE_RESULT := $(call ReadFile, $(READ_WRITE_FILE)) 14933965Sjdp 15033965Sjdpifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT)) 15133965Sjdp $(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<) 15233965Sjdpendif 15333965Sjdp 15433965Sjdp################################################################################ 15533965Sjdp# Test creating dependencies on make variables 15633965Sjdp 15733965SjdpVARDEP_DIR := $(OUTPUT_DIR)/vardep 15833965SjdpVARDEP_SRC_FILE := $(VARDEP_DIR)/src-file 15933965SjdpVARDEP_TARGET_FILE := $(VARDEP_DIR)/target-file 16033965SjdpVARDEP_FLAG_FILE := $(VARDEP_DIR)/flag-file 16133965Sjdp 16233965Sjdp$(VARDEP_DIR)/src-file: 16333965Sjdp $(MKDIR) -p $(@D) 16433965Sjdp $(ECHO) "some string XXX" > $@ 16533965Sjdp 16633965Sjdp$(VARDEP_TARGET_FILE): $(VARDEP_DIR)/src-file \ 16733965Sjdp $(call DependOnVariable, VARDEP_TEST_VAR) 16833965Sjdp $(MKDIR) -p $(@D) 16933965Sjdp $(SED) -e 's/XXX/$(VARDEP_TEST_VAR)/g' $< > $@ 17033965Sjdp $(TOUCH) $(VARDEP_FLAG_FILE) 17133965Sjdp 17233965Sjdptest-vardep: 17333965Sjdp $(RM) $(VARDEP_SRC_FILE) $(VARDEP_TARGET_FILE) $(VARDEP_FLAG_FILE) 17433965Sjdp # 175130561Sobrien # Simply create the target file and verify that it has the correct value 176130561Sobrien # 177130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value1 $(VARDEP_TARGET_FILE) 178130561Sobrien $(PRINTF) "Expecting value1: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 179130561Sobrien test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`" 180130561Sobrien test -e $(VARDEP_FLAG_FILE) 181130561Sobrien # 182130561Sobrien # Make the target file again and verify that the value is updated with 183130561Sobrien # the new value 184130561Sobrien # 18533965Sjdp $(SLEEP_ON_MAC) 186130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) 187130561Sobrien $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 188130561Sobrien test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" 189130561Sobrien test -e $(VARDEP_FLAG_FILE) 190130561Sobrien # 191130561Sobrien # Make the target again with the same value and verify that the recipe 192130561Sobrien # was never run by checking that the flag file was not recreated 193130561Sobrien # 194130561Sobrien $(SLEEP_ON_MAC) 195130561Sobrien $(RM) $(VARDEP_FLAG_FILE) 196130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) 197130561Sobrien $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 198130561Sobrien test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" 199130561Sobrien test ! -e $(VARDEP_FLAG_FILE) 200130561Sobrien # 201130561Sobrien # Test running with spaces at the end and the middle of the value 202130561Sobrien # and verify that the file isn't rewritten the second time 203130561Sobrien # 204130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo " $(VARDEP_TARGET_FILE) 205130561Sobrien $(RM) $(VARDEP_FLAG_FILE) 206130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo" $(VARDEP_TARGET_FILE) 207130561Sobrien test ! -e $(VARDEP_FLAG_FILE) 208130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=" value3 foo" $(VARDEP_TARGET_FILE) 209130561Sobrien test ! -e $(VARDEP_FLAG_FILE) 210130561Sobrien # 211130561Sobrien # Test including some problematic characters 212130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$ORIGIN' $(VARDEP_TARGET_FILE) 213130561Sobrien $(RM) $(VARDEP_FLAG_FILE) 214130561Sobrien $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$ORIGIN' $(VARDEP_TARGET_FILE) 215130561Sobrien test ! -e $(VARDEP_FLAG_FILE) 216130561Sobrien 217130561Sobrien# Test specifying a specific value file to store variable in 218130561SobrienVARDEP_VALUE_FILE := $(VARDEP_DIR)/value-file 219130561SobrienVARDEP_TEST_VAR2 := value3 220130561Sobrien 221130561SobrienVARDEP_RETURN_VALUE := $(call DependOnVariable, VARDEP_TEST_VAR2, $(VARDEP_VALUE_FILE)) 222130561Sobrien$(eval $(call assert-equals, $(VARDEP_RETURN_VALUE), $(VARDEP_VALUE_FILE), \ 223130561Sobrien Wrong filename returned)) 224130561Sobrien-include $(VARDEP_VALUE_FILE) 225130561Sobrien$(eval $(call assert-equals, $(VARDEP_TEST_VAR2_old), $(VARDEP_TEST_VAR2), \ 226130561Sobrien Wrong contents in vardeps file)) 227130561Sobrien 228130561Sobrien# Test with a variable value containing some problematic characters 229130561SobrienVARDEP_TEST_VAR3 := foo '""' "''" bar \$$ORIGIN &\#x00a9 230130561SobrienVARDEP_VALUE_FILE := $(call DependOnVariable, VARDEP_TEST_VAR3) 231130561Sobrien-include $(VARDEP_VALUE_FILE) 232130561Sobrien$(eval $(call assert-equals, $(call EscapeHash,$(VARDEP_TEST_VAR3_old)), \ 233130561Sobrien $(call EscapeHash,$(VARDEP_TEST_VAR3)), \ 234130561Sobrien Wrong contents in vardep file)) 235130561Sobrien 236130561SobrienTEST_TARGETS += test-vardep 237130561Sobrien 238130561Sobrien################################################################################ 239130561Sobrien# Test sequence 240130561Sobrien 241130561Sobrienifneq ($(call sequence, 1, 1), 1) 242130561Sobrien $(error Sequence 1, 1 should be "1", but was $(call sequence, 1, 1)) 243130561Sobrienendif 244130561Sobrien 245130561Sobrienifneq ($(call sequence, 2, 3), 2 3) 246130561Sobrien $(error Sequence 2, 3 should be "2 3", but was $(call sequence, 2, 3)) 247130561Sobrienendif 248130561Sobrien 24933965Sjdpifneq ($(call sequence, 4, 9), 4 5 6 7 8 9) 25033965Sjdp $(error Sequence 4, 9 should be "4 5 6 7 8 9", but was $(call sequence, 4, 9)) 25133965Sjdpendif 25233965Sjdp 25333965Sjdpifneq ($(call sequence, 5, 15), 5 6 7 8 9 10 11 12 13 14 15) 25433965Sjdp $(error Sequence 5, 15 should be "5 6 7 8 9 10 11 12 13 14 15", \ 25533965Sjdp but was $(call sequence, 5, 15)) 25633965Sjdpendif 25733965Sjdp 25833965Sjdp################################################################################ 25933965Sjdp# Test that PathList is safe when called multiple nested times. 26033965Sjdp 26133965SjdpPATHLIST_INPUT := foo bar baz 26233965Sjdp 26333965Sjdp$(eval $(call assert-equals, \ 26433965Sjdp $(call PathList, $(call PathList, $(PATHLIST_INPUT))), \ 26533965Sjdp $(call PathList, $(PATHLIST_INPUT)), \ 26633965Sjdp PathList call not safe for calling twice)) 26733965Sjdp 26833965Sjdp################################################################################ 26933965Sjdp# Test FindCommonPathPrefix 27033965Sjdp 27133965Sjdp$(eval $(call assert-equals, \ 27233965Sjdp $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/banan), \ 27333965Sjdp /foo/bar, \ 27433965Sjdp FindCommonPathPrefix, \ 27533965Sjdp)) 27633965Sjdp 27733965Sjdp$(eval $(call assert-equals, \ 27833965Sjdp $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar), \ 27933965Sjdp /foo/bar, \ 28033965Sjdp FindCommonPathPrefix, \ 28133965Sjdp)) 28233965Sjdp 28333965Sjdp$(eval $(call assert-equals, \ 28433965Sjdp $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/), \ 28533965Sjdp /foo/bar, \ 28633965Sjdp FindCommonPathPrefix, \ 28733965Sjdp)) 28833965Sjdp 28933965Sjdp$(eval $(call assert-equals, \ 29033965Sjdp $(call FindCommonPathPrefix, foo/bar/baz, foo/bar/banan), \ 29133965Sjdp foo/bar, \ 29233965Sjdp FindCommonPathPrefix, \ 29333965Sjdp)) 29433965Sjdp 29533965Sjdp$(eval $(call assert-equals, \ 29633965Sjdp $(call FindCommonPathPrefix, foo/bar/baz, /foo/bar/banan), \ 29733965Sjdp , \ 29833965Sjdp FindCommonPathPrefix, \ 29933965Sjdp)) 30033965Sjdp 301130561Sobrien################################################################################ 302130561Sobrien# DirToDotDot 30333965Sjdp 30433965Sjdp$(eval $(call assert-equals, \ 30533965Sjdp $(call DirToDotDot, foo/bar/baz/), \ 30633965Sjdp ../../.., \ 30733965Sjdp DirToDotDot, \ 30833965Sjdp)) 30933965Sjdp 31033965Sjdp$(eval $(call assert-equals, \ 31133965Sjdp $(call DirToDotDot, foo/bar), \ 31233965Sjdp ../.., \ 31333965Sjdp DirToDotDot, \ 31433965Sjdp)) 31533965Sjdp 31633965Sjdp$(eval $(call assert-equals, \ 31733965Sjdp $(call DirToDotDot, /foo), \ 31833965Sjdp .., \ 31933965Sjdp DirToDotDot, \ 32033965Sjdp)) 32133965Sjdp 32233965Sjdp################################################################################ 32333965Sjdp# RelativePath 32433965Sjdp 32533965Sjdp$(eval $(call assert-equals, \ 32633965Sjdp $(call RelativePath, foo/bar/baz, foo/bar/banan), \ 32733965Sjdp ../baz, \ 32833965Sjdp RelativePath, \ 32933965Sjdp)) 33033965Sjdp 33133965Sjdp$(eval $(call assert-equals, \ 33233965Sjdp $(call RelativePath, foo/bar/baz/banan/kung, foo/bar/banan/kung), \ 33333965Sjdp ../../baz/banan/kung, \ 33433965Sjdp RelativePath, \ 33533965Sjdp)) 33633965Sjdp 337130561Sobrien$(eval $(call assert-equals, \ 338130561Sobrien $(call RelativePath, /foo/bar/baz/banan/kung, /foo/bar/banan/kung/), \ 339130561Sobrien ../../baz/banan/kung, \ 34033965Sjdp RelativePath, \ 34133965Sjdp)) 34233965Sjdp 34333965Sjdp################################################################################ 34433965Sjdp 34533965Sjdpall: $(TEST_TARGETS) 34633965Sjdp