Skip to content

Commit

Permalink
7903193: [jtreg] build and test failures using JDK 18
Browse files Browse the repository at this point in the history
7903645: tests that set SecurityManager fail due to UnsupportedOperationException in Java 21
7903646: test/BasicAgent.vm fails when run with Java 21

Reviewed-by: cstein, jlahoda
  • Loading branch information
jaikiran committed Oct 21, 2024
1 parent cf42c7c commit 857ed61
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: oracle-actions/setup-java@v1
with:
website: oracle.com
release: 17
release: 21

- name: 'Build JTReg'
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion make/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#
# Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, 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 Down Expand Up @@ -395,6 +395,7 @@ sanity_check_java_home() {
error "JDK 11 or newer is required to build jtreg"
exit 1
fi
JAVA_SPECIFICATION_VERSION=${vnum}
}

checkJavaOSVersion() {
Expand Down Expand Up @@ -778,6 +779,7 @@ make ASMTOOLS_JAR="${ASMTOOLS_JAR}" \\
BUILD_VERSION="${JTREG_VERSION}" \\
BUILD_VERSION_STRING="${JTREG_VERSION_STRING}" \\
JAVATEST_JAR="$(mixed_path "${JTHARNESS_JAVATEST_JAR}")" \\
JAVA_SPECIFICATION_VERSION="${JAVA_SPECIFICATION_VERSION}" \\
JDKHOME="$(mixed_path ${JAVA_HOME})" \\
JTHARNESS_NOTICES="${JTHARNESS_NOTICES}" \\
JTREG_HOME="" \\
Expand Down
12 changes: 11 additions & 1 deletion test/SecurityManager/SecurityManagerTests.gmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1997, 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 @@ -24,6 +24,8 @@
#

#----------------------------------------------------------------------
# only run the test on Java version lesser than 18
INCLUDE_SEC_MGR_TEST := $(shell if [ ${JAVA_SPECIFICATION_VERSION} -lt 18 ]; then echo 1; else echo 0; fi)

$(BUILDTESTDIR)/GoodSecurityManagerTest.ok: \
$(JTREG_IMAGEDIR)/lib/jtreg.jar \
Expand All @@ -35,8 +37,10 @@ $(BUILDTESTDIR)/GoodSecurityManagerTest.ok: \
$(TESTDIR)/SecurityManager/pass
echo "test passed at `date`" > $@

ifeq ($(INCLUDE_SEC_MGR_TEST),1)
TESTS.jtreg += \
$(BUILDTESTDIR)/GoodSecurityManagerTest.ok
endif

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

Expand All @@ -53,8 +57,10 @@ $(BUILDTESTDIR)/BadSecurityManagerTest.ok: \
grep "Cannot reset security manager" $(@:%.ok=%)/work/error/BadSecurityManagerTest.jtr
echo "test passed at `date`" > $@

ifeq ($(INCLUDE_SEC_MGR_TEST),1)
TESTS.jtreg += \
$(BUILDTESTDIR)/BadSecurityManagerTest.ok
endif

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

Expand All @@ -72,8 +78,10 @@ $(BUILDTESTDIR)/SecurityManagerTest_agentvm_forbid.ok: \
grep "Test results: failed: 5" $(@:%.ok=%)/out.txt
echo "test passed at `date`" > $@

ifeq ($(INCLUDE_SEC_MGR_TEST),1)
TESTS.jtreg += \
$(BUILDTESTDIR)/SecurityManagerTest_agentvm_forbid.ok
endif

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

Expand All @@ -87,8 +95,10 @@ $(BUILDTESTDIR)/SecurityManagerTest_othervm.ok: \
$(TESTDIR)/SecurityManager
echo "test passed at `date`" > $@

ifeq ($(INCLUDE_SEC_MGR_TEST),1)
TESTS.jtreg += \
$(BUILDTESTDIR)/SecurityManagerTest_othervm.ok
endif

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

Expand Down
3 changes: 2 additions & 1 deletion test/SecurityManager/pass/SimpleSecurityManagerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -23,6 +23,7 @@

/*
* @test
* @requires jdk.version.major < 18
*/

/*
Expand Down
21 changes: 17 additions & 4 deletions test/badtests/BadTests.gmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1997, 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 Down Expand Up @@ -41,7 +41,11 @@ $(BUILDTESTDIR)/BadTests.othervm.ok: \
$(TESTDIR)/badtests \
> $(@:%.ok=%/jt.log) 2>&1 || \
true "non-zero exit code from JavaTest intentionally ignored"
$(GREP) -s 'Test results: passed: 18; failed: 2' $(@:%.ok=%/jt.log) > /dev/null
if [ ${JAVA_SPECIFICATION_VERSION} -lt 18 ]; then \
$(GREP) -s 'Test results: passed: 18; failed: 2' $(@:%.ok=%/jt.log) > /dev/null ; \
else \
$(GREP) -s 'Test results: passed: 15; failed: 2' $(@:%.ok=%/jt.log) > /dev/null ; \
fi
echo "test passed at `date`" > $@

# Run bad tests in agentvm mode
Expand All @@ -67,9 +71,18 @@ $(BUILDTESTDIR)/BadTests.agentvm.ok: \
$(TESTDIR)/badtests \
> $(@:%.ok=%/jt.log) 2>&1 || \
true "non-zero exit code from JavaTest intentionally ignored"
$(GREP) -s 'Test results: passed: 17; failed: 1; error: 2' $(@:%.ok=%/jt.log) > /dev/null
agents=`$(GREP) '^\[[-0-9 :,]*\] Agent\[[0-9][0-9]*\]: Launching' $(@:%.ok=%/jt.log) | wc -l` ; \
if [ $${agents} -ne 4 ]; then echo "Unexpected number of agents used: $${agents}" ; exit 1 ; fi
if [ ${JAVA_SPECIFICATION_VERSION} -lt 18 ]; then \
$(GREP) -s 'Test results: passed: 17; failed: 1; error: 2' $(@:%.ok=%/jt.log) > /dev/null ; \
if [ $${agents} -ne 4 ]; then \
echo "Unexpected number of agents used: $${agents}" ; exit 1 ; \
fi \
else \
$(GREP) -s 'Test results: passed: 15; failed: 2' $(@:%.ok=%/jt.log) > /dev/null ; \
if [ $${agents} -ne 2 ]; then \
echo "Unexpected number of agents used: $${agents}" ; exit 1 ; \
fi \
fi
echo "test passed at `date`" > $@

ifneq ($(OS_NAME), windows)
Expand Down
5 changes: 4 additions & 1 deletion test/badtests/ExitTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -23,16 +23,19 @@

/*
* @test
* @requires jdk.version.major < 18
* @run main ExitTest pass
*/

/*
* @test
* @requires jdk.version.major < 18
* @run main ExitTest fail
*/

/*
* @test
* @requires jdk.version.major < 18
* @run main ExitTest pass
*/

Expand Down
6 changes: 5 additions & 1 deletion test/basic/Basic.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ $(BUILDTESTDIR)/Basic.check.ok: \
$(TESTDIR)/share/basic \
> $(@:%.ok=%/log) 2>&1|| \
true "non-zero exit code from JavaTest intentionally ignored"
$(GREP) -s 'Test results: passed: 157; error: 84' $(@:%.ok=%/log) > /dev/null
if [ ${JAVA_SPECIFICATION_VERSION} -lt 18 ]; then \
$(GREP) -s 'Test results: passed: 157; error: 84' $(@:%.ok=%/log) > /dev/null ; \
else \
$(GREP) -s 'Test results: passed: 142; error: 84' $(@:%.ok=%/log) > /dev/null ; \
fi
echo $@ passed at `date` > $@

INITIAL_TESTS += \
Expand Down
18 changes: 18 additions & 0 deletions test/basic/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@

public class Basic
{
private static final boolean IS_JAVA18_PLUS;

static {
String javaSpecVersion = System.getProperty("java.specification.version");
// use of Double.valueOf() allows for JDK 8, whose value is 1.8
IS_JAVA18_PLUS = Double.valueOf(javaSpecVersion).intValue() >= 18;
}

public static void main(String[] args) {
try {
Basic basic = new Basic(args);
Expand Down Expand Up @@ -227,6 +235,16 @@ private void setExpectedTestStats() {
numMain += 2;
numShell += 1;

if (IS_JAVA18_PLUS) {
// on Java versions 18 and higher we don't run some SecurityManager related tests.
// we adjust the counts for those here.

// 2 less "Passed" expected in main/Exit.java and 1 less expected in driver/Exit.java
numPassed -= 3;
// 10 less "Failed" expected in main/Exit.java and 2 less expected in driver/Exit.java
numFailed -= 12;
numError += 0; // no change in error count
}
actionTable.put("applet", Integer.valueOf(numApplet));
actionTable.put("build", Integer.valueOf(numBuild));
actionTable.put("clean", Integer.valueOf(numClean));
Expand Down
18 changes: 14 additions & 4 deletions test/basic/ReportOnlyTest.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ $(BUILDTESTDIR)/ReportOnlyTest.ok: $(BUILDTESTDIR)/Basic.othervm.ok \
$(CAT) $(@:%.ok=%.jt.log)
$(GREP) headless $(BUILDTESTDIR)/Basic.othervm/log
if $(GREP) "headless: *true" $(BUILDTESTDIR)/Basic.othervm/log > /dev/null ; then \
EXPECT_PASS=92 ; \
EXPECT_FAIL=40 ; \
if [ ${JAVA_SPECIFICATION_VERSION} -lt 18 ]; then \
EXPECT_PASS=92 ; \
EXPECT_FAIL=40 ; \
else \
EXPECT_PASS=89 ; \
EXPECT_FAIL=28 ; \
fi ; \
else \
EXPECT_PASS=94 ; \
EXPECT_FAIL=44 ; \
if [ ${JAVA_SPECIFICATION_VERSION} -lt 18 ]; then \
EXPECT_PASS=94 ; \
EXPECT_FAIL=44 ; \
else \
EXPECT_PASS=91 ; \
EXPECT_FAIL=32 ; \
fi ; \
fi ; \
echo "Expect: Test results: passed: $${EXPECT_PASS}; failed: $${EXPECT_FAIL}; error: 88" ; \
$(GREP) -s "Test results: passed: $${EXPECT_PASS}; failed: $${EXPECT_FAIL}; error: 88" $(@:%.ok=%.jt.log) > /dev/null
Expand Down
5 changes: 4 additions & 1 deletion test/share/basic/driver/Exit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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 @@ -24,18 +24,21 @@
/**
* @test
* @summary Passed: Execution successful
* @requires jdk.version.major < 18
* @run driver Exit
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 0]
* @requires jdk.version.major < 18
* @run driver Exit 0
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 1]
* @requires jdk.version.major < 18
* @run driver Exit 1
*/
public class Exit
Expand Down
14 changes: 13 additions & 1 deletion test/share/basic/main/Exit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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 @@ -24,72 +24,84 @@
/**
* @test
* @summary Passed: Execution successful
* @requires jdk.version.major < 18
* @run main Exit
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 0]
* @requires jdk.version.major < 18
* @run main Exit 0
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 1]
* @requires jdk.version.major < 18
* @run main Exit 1
*/

/**
* @test
* @summary Passed: Execution successful
* @requires jdk.version.major < 18
* @run main/othervm Exit
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 0]
* @requires jdk.version.major < 18
* @run main/othervm Exit 0
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 1]
* @requires jdk.version.major < 18
* @run main/othervm Exit 1
*/

/**
* @test
* @summary Failed: Execution passed unexpectedly
* @requires jdk.version.major < 18
* @run main/fail Exit
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 0]
* @requires jdk.version.major < 18
* @run main/fail Exit 0
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 1]
* @requires jdk.version.major < 18
* @run main/fail Exit 1
*/

/**
* @test
* @summary Failed: Execution passed unexpectedly
* @requires jdk.version.major < 18
* @run main/othervm/fail Exit
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 0]
* @requires jdk.version.major < 18
* @run main/othervm/fail Exit 0
*/

/**
* @test
* @summary Failed: Unexpected exit from test [exit code: 1]
* @requires jdk.version.major < 18
* @run main/othervm/fail Exit 1
*/

Expand Down
Loading

0 comments on commit 857ed61

Please sign in to comment.