test/make/TestMakeBase.gmk
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 42134 bbcdb49521b1
child 44027 3a3050924db2
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill

#
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

default: all

include $(SPEC)
include MakeBase.gmk

THIS_FILE := $(SRC_ROOT)/test/make/TestMakeBase.gmk
DEPS := $(THIS_FILE) \
    $(SRC_ROOT)/make/common/MakeBase.gmk \
    #

# Assert two strings are equal
# 1 - Tested value
# 2 - Exepected value
# 3 - Error message
define assert-equals
  ifneq ($$(strip $1),$$(strip $2))
    $$(error $3 - Expected >$$(strip $2)< - Got >$$(strip $1)<)
  endif
endef

# On macosx, file system timestamps only have 1 second resultion so must add
# sleeps to properly test dependencies.
ifeq ($(OPENJDK_BUILD_OS), macosx)
  SLEEP_ON_MAC := sleep 1
endif

OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/make-base
$(call MakeDir, $(OUTPUT_DIR))

################################################################################
# Escape $
ifneq ($(call EscapeDollar, foo$$bar), foo\$$bar)
  $(error EscapeDollar failed $(call EscapeDollar, foo$$bar) foo\$$bar)
endif

ESCAPE_DOLLAR_DIR := $(OUTPUT_DIR)/escape-dollar

$(ESCAPE_DOLLAR_DIR)/_escape_dollar: $(DEPS)
	$(RM) -r $(@D)
	$(MKDIR) -p $(@D)
	$(ECHO) foo\$$bar > $(@D)/file1
	$(ECHO) $(call EscapeDollar, foo$$bar) > $(@D)/file2
	$(ECHO) $(call EscapeDollar, foo\$$bar) > $(@D)/file3
	$(DIFF) $(@D)/file1 $(@D)/file2
	$(DIFF) $(@D)/file1 $(@D)/file3
	$(TOUCH) $@

TEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar

################################################################################
# Test containing and not-containing

CONT_LIST := foo bar baz foobar foobaz

# Param 1 - string to look for
# Param 2 - expected result
define TestContaining
  value := $$(call containing, $1, $(CONT_LIST))
  ifneq ($$(value), $2)
    $$(info (call containing, $1, $(CONT_LIST)))
    $$(error result >$$(value)<, expected >$2<)
  endif
endef

$(eval $(call TestContaining,bar,bar foobar))
$(eval $(call TestContaining,foo bar,foo bar foobar foobaz))

# Param 1 - string to look for
# Param 2 - expected result
define TestNotContaining
  value := $$(call not-containing, $1, $(CONT_LIST))
  ifneq ($$(value), $2)
    $$(info (call not-containing, $1, $(CONT_LIST)))
    $$(error result >$$(value)<, expected >$2<)
  endif
endef

$(eval $(call TestNotContaining,bar,foo baz foobaz))
$(eval $(call TestNotContaining,foo bar,baz))

################################################################################
# Test Equals

EQUALS_VALUE1 := value1$(SPACE)
EQUALS_VALUE2 := value2

ifneq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE2)), )
  $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE2)< are equal)
endif

ifeq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE1)), )
  $(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE1)< are not equal)
endif

################################################################################
# Test remove-prefixes

$(eval $(call assert-equals, \
    $(call remove-prefixes, pre, prefix postfix), fix postfix, \
    Prefixes not properly removed))

$(eval $(call assert-equals, \
    $(call remove-prefixes, pre post, prefix postfix), fix fix, \
    Prefixes not properly removed))

################################################################################
# Test ShellQuote

SHELL_QUOTE_VALUE := foo '""' "''" bar
SHELL_QUOTE_RESULT := $(shell $(ECHO) $(call ShellQuote, \
    $(SHELL_QUOTE_VALUE)))

ifneq ($(SHELL_QUOTE_VALUE), $(SHELL_QUOTE_RESULT))
  $(error Expected: >$(SHELL_QUOTE_VALUE)< - Result: >$(SHELL_QUOTE_RESULT)<)
endif

################################################################################
# Test read and write to file

READ_WRITE_FILE := $(OUTPUT_DIR)/read-write
READ_WRITE_VALUE := foo '""' "''" \t\n\\ bar
$(call WriteFile, $(READ_WRITE_VALUE), $(READ_WRITE_FILE))
READ_WRITE_RESULT := $(call ReadFile, $(READ_WRITE_FILE))

ifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT))
  $(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<)
endif

################################################################################
# Test creating dependencies on make variables

VARDEP_DIR := $(OUTPUT_DIR)/vardep
VARDEP_SRC_FILE := $(VARDEP_DIR)/src-file
VARDEP_TARGET_FILE := $(VARDEP_DIR)/target-file
VARDEP_FLAG_FILE := $(VARDEP_DIR)/flag-file

$(VARDEP_DIR)/src-file:
	$(MKDIR) -p $(@D)
	$(ECHO) "some string XXX" > $@

$(VARDEP_TARGET_FILE): $(VARDEP_DIR)/src-file \
    $(call DependOnVariable, VARDEP_TEST_VAR)
	$(MKDIR) -p $(@D)
	$(SED) -e 's/XXX/$(VARDEP_TEST_VAR)/g' $< > $@
	$(TOUCH) $(VARDEP_FLAG_FILE)

test-vardep:
	$(RM) $(VARDEP_SRC_FILE) $(VARDEP_TARGET_FILE) $(VARDEP_FLAG_FILE)
        #
        # Simply create the target file and verify that it has the correct value
        #
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value1 $(VARDEP_TARGET_FILE)
	$(PRINTF) "Expecting value1: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`"
	test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`"
	test -e $(VARDEP_FLAG_FILE)
        #
        # Make the target file again and verify that the value is updated with 
        # the new value
        #
	$(SLEEP_ON_MAC)
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE)
	$(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`"
	test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`"
	test -e $(VARDEP_FLAG_FILE)
        #
        # Make the target again with the same value and verify that the recipe
        # was never run by checking that the flag file was not recreated
        #
	$(SLEEP_ON_MAC)
	$(RM) $(VARDEP_FLAG_FILE)
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE)
	$(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`"
	test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`"
	test ! -e $(VARDEP_FLAG_FILE)
        #
        # Test running with spaces at the end and the middle of the value
        # and verify that the file isn't rewritten the second time
        #
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3  foo " $(VARDEP_TARGET_FILE)
	$(RM) $(VARDEP_FLAG_FILE)
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo" $(VARDEP_TARGET_FILE)
	test ! -e $(VARDEP_FLAG_FILE)
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=" value3  foo" $(VARDEP_TARGET_FILE)
	test ! -e $(VARDEP_FLAG_FILE)
        #
        # Test including some problematic characters
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$ORIGIN' $(VARDEP_TARGET_FILE)
	$(RM) $(VARDEP_FLAG_FILE)
	$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$ORIGIN' $(VARDEP_TARGET_FILE)
	test ! -e $(VARDEP_FLAG_FILE)

# Test specifying a specific value file to store variable in
VARDEP_VALUE_FILE := $(VARDEP_DIR)/value-file
VARDEP_TEST_VAR2 := value3

VARDEP_RETURN_VALUE := $(call DependOnVariable, VARDEP_TEST_VAR2, $(VARDEP_VALUE_FILE))
$(eval $(call assert-equals, $(VARDEP_RETURN_VALUE), $(VARDEP_VALUE_FILE), \
    Wrong filename returned))
-include $(VARDEP_VALUE_FILE)
$(eval $(call assert-equals, $(VARDEP_TEST_VAR2_old), $(VARDEP_TEST_VAR2), \
    Wrong contents in vardeps file))

# Test with a variable value containing some problematic characters
VARDEP_TEST_VAR3 := foo '""' "''" bar \$$ORIGIN &\#x00a9
VARDEP_VALUE_FILE := $(call DependOnVariable, VARDEP_TEST_VAR3)
-include $(VARDEP_VALUE_FILE)
$(eval $(call assert-equals, $(call EscapeHash,$(VARDEP_TEST_VAR3_old)), \
    $(call EscapeHash,$(VARDEP_TEST_VAR3)), \
    Wrong contents in vardep file))

TEST_TARGETS += test-vardep

################################################################################
# Test sequence

ifneq ($(call sequence, 1, 1), 1)
  $(error Sequence 1, 1 should be "1", but was $(call sequence, 1, 1))
endif

ifneq ($(call sequence, 2, 3), 2 3)
  $(error Sequence 2, 3 should be "2 3", but was $(call sequence, 2, 3))
endif

ifneq ($(call sequence, 4, 9), 4 5 6 7 8 9)
  $(error Sequence 4, 9 should be "4 5 6 7 8 9", but was $(call sequence, 4, 9))
endif

ifneq ($(call sequence, 5, 15), 5 6 7 8 9 10 11 12 13 14 15)
  $(error Sequence 5, 15 should be "5 6 7 8 9 10 11 12 13 14 15", \
      but was $(call sequence, 5, 15))
endif

################################################################################
# Test that PathList is safe when called multiple nested times.

PATHLIST_INPUT := foo bar baz

$(eval $(call assert-equals, \
    $(call PathList, $(call PathList, $(PATHLIST_INPUT))), \
    $(call PathList, $(PATHLIST_INPUT)), \
    PathList call not safe for calling twice))

################################################################################
# Test FindCommonPathPrefix

$(eval $(call assert-equals, \
    $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/banan), \
    /foo/bar, \
    FindCommonPathPrefix, \
))

$(eval $(call assert-equals, \
    $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar), \
    /foo/bar, \
    FindCommonPathPrefix, \
))

$(eval $(call assert-equals, \
    $(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/), \
    /foo/bar, \
    FindCommonPathPrefix, \
))

$(eval $(call assert-equals, \
    $(call FindCommonPathPrefix, foo/bar/baz, foo/bar/banan), \
    foo/bar, \
    FindCommonPathPrefix, \
))

$(eval $(call assert-equals, \
    $(call FindCommonPathPrefix, foo/bar/baz, /foo/bar/banan), \
    , \
    FindCommonPathPrefix, \
))

################################################################################
# DirToDotDot

$(eval $(call assert-equals, \
    $(call DirToDotDot, foo/bar/baz/), \
    ../../.., \
    DirToDotDot, \
))

$(eval $(call assert-equals, \
    $(call DirToDotDot, foo/bar), \
    ../.., \
    DirToDotDot, \
))

$(eval $(call assert-equals, \
    $(call DirToDotDot, /foo), \
    .., \
    DirToDotDot, \
))

################################################################################
# RelativePath

$(eval $(call assert-equals, \
    $(call RelativePath, foo/bar/baz, foo/bar/banan), \
    ../baz, \
    RelativePath, \
))

$(eval $(call assert-equals, \
    $(call RelativePath, foo/bar/baz/banan/kung, foo/bar/banan/kung), \
    ../../baz/banan/kung, \
    RelativePath, \
))

$(eval $(call assert-equals, \
    $(call RelativePath, /foo/bar/baz/banan/kung, /foo/bar/banan/kung/), \
    ../../baz/banan/kung, \
    RelativePath, \
))

################################################################################

all: $(TEST_TARGETS)