Allow cloc tests to be run from default location.

Change-Id: Ic5f8e34ff261b45100c98a6065b1aeaab3c4d665
This commit is contained in:
Zdunowski, Piotr 2018-02-21 14:42:23 +01:00 committed by sys_ocldev
parent b4f79e036f
commit 46f3efd79c
2 changed files with 25 additions and 3 deletions

View File

@ -272,11 +272,13 @@ int main(int argc, char **argv) {
#ifdef WIN32
#include <direct.h>
_chdir(hardwarePrefix[productFamily]);
if (_chdir(hardwarePrefix[productFamily])) {
std::cout << "chdir into " << hardwarePrefix[productFamily] << " directory failed.\nThis might cause test failures." << std::endl;
}
#elif defined(__linux__)
#include <unistd.h>
if (chdir(hardwarePrefix[productFamily]) != 0) {
std::cout << "chdir failed! Ignoring." << std::endl;
std::cout << "chdir into " << hardwarePrefix[productFamily] << " directory failed.\nThis might cause test failures." << std::endl;
}
#endif

View File

@ -43,7 +43,15 @@ std::string getRunPath(char *argv0) {
auto pos = res.rfind(fSeparator);
if (pos != std::string::npos)
return res.substr(0, pos);
res = res.substr(0, pos);
if (res == "." || pos == std::string::npos) {
#if defined(__linux__)
res = getcwd(nullptr, 0);
#else
res = _getcwd(nullptr, 0);
#endif
}
return res;
}
@ -96,6 +104,18 @@ int main(int argc, char **argv) {
nTestFiles.append(testFiles);
testFiles = nTestFiles;
#ifdef WIN32
#include <direct.h>
if (_chdir(devicePrefix.c_str())) {
std::cout << "chdir into " << devicePrefix << " directory failed.\nThis might cause test failures." << std::endl;
}
#elif defined(__linux__)
#include <unistd.h>
if (chdir(devicePrefix.c_str()) != 0) {
std::cout << "chdir into " << devicePrefix << " directory failed.\nThis might cause test failures." << std::endl;
}
#endif
if (useDefaultListener == false) {
::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
::testing::TestEventListener *defaultListener = listeners.default_result_printer();