Browse Source

Investigation logs added

master
Ludovic 'Archivist' Lagouardette 2 years ago
parent
commit
c501155230
1 changed files with 22 additions and 3 deletions
  1. +22
    -3
      tests/issue15_test.cpp

+ 22
- 3
tests/issue15_test.cpp View File

@ -41,9 +41,10 @@ struct std_allocator : gp::allocator {
log_segment("data deallocated", "Trying deallocation");
log_segment("data deallocated", ("Target: @" + std::to_string((uintptr_t)ptr)).c_str());
if(!debug_info.contains(ptr))
gp_config::assertion(false, "Double free detected");
if(!debug_info.contains(ptr)) {
print_logs();
gp_config::assertion(false, "Double free detected");
}
delete (char*)ptr;
log_segment("data deallocated", (std::to_string(debug_info[ptr]) + " bytes @"+std::to_string((uintptr_t)ptr)).c_str());
@ -107,12 +108,14 @@ gp::pair, parsing_state> read_cbor(parsin
size_t seq, attempts;
identifier_t uuid;
gp::vector<char> data{alloc};
log_segment("INFO", "Init stage");
bool ok = true;
auto array_parser = [&](parsing_state state, allocator& alloc){
for(size_t idx : {0,1,2,3})
switch(idx) {
case 0:{
log_segment("INFO", "Array stage 0");
auto [v ,new_state] = read_cbor<uint64_t>(state, alloc);
if(v.has_value()) {
seq = v.value();
@ -120,6 +123,7 @@ gp::pair, parsing_state> read_cbor(parsin
}
}break;
case 1:{
log_segment("INFO", "Array stage 1");
auto [v ,new_state] = read_cbor<uint64_t>(state, alloc);
if(v.has_value()) {
attempts = v.value();
@ -127,22 +131,29 @@ gp::pair, parsing_state> read_cbor(parsin
}
}break;
case 2:{
log_segment("INFO", "Array stage 2");
auto [tg ,nc_state] = read_cbor<cbor_tag_initiator>(state, alloc);
if(!tg.has_value()) break;
if(tg.value().as_integer != 37) break;
log_segment("INFO", "\tGet UUID");
auto [v ,new_state] = read_cbor<gp::vector<char>>(nc_state, alloc);
if(v.has_value()) {
log_segment("INFO", "\tUUID obtained");
for(size_t idx : {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}) {
uuid[idx] = v.value()[idx];
}
return new_state;
}
log_segment("INFO", "\tUUID not found");
}break;
case 3:{
log_segment("INFO", "Array stage 3");
auto [v ,new_state] = read_cbor<gp::vector<char>>(state, alloc);
if(v.has_value()) {
log_segment("INFO", "Data copy");
data = v.value();
log_segment("INFO", "ready to return last stale");
return new_state;
}
}break;
@ -154,22 +165,27 @@ gp::pair, parsing_state> read_cbor(parsin
parsing_state nc_state = state;
{
log_segment("INFO", "Tag stage");
auto [value, new_state] = read_cbor<cbor_tag_initiator>(nc_state, alloc);
if(!value.has_value()) return {gp::nullopt, state};
nc_state = new_state;
}
{
log_segment("INFO", "Array info stage");
auto new_state = read_cbor_array(nc_state, alloc, array_parser, [&](size_t sz){
ok &= sz == 4;
log_segment("ok", ok ? "true" : "false");
return ok;
});
log_segment("INFO", "Parser returned... Testing");
if(ok && new_state.size() != nc_state.size()) {
log_segment("INFO", "Parsing terminated successfully");
return {packet_info{.attempts = attempts, .sequence = seq, .data = gp::move(data)}, new_state};
}
else
else{
log_segment("INFO", ("Parsing failed with ok=" + std::string(ok ? "true" : "false")).c_str());
return {nullopt, state};
}
}
}}
@ -214,12 +230,15 @@ struct packet_info_deserialization_test : public test_scaffold {
for(auto idx : {0,1,2,3,4,5,6,7,8,9}) item.data.push_back(idx);
gp::vector<char> serialized(allocator);
log_segment("INFO", "Serialization init");
push_as_cbor(serialized, item);
log_segment("INFO", "Item serialized");
log_segment("size", std::to_string(serialized.size()).c_str());
gp_config::assertion(serialized.size() == 36, "serialization of the wrong size");
log_segment("INFO", "Item controlled");
auto [value, state] = gp::read_cbor<packet_info>(serialized.as_buffer(), allocator);

Loading…
Cancel
Save