-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18369 from JasonFengJ9/timedelta
CRIU checkpointRestoreTimeDelta adjustment & add time compensation tests
- Loading branch information
Showing
10 changed files
with
447 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
test/functional/TestUtilities/src/org/openj9/test/util/TimeUtilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/******************************************************************************* | ||
* Copyright IBM Corp. and others 2023 | ||
* | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which accompanies this | ||
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* or the Apache License, Version 2.0 which accompanies this distribution and | ||
* is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* This Source Code may also be made available under the following | ||
* Secondary Licenses when the conditions for such availability set | ||
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU | ||
* General Public License, version 2 with the GNU Classpath | ||
* Exception [1] and GNU General Public License, version 2 with the | ||
* OpenJDK Assembly Exception [2]. | ||
* | ||
* [1] https://www.gnu.org/software/classpath/license.html | ||
* [2] https://openjdk.org/legal/assembly-exception.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0 | ||
*******************************************************************************/ | ||
package org.openj9.test.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
/** | ||
* Utility class to check time. | ||
*/ | ||
public class TimeUtilities { | ||
public final static long TIME_NANOSECONDS_PER_MILLIS = 1000000; | ||
|
||
public static void showThreadCurrentTime(String msgHeader) { | ||
System.out.println(msgHeader + ", current thread name: " + Thread.currentThread().getName() + ", " + new Date() | ||
+ ", System.currentTimeMillis() " + System.currentTimeMillis() + ", System.nanoTime() " | ||
+ System.nanoTime()); | ||
} | ||
|
||
public static boolean checkElapseTime(String testName, long startMillisTime, long startNanoTime, | ||
long minElapsedMillisTime, long maxElapsedMillisTime, long minElapsedNanoTimeInMillis, | ||
long maxElapsedNanoTimeInMillis) { | ||
boolean result = true; | ||
final long currentMillisTime = System.currentTimeMillis(); | ||
final long currentNanoTime = System.nanoTime(); | ||
showThreadCurrentTime(testName + " checkElapseTime starts"); | ||
|
||
final long elapsedMillisTime = currentMillisTime - startMillisTime; | ||
final long elapsedNanoTime = currentNanoTime - startNanoTime; | ||
// Get the smallest value that is greater than or equal to the elapsed nano time | ||
// in milliseconds for the case that the elapsed nano | ||
// time is slightly less than the elapsedMillisTime, such as the elapsedNanoTime | ||
// (1999997603ns) less than elapsedMillisTime * TIME_NANOSECONDS_PER_MILLIS | ||
// (2000000000ns) | ||
// This behaviour was observed in both RI and OpenJ9. | ||
final long elapsedNanoTimeInMillis = elapsedNanoTime / TIME_NANOSECONDS_PER_MILLIS | ||
+ ((elapsedNanoTime % TIME_NANOSECONDS_PER_MILLIS == 0) ? 0 : 1); | ||
|
||
System.out.println(testName + ": startMillisTime (" + startMillisTime + "ms) startNanoTime (" + startNanoTime | ||
+ "ns)" + " currentMillisTime (" + currentMillisTime + "ms) currentNanoTime (" + currentNanoTime | ||
+ "ns) elapsedMillisTime (" + elapsedMillisTime + "ms) elapsedNanoTime (" + elapsedNanoTime + "ns)"); | ||
if (elapsedMillisTime < minElapsedMillisTime) { | ||
result = false; | ||
System.out.println("FAILED: " + testName + " elapsedMillisTime (" + elapsedMillisTime | ||
+ "ms) should NOT be less than minElapsedMillisTime (" + minElapsedMillisTime + "ms)"); | ||
} else if (elapsedMillisTime > maxElapsedMillisTime) { | ||
result = false; | ||
System.out.println("FAILED: " + testName + " elapsedMillisTime (" + elapsedMillisTime | ||
+ "ms) should NOT be greater than maxElapsedMillisTime (" + maxElapsedMillisTime + "ms)"); | ||
} | ||
if (elapsedNanoTimeInMillis < minElapsedNanoTimeInMillis) { | ||
result = false; | ||
System.out.println("FAILED: " + testName + " elapsedNanoTimeInMillis (" + elapsedNanoTimeInMillis | ||
+ "ms) should NOT be less than minElapsedNanoTimeInMillis (" + minElapsedNanoTimeInMillis + "ms)"); | ||
} else if (elapsedNanoTimeInMillis > maxElapsedNanoTimeInMillis) { | ||
result = false; | ||
System.out.println("FAILED: " + testName + " elapsedNanoTimeInMillis (" + elapsedNanoTimeInMillis | ||
+ "ms) should NOT be greater than maxElapsedNanoTimeInMillis (" + maxElapsedNanoTimeInMillis | ||
+ "ms)"); | ||
} | ||
showThreadCurrentTime(testName + " checkElapseTime ends"); | ||
|
||
return result; | ||
} | ||
|
||
private volatile boolean tasksPassed = true; | ||
private volatile int taskRunning = 0; | ||
private volatile int taskStarted = 0; | ||
private volatile int taskExecuted = 0; | ||
private final ArrayList<Timer> timers = new ArrayList<Timer>(); | ||
|
||
public void timerSchedule(String testName, long startMillisTime, long startNanoTime, long minElapsedMillisTime, | ||
long maxElapsedMillisTime, long minElapsedNanoTimeInMillis, long maxElapsedNanoTimeInMillis, long delay) { | ||
Timer timer = new Timer(testName); | ||
timer.schedule(new TimeTestTask(testName, startMillisTime, startNanoTime, minElapsedMillisTime, | ||
maxElapsedMillisTime, minElapsedNanoTimeInMillis, maxElapsedNanoTimeInMillis), delay); | ||
timers.add(timer); | ||
} | ||
|
||
public boolean getResultAndCancelTimers() { | ||
showThreadCurrentTime("getResultAndCancelTimers before Thread.yield() taskRunning = " + taskRunning); | ||
while (taskRunning > 0) { | ||
Thread.yield(); | ||
} | ||
|
||
showThreadCurrentTime("getResultAndCancelTimers before timer.cancel()"); | ||
for (Timer timer : timers) { | ||
timer.cancel(); | ||
} | ||
|
||
showThreadCurrentTime("TimeTestTask tasksPassed: " + tasksPassed + ", taskStarted: " + taskStarted | ||
+ ", taskExecuted: " + taskExecuted); | ||
return tasksPassed && (taskStarted == taskExecuted); | ||
} | ||
|
||
class TimeTestTask extends TimerTask { | ||
|
||
private final String testName; | ||
private final long startMillisTime; | ||
private final long startNanoTime; | ||
private final long minElapsedMillisTime; | ||
private final long maxElapsedMillisTime; | ||
private final long minElapsedNanoTimeInMillis; | ||
private final long maxElapsedNanoTimeInMillis; | ||
|
||
TimeTestTask(String testName, long startMillisTime, long startNanoTime, long minElapsedMillisTime, | ||
long maxElapsedMillisTime, long minElapsedNanoTimeInMillis, long maxElapsedNanoTimeInMillis) { | ||
this.testName = testName; | ||
this.startMillisTime = startMillisTime; | ||
this.startNanoTime = startNanoTime; | ||
this.minElapsedMillisTime = minElapsedMillisTime; | ||
this.maxElapsedMillisTime = maxElapsedMillisTime; | ||
this.minElapsedNanoTimeInMillis = minElapsedNanoTimeInMillis; | ||
this.maxElapsedNanoTimeInMillis = maxElapsedNanoTimeInMillis; | ||
|
||
taskStarted++; | ||
taskRunning++; | ||
} | ||
|
||
public void run() { | ||
taskExecuted++; | ||
if (!checkElapseTime(testName, startMillisTime, startNanoTime, minElapsedMillisTime, maxElapsedMillisTime, | ||
minElapsedNanoTimeInMillis, maxElapsedNanoTimeInMillis)) { | ||
tasksPassed = false; | ||
} | ||
taskRunning--; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
test/functional/cmdLineTests/cmdLineTest_J9tests/j9tests_elapsedTime.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
|
||
<!-- | ||
Copyright IBM Corp. and others 2023 | ||
This program and the accompanying materials are made available under | ||
the terms of the Eclipse Public License 2.0 which accompanies this | ||
distribution and is available at https://www.eclipse.org/legal/epl-2.0/ | ||
or the Apache License, Version 2.0 which accompanies this distribution and | ||
is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
This Source Code may also be made available under the following | ||
Secondary Licenses when the conditions for such availability set | ||
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU | ||
General Public License, version 2 with the GNU Classpath | ||
Exception [1] and GNU General Public License, version 2 with the | ||
OpenJDK Assembly Exception [2]. | ||
[1] https://www.gnu.org/software/classpath/license.html | ||
[2] https://openjdk.org/legal/assembly-exception.html | ||
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0 | ||
--> | ||
<!DOCTYPE suite SYSTEM "cmdlinetester.dtd"> | ||
|
||
<suite id="Elapsed time measurement" timeout="180"> | ||
<test id="Verify the elapsed time"> | ||
<command>$EXE$ -cp $Q$$JARPATH$$Q$ ElapsedTime</command> | ||
<output type="success" caseSensitive="yes" regex="no">Thread-0</output> | ||
<output type="success" caseSensitive="yes" regex="no">PASSED: testElapsedTime</output> | ||
<output type="failure" caseSensitive="yes" regex="no">FAILED: testElapsedTime</output> | ||
</test> | ||
</suite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.