TestMakeBase.gmk revision 2264:278f9a9e9329
1204917Sdes# 292555Sdes# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 376259Sgreen# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 476259Sgreen# 576259Sgreen# This code is free software; you can redistribute it and/or modify it 676259Sgreen# under the terms of the GNU General Public License version 2 only, as 776259Sgreen# published by the Free Software Foundation. Oracle designates this 876259Sgreen# particular file as subject to the "Classpath" exception as provided 976259Sgreen# by Oracle in the LICENSE file that accompanied this code. 1076259Sgreen# 1176259Sgreen# This code is distributed in the hope that it will be useful, but WITHOUT 1276259Sgreen# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1376259Sgreen# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1476259Sgreen# version 2 for more details (a copy is included in the LICENSE file that 1576259Sgreen# accompanied this code). 1676259Sgreen# 17162852Sdes# You should have received a copy of the GNU General Public License version 1876259Sgreen# 2 along with this work; if not, write to the Free Software Foundation, 19181111Sdes# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20204917Sdes# 21204917Sdes# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22137015Sdes# or visit www.oracle.com if you need additional information or have any 23162852Sdes# questions. 2492555Sdes# 2592555Sdes 26162852Sdesdefault: all 2792555Sdes 28include $(SPEC) 29include MakeBase.gmk 30 31THIS_FILE := $(SRC_ROOT)/test/make/TestMakeBase.gmk 32DEPS := $(THIS_FILE) \ 33 $(SRC_ROOT)/make/common/MakeBase.gmk \ 34 # 35 36# Assert two strings are equal 37# 1 - Tested value 38# 2 - Exepected value 39# 3 - Error message 40define assert-equals 41 ifneq ($$(strip $1),$$(strip $2)) 42 $$(error $3 - Expected >$$(strip $2)< - Got >$$(strip $1)<) 43 endif 44endef 45 46# On macosx, file system timestamps only have 1 second resultion so must add 47# sleeps to properly test dependencies. 48ifeq ($(OPENJDK_BUILD_OS), macosx) 49 SLEEP_ON_MAC := sleep 1 50endif 51 52OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/make-base 53$(call MakeDir, $(OUTPUT_DIR)) 54 55################################################################################ 56# Escape $ 57ifneq ($(call EscapeDollar, foo$$bar), foo\$$bar) 58 $(error EscapeDollar failed $(call EscapeDollar, foo$$bar) foo\$$bar) 59endif 60 61ESCAPE_DOLLAR_DIR := $(OUTPUT_DIR)/escape-dollar 62 63$(ESCAPE_DOLLAR_DIR)/_escape_dollar: $(DEPS) 64 $(RM) -r $(@D) 65 $(MKDIR) -p $(@D) 66 $(ECHO) foo\$$bar > $(@D)/file1 67 $(ECHO) $(call EscapeDollar, foo$$bar) > $(@D)/file2 68 $(ECHO) $(call EscapeDollar, foo\$$bar) > $(@D)/file3 69 $(DIFF) $(@D)/file1 $(@D)/file2 70 $(DIFF) $(@D)/file1 $(@D)/file3 71 $(TOUCH) $@ 72 73TEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar 74 75################################################################################ 76# Test containing and not-containing 77 78CONT_LIST := foo bar baz foobar foobaz 79 80# Param 1 - string to look for 81# Param 2 - expected result 82define TestContaining 83 value := $$(call containing, $1, $(CONT_LIST)) 84 ifneq ($$(value), $2) 85 $$(info (call containing, $1, $(CONT_LIST))) 86 $$(error result >$$(value)<, expected >$2<) 87 endif 88endef 89 90$(eval $(call TestContaining,bar,bar foobar)) 91$(eval $(call TestContaining,foo bar,foo bar foobar foobaz)) 92 93# Param 1 - string to look for 94# Param 2 - expected result 95define TestNotContaining 96 value := $$(call not-containing, $1, $(CONT_LIST)) 97 ifneq ($$(value), $2) 98 $$(info (call not-containing, $1, $(CONT_LIST))) 99 $$(error result >$$(value)<, expected >$2<) 100 endif 101endef 102 103$(eval $(call TestNotContaining,bar,foo baz foobaz)) 104$(eval $(call TestNotContaining,foo bar,baz)) 105 106################################################################################ 107# Test Equals 108 109EQUALS_VALUE1 := value1$(SPACE) 110EQUALS_VALUE2 := value2 111 112ifneq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE2)), ) 113 $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE2)< are equal) 114endif 115 116ifeq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE1)), ) 117 $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE1)< are not equal) 118endif 119 120################################################################################ 121# Test remove-prefixes 122 123$(eval $(call assert-equals, \ 124 $(call remove-prefixes, pre, prefix postfix), fix postfix, \ 125 Prefixes not properly removed)) 126 127$(eval $(call assert-equals, \ 128 $(call remove-prefixes, pre post, prefix postfix), fix fix, \ 129 Prefixes not properly removed)) 130 131################################################################################ 132# Test ShellQuote 133 134SHELL_QUOTE_VALUE := foo '""' "''" bar 135SHELL_QUOTE_RESULT := $(shell $(ECHO) $(call ShellQuote, \ 136 $(SHELL_QUOTE_VALUE))) 137 138ifneq ($(SHELL_QUOTE_VALUE), $(SHELL_QUOTE_RESULT)) 139 $(error Expected: >$(SHELL_QUOTE_VALUE)< - Result: >$(SHELL_QUOTE_RESULT)<) 140endif 141 142################################################################################ 143# Test read and write to file 144 145READ_WRITE_FILE := $(OUTPUT_DIR)/read-write 146READ_WRITE_VALUE := foo '""' "''" \t\n\\ bar 147$(call WriteFile, $(READ_WRITE_VALUE), $(READ_WRITE_FILE)) 148READ_WRITE_RESULT := $(call ReadFile, $(READ_WRITE_FILE)) 149 150ifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT)) 151 $(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<) 152endif 153 154################################################################################ 155# Test creating dependencies on make variables 156 157VARDEP_DIR := $(OUTPUT_DIR)/vardep 158VARDEP_SRC_FILE := $(VARDEP_DIR)/src-file 159VARDEP_TARGET_FILE := $(VARDEP_DIR)/target-file 160VARDEP_FLAG_FILE := $(VARDEP_DIR)/flag-file 161 162$(VARDEP_DIR)/src-file: 163 $(MKDIR) -p $(@D) 164 $(ECHO) "some string XXX" > $@ 165 166$(VARDEP_TARGET_FILE): $(VARDEP_DIR)/src-file \ 167 $(call DependOnVariable, VARDEP_TEST_VAR) 168 $(MKDIR) -p $(@D) 169 $(SED) -e 's/XXX/$(VARDEP_TEST_VAR)/g' $< > $@ 170 $(TOUCH) $(VARDEP_FLAG_FILE) 171 172test-vardep: 173 $(RM) $(VARDEP_SRC_FILE) $(VARDEP_TARGET_FILE) $(VARDEP_FLAG_FILE) 174 # 175 # Simply create the target file and verify that it has the correct value 176 # 177 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value1 $(VARDEP_TARGET_FILE) 178 $(PRINTF) "Expecting value1: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 179 test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`" 180 test -e $(VARDEP_FLAG_FILE) 181 # 182 # Make the target file again and verify that the value is updated with 183 # the new value 184 # 185 $(SLEEP_ON_MAC) 186 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) 187 $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 188 test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" 189 test -e $(VARDEP_FLAG_FILE) 190 # 191 # Make the target again with the same value and verify that the recipe 192 # was never run by checking that the flag file was not recreated 193 # 194 $(SLEEP_ON_MAC) 195 $(RM) $(VARDEP_FLAG_FILE) 196 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) 197 $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 198 test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" 199 test ! -e $(VARDEP_FLAG_FILE) 200 # 201 # Test running with spaces at the end and the middle of the value 202 # and verify that the file isn't rewritten the second time 203 # 204 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo " $(VARDEP_TARGET_FILE) 205 $(RM) $(VARDEP_FLAG_FILE) 206 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo" $(VARDEP_TARGET_FILE) 207 test ! -e $(VARDEP_FLAG_FILE) 208 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=" value3 foo" $(VARDEP_TARGET_FILE) 209 test ! -e $(VARDEP_FLAG_FILE) 210 # 211 # Test including some problematic characters 212 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$$$ORIGIN' $(VARDEP_TARGET_FILE) 213 $(RM) $(VARDEP_FLAG_FILE) 214 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$$$ORIGIN' $(VARDEP_TARGET_FILE) 215 test ! -e $(VARDEP_FLAG_FILE) 216 217# Test specifying a specific value file to store variable in 218VARDEP_VALUE_FILE := $(VARDEP_DIR)/value-file 219VARDEP_TEST_VAR2 := value3 220 221VARDEP_RETURN_VALUE := $(call DependOnVariable, VARDEP_TEST_VAR2, $(VARDEP_VALUE_FILE)) 222$(eval $(call assert-equals, $(VARDEP_RETURN_VALUE), $(VARDEP_VALUE_FILE), \ 223 Wrong filename returned)) 224-include $(VARDEP_VALUE_FILE) 225$(eval $(call assert-equals, $(VARDEP_TEST_VAR2_old), $(VARDEP_TEST_VAR2), \ 226 Wrong contents in vardeps file)) 227 228# Test with a variable value containing some problematic characters 229VARDEP_TEST_VAR3 := foo '""' "''" bar \$$ORIGIN 230VARDEP_VALUE_FILE := $(call DependOnVariable, VARDEP_TEST_VAR3) 231-include $(VARDEP_VALUE_FILE) 232$(eval $(call assert-equals, $(VARDEP_TEST_VAR3_old), $(VARDEP_TEST_VAR3), \ 233 Wrong contents in vardep file)) 234 235TEST_TARGETS += test-vardep 236 237################################################################################ 238# Test sequence 239 240ifneq ($(call sequence, 1, 1), 1) 241 $(error Sequence 1, 1 should be "1", but was $(call sequence, 1, 1)) 242endif 243 244ifneq ($(call sequence, 2, 3), 2 3) 245 $(error Sequence 2, 3 should be "2 3", but was $(call sequence, 2, 3)) 246endif 247 248ifneq ($(call sequence, 4, 9), 4 5 6 7 8 9) 249 $(error Sequence 4, 9 should be "4 5 6 7 8 9", but was $(call sequence, 4, 9)) 250endif 251 252ifneq ($(call sequence, 5, 15), 5 6 7 8 9 10 11 12 13 14 15) 253 $(error Sequence 5, 15 should be "5 6 7 8 9 10 11 12 13 14 15", \ 254 but was $(call sequence, 5, 15)) 255endif 256 257################################################################################ 258# Test that PathList is safe when called multiple nested times. 259 260PATHLIST_INPUT := foo bar baz 261 262$(eval $(call assert-equals, \ 263 $(call PathList, $(call PathList, $(PATHLIST_INPUT))), \ 264 $(call PathList, $(PATHLIST_INPUT)), \ 265 PathList call not safe for calling twice)) 266 267################################################################################ 268# Test FindCommonPathPrefix 269 270$(eval $(call assert-equals, \ 271 $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/banan), \ 272 /foo/bar, \ 273 FindCommonPathPrefix, \ 274)) 275 276$(eval $(call assert-equals, \ 277 $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar), \ 278 /foo/bar, \ 279 FindCommonPathPrefix, \ 280)) 281 282$(eval $(call assert-equals, \ 283 $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/), \ 284 /foo/bar, \ 285 FindCommonPathPrefix, \ 286)) 287 288$(eval $(call assert-equals, \ 289 $(call FindCommonPathPrefix, foo/bar/baz, foo/bar/banan), \ 290 foo/bar, \ 291 FindCommonPathPrefix, \ 292)) 293 294$(eval $(call assert-equals, \ 295 $(call FindCommonPathPrefix, foo/bar/baz, /foo/bar/banan), \ 296 , \ 297 FindCommonPathPrefix, \ 298)) 299 300################################################################################ 301# DirToDotDot 302 303$(eval $(call assert-equals, \ 304 $(call DirToDotDot, foo/bar/baz/), \ 305 ../../.., \ 306 DirToDotDot, \ 307)) 308 309$(eval $(call assert-equals, \ 310 $(call DirToDotDot, foo/bar), \ 311 ../.., \ 312 DirToDotDot, \ 313)) 314 315$(eval $(call assert-equals, \ 316 $(call DirToDotDot, /foo), \ 317 .., \ 318 DirToDotDot, \ 319)) 320 321################################################################################ 322# RelativePath 323 324$(eval $(call assert-equals, \ 325 $(call RelativePath, foo/bar/baz, foo/bar/banan), \ 326 ../baz, \ 327 RelativePath, \ 328)) 329 330$(eval $(call assert-equals, \ 331 $(call RelativePath, foo/bar/baz/banan/kung, foo/bar/banan/kung), \ 332 ../../baz/banan/kung, \ 333 RelativePath, \ 334)) 335 336$(eval $(call assert-equals, \ 337 $(call RelativePath, /foo/bar/baz/banan/kung, /foo/bar/banan/kung/), \ 338 ../../baz/banan/kung, \ 339 RelativePath, \ 340)) 341 342################################################################################ 343 344all: $(TEST_TARGETS) 345