Esempio n. 1
0
LibraryHandle getLibraryHandleForPlugin(const CharString pluginAbsolutePath) {
  HMODULE libraryHandle = LoadLibraryExA((LPCSTR)pluginAbsolutePath->data, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  DWORD errorCode = GetLastError();
  if(libraryHandle == NULL) {
    if(errorCode == ERROR_BAD_EXE_FORMAT) {
      logError("Could not open library, wrong architecture");
    }
    else {
      logError("Could not open library, error code '%s'", stringForLastError(errorCode));
    }
    return NULL;
  }
  return libraryHandle;
}
Esempio n. 2
0
int runIntegrationTest(const char *testName, CharString testArguments,
                       ReturnCode expectedResultCode,
                       const TestOutputType testOutputType,
                       const CharString mrsWatsonExePath,
                       const CharString resourcesPath) {
  int result = 0;
  int returnCode;
  ReturnCode resultCode;
  ChannelCount failedAnalysisChannel;
  SampleCount failedAnalysisFrame;

#if WINDOWS
  STARTUPINFOA startupInfo;
  PROCESS_INFORMATION processInfo;
#endif

  // Remove files from a previous test run
  File outputFolder = newFileWithPathCString(kApplicationRunnerOutputFolder);

  if (fileExists(outputFolder)) {
    _removeOutputFiles(testName);
  } else {
    fileCreate(outputFolder, kFileTypeDirectory);
  }

  freeFile(outputFolder);

  if (mrsWatsonExePath == NULL) {
    return -1;
  } else {
    File mrsWatsonExe = newFileWithPath(mrsWatsonExePath);
    boolByte mrsWatsonExeExists = fileExists(mrsWatsonExe);
    freeFile(mrsWatsonExe);

    if (!mrsWatsonExeExists) {
      freeCharString(testArguments);
      return -1;
    }
  }

  if (resourcesPath == NULL) {
    freeCharString(testArguments);
    return -1;
  } else {
    File resourcesFile = newFileWithPath(resourcesPath);
    boolByte resourcesExists = fileExists(resourcesFile);
    freeFile(resourcesFile);

    if (!resourcesExists) {
      freeCharString(testArguments);
      return -1;
    }
  }

  // Create the command line argument
  CharString arguments = newCharStringWithCapacity(kCharStringLengthLong);
  charStringAppendCString(arguments, "\"");
  charStringAppend(arguments, mrsWatsonExePath);
  charStringAppendCString(arguments, "\"");
  charStringAppendCString(arguments, " ");
  CharString defaultArguments;
  CharString outputFilename = getTestOutputFilename(testName, testOutputType);
  defaultArguments =
      _getDefaultArguments(testName, resourcesPath, outputFilename);
  charStringAppend(arguments, defaultArguments);
  freeCharString(defaultArguments);
  charStringAppendCString(arguments, " ");
  charStringAppend(arguments, testArguments);
  // Although testArguments is passed into this function (and hence, it would
  // generally not take ownership of it), in this case we free the arguments
  // here to make writing the test cases simpler and reduce the amount of
  // boilerplate code.
  freeCharString(testArguments);

#if WINDOWS
  memset(&startupInfo, 0, sizeof(startupInfo));
  memset(&processInfo, 0, sizeof(processInfo));
  startupInfo.cb = sizeof(startupInfo);
  returnCode = CreateProcessA(
      (LPCSTR)(mrsWatsonExePath->data), (LPSTR)(arguments->data), 0, 0, false,
      CREATE_DEFAULT_ERROR_MODE, 0, 0, &startupInfo, &processInfo);

  if (returnCode) {
    // TODO: Check return codes for these calls
    WaitForSingleObject(processInfo.hProcess,
                        kApplicationRunnerWaitTimeoutInMs);
    GetExitCodeProcess(processInfo.hProcess, (LPDWORD)&resultCode);
    CloseHandle(processInfo.hProcess);
    CloseHandle(processInfo.hThread);
  } else {
    logCritical("Could not launch process, got error %s",
                stringForLastError(GetLastError()));
    return 1;
  }

#else
  returnCode = system(arguments->data);
  resultCode = (ReturnCode)WEXITSTATUS(returnCode);
#endif
  freeCharString(arguments);

  if (resultCode == RETURN_CODE_FORK_FAILED ||
      resultCode == RETURN_CODE_SHELL_FAILED ||
      resultCode == RETURN_CODE_LAUNCH_FAILED_OTHER) {
    logCritical("Could not launch shell, got return code %d\n\
Please check the executable path specified in the --mrswatson-path argument.",
                resultCode);
    return 1;
  } else if (resultCode == expectedResultCode) {
    CharString failedAnalysisFunctionName = newCharString();
    if (testOutputType != kTestOutputNone) {
      if (analyzeFile(outputFilename->data, failedAnalysisFunctionName,
                      &failedAnalysisChannel, &failedAnalysisFrame)) {
        // TODO:
        //                if (!testEnvironment->results->keepFiles) {
        //                    _removeOutputFiles(testName);
        //                }
        result = 0;
      } else {
        fprintf(stderr,
                "Audio analysis check for %s failed at frame %lu, channel %d. ",
                failedAnalysisFunctionName->data, failedAnalysisFrame,
                failedAnalysisChannel);
        result = 1;
      }
    } else {
      result = 0;

      // TODO:
      //            if (!testEnvironment->results->keepFiles) {
      //                _removeOutputFiles(testName);
      //            }
    }
    freeCharString(failedAnalysisFunctionName);
  } else {
    fprintf(stderr, "Expected result code %d (%s), got %d (%s). ",
            expectedResultCode, _getResultCodeString(expectedResultCode),
            resultCode, _getResultCodeString(resultCode));
    result = 1;
  }

  freeCharString(outputFilename);
  return result;
}