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