Skip to content

Commit

Permalink
Added key to fetch os.name from HostVM and created test to check in J…
Browse files Browse the repository at this point in the history
…PF enviornment
  • Loading branch information
Harsh4902 committed Sep 13, 2024
1 parent 0de04fa commit 201d68b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/classes/modules/java.base/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions src/peers/gov/nasa/jpf/vm/JPF_java_lang_System.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/tests/gov/nasa/jpf/test/java/misc/VMTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}

0 comments on commit 201d68b

Please sign in to comment.