#include "log/messages.h"
#include "main/thread.h"
+#include "managers/module_manager.h"
#include "profiler/profiler.h"
#include "time/periodic.h"
#include "trace/trace_api.h"
void Profiler::register_module(const char*, const char*, snort::Module*) { }
+void ModuleManager::accumulate_module(const char*) { }
+
//--------------------------------------------------------------------------
// mocks
//--------------------------------------------------------------------------
}
+void set_thread_type(SThreadType)
+{ pkt_thread = false; }
+
static void free_space()
{
pkt_thread = true;
pkt_thread = false;
}
+static MemoryCounts& get_main_stats()
+{
+ return MemoryCap::get_mem_stats();
+}
+
+static MemoryCounts& get_pkt_stats()
+{
+ pkt_thread = true;
+ MemoryCounts& res = MemoryCap::get_mem_stats();
+ pkt_thread = false;
+ return res;
+}
+
//--------------------------------------------------------------------------
// tests
//--------------------------------------------------------------------------
MemoryCap::start(config, pruner);
MemoryCap::thread_init();
- const MemoryCounts& mc = MemoryCap::get_mem_stats();
+ const MemoryCounts& mc = get_main_stats();
+ const MemoryCounts& pc = get_pkt_stats();
CHECK(mc.start_up_use == start);
fd.flows = 3;
free_space(); // finish pruning
UNSIGNED_LONGS_EQUAL(1, fd.flows);
- UNSIGNED_LONGS_EQUAL(2, mc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_decrease);
free_space();
UNSIGNED_LONGS_EQUAL(1, fd.flows);
- UNSIGNED_LONGS_EQUAL(2, mc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_decrease);
periodic_check(); // still over the limit
CHECK(heap->epoch == 3);
free_space(); // abort
UNSIGNED_LONGS_EQUAL(0, fd.flows);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_decrease);
heap->total = cap + 1; // over the limit
periodic_check();
free_space(); // abort, reap_increase update
UNSIGNED_LONGS_EQUAL(0, fd.flows);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(4, mc.reap_increase);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(4, pc.reap_increase);
heap->total = cap + 1; // over the limit
periodic_check();
free_space(); // abort, reap_increase update
UNSIGNED_LONGS_EQUAL(0, fd.flows);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(6, mc.reap_increase);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(6, pc.reap_increase);
UNSIGNED_LONGS_EQUAL(start, mc.start_up_use);
UNSIGNED_LONGS_EQUAL(cap + 1, mc.max_in_use);
UNSIGNED_LONGS_EQUAL(cap, mc.cur_in_use);
UNSIGNED_LONGS_EQUAL(heap->epoch, mc.epochs);
- UNSIGNED_LONGS_EQUAL(heap->alloc, mc.allocated);
- UNSIGNED_LONGS_EQUAL(heap->dealloc, mc.deallocated);
+ UNSIGNED_LONGS_EQUAL(heap->alloc, pc.allocated);
+ UNSIGNED_LONGS_EQUAL(heap->dealloc, pc.deallocated);
- UNSIGNED_LONGS_EQUAL(4, mc.reap_cycles);
- UNSIGNED_LONGS_EQUAL(5, mc.reap_attempts);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_failures);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_aborts);
+ UNSIGNED_LONGS_EQUAL(4, pc.reap_cycles);
+ UNSIGNED_LONGS_EQUAL(5, pc.reap_attempts);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_failures);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_aborts);
heap->total = start;
MemoryCap::stop();
free_space();
CHECK(fd.flows == 0);
- const MemoryCounts& mc = MemoryCap::get_mem_stats();
- UNSIGNED_LONGS_EQUAL(1, mc.reap_cycles);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_attempts);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_failures);
- UNSIGNED_LONGS_EQUAL(1, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_increase);
+ const MemoryCounts& pc = get_pkt_stats();
+ UNSIGNED_LONGS_EQUAL(1, pc.reap_cycles);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_attempts);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_failures);
+ UNSIGNED_LONGS_EQUAL(1, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_increase);
MemoryCap::stop();
}
free_space();
CHECK(fd.flows == 1);
- const MemoryCounts& mc = MemoryCap::get_mem_stats();
- UNSIGNED_LONGS_EQUAL(2, mc.reap_cycles);
- UNSIGNED_LONGS_EQUAL(2, mc.reap_attempts);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_failures);
- UNSIGNED_LONGS_EQUAL(11, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_increase);
+ const MemoryCounts& pc = get_pkt_stats();
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_cycles);
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_attempts);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_failures);
+ UNSIGNED_LONGS_EQUAL(11, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_increase);
MemoryCap::stop();
}
MemoryCap::start(config, pruner);
MemoryCap::thread_init();
- const MemoryCounts& mc = MemoryCap::get_mem_stats();
+ const MemoryCounts& pc = get_pkt_stats();
fd.flows = 1;
heap->total = cap + 1;
free_space(); // reap failure
CHECK(fd.flows == -1);
- UNSIGNED_LONGS_EQUAL(1, mc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(1, pc.reap_decrease);
fd.flows = 1;
heap->total = cap + 1;
free_space(); // reap failure, reap_increase update
CHECK(fd.flows == -1);
- UNSIGNED_LONGS_EQUAL(1, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(2, mc.reap_increase);
+ UNSIGNED_LONGS_EQUAL(1, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_increase);
fd.flows = 1;
heap->total = cap + 1;
free_space(); // reap failure, reap_increase update
CHECK(fd.flows == -1);
- UNSIGNED_LONGS_EQUAL(1, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_increase);
+ UNSIGNED_LONGS_EQUAL(1, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_increase);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_cycles);
- UNSIGNED_LONGS_EQUAL(6, mc.reap_attempts);
- UNSIGNED_LONGS_EQUAL(3, mc.reap_failures);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_cycles);
+ UNSIGNED_LONGS_EQUAL(6, pc.reap_attempts);
+ UNSIGNED_LONGS_EQUAL(3, pc.reap_failures);
MemoryCap::stop();
}
free_space();
UNSIGNED_LONGS_EQUAL(0, fd.flows);
- const MemoryCounts& mc = MemoryCap::get_mem_stats();
- UNSIGNED_LONGS_EQUAL(1, mc.reap_cycles);
- UNSIGNED_LONGS_EQUAL(2, mc.reap_attempts);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_failures);
- UNSIGNED_LONGS_EQUAL(2, mc.reap_decrease);
- UNSIGNED_LONGS_EQUAL(0, mc.reap_increase);
+ const MemoryCounts& pc = get_pkt_stats();
+ UNSIGNED_LONGS_EQUAL(1, pc.reap_cycles);
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_attempts);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_failures);
+ UNSIGNED_LONGS_EQUAL(2, pc.reap_decrease);
+ UNSIGNED_LONGS_EQUAL(0, pc.reap_increase);
MemoryCap::stop();
}