tests/cpp11_mutex: fix NDEBUG compile problem

This commit is contained in:
Gunar Schorcht
2020-03-12 18:04:42 +01:00
parent 944fb3909e
commit bc071044d7
2 changed files with 43 additions and 35 deletions
+11 -4
View File
@@ -19,7 +19,6 @@
*/
#include <string>
#include <cstdio>
#include <cassert>
#include <system_error>
#include "riot/mutex.hpp"
@@ -27,6 +26,8 @@
#include "riot/thread.hpp"
#include "riot/condition_variable.hpp"
#include "test_utils/expect.h"
using namespace std;
using namespace riot;
@@ -46,16 +47,22 @@ int main() {
m.unlock();
}
};
#ifndef NDEBUG
/* We can't use expect here, otherwise cppcheck will produce errors */
assert(resource == 0);
#endif
auto start = std::chrono::system_clock::now();
thread t1(f);
thread t2(f);
t1.join();
t2.join();
#ifndef NDEBUG
/* We can't use expect here, otherwise cppcheck will produce errors */
assert(resource == 6);
#endif
auto duration = std::chrono::duration_cast
<chrono::milliseconds>(std::chrono::system_clock::now() - start);
assert(duration.count() >= 600);
expect(duration.count() >= 600);
}
puts("Done\n");
@@ -65,7 +72,7 @@ int main() {
m.lock();
thread([&m] {
auto res = m.try_lock();
assert(res == false);
expect(res == false);
}).detach();
m.unlock();
}
@@ -74,7 +81,7 @@ int main() {
mutex m;
thread([&m] {
auto res = m.try_lock();
assert(res == true);
expect(res == true);
m.unlock();
}).detach();
}