TestMakeBase.gmk revision 1476:86c2383bb8e6
1# 2# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# This code is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License version 2 only, as 7# published by the Free Software Foundation. Oracle designates this 8# particular file as subject to the "Classpath" exception as provided 9# by Oracle in the LICENSE file that accompanied this code. 10# 11# This code is distributed in the hope that it will be useful, but WITHOUT 12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14# version 2 for more details (a copy is included in the LICENSE file that 15# accompanied this code). 16# 17# You should have received a copy of the GNU General Public License version 18# 2 along with this work; if not, write to the Free Software Foundation, 19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22# or visit www.oracle.com if you need additional information or have any 23# questions. 24# 25 26default: all 27 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 Equals 77 78EQUALS_VALUE1 := value1$(SPACE) 79EQUALS_VALUE2 := value2 80 81ifneq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE2)), ) 82 $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE2)< are equal) 83endif 84 85ifeq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE1)), ) 86 $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE1)< are not equal) 87endif 88 89################################################################################ 90# Test remove-prefixes 91 92$(eval $(call assert-equals, \ 93 $(call remove-prefixes, pre, prefix postfix), fix postfix, \ 94 Prefixes not properly removed)) 95 96$(eval $(call assert-equals, \ 97 $(call remove-prefixes, pre post, prefix postfix), fix fix, \ 98 Prefixes not properly removed)) 99 100################################################################################ 101# Test ShellQuote 102 103SHELL_QUOTE_VALUE := foo '""' "''" bar 104SHELL_QUOTE_RESULT := $(shell $(ECHO) $(call ShellQuote, \ 105 $(SHELL_QUOTE_VALUE))) 106 107ifneq ($(SHELL_QUOTE_VALUE), $(SHELL_QUOTE_RESULT)) 108 $(error Expected: >$(SHELL_QUOTE_VALUE)< - Result: >$(SHELL_QUOTE_RESULT)<) 109endif 110 111################################################################################ 112# Test read and write to file 113 114READ_WRITE_FILE := $(OUTPUT_DIR)/read-write 115READ_WRITE_VALUE := foo '""' "''" \t\n\\ bar 116$(call WriteFile, $(READ_WRITE_VALUE), $(READ_WRITE_FILE)) 117READ_WRITE_RESULT := $(call ReadFile, $(READ_WRITE_FILE)) 118 119ifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT)) 120 $(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<) 121endif 122 123################################################################################ 124# Test creating dependencies on make variables 125 126VARDEP_DIR := $(OUTPUT_DIR)/vardep 127VARDEP_SRC_FILE := $(VARDEP_DIR)/src-file 128VARDEP_TARGET_FILE := $(VARDEP_DIR)/target-file 129VARDEP_FLAG_FILE := $(VARDEP_DIR)/flag-file 130 131$(VARDEP_DIR)/src-file: 132 $(MKDIR) -p $(@D) 133 $(ECHO) "some string XXX" > $@ 134 135$(VARDEP_TARGET_FILE): $(VARDEP_DIR)/src-file \ 136 $(call DependOnVariable, VARDEP_TEST_VAR) 137 $(MKDIR) -p $(@D) 138 $(SED) -e 's/XXX/$(VARDEP_TEST_VAR)/g' $< > $@ 139 $(TOUCH) $(VARDEP_FLAG_FILE) 140 141test-vardep: 142 $(RM) $(VARDEP_SRC_FILE) $(VARDEP_TARGET_FILE) $(VARDEP_FLAG_FILE) 143 # 144 # Simply create the target file and verify that it has the correct value 145 # 146 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value1 $(VARDEP_TARGET_FILE) 147 $(PRINTF) "Expecting value1: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 148 test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`" 149 test -e $(VARDEP_FLAG_FILE) 150 # 151 # Make the target file again and verify that the value is updated with 152 # the new value 153 # 154 $(SLEEP_ON_MAC) 155 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) 156 $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 157 test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" 158 test -e $(VARDEP_FLAG_FILE) 159 # 160 # Make the target again with the same value and verify that the recipe 161 # was never run by checking that the flag file was not recreated 162 # 163 $(SLEEP_ON_MAC) 164 $(RM) $(VARDEP_FLAG_FILE) 165 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE) 166 $(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`" 167 test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`" 168 test ! -e $(VARDEP_FLAG_FILE) 169 # 170 # Test running with spaces at the end and the middle of the value 171 # and verify that the file isn't rewritten the second time 172 # 173 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo " $(VARDEP_TARGET_FILE) 174 $(RM) $(VARDEP_FLAG_FILE) 175 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo" $(VARDEP_TARGET_FILE) 176 test ! -e $(VARDEP_FLAG_FILE) 177 $(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=" value3 foo" $(VARDEP_TARGET_FILE) 178 test ! -e $(VARDEP_FLAG_FILE) 179 180# Test specifying a specific value file to store variable in 181VARDEP_VALUE_FILE := $(VARDEP_DIR)/value-file 182VARDEP_TEST_VAR2 := value3 183 184VARDEP_RETURN_VALUE := $(call DependOnVariable, VARDEP_TEST_VAR2, $(VARDEP_VALUE_FILE)) 185ifneq ($(VARDEP_VALUE_FILE), $(VARDEP_RETURN_VALUE)) 186 $(error Expected: $(VARDEP_VALUE_FILE) - DependOnVariable: $(VARDEP_RETURN_VALUE)) 187endif 188VARDEP_FILE_CONTENTS := $(shell $(CAT) $(VARDEP_VALUE_FILE)) 189ifneq ($(VARDEP_TEST_VAR2), $(VARDEP_FILE_CONTENTS)) 190 $(error Expected: $(VARDEP_TEST_VAR2) - DependOnVariable file contained: \ 191 $(VARDEP_FILE_CONTENTS)) 192endif 193 194# Test with a variable value containing some problematic characters 195VARDEP_TEST_VAR3 := foo '""' "''" bar 196VARDEP_VALUE_FILE := $(call DependOnVariable, VARDEP_TEST_VAR3) 197VARDEP_FILE_CONTENTS := $(shell $(CAT) $(VARDEP_VALUE_FILE)) 198ifneq ($(VARDEP_TEST_VAR3), $(VARDEP_FILE_CONTENTS)) 199 $(error Expected: >$(VARDEP_TEST_VAR3)< - DependOnVariable file contained: \ 200 >$(VARDEP_FILE_CONTENTS)<) 201endif 202 203TEST_TARGETS += test-vardep 204 205################################################################################ 206# Test sequence 207 208ifneq ($(call sequence, 1, 1), 1) 209 $(error Sequence 1, 1 should be "1", but was $(call sequence, 1, 1)) 210endif 211 212ifneq ($(call sequence, 2, 3), 2 3) 213 $(error Sequence 2, 3 should be "2 3", but was $(call sequence, 2, 3)) 214endif 215 216ifneq ($(call sequence, 4, 9), 4 5 6 7 8 9) 217 $(error Sequence 4, 9 should be "4 5 6 7 8 9", but was $(call sequence, 4, 9)) 218endif 219 220ifneq ($(call sequence, 5, 15), 5 6 7 8 9 10 11 12 13 14 15) 221 $(error Sequence 5, 15 should be "5 6 7 8 9 10 11 12 13 14 15", \ 222 but was $(call sequence, 5, 15)) 223endif 224 225all: $(TEST_TARGETS) 226