From 201d68bdb3eb226ff776953575c980017205e8af Mon Sep 17 00:00:00 2001 From: Harsh4902 Date: Fri, 13 Sep 2024 06:02:29 +0000 Subject: [PATCH] Added key to fetch os.name from HostVM and created test to check in JPF enviornment --- .../modules/java.base/java/lang/System.java | 4 +++ .../gov/nasa/jpf/vm/JPF_java_lang_System.java | 1 + .../gov/nasa/jpf/test/java/misc/VMTest.java | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/tests/gov/nasa/jpf/test/java/misc/VMTest.java diff --git a/src/classes/modules/java.base/java/lang/System.java b/src/classes/modules/java.base/java/lang/System.java index f0fa50bb..519f1777 100644 --- a/src/classes/modules/java.base/java/lang/System.java +++ b/src/classes/modules/java.base/java/lang/System.java @@ -25,6 +25,7 @@ import java.util.Properties; import jdk.internal.misc.JavaLangAccess; import jdk.internal.misc.SharedSecrets; +import jdk.internal.misc.VM; import jdk.internal.reflect.ConstantPool; import sun.nio.ch.Interruptible; import sun.reflect.annotation.AnnotationType; @@ -70,6 +71,9 @@ public class System { // <2do> this is an approximation that isn't particularly safe since we don't // initialize sun.misc.VM //sun.misc.VM.booted(); + + //Loading all Properties to VM + VM.saveAndRemoveProperties(properties); } static JavaLangAccess createJavaLangAccess () { diff --git a/src/peers/gov/nasa/jpf/vm/JPF_java_lang_System.java b/src/peers/gov/nasa/jpf/vm/JPF_java_lang_System.java index cd57392f..9e608952 100644 --- a/src/peers/gov/nasa/jpf/vm/JPF_java_lang_System.java +++ b/src/peers/gov/nasa/jpf/vm/JPF_java_lang_System.java @@ -184,6 +184,7 @@ int getSelectedSysPropsFromHost (MJIEnv env){ "java.home", "java.version", "java.io.tmpdir", + "os.name", JAVA_CLASS_PATH //... and probably some more // <2do> what about -Dkey=value commandline options diff --git a/src/tests/gov/nasa/jpf/test/java/misc/VMTest.java b/src/tests/gov/nasa/jpf/test/java/misc/VMTest.java new file mode 100644 index 00000000..24b4e82e --- /dev/null +++ b/src/tests/gov/nasa/jpf/test/java/misc/VMTest.java @@ -0,0 +1,31 @@ +package gov.nasa.jpf.test.java.misc; + +import gov.nasa.jpf.util.test.TestJPF; +import jdk.internal.misc.VM; +import org.junit.Test; + +/** + * Simple test to verify properties are loaded correctly to VM + */ +public class VMTest extends TestJPF { + + /** + * Test to verify all the properties of System is loaded to VM + */ + @Test + public void getSavedPropertiesTest(){ + if(verifyNoPropertyViolation()){ + assertEquals(System.getProperties().size(),VM.getSavedProperties().size()); + } + } + + /** + * Test to verify property "os.name" is loaded in VM + */ + @Test + public void getSavedPropertyTest(){ + if(verifyNoPropertyViolation()){ + assertNotNull(VM.getSavedProperty("os.name")); + } + } +}