예제 #1
0
/*
 * Test scenarios for ArgEmptyC and ArgEmptyCPP:
 *  - dllPath is empty string
 *  - arg is empty string
 *
 * This test is disabled until it is fixed. We expect it has consistent behavior as arg is NULL
 */
TEST_F(RASAgentNegativeTest, DISABLED_ArgEmptyC)
{
	struct OMR_Agent *agent = omr_agent_create(&testVM.omrVM, "=abc");
	ASSERT_TRUE(NULL == agent);

	agent = omr_agent_create(&testVM.omrVM, "");
	ASSERT_TRUE(NULL == agent);
}
예제 #2
0
TEST(RASMemoryCategoriesTest, Agent)
{
	/* OMR VM data structures */
	OMRTestVM testVM;
	OMR_VMThread *vmthread = NULL;

	const char *agentName = "memorycategoriesagent";
	struct OMR_Agent *agent = NULL;

	OMRTEST_ASSERT_ERROR_NONE(omrTestVMInit(&testVM, rasTestEnv->getPortLibrary()));

	OMRTEST_ASSERT_ERROR_NONE(OMR_Thread_Init(&testVM.omrVM, NULL, &vmthread, "memoryCategoriesTest"));

	/* load memorycategoriesagent */
	agent = omr_agent_create(&testVM.omrVM, agentName);
	ASSERT_FALSE(NULL == agent) << "createAgent(" << agentName << ") failed";

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_openLibrary(agent));

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnLoad(agent));

	/** The test code is actually in the OnLoadFunction **/

	/* Unload the agent */
	omr_agent_callOnUnload(agent);
	omr_agent_destroy(agent);

	OMRTEST_ASSERT_ERROR_NONE(OMR_Thread_Free(vmthread));

	/* Now clear up the VM we started for this test case. */
	OMRTEST_ASSERT_ERROR_NONE(omrTestVMFini(&testVM));
}
예제 #3
0
/*
 * Test scenarios for InvalidAgentC and InvalidAgentCPP:
 *  - missing OnLoad entry point in agent
 *  - missing OnUnload entry point in agent
 *  - <dllpath> indicates nonexistent file
 *
 *  Please see INSTANTIATE_TEST_CASE_P for GetParam() values
 */
TEST_P(RASAgentNegativeTest, InvalidAgentC)
{
	struct OMR_Agent *agent = omr_agent_create(&testVM.omrVM, GetParam());
	ASSERT_FALSE(NULL == agent) << "testAgent: createAgent() failed";
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, omr_agent_openLibrary(agent));
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, omr_agent_callOnLoad(agent));
	OMRTEST_ASSERT_ERROR(OMR_ERROR_INTERNAL, omr_agent_callOnUnload(agent));
	omr_agent_destroy(agent);
}
예제 #4
0
/*
 * Test scenarios for AgentReturnErrorC and AgentReturnErrorCPP:
 *  - agent's OnLoad() function returns OMR_ERROR_OUT_OF_NATIVE_MEMORY
 *  - agent's OnUnload() function returns OMR_ERROR_ILLEGAL_ARGUMENT
 */
TEST_F(RASAgentNegativeTest, AgentReturnErrorC)
{
	struct OMR_Agent *agent = omr_agent_create(&testVM.omrVM, "invalidAgentReturnError=abc");
	ASSERT_FALSE(NULL == agent) << "testAgent: createAgent() failed";
	OMRTEST_ASSERT_ERROR_NONE(omr_agent_openLibrary(agent));
	OMRTEST_ASSERT_ERROR(OMR_ERROR_OUT_OF_NATIVE_MEMORY, omr_agent_callOnLoad(agent));
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, omr_agent_callOnUnload(agent));
	omr_agent_destroy(agent);
}
예제 #5
0
TEST(RASTraceOptionTest, TraceOptionAgent)
{
	/* OMR VM data structures */
	OMRTestVM testVM;
	OMR_VMThread *vmthread = NULL;

	/* OMR Trace data structures */
	const char *trcOpts = "print=all";

	struct OMR_Agent *agent = NULL;
	OMRPORT_ACCESS_FROM_OMRPORT(rasTestEnv->getPortLibrary());
	char *datDir = NULL;

	OMRTEST_ASSERT_ERROR_NONE(omrTestVMInit(&testVM, OMRPORTLIB));

	OMRTEST_ASSERT_ERROR_NONE(OMR_Thread_Init(&testVM.omrVM, NULL, &vmthread, "traceOptionTest"));

	datDir = getTraceDatDir(rasTestEnv->_argc, (const char **)rasTestEnv->_argv);

	OMRTEST_ASSERT_ERROR_NONE(omr_ras_initTraceEngine(&testVM.omrVM, trcOpts, datDir));
	OMRTEST_ASSERT_ERROR_NONE(omr_trc_startThreadTrace(vmthread, "initialization thread"));

	/* load agent */
	agent = omr_agent_create(&testVM.omrVM, "traceOptionAgent");
	ASSERT_FALSE(NULL == agent) << "testAgent: createAgent() traceOptionAgent failed";

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_openLibrary(agent));

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnLoad(agent));

	/* Initialise the omr_test module for tracing */
	UT_OMR_TEST_MODULE_LOADED(testVM.omrVM._trcEngine->utIntf);

	/* Fire some trace points! */
	Trc_OMR_Test_Init();
	Trc_OMR_Test_Ptr(vmthread, vmthread);
	Trc_OMR_Test_Int(vmthread, 10);
	Trc_OMR_Test_Int(vmthread, 99);
	Trc_OMR_Test_ManyParms(vmthread, "Hello again!", vmthread, 10);

	UT_OMR_TEST_MODULE_UNLOADED(testVM.omrVM._trcEngine->utIntf);

	/* Unload the agent */
	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnUnload(agent));
	omr_agent_destroy(agent);

	Trc_OMR_Test_String(vmthread, "This tracepoint should be ignored.");

	OMRTEST_ASSERT_ERROR_NONE(omr_ras_cleanupTraceEngine(vmthread));

	OMRTEST_ASSERT_ERROR_NONE(OMR_Thread_Free(vmthread));

	/* Now clear up the VM we started for this test case. */
	OMRTEST_ASSERT_ERROR_NONE(omrTestVMFini(&testVM));
}
예제 #6
0
/*
 * Test scenario for CorruptedAgent:
 * 	- create an empty agent file
 *  - call omr_agent_create() and OMR_Agent::createAgent by providing the empty agent file
 *  - expect openLibrary() to fail
 */
TEST_F(RASAgentNegativeTest, CorruptedAgent)
{
	intptr_t fileDescriptor;
	char fileName[256];
	char agentName[256];
	char hostname[128];
	OMRPORT_ACCESS_FROM_OMRVM(&testVM.omrVM);
	ASSERT_EQ(0, gethostname(hostname, sizeof(hostname)));

	/* generate machine specific file name to prevent conflict between multiple tests running on shared drive */
	omrstr_printf(agentName, sizeof(agentName), "corruptedAgent_%s", hostname);

	/* create fileName with platform-dependent shared library prefix & suffix.
	 *  for Windows, fileName = corruptedAgent_<hostname>.dll
	 *  for Unix, fileName = libcorruptedAgent_<hostname>.so
	 *  for OSX, fileName = libcorruptedAgent_<hostname>.dylib
	 */
#if defined(WIN32) || defined(WIN64)
	omrstr_printf(fileName, sizeof(fileName), "%s.dll", agentName);
#elif defined(OSX)
	omrstr_printf(fileName, sizeof(fileName), "lib%s.dylib", agentName);
#else /* defined(OSX) */
	omrstr_printf(fileName, sizeof(fileName), "lib%s.so", agentName);
#endif /* defined(WIN32) || defined(WIN64) */

	/* create the empty agent file with permission 751*/
	fileDescriptor = omrfile_open(fileName, EsOpenCreate | EsOpenWrite, 0751);
	ASSERT_NE(-1, fileDescriptor) << "omrfile_open \"" << fileName << "\" failed";
	omrfile_close(fileDescriptor);

	/* call omr_agent_create() by providing the empty agent file */
	struct OMR_Agent *agentC = omr_agent_create(&testVM.omrVM, agentName);
	ASSERT_FALSE(NULL == agentC) << "testAgent: createAgent() " << agentName << " failed";
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, omr_agent_openLibrary(agentC));

	/* call OMR_Agent::createAgent() by providing the empty agent file */
	OMR_Agent *agentCPP = OMR_Agent::createAgent(&testVM.omrVM, agentName);
	ASSERT_FALSE(NULL == agentCPP) << "testAgent: createAgent() failed";
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, agentCPP->openLibrary());

	omrfile_unlink(fileName);
}
예제 #7
0
TEST(RASTraceTest, TraceAgent)
{
	struct OMR_Agent *agent = NULL;

	/* OMR VM data structures */
	OMRTestVM testVM;
	OMR_VMThread *vmthread = NULL;

	/* child thread data */
	omrthread_t childThread = NULL;
	TestChildThreadData *childData = NULL;


	OMRPORT_ACCESS_FROM_OMRPORT(rasTestEnv->getPortLibrary());
	char *datDir = getTraceDatDir(rasTestEnv->_argc, (const char **)rasTestEnv->_argv);

	OMRTEST_ASSERT_ERROR_NONE(omrTestVMInit(&testVM, OMRPORTLIB));

	/* WARNING: This negative test leaks memory. */
	OMRTEST_ASSERT_ERROR(omr_ras_initTraceEngine(&testVM.omrVM, "print=all:duck=quack", datDir), OMR_ERROR_ILLEGAL_ARGUMENT);

	OMRTEST_ASSERT_ERROR_NONE(omr_ras_initTraceEngine(&testVM.omrVM, "maximal=all", datDir));

	OMRTEST_ASSERT_ERROR_NONE(OMR_Thread_Init(&testVM.omrVM, NULL, &vmthread, "traceTest"));

#if TEST_TRACEAGENT
	/* load traceagent */
	{
		agent = omr_agent_create(&testVM.omrVM, "traceagent");
		ASSERT_FALSE(NULL == agent) << "testAgent: createAgent() traceagent failed";

		OMRTEST_ASSERT_ERROR_NONE(omr_agent_openLibrary(agent));

		OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnLoad(agent));
	}
#endif /* TEST_TRACEAGENT */

	/* Initialise the omr_test module for tracing */
	UT_OMR_TEST_MODULE_LOADED(testVM.omrVM._trcEngine->utIntf);

	/* Fire some trace points! */
	Trc_OMR_Test_Init();
	Trc_OMR_Test_String(vmthread, "Hello World!");
	Trc_OMR_Test_Ptr(vmthread, vmthread);
	Trc_OMR_Test_Int(vmthread, 10);
	Trc_OMR_Test_ManyParms(vmthread, "Hello again!", vmthread, 10);

	/* Fire some trace points in another thread. */
	OMRTEST_ASSERT_ERROR_NONE(startTestChildThread(&testVM, vmthread, &childThread, &childData));

	OMRTEST_ASSERT_ERROR_NONE(waitForTestChildThread(&testVM, childThread, childData));

	/* Confirm that the test worked! */
	/* OMRTODO Check something */

	UT_OMR_TEST_MODULE_UNLOADED(testVM.omrVM._trcEngine->utIntf);

#if TEST_TRACEAGENT
	/* Unload the traceagent */
	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnUnload(agent));
	omr_agent_destroy(agent);
#endif /* TEST_TRACEAGENT */

	/* Load sampleSubscriber agent */
#if defined(WIN32)
	agent = omr_agent_create(&testVM.omrVM, "sampleSubscriber=NUL");
#else /* defined(WIN32) */
	agent = omr_agent_create(&testVM.omrVM, "sampleSubscriber=/dev/null");
#endif /* defined(WIN32) */
	ASSERT_FALSE(NULL == agent) << "testAgent: createAgent() sampleSubscriber failed";

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_openLibrary(agent));

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnLoad(agent));

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnUnload(agent));
	omr_agent_destroy(agent);

	/* Load bindthreadagent agent */
	agent = omr_agent_create(&testVM.omrVM, "bindthreadagent");
	ASSERT_FALSE(NULL == agent) << "testAgent: createAgent() bindthreadagent failed";

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_openLibrary(agent));

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnLoad(agent));

	OMRTEST_ASSERT_ERROR_NONE(omr_agent_callOnUnload(agent));
	omr_agent_destroy(agent);

	OMRTEST_ASSERT_ERROR_NONE(omr_ras_cleanupTraceEngine(vmthread));

	OMRTEST_ASSERT_ERROR_NONE(OMR_Thread_Free(vmthread));

	/* Now clear up the VM we started for this test case. */
	OMRTEST_ASSERT_ERROR_NONE(omrTestVMFini(&testVM));
}