Skip to content

Commit

Permalink
Adding more steps in test function
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers committed Dec 12, 2024
1 parent 575ec1a commit c87d533
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ jobs:
cd ${{ github.workspace }}/tests/native
g++ -I $JAVA_HOME/include -I $JAVA_HOME/include/darwin -L $JAVA_HOME/lib/server -ljvm CreateVM.cpp -o CreateVM.out
- name: Export location
shell: bash
run: echo "DYLD_LIBRARY_PATH=$(echo $JAVA_HOME/lib/server)" >> $GITHUB_ENV

- name: Execute CreateVM
shell: bash
run: |
export
echo "GITHUB_ENV_LD_LIBRARY_PATH=$(echo $JAVA_HOME/lib/server)" >> $GITHUB_ENV
export LD_LIBRARY_PATH=/Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.13-11/x64/Contents/Home/lib/server
export DYLD_LIBRARY_PATH=/Users/runner/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.13-11/x64/Contents/Home/lib/server
export
${{ github.workspace }}/tests/native/CreateVM.out
Expand Down
61 changes: 59 additions & 2 deletions tests/native/CreateVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,79 @@

int main()
{
const int arguments = 1;
const int arguments = 4;

std::cout << "Starting JNI_CreateJavaVM test" << std::endl;

JavaVM *jvm; /* denotes a Java VM */
JNIEnv *env; /* pointer to native method interface */

int numVms;

jint ret = JNI_GetCreatedJavaVMs(&jvm, 1, &numVms);
if (ret != JNI_OK)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error"; << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM"; << std::endl; return;
case -3: std::cout << "failed - JNI version error"; << std::endl; return;
case -4: std::cout << "failed - not enough memory"; << std::endl; return;
case -5: std::cout << "failed - VM already created"; << std::endl; return;
case -6: std::cout << "failed - invalid arguments"; << std::endl; return;
default: break;
}
}

if (numVms >= 0)
{
std::cout << "JNI_GetCreatedJavaVMs returned with an already created JVM"; << std::endl;
return;
}

JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */

ret = JNI_GetDefaultJavaVMInitArgs(&vm_args);
if (ret != JNI_OK)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error"; << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM"; << std::endl; return;
case -3: std::cout << "failed - JNI version error"; << std::endl; return;
case -4: std::cout << "failed - not enough memory"; << std::endl; return;
case -5: std::cout << "failed - VM already created"; << std::endl; return;
case -6: std::cout << "failed - invalid arguments"; << std::endl; return;
default: break;
}
}

JavaVMOption* options = new JavaVMOption[arguments];
options[0].optionString = "-Djava.class.path=/usr/lib/java";
options[1].optionString = "--add-opens=java.base/java.nio=ALL-UNNAMED";
options[2].optionString = "-Xmx4G";
options[3].optionString = "-Xms1G";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = arguments;
vm_args.options = options;
vm_args.ignoreUnrecognized = true;
/* load and initialize a Java VM, return a JNI interface
* pointer in env */
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (ret != JNI_OK)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error"; << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM"; << std::endl; return;
case -3: std::cout << "failed - JNI version error"; << std::endl; return;
case -4: std::cout << "failed - not enough memory"; << std::endl; return;
case -5: std::cout << "failed - VM already created"; << std::endl; return;
case -6: std::cout << "failed - invalid arguments"; << std::endl; return;
default: break;
}
}

delete[] options;
/* invoke the Main.test method using the JNI */
// jclass cls = env->FindClass("Main");
Expand Down

0 comments on commit c87d533

Please sign in to comment.