blob: 7963ce5e7ae71b34d56831b49f4f1cce3035d01c [file] [log] [blame]
/**
* @author Petr Ivanov
*
*/
/* *********************************************************************** */
#include "events.h"
#include "utils.h"
#include "ncai.h"
static bool test = false;
static bool util = false;
static bool flag = false;
const char test_case_name[] = "ReadMemory02";
static char buf[] = "1234567890qwerty";
/* *********************************************************************** */
JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
{
Callbacks CB;
check_AGENT_ONLOAD;
jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_VM_DEATH };
cb_exc;
cb_death;
return func_for_Agent_OnLoad(vm, options, reserved, &CB,
events, sizeof(events)/sizeof(jvmtiEvent), test_case_name, DEBUG_OUT);
}
/* *********************************************************************** */
void JNICALL callbackException(prms_EXCPT)
{
check_EXCPT;
if (flag) return;
/*
* Function separate all other exceptions in all other method
*/
if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
"special_method", DEBUG_OUT)) return;
flag = true;
util = true;
jvmtiError err;
ncaiError ncai_err;
jvmtiExtensionFunctionInfo* ext_info = NULL;
jint ext_count = 0;
err = jvmti_env->GetExtensionFunctions(&ext_count, &ext_info);
if (err != JVMTI_ERROR_NONE)
{
fprintf(stderr, "test_function: GetExtensionFunctions() returned error: %d, '%s'\n",
err, get_jvmti_eror_text(err));
test = false;
return;
}
if (ext_count == 0 || ext_info == NULL)
{
fprintf(stderr, "test_function: GetExtensionFunctions() returned no extensions\n");
test = false;
return;
}
jvmtiExtensionFunction get_ncai_func = NULL;
for (int i = 0; i < ext_count; i++)
{
if (strcmp(ext_info[i].id, "org.apache.harmony.vm.GetExtensionEnv") == 0)
{
get_ncai_func = ext_info[i].func;
break;
}
}
if (get_ncai_func == NULL)
{
fprintf(stderr, "test_function: GetNCAIEnvironment() nas not been found among JVMTI extensions\n");
test = false;
return;
}
ncaiEnv* ncai_env = NULL;
err = get_ncai_func(jvmti_env, &ncai_env, NCAI_VERSION_1_0);
if (err != JVMTI_ERROR_NONE)
{
fprintf(stderr, "test_function: get_ncai_func() returned error: %d, '%s'\n",
err, get_jvmti_eror_text(err));
test = false;
return;
}
if (ncai_env == NULL)
{
fprintf(stderr, "test_function: get_ncai_func() returned NULL environment\n");
test = false;
return;
}
char out_buf[100];
ncai_err = ncai_env->ReadMemory(&buf, 16, &out_buf);
if(ncai_err != NCAI_ERROR_NONE)
{
fprintf(stderr, "ReadMemory returned error: %d\n", ncai_err);
test = false;
return;
}
for(int k = 0; k < 16; k++)
{
if(out_buf[k] != buf[k])
{
test = false;
return;
}
}
test = true;
}
void JNICALL callbackVMDeath(prms_VMDEATH)
{
check_VMDEATH;
func_for_callback_VMDeath(jni_env, jvmti_env, test_case_name, test, util);
}
/* *********************************************************************** */