Replace debug_assert, permanent_assert with DCHECK/CHECK

Summary:
Phase 2.

Phase 3.

Phase 4.

Phase 5.

Complete refactor.

Reviewers: florijan, mislav.bradac

Reviewed By: mislav.bradac

Subscribers: mislav.bradac, pullbot

Differential Revision: https://phabricator.memgraph.io/D895
This commit is contained in:
Dominik Gleich
2017-10-11 13:19:10 +02:00
parent 4f7f59f9fc
commit fcecb14545
81 changed files with 612 additions and 692 deletions

View File

@@ -11,7 +11,6 @@
#include "data_structures/concurrent/concurrent_map.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
#include "data_structures/concurrent/skiplist.hpp"
#include "utils/assert.hpp"
// NOTE: this file is highly coupled to data_structures
// TODO: REFACTOR
@@ -44,8 +43,7 @@ template <typename S>
void check_present_same(typename S::Accessor &acc, size_t data,
std::vector<size_t> &owned) {
for (auto num : owned) {
permanent_assert(acc.find(num)->second == data,
"My data is present and my");
CHECK(acc.find(num)->second == data) << "My data is present and my";
}
}
@@ -61,8 +59,8 @@ template <typename S>
void check_size_list(S &acc, long long size) {
// check size
permanent_assert(acc.size() == size,
"Size should be " << size << ", but size is " << acc.size());
CHECK(acc.size() == size)
<< "Size should be " << size << ", but size is " << acc.size();
// check count
@@ -71,16 +69,16 @@ void check_size_list(S &acc, long long size) {
for ([[gnu::unused]] auto elem : acc) {
++iterator_counter;
}
permanent_assert(static_cast<int64_t>(iterator_counter) == size,
"Iterator count should be " << size << ", but size is "
<< iterator_counter);
CHECK(static_cast<int64_t>(iterator_counter) == size)
<< "Iterator count should be " << size << ", but size is "
<< iterator_counter;
}
template <typename S>
void check_size(typename S::Accessor &acc, long long size) {
// check size
permanent_assert(acc.size() == size,
"Size should be " << size << ", but size is " << acc.size());
CHECK(acc.size() == size)
<< "Size should be " << size << ", but size is " << acc.size();
// check count
@@ -89,9 +87,9 @@ void check_size(typename S::Accessor &acc, long long size) {
for ([[gnu::unused]] auto elem : acc) {
++iterator_counter;
}
permanent_assert(static_cast<int64_t>(iterator_counter) == size,
"Iterator count should be " << size << ", but size is "
<< iterator_counter);
CHECK(static_cast<int64_t>(iterator_counter) == size)
<< "Iterator count should be " << size << ", but size is "
<< iterator_counter;
}
// Checks if order in list is maintened. It expects map
@@ -110,16 +108,14 @@ void check_order(typename S::Accessor &acc) {
void check_zero(size_t key_range, long array[], const char *str) {
for (int i = 0; i < static_cast<int>(key_range); i++) {
permanent_assert(array[i] == 0,
str << " doesn't hold it's guarantees. It has " << array[i]
<< " extra elements.");
CHECK(array[i] == 0) << str << " doesn't hold it's guarantees. It has "
<< array[i] << " extra elements.";
}
}
void check_set(DynamicBitset<> &db, std::vector<bool> &set) {
for (int i = 0; i < static_cast<int>(set.size()); i++) {
permanent_assert(!(set[i] ^ db.at(i)),
"Set constraints aren't fullfilled.");
CHECK(!(set[i] ^ db.at(i))) << "Set constraints aren't fullfilled.";
}
}

View File

@@ -15,7 +15,7 @@ constexpr size_t no_insert_for_one_delete = 1;
int main(int argc, char **argv) {
google::InitGoogleLogging(argv[0]);
ConcurrentList<std::pair<int, int>> list;
permanent_assert(list.size() == 0, "The list isn't empty");
CHECK(list.size() == 0) << "The list isn't empty";
auto futures =
run<std::pair<long long, long long>>(THREADS_NO, [&](auto index) mutable {
@@ -47,7 +47,7 @@ int main(int argc, char **argv) {
} else {
for (auto &v : list) {
if (v.first == num) {
permanent_assert(v.second == data, "Data is invalid");
CHECK(v.second == data) << "Data is invalid";
break;
}
}
@@ -69,7 +69,7 @@ int main(int argc, char **argv) {
sums -= e.second;
}
permanent_assert(sums == 0, "Same values aren't present");
CHECK(sums == 0) << "Same values aren't present";
check_size_list<ConcurrentList<std::pair<int, int>>>(list, counters);
std::this_thread::sleep_for(1s);

View File

@@ -23,9 +23,8 @@ void test_lock(int) {
std::unique_lock<Futex> guard(futex);
x++;
std::this_thread::sleep_for(std::chrono::milliseconds(dis(gen)));
permanent_assert(x == 1,
"Other thread shouldn't be able to "
"change the value of x");
CHECK(x == 1) << "Other thread shouldn't be able to "
"change the value of x";
x--;
}
std::this_thread::sleep_for(std::chrono::milliseconds(dis(gen)));

View File

@@ -30,8 +30,8 @@ int main(int, char **argv) {
// get skiplist size
{
auto accessor = skiplist.access();
permanent_assert(accessor.size() == THREADS_NO * elems_per_thread,
"all elements in skiplist");
CHECK(accessor.size() == THREADS_NO * elems_per_thread)
<< "all elements in skiplist";
}
for (size_t thread_i = 0; thread_i < THREADS_NO; ++thread_i) {
@@ -39,7 +39,7 @@ int main(int, char **argv) {
[&skiplist](size_t start, size_t end) {
auto accessor = skiplist.access();
for (size_t elem_i = start; elem_i < end; ++elem_i) {
permanent_assert(accessor.remove(elem_i) == true, "");
CHECK(accessor.remove(elem_i) == true) << "";
}
},
thread_i * elems_per_thread,
@@ -53,8 +53,8 @@ int main(int, char **argv) {
// check size
{
auto accessor = skiplist.access();
permanent_assert(accessor.size() == 0, "Size should be 0, but size is "
<< accessor.size());
CHECK(accessor.size() == 0)
<< "Size should be 0, but size is " << accessor.size();
}
// check count
@@ -65,11 +65,12 @@ int main(int, char **argv) {
++iterator_counter;
cout << elem.first << " ";
}
permanent_assert(iterator_counter == 0, "deleted elements");
CHECK(iterator_counter == 0) << "deleted elements";
}
{
auto accessor = skiplist.access();
check_order<map_t>(accessor);
}
return 0;
}

View File

@@ -35,8 +35,8 @@ int main(int, char **argv) {
// get skiplist size
{
auto accessor = skiplist.access();
permanent_assert(accessor.size() == THREADS_NO * elems_per_thread,
"all elements in skiplist");
CHECK(accessor.size() == THREADS_NO * elems_per_thread)
<< "all elements in skiplist";
}
for (size_t thread_i = 0; thread_i < THREADS_NO; ++thread_i) {
@@ -44,7 +44,7 @@ int main(int, char **argv) {
[&skiplist](size_t start, size_t end) {
auto accessor = skiplist.access();
for (size_t elem_i = start; elem_i < end; ++elem_i) {
permanent_assert(accessor.remove(elem_i) == true, "");
CHECK(accessor.remove(elem_i) == true) << "";
}
},
thread_i * elems_per_thread,
@@ -58,8 +58,8 @@ int main(int, char **argv) {
// check size
{
auto accessor = skiplist.access();
permanent_assert(accessor.size() == 0, "Size should be 0, but size is "
<< accessor.size());
CHECK(accessor.size() == 0)
<< "Size should be 0, but size is " << accessor.size();
}
// check count
@@ -70,6 +70,7 @@ int main(int, char **argv) {
++iterator_counter;
cout << elem.first << " ";
}
permanent_assert(iterator_counter == 0, "deleted elements");
CHECK(iterator_counter == 0) << "deleted elements";
}
return 0;
}

View File

@@ -58,7 +58,8 @@ int main(int argc, char **argv) {
for (auto &e : accessor) {
sums -= e.second;
}
permanent_assert(sums == 0, "Aproximetly Same values are present");
CHECK(sums == 0) << "Aproximetly Same values are present";
check_size<map_t>(accessor, counters);
check_order<map_t>(accessor);
return 0;
}

View File

@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
do {
if (owned.size() != 0 && rand_op()) {
auto rem = rand() % owned.size();
permanent_assert(acc.remove(owned[rem]), "Owned data removed");
CHECK(acc.remove(owned[rem])) << "Owned data removed";
owned.erase(owned.begin() + rem);
downcount--;
} else {
@@ -46,4 +46,5 @@ int main(int argc, char **argv) {
}
check_size<map_t>(accessor, count);
check_order<map_t>(accessor);
return 0;
}

View File

@@ -56,7 +56,8 @@ int main(int argc, char **argv) {
for (auto &e : accessor) {
sums -= e.second;
}
permanent_assert(sums == 0, "Aproximetly Same values are present");
CHECK(sums == 0) << "Aproximetly Same values are present";
check_size<map_t>(accessor, counters);
check_order<map_t>(accessor);
return 0;
}

View File

@@ -50,9 +50,9 @@ int main(int argc, char **argv) {
auto accessor = skiplist.access();
for (int i = 0; i < key_range; i++) {
permanent_assert(set[i] == 0 || set[i] == 1 ||
(set[i] == 1) ^ accessor.contains(std::to_string(i)),
"Set doesn't hold it's guarantees.");
CHECK(set[i] == 0 || set[i] == 1 ||
(set[i] == 1) ^ accessor.contains(std::to_string(i)))
<< "Set doesn't hold it's guarantees.";
}
for (auto &e : accessor) {
@@ -60,4 +60,5 @@ int main(int argc, char **argv) {
}
check_zero(key_range, set, "Set");
return 0;
}

View File

@@ -43,8 +43,8 @@ int main(int argc, char **argv) {
}
} else {
auto value = acc.find(num);
permanent_assert(value == acc.end() || value->second == data,
"Data is invalid");
CHECK(value == acc.end() || value->second == data)
<< "Data is invalid";
}
}
@@ -62,7 +62,7 @@ int main(int argc, char **argv) {
for (auto &e : accessor) {
sums -= e.second;
}
permanent_assert(sums == 0, "Same values aren't present");
CHECK(sums == 0) << "Same values aren't present";
check_size<map_t>(accessor, counters);
check_order<map_t>(accessor);
}

View File

@@ -4,8 +4,9 @@
#include <thread>
#include <vector>
#include "glog/logging.h"
#include "threading/sync/spinlock.hpp"
#include "utils/assert.hpp"
int x = 0;
SpinLock lock;
@@ -19,10 +20,8 @@ void test_lock() {
std::this_thread::sleep_for(25ms);
permanent_assert(
x < 2,
"x always has to be less than 2 (other "
"threads shouldn't be able to change the x simultaneously");
CHECK(x < 2) << "x always has to be less than 2 (other "
"threads shouldn't be able to change the x simultaneously";
x--;
}
}

View File

@@ -1,8 +1,9 @@
#include <thread>
#include <vector>
#include "glog/logging.h"
#include "transactions/engine.hpp"
#include "utils/assert.hpp"
int main() {
// (try to) test correctness of the transaction life cycle
@@ -41,5 +42,6 @@ int main() {
for (uint64_t i = 1; i <= THREADS * TRANSACTIONS; ++i) sum_actual += i;
std::cout << sum_computed << " " << sum_actual << std::endl;
permanent_assert(sum_computed == sum_actual, "sums have to be the same");
CHECK(sum_computed == sum_actual) << "sums have to be the same";
return 0;
}