Changeset View
Changeset View
Standalone View
Standalone View
src/test/util_tests.cpp
Show First 20 Lines • Show All 1,248 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_ParseFixedPoint) { | ||||
BOOST_CHECK(!ParseFixedPoint("1.", 8, &amount)); | BOOST_CHECK(!ParseFixedPoint("1.", 8, &amount)); | ||||
} | } | ||||
static void TestOtherThread(fs::path dirname, std::string lockname, | static void TestOtherThread(fs::path dirname, std::string lockname, | ||||
bool *result) { | bool *result) { | ||||
*result = LockDirectory(dirname, lockname); | *result = LockDirectory(dirname, lockname); | ||||
} | } | ||||
#ifndef WIN32 // Cannot do this test on WIN32 due to lack of fork() | #ifndef WIN32 // Cannot do this test on WIN32 due to lack of fork() | ||||
markblundeberg: Note - this test only runs in non-WIN32 systems as seen here, and "true" is a fairly old and… | |||||
static constexpr char LockCommand = 'L'; | static constexpr char LockCommand = 'L'; | ||||
static constexpr char UnlockCommand = 'U'; | static constexpr char UnlockCommand = 'U'; | ||||
static constexpr char ExitCommand = 'X'; | static constexpr char ExitCommand = 'X'; | ||||
static void TestOtherProcess(fs::path dirname, std::string lockname, int fd) { | static void TestOtherProcess(fs::path dirname, std::string lockname, int fd) { | ||||
char ch; | char ch; | ||||
while (true) { | while (true) { | ||||
// Wait for command | // Wait for command | ||||
int rv = read(fd, &ch, 1); | int rv = read(fd, &ch, 1); | ||||
assert(rv == 1); | assert(rv == 1); | ||||
switch (ch) { | switch (ch) { | ||||
case LockCommand: | case LockCommand: | ||||
ch = LockDirectory(dirname, lockname); | ch = LockDirectory(dirname, lockname); | ||||
rv = write(fd, &ch, 1); | rv = write(fd, &ch, 1); | ||||
assert(rv == 1); | assert(rv == 1); | ||||
break; | break; | ||||
case UnlockCommand: | case UnlockCommand: | ||||
ReleaseDirectoryLocks(); | ReleaseDirectoryLocks(); | ||||
ch = true; // Always succeeds | ch = true; // Always succeeds | ||||
rv = write(fd, &ch, 1); | rv = write(fd, &ch, 1); | ||||
assert(rv == 1); | assert(rv == 1); | ||||
break; | break; | ||||
case ExitCommand: | case ExitCommand: | ||||
close(fd); | close(fd); | ||||
exit(0); | // As an alternative to exit() which runs the exit handlers | ||||
// (which seem to be flakey with Boost test suite with JUNIT | |||||
// logging in a forked process), just vanish this process as | |||||
// fast as possible. (quick_exit() would also work, but it | |||||
// triggers a spurious glibc-valgrind error in pre-3.15 | |||||
// versions.) Using exec also stops valgrind from thinking it | |||||
// needs to analyze the memory leaks in this forked process. | |||||
execlp("true", "true", (char *)NULL); | |||||
default: | default: | ||||
assert(0); | assert(0); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
BOOST_AUTO_TEST_CASE(test_LockDirectory) { | BOOST_AUTO_TEST_CASE(test_LockDirectory) { | ||||
▲ Show 20 Lines • Show All 198 Lines • Show Last 20 Lines |
Note - this test only runs in non-WIN32 systems as seen here, and "true" is a fairly old and trustworthy command on unix systems which I imagine are the only ones that do support fork(). https://en.wikipedia.org/wiki/True_and_false_(commands)