123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "test_base.hpp"
- #include <unistd.h>
- #include <string.h>
- #include <cerrno>
- #include <string>
- #include <utility>
- #include "cnstream_logging.hpp"
- extern int errno;
- std::string GetExePath() {
- char path[PATH_MAX_LENGTH];
- int cnt = readlink("/proc/self/exe", path, PATH_MAX_LENGTH);
- if (cnt < 0 || cnt >= PATH_MAX_LENGTH) {
- return "";
- }
- for (int i = cnt - 1; i >= 0; --i) {
- if ('/' == path[i]) {
- path[i + 1] = '\0';
- break;
- }
- }
- std::string result(path);
- return result;
- }
- void CheckExePath(const std::string& path) {
- if (path.size() == 0) {
- LOGF_IF(COREUNITEST, 0 != errno) << std::string(strerror(errno));
- LOGF(COREUNITEST) << "length of exe path is larger than " << PATH_MAX_LENGTH;
- }
- }
- std::pair<int, std::string> CreateTempFile(const std::string& filename_prefix) {
- char filename[1024];
- if (filename_prefix.size() > 1024 - 7) {
- LOGF(COREUNITEST) << "filename_prefix is too long, must be less than " << 1024 - 7 << std::endl;
- }
- strncpy(filename, filename_prefix.c_str(), filename_prefix.size());
- strncpy(filename + filename_prefix.size(), "XXXXXX", 6);
- filename[filename_prefix.size() + 6] = '\0';
- int fd = mkstemp(filename);
- LOGF_IF(COREUNITEST, -1 == fd) << "Create temporary file for BuildPipelineByJSONFile test case failed! "
- << strerror(errno);
- return std::make_pair(fd, std::string(filename));
- }
|