示例#1
0
/**
 * Verify port library management.
 *
 * The JIT needs to verify that the function it wants to optimize is what
 * it expects, that is an application has not provided it's own implementation.
 * The port library table function
 * @ref omrport.c::omrport_isFunctionOverridden "omrport_isFunctionOverridden"
 * is used for this purpose.
 */
TEST(PortTest, port_test7)
{
	OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
	const char *testName = "omrport_test7";

	OMRPortLibrary *fakePtr = &portLibraryToTest;
	int32_t rc;

	reportTestEntry(OMRPORTLIB, testName);

	memset(&portLibraryToTest, '0', sizeof(OMRPortLibrary));
	rc = omrport_init_library(&portLibraryToTest, sizeof(OMRPortLibrary));
	if (0 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_init_library() returned %d expected 0\n", rc);
	}

	/* override a couple of function */
	fakePtr->mem_startup = fake_mem_startup;
	fakePtr->mem_shutdown = NULL;
	fakePtr->time_hires_clock = NULL;
	fakePtr->time_startup = fakePtr->tty_startup;

	rc = fakePtr->port_isFunctionOverridden(fakePtr, offsetof(OMRPortLibrary, mem_startup));
	if (1 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_isFunctionOverridden returned %d expected 1\n", rc);
	}

	rc = fakePtr->port_isFunctionOverridden(fakePtr, offsetof(OMRPortLibrary, mem_shutdown));
	if (1 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_isFunctionOverridden returned %d expected 1\n", rc);
	}

	rc = fakePtr->port_isFunctionOverridden(fakePtr, offsetof(OMRPortLibrary, time_hires_clock));
	if (1 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_isFunctionOverridden returned %d expected 1\n", rc);
	}

	rc = fakePtr->port_isFunctionOverridden(fakePtr, offsetof(OMRPortLibrary, time_startup));
	if (1 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_isFunctionOverridden returned %d expected 1\n", rc);
	}

	rc = fakePtr->port_isFunctionOverridden(fakePtr, offsetof(OMRPortLibrary, time_hires_frequency));
	if (0 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_isFunctionOverridden returned %d expected 0\n", rc);
	}

	rc = fakePtr->port_isFunctionOverridden(fakePtr, offsetof(OMRPortLibrary, tty_printf));
	if (0 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_isFunctionOverridden returned %d expected 0\n", rc);
	}

	reportTestExit(OMRPORTLIB, testName);
}
示例#2
0
/**
 * Verify port library management.
 *
 * The port library allocates resources as part of it's normal running.  Thus
 * prior to terminating the application the port library must free all it's
 * resource via the port library table function
 * @ref omrport.c::omrport_shutdown_library "omrport_shutdown_library()"
 *
 * @note self allocated port libraries de-allocate their memory as part of this
 * function.
 */
TEST(PortTest, port_test6)
{
	OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
	const char *testName = "omrport_test6";

	OMRPortLibrary *fakePtr;
	int32_t rc;
	omrthread_t attachedThread = NULL;

	reportTestEntry(OMRPORTLIB, testName);

	if (0 != omrthread_attach_ex(&attachedThread, J9THREAD_ATTR_DEFAULT)) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "Failed to attach to omrthread\n");
		goto exit;
	}

	memset(&portLibraryToTest, '0', sizeof(OMRPortLibrary));
	fakePtr = &portLibraryToTest;
	rc = omrport_init_library(fakePtr, sizeof(OMRPortLibrary));
	if (0 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_init_library() returned %d expected 0\n", rc);
	}
	/* Shut it down */
	portLibraryToTest.port_shutdown_library(fakePtr);
	omrthread_detach(attachedThread);

	/* Global pointer should be NULL */
	if (NULL != fakePtr->portGlobals) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "port_shutdown_library() portGlobal pointer is not NULL\n");
	}

	/* Shutdown again, should be ok, nothing to check ...
	 * TODO support this?
	portLibraryToTest.port_shutdown_library(fakePtr);
	 */

	/* Let's do it all over again, this time self allocated
	 * Note a self allocated library does not startup, so there are no
	 * port globals etc.  Verifies the shutdown routines are safe
	 */
	fakePtr = NULL;
	rc = omrport_allocate_library(&fakePtr);
	if (0 != rc) {
		outputErrorMessage(PORTTEST_ERROR_ARGS, "omrport_allocate_library() returned %d expected 0\n", rc);
		goto exit;
	}
	/*	TODO library not started, fair to shut it down ?
	fakePtr->port_shutdown_library(fakePtr);
	*/
	fakePtr = NULL;

exit:
	reportTestExit(OMRPORTLIB, testName);
}
示例#3
0
int main(void)
{
	int32_t totalFiles = 0;
	intptr_t rc = 0;
	char resultBuffer[128];
	uintptr_t rcFile;
	uintptr_t handle;
	OMRPortLibrary portLibrary;

	rc = omrthread_attach_ex(NULL, J9THREAD_ATTR_DEFAULT);
	if (0 != rc) {
		fprintf(stderr, "omrthread_attach_ex(NULL, J9THREAD_ATTR_DEFAULT) failed, rc=%d\n", (int)rc);
		return -1;
	}

	rc = omrport_init_library(&portLibrary, sizeof(OMRPortLibrary));
	if (0 != rc) {
		fprintf(stderr, "omrport_init_library(&portLibrary, sizeof(OMRPortLibrary)), rc=%d\n", (int)rc);
		return -1;
	}

	OMRPORT_ACCESS_FROM_OMRPORT(&portLibrary);

	rcFile = handle = omrfile_findfirst(SRC_DIR, resultBuffer);

	if(rcFile == (uintptr_t)-1) {
		fprintf(stderr, "omrfile_findfirst(SRC_DIR, resultBuffer), return code=%d\n", (int)rcFile);
		return -1;
	}

	while ((uintptr_t)-1 != rcFile) {
		if (strncmp(resultBuffer, VERBOSE_GC_FILE_PREFIX, strlen(VERBOSE_GC_FILE_PREFIX)) == 0) {
			analyze(resultBuffer, portLibrary);
			totalFiles++;
			/* Clean up verbose log file */
			omrfile_unlink(resultBuffer);
		}
		rcFile = omrfile_findnext(handle, resultBuffer);
	}
	if (handle != (uintptr_t)-1) {
		omrfile_findclose(handle);
	}

	if(totalFiles < 1) {
		omrtty_printf("Failed to find any verbose GC file to process!\n\n");
	}

	portLibrary.port_shutdown_library(&portLibrary);
	omrthread_detach(NULL);
}
示例#4
0
文件: JitTest.hpp 项目: LinHu2016/omr
 /**
  * @brief Initialize port library and thread library as a dependency
  *
  * Initialization should happen before any tests deriving from the JitTest
  * fixture are executed. If an error occures during one of the initialization
  * steps, an exception is thrown.
  */
 static void initPortLib()
    {
    if (0 != omrthread_init_library()) { throw FailedThreadLibraryInit(); }
    if (0 != omrthread_attach_ex(&current_thread, J9THREAD_ATTR_DEFAULT)) { throw FailedCurrentThreadAttachment(); }
    if (0 != omrport_init_library(&PortLib, sizeof(OMRPortLibrary))) { throw FailedPortLibraryInit(); }
    }
示例#5
0
文件: main.cpp 项目: bjornvar/omr
int
main(int argc, char *argv[])
{
	omrthread_attach(NULL);

	OMRPortLibrary portLibrary;
	omrport_init_library(&portLibrary, sizeof(portLibrary));
	DDR_RC rc = DDR_RC_OK;

	/* Get options. */
	const char *macroFile = "src/macros/test/macroList";
	const char *supersetFile = "superset.out";
	const char *blobFile = "blob.dat";
	const char *overrideFile = NULL;
	vector<string> debugFiles;
	rc = getOptions(&portLibrary, argc, argv, &macroFile, &supersetFile, &blobFile, &overrideFile, &debugFiles);

	/* Create IR from input. */
#if defined(_MSC_VER)
	PdbScanner scanner;
#else /* defined(_MSC_VER) */
	DwarfScanner scanner;
#endif /* defined(_MSC_VER) */
	Symbol_IR ir;
	if ((DDR_RC_OK == rc) && !debugFiles.empty()) {
		rc = scanner.startScan(&portLibrary, &ir, &debugFiles);
	}

	/* Compute field offsets for UDTs. */
	if (DDR_RC_OK == rc) {
		rc = ir.computeOffsets();
	}
	/* Remove duplicate types. */
	if (DDR_RC_OK == rc) {
		rc = ir.removeDuplicates();
	}
	MacroTool macroTool;
	/* Read macros. */
	if ((DDR_RC_OK == rc) && (NULL != macroFile)) {
		rc = macroTool.getMacros(macroFile);
	}
	/* Add Macros to IR. */
	if (DDR_RC_OK == rc) {
		rc = macroTool.addMacrosToIR(&ir);
	}

	/* Apply Type Overrides; must be after scanning and loading macros. */
	if ((DDR_RC_OK == rc) && (NULL != overrideFile)) {
		rc = ir.applyOverrideList(&portLibrary, overrideFile);
	}

	/* Generate output. */
	if ((DDR_RC_OK == rc) && !ir._types.empty()) {
		rc = genBlob(&portLibrary, &ir, supersetFile, blobFile);
	}

	portLibrary.port_shutdown_library(&portLibrary);
	omrthread_detach(NULL);
	omrthread_shutdown_library();
	return 0;
}