GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/util/testing.h
Date: 2025-06-29 02:35:41
Exec Total Coverage
Lines: 0 29 0.0%
Branches: 0 42 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_UTIL_TESTING_H_
6 #define CVMFS_UTIL_TESTING_H_
7
8
9 #include <cstdlib>
10
11
12 #ifdef CVMFS_NAMESPACE_GUARD
13 namespace CVMFS_NAMESPACE_GUARD {
14 #endif
15
16 #ifdef DEBUGMSG
17 // Let an external program pause cvmfs if
18 // - program runs in debug mode
19 // - the given environment variable is defined _and_
20 // - points to an existing file
21 // - whose content is stop/start
22 void CVMFS_TEST_INJECT_BARRIER(const char *env) {
23 char *value = getenv(env);
24 if (value == NULL)
25 return;
26 int fd = open(value, O_RDONLY);
27 if (fd < 0)
28 return;
29 std::string action;
30 bool retval = SafeReadToString(fd, &action);
31 close(fd);
32 if (!retval)
33 return;
34 action = Trim(action, true /* trim_newline */);
35 if (action != "pause")
36 return;
37 Prng prng;
38 prng.InitLocaltime();
39 while (true) {
40 int fd = open(value, O_RDONLY);
41 if (fd < 0)
42 return;
43 retval = SafeReadToString(fd, &action);
44 close(fd);
45 action = Trim(action, true /* trim_newline */);
46 if (action == "resume")
47 break;
48 if (action == "resume one") {
49 SafeWriteToFile("pause", value, 0644);
50 break;
51 }
52 SafeSleepMs(prng.Next(1000));
53 }
54 }
55 #else
56 #define CVMFS_TEST_INJECT_BARRIER(...) ((void)0)
57 #endif
58
59 #ifdef CVMFS_NAMESPACE_GUARD
60 } // namespace CVMFS_NAMESPACE_GUARD
61 #endif
62
63 #endif // CVMFS_UTIL_TESTING_H_
64