Skip to content

Commit

Permalink
7903746: jtreg tests run extremely slow on some environments due to h…
Browse files Browse the repository at this point in the history
…ostname lookups

Reviewed-by: jjg, msheppar
  • Loading branch information
jaikiran committed Jul 11, 2024
1 parent d8a6518 commit 08d003a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, 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
Expand All @@ -25,6 +25,8 @@

package com.sun.javatest.regtest.config;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;

import com.sun.javatest.TestEnvironment;
Expand All @@ -46,5 +48,27 @@ public TestEnvironment copy() {
return new RegressionEnvironment(this);
}

/**
* {@return the hostname of the host in which this test harness is being run}
*/
public final String getHostName() {
return CachedCanonicalHostName.HOST_NAME;
}

public final RegressionParameters params;


private static final class CachedCanonicalHostName {
private static final String HOST_NAME;

static {
String hostname;
try {
hostname = InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException e) {
hostname = "127.0.0.1";
}
HOST_NAME = hostname;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,7 @@ public Status run(String[] argv, TestDescription td, TestEnvironment env) {
// defaults

testResult = getTestResult();

String hostname;
try {
hostname = InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException e) {
hostname = "127.0.0.1";
}
testResult.putProperty("hostname", hostname);
testResult.putProperty("hostname", regEnv.getHostName());
String[] props = { "user.name" };
for (String p: props) {
testResult.putProperty(p, System.getProperty(p));
Expand Down
Empty file added test/jtrContentTest/TEST.ROOT
Empty file.
31 changes: 31 additions & 0 deletions test/jtrContentTest/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024, 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.
*
* 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.
*/

/*
* @test
*/
public class Test {
public static void main(String... args) {
System.out.println("hello!");
}
}
42 changes: 42 additions & 0 deletions test/jtrContentTest/VerifyHostname.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Copyright (c) 2024, 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.
#

#----------------------------------------------------------------------

# verifies that the .jtr file contains the "hostname" property in the
# testresult
$(BUILDTESTDIR)/VerifyHostname.ok: \
$(JTREG_IMAGEDIR)/lib/javatest.jar \
$(JTREG_IMAGEDIR)/lib/jtreg.jar
$(RM) $(@:%.ok=%) ; $(MKDIR) $(@:%.ok=%)
$(JDKHOME)/bin/java -jar $(JTREG_IMAGEDIR)/lib/jtreg.jar \
-w $(@:%.ok=%)/work/ -r $(@:%.ok=%)/report/ \
$(TESTDIR)/jtrContentTest/Test.java > $(@:%.ok=%/jt.log) 2>&1; \
$(GREP) 'hostname=' $(@:%.ok=%)/work/Test.jtr > /dev/null ; found=$$?; \
if [ "$$found" != 0 ]; then echo "Missing hostname in testresult of Test.jtr" ; exit 1 ; fi
echo $@ passed at `date` > $@

TESTS.jtreg += $(BUILDTESTDIR)/VerifyHostname.ok

0 comments on commit 08d003a

Please sign in to comment.