More work on debug_string

This commit is contained in:
2021-07-21 16:10:29 -04:00
parent c2a69b5b23
commit 49a4ec220d
6 changed files with 142 additions and 95 deletions

View File

@@ -1,11 +1,10 @@
#include "idalloc.hpp"
#include <iostream>
#include <map>
#include <sstream>
#include <ostream>
static int64_t nthbatch(int64_t n) {
return int64_t(0x0001000000000000) + n*256;
}
static bool ranges_equal(const std::deque<int64_t> &dq, int64_t a, int64_t b, int64_t c) {
if (dq.size() != 3) return false;
@@ -100,6 +99,17 @@ void IdGlobalPool::deserialize(StreamBuffer *sb) {
}
}
std::string IdGlobalPool::debug_string() const {
std::ostringstream oss;
oss << "next_batch:" << util::hex64() << next_batch_ << " ";
oss << "next_id:" << util::hex64() << next_id_ << " ";
oss << "salvaged:";
for (const int64_t val : salvaged_) {
oss << " " << util::hex64() << val;
}
return oss.str();
}
IdPlayerPool::IdPlayerPool(IdGlobalPool *g) {
global_ = g;
fifo_capacity_ = 0;
@@ -252,6 +262,20 @@ void IdPlayerPool::apply_patch(StreamBuffer *sb) {
}
}
std::string IdPlayerPool::debug_string() const {
std::ostringstream oss;
oss << "cap:" << fifo_capacity_ << " ids:";
for (int i = 0; i < int(ranges_.size()); i++) {
if (i > 0) oss << ",";
oss << util::hex64() << ranges_[i];
}
return oss.str();
}
static int64_t nthbatch(int64_t n) {
return int64_t(0x0001000000000000) + n*256;
}
LuaDefine(unittests_idalloc, "c") {
IdGlobalPool gp;
IdPlayerPool pp(&gp);
@@ -425,12 +449,10 @@ LuaDefine(unittests_idalloc, "c") {
pp.test_push_back(123);
pp.test_push_back(456);
// transmit and compare. Add extra bytes
// transmit and compare.
sb.clear();
LuaAssert(L, ppds.make_patch(pp, &sb));
sb.write_uint32(0);
ppds.apply_patch(&sb);
LuaAssert(L, sb.total_writes() - sb.total_reads() == 4);
LuaAssert(L, ppds.exactly_equal(pp));
// Pop a value from master pool