aboutsummaryrefslogtreecommitdiff
path: root/test_common/harness/os_helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test_common/harness/os_helpers.cpp')
-rw-r--r--test_common/harness/os_helpers.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/test_common/harness/os_helpers.cpp b/test_common/harness/os_helpers.cpp
index 8fc91108..3989edf6 100644
--- a/test_common/harness/os_helpers.cpp
+++ b/test_common/harness/os_helpers.cpp
@@ -30,8 +30,17 @@
#if defined(__ANDROID__)
#include <android/api-level.h>
+#include "harness/mt19937.h"
#endif
+#if !defined(_WIN32)
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
+#include <unistd.h>
+#endif
+
+
#define CHECK_PTR(ptr) \
if ((ptr) == NULL) \
{ \
@@ -283,7 +292,7 @@ std::string exe_path()
exit(2);
}; // if
- if (len < path.size())
+ if (static_cast<size_t>(len) < path.size())
{
// We got the path.
path.resize(len);
@@ -556,4 +565,27 @@ char* get_exe_dir()
} // get_exe_dir
+char* get_temp_filename()
+{
+ char gFileName[256] = "";
+ // Create a unique temporary file to allow parallel executed tests.
+#if (defined(__linux__) || defined(__APPLE__)) && (!defined(__ANDROID__))
+ sprintf(gFileName, "/tmp/tmpfile.XXXXXX");
+ int fd = mkstemp(gFileName);
+ if (fd == -1) return strdup(gFileName);
+ close(fd);
+#elif defined(_WIN32)
+ UINT ret = GetTempFileName(".", "tmp", 0, gFileName);
+ if (ret == 0) return gFileName;
+#else
+ MTdata d = init_genrand((cl_uint)time(NULL));
+ sprintf(gFileName, "tmpfile.%u", genrand_int32(d));
+#endif
+
+ char* fn = strdup(gFileName);
+ CHECK_PTR(fn);
+ return fn;
+}
+
+
// end of file //