1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 11 февр. 2019 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef TEST_MAIN_TYPES_H_ 23 #define TEST_MAIN_TYPES_H_ 24 25 #include <common/types.h> 26 #include <data/cvector.h> 27 #include <test/ptest.h> 28 #include <test/utest.h> 29 #include <test/mtest.h> 30 #include <sys/stat.h> 31 32 #ifdef PLATFORM_WINDOWS 33 #include <processthreadsapi.h> 34 #include <sysinfoapi.h> 35 #include <errhandlingapi.h> 36 #endif 37 38 #ifdef PLATFORM_UNIX_COMPATIBLE 39 #include <unistd.h> 40 #include <sys/wait.h> 41 42 #include <fcntl.h> 43 #endif /* PLATFORM_UNIX_COMPATIBLE */ 44 45 #if defined(PLATFORM_LINUX) && defined(USE_GLIBC) 46 #include <mcheck.h> 47 #endif /* PLATFORM_LINUX */ 48 49 #if defined(PLATFORM_WINDOWS) 50 typedef PROCESS_INFORMATION test_pid_t; 51 typedef FILETIME test_clock_t; 52 #else 53 typedef pid_t test_pid_t; 54 typedef struct timespec test_clock_t; 55 #endif 56 57 namespace lsp 58 { 59 typedef struct stats_t 60 { 61 size_t total; 62 double overall; 63 64 cvector<test::Test> success; // List of failed tests 65 cvector<test::Test> failed; // List of failed tests 66 cvector<test::Test> ignored; // List of ignored tests 67 } stats_t; 68 69 typedef struct task_t 70 { 71 pid_t pid; 72 struct timespec submitted; 73 test::UnitTest *utest; 74 } task_t; 75 76 #if defined(PLATFORM_WINDOWS) get_test_time(test_clock_t * clock)77 inline void get_test_time(test_clock_t *clock) 78 { 79 GetSystemTimeAsFileTime(clock); 80 } 81 calc_test_time_difference(const test_clock_t * begin,const test_clock_t * end)82 inline double calc_test_time_difference(const test_clock_t *begin, const test_clock_t *end) 83 { 84 uint64_t ibegin = (uint64_t(begin->dwHighDateTime) << 32) | begin->dwLowDateTime; 85 uint64_t iend = (uint64_t(end->dwHighDateTime) << 32) | end->dwLowDateTime; 86 return (iend - ibegin) * 1e-7; 87 } 88 #else get_test_time(test_clock_t * clock)89 inline void get_test_time(test_clock_t *clock) 90 { 91 clock_gettime(CLOCK_REALTIME, clock); 92 } 93 calc_test_time_difference(const test_clock_t * begin,const test_clock_t * end)94 inline double calc_test_time_difference(const test_clock_t *begin, const test_clock_t *end) 95 { 96 return (end->tv_sec - begin->tv_sec) + (end->tv_nsec - begin->tv_nsec) * 1e-9; 97 } 98 #endif /* PLATFORM_WINDOWS */ 99 } 100 101 #endif /* TEST_MAIN_TYPES_H_ */ 102