6954064: Fix the windows arch settings in the makefiles and chmod logic in test/Makefile

Reviewed-by: wetmore
diff --git a/jdk/test/Makefile b/jdk/test/Makefile
index 5d5d04a..16be47e 100644
--- a/jdk/test/Makefile
+++ b/jdk/test/Makefile
@@ -79,21 +79,25 @@
   endif
   OS_VERSION := $(shell $(UNAME) -r)
 endif
-ifndef OS_NAME
-  ifneq ($(PROCESSOR_IDENTIFIER), )
-    OS_NAME = windows
-    SLASH_JAVA = J:
-    # A variety of ways to say X64 arch :^(
-    OS_ARCH:=$(word 1, $(PROCESSOR_IDENTIFIER))
-    EXESUFFIX = .exe
-    # These need to be different depending on MKS or CYGWIN
-    ifeq ($(findstring cygdrive,$(shell ($(CD) C:/ && $(PWD)))), )
-      GETMIXEDPATH  = dosname -s
-      OS_VERSION   := $(shell $(UNAME) -r)
-    else
-      GETMIXEDPATH  = cygpath -m -s
-      OS_VERSION   := $(shell $(UNAME) -s | $(CUT) -d'-' -f2)
-    endif
+ifeq ($(OS_NAME),)
+  OS_NAME = windows
+  # GNU Make or MKS overrides $(PROCESSOR_ARCHITECTURE) to always
+  # return "x86". Use the first word of $(PROCESSOR_IDENTIFIER) instead.
+  ifeq ($(PROCESSOR_IDENTIFIER),)
+    PROC_ARCH:=$(shell $(UNAME) -m)
+  else
+    PROC_ARCH:=$(word 1, $(PROCESSOR_IDENTIFIER))
+  endif
+  OS_ARCH:=$(PROC_ARCH)
+  SLASH_JAVA = J:
+  EXESUFFIX = .exe
+  # These need to be different depending on MKS or CYGWIN
+  ifeq ($(findstring cygdrive,$(shell ($(CD) C:/ && $(PWD)))), )
+    GETMIXEDPATH  = dosname -s
+    OS_VERSION   := $(shell $(UNAME) -r)
+  else
+    GETMIXEDPATH  = cygpath -m -s
+    OS_VERSION   := $(shell $(UNAME) -s | $(CUT) -d'-' -f2)
   endif
 endif
 
@@ -110,22 +114,27 @@
 #OS_ARCH2-x64:=amd64
 
 # Try and use the arch names consistently
-OS_ARCH:=$(subst x64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst X64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst AMD64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst amd64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst x86_64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst EM64T,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst em64t,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst intel64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst Intel64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst INTEL64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
-OS_ARCH:=$(subst IA64,ia64,$(OS_ARCH))
-OS_ARCH:=$(subst X86,i586,$(OS_ARCH))
-OS_ARCH:=$(subst x86,i586,$(OS_ARCH))
-OS_ARCH:=$(subst i386,i586,$(OS_ARCH))
-OS_ARCH:=$(subst i486,i586,$(OS_ARCH))
-OS_ARCH:=$(subst i686,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst x64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst X64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst AMD64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst amd64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst x86_64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst 8664,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst EM64T,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst em64t,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst intel64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst Intel64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst INTEL64,$(OS_ARCH_X64_NAME),$(OS_ARCH))
+OS_ARCH:=$(patsubst IA64,ia64,$(OS_ARCH))
+OS_ARCH:=$(patsubst X86,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst x86,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst i386,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst i486,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst i686,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst 386,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst 486,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst 586,i586,$(OS_ARCH))
+OS_ARCH:=$(patsubst 686,i586,$(OS_ARCH))
 
 # Default  ARCH_DATA_MODEL settings
 ARCH_DATA_MODEL-i586 = 32
@@ -237,33 +246,9 @@
   endif
 endif
 
-# Temp file to hold list of shared library files possibly needing execute 
-#   permissions at runtime. 
-SHARED_LIBRARY_LIST=$(ABS_TEST_OUTPUT_DIR)/shared_libraries.txt
-
-# Macro that may change execute permissions on library files and check for them.
-#  Files in repositories should not really have execute permissions, however
-#  windows dll files require execute permission. Adding execute permission
-#  may happen automatically on windows when using certain versions of mercurial
-#  but it cannot be guaranteed. And blindly adding execute permission might
-#  be seen as a mercurial 'change', so we avoid adding execute permission to
-#  repository files. Testing from a plain source tree may need the chmod a+x.
-#  Used on select directories.
-define CheckLibraryExecutePermissions # dir
-$(MKDIR) -p `$(DIRNAME) $(SHARED_LIBRARY_LIST)`
-$(RM) $(SHARED_LIBRARY_LIST)
-$(FIND) $1 -name \*.dll -o -name \*.DLL -o -name \*.so > $(SHARED_LIBRARY_LIST)
-if [ -s $(SHARED_LIBRARY_LIST) -a ! -d $(TEST_ROOT)/../.hg ] ; then    \
-  $(ECHO) "$(CHMOD) a+x `$(CAT) $(SHARED_LIBRARY_LIST)`";              \
-  $(CHMOD) a+x `$(CAT) $(SHARED_LIBRARY_LIST)`;                        \
-fi
-if [ -s $(SHARED_LIBRARY_LIST) ] ; then                                \
-  for i in `$(CAT) $(SHARED_LIBRARY_LIST)` ; do                        \
-    if [ ! -x $${i} ] ; then                                           \
-      $(ECHO) "WARNING: File does not have execute permission: $${i}"; \
-    fi;                                                                \
-  done;                                                                \
-fi
+# Macro to run make and set the shared library permissions
+define SharedLibraryPermissions
+$(MAKE) SHARED_LIBRARY_DIR=$1 UNIQUE_DIR=$@ shared_library_permissions
 endef
 
 # Expect JPRT to set JPRT_ARCHIVE_BUNDLE (path to zip bundle for results)
@@ -515,7 +500,7 @@
 JDK_ALL_TARGETS += jdk_nio2
 jdk_nio2: java/nio/Buffer java/nio/ByteOrder \
           java/nio/channels java/nio/BufferPoolMXBean java/nio/MappedByteBuffer
-	$(call CheckLibraryExecutePermissions,java/nio/channels)
+	$(call SharedLibraryPermissions,java/nio/channels)
 	$(call RunOthervmBatch)
 
 # Stable othervm testruns (minus items from PROBLEM_LIST)
@@ -549,7 +534,7 @@
 #   Using samevm has serious problems with these tests
 JDK_ALL_TARGETS += jdk_security3
 jdk_security3: com/sun/security lib/security javax/security sun/security
-	$(call CheckLibraryExecutePermissions,sun/security)
+	$(call SharedLibraryPermissions,sun/security)
 	$(call RunOthervmBatch)
 
 # All security tests
@@ -576,7 +561,7 @@
 #   Using samevm has serious problems with these tests
 JDK_ALL_TARGETS += jdk_tools2
 jdk_tools2: com/sun/tools sun/jvmstat sun/tools tools vm com/sun/servicetag com/sun/tracing
-	$(call CheckLibraryExecutePermissions,tools/launcher)
+	$(call SharedLibraryPermissions,tools/launcher)
 	$(call RunOthervmBatch)
 
 # All tools tests
@@ -646,7 +631,26 @@
 	  ) ; $(BUNDLE_UP_AND_EXIT)                                          \
 	) 2>&1 | $(TEE) $(ABS_TEST_OUTPUT_DIR)/output.txt ; $(TESTEXIT)
 
-PHONY_LIST += jtreg_tests
+# Rule that may change execute permissions on shared library files.
+#  Files in repositories should never have execute permissions, but there
+#  are some tests that have pre-built shared libraries, and these windows
+#  dll files must have execute permission. Adding execute permission
+#  may happen automatically on windows when using certain versions of mercurial
+#  but it cannot be guaranteed. And blindly adding execute permission might
+#  be seen as a mercurial 'change', so we avoid adding execute permission to
+#  repository files. But testing from a plain source tree needs the chmod a+rx.
+#  Used on select directories and applying the chmod to all shared libraries
+#  not just dll files. On windows, this may not work with MKS if the files
+#  were installed with CYGWIN unzip or untar (MKS chmod may not do anything).
+#  And with CYGWIN and sshd service, you may need CYGWIN=ntsec for this to work.
+#
+shared_library_permissions: $(SHARED_LIBRARY_DIR)
+	if [ ! -d $(TEST_ROOT)/../.hg ] ; then                          \
+	  $(FIND) $< \( -name \*.dll -o -name \*.DLL -o -name \*.so \)  \
+	        -exec $(CHMOD) a+rx {} \; ;                             \
+        fi
+
+PHONY_LIST += jtreg_tests shared_library_permissions
 
 ################################################################
 
@@ -679,7 +683,7 @@
 # perftest to collect statistics  
 
 # Expect JPRT to set JPRT_PACKTEST_HOME.
-PERFTEST_HOME = ${TEST_ROOT}/perf
+PERFTEST_HOME = $(TEST_ROOT)/perf
 ifdef JPRT_PERFTEST_HOME
   PERFTEST_HOME = $(JPRT_PERFTEST_HOME)
 endif