Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / helpers / tests_file_utils.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * \brief TODO: short file description
7  * \file file_utils.h
8  */
9 #pragma once
10 #include <string>
11 #ifdef _WIN32
12 #define _WINSOCKAPI_
13 #include <windows.h>
14 #endif
15
16 #ifdef __MACH__
17 #include <mach/clock.h>
18 #include <mach/mach.h>
19 #endif
20
21 namespace testing { namespace FileUtils {
22 #ifdef _WIN32
23     /// @brief TODO: description
24     const std::string FileSeparator = "\\";
25 #else
26     /// @brief TODO: description
27     const std::string FileSeparator = "/";
28 #endif
29     /// @brief TODO: description
30     const std::string FileSeparator2 = "/"; // second option
31
32     /**
33      * @brief TODO: description
34      * @param fileName - TODO: param
35      * @return TODO: ret obj
36      */
37     long long fileSize(const char *fileName);
38
39     /**
40      * @brief TODO: description
41      * @param f - TODO: param
42      * @return TODO: ret obj
43      */
44     inline long long fileSize(const std::string& f) {
45         return fileSize(f.c_str());
46     }
47
48     /**
49      * @brief TODO: description
50      * @param fileName - TODO: param
51      * @return TODO: ret obj
52      */
53     inline bool fileExist(const char *fileName) {
54         return fileSize(fileName)>=0;
55     }
56
57     /**
58      * @brief TODO: description
59      * @param fileName - TODO: param
60      * @return TODO: ret obj
61      */
62     inline bool fileExist(const std::string &fileName) {
63         return fileExist(fileName.c_str());
64     }
65
66     /**
67      * @brief TODO: description
68      * @param file_name - TODO: param
69      * @param buffer - TODO: param
70      * @param maxSize - TODO: param
71      */
72     void readAllFile(const std::string& file_name, void* buffer, size_t maxSize);
73
74     /**
75      * @brief TODO: description
76      * @param filepath - TODO: param
77      * @return TODO: ret obj
78      */
79     std::string folderOf(const std::string &filepath);
80
81     /**
82      * @brief TODO: description
83      * @param folder - TODO: param
84      * @param file - TODO: param
85      * @return TODO: ret obj
86      */
87     std::string makePath(const std::string& folder, const std::string& file);
88
89     /**
90      * @brief TODO: description
91      * @param filepath - TODO: param
92      * @return TODO: ret obj
93      */
94     std::string fileNameNoExt(const std::string &filepath);
95
96     /**
97      * @brief TODO: description
98      * @param filename - TODO: param
99      * @return TODO: ret obj
100      */
101     std::string fileExt(const char* filename);
102
103     /**
104      * @brief TODO: description
105      * @param filename - TODO: param
106      * @return TODO: ret obj
107      */
108     std::string fileExt(const std::string &filename);
109
110     /**
111      * @brief TODO: description
112      * @return TODO: please use c++11 chrono module for time operations
113      */
114     inline long long GetMicroSecTimer() {
115
116     #ifdef _WIN32
117         static LARGE_INTEGER Frequency = { 0 };
118         LARGE_INTEGER timer;
119         if (Frequency.QuadPart==0) QueryPerformanceFrequency(&Frequency);   
120         QueryPerformanceCounter(&timer);
121         return (timer.QuadPart * 1000000) / Frequency.QuadPart;
122     #else
123         struct timespec now;
124         #ifdef __MACH__
125             clock_serv_t cclock;
126             mach_timespec_t mts;
127             host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
128             clock_get_time(cclock, &mts);
129             mach_port_deallocate(mach_task_self(), cclock);
130             now.tv_sec = mts.tv_sec;
131             now.tv_nsec = mts.tv_nsec;
132         #else
133             clock_gettime(CLOCK_REALTIME, &now);
134         #endif
135         return now.tv_sec * 1000000L + now.tv_nsec / 1000;
136     #endif
137
138
139     }
140 }}
141