mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Make --disable-buf-freelists build and pass unit tests
This commit is contained in:
parent
cdc64f020c
commit
91ff10f6be
@ -117,6 +117,9 @@ chunk_repack(chunk_t *chunk)
|
|||||||
chunk->data = &chunk->mem[0];
|
chunk->data = &chunk->mem[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Keep track of total size of allocated chunks for consistency asserts */
|
||||||
|
static size_t total_bytes_allocated_in_chunks = 0;
|
||||||
|
|
||||||
#if defined(ENABLE_BUF_FREELISTS) || defined(RUNNING_DOXYGEN)
|
#if defined(ENABLE_BUF_FREELISTS) || defined(RUNNING_DOXYGEN)
|
||||||
/** A freelist of chunks. */
|
/** A freelist of chunks. */
|
||||||
typedef struct chunk_freelist_t {
|
typedef struct chunk_freelist_t {
|
||||||
@ -148,9 +151,6 @@ static chunk_freelist_t freelists[] = {
|
|||||||
* could help with? */
|
* could help with? */
|
||||||
static uint64_t n_freelist_miss = 0;
|
static uint64_t n_freelist_miss = 0;
|
||||||
|
|
||||||
/** DOCDOC */
|
|
||||||
static size_t total_bytes_allocated_in_chunks = 0;
|
|
||||||
|
|
||||||
static void assert_freelist_ok(chunk_freelist_t *fl);
|
static void assert_freelist_ok(chunk_freelist_t *fl);
|
||||||
|
|
||||||
/** Return the freelist to hold chunks of size <b>alloc</b>, or NULL if
|
/** Return the freelist to hold chunks of size <b>alloc</b>, or NULL if
|
||||||
|
@ -481,13 +481,22 @@ test_buffer_allocation_tracking(void *arg)
|
|||||||
fetch_from_buf(junk, 4096, buf1); /* drop a 1k chunk... */
|
fetch_from_buf(junk, 4096, buf1); /* drop a 1k chunk... */
|
||||||
tt_int_op(buf_allocation(buf1), ==, 3*4096); /* now 3 4k chunks */
|
tt_int_op(buf_allocation(buf1), ==, 3*4096); /* now 3 4k chunks */
|
||||||
|
|
||||||
|
#ifdef ENABLE_BUF_FREELISTS
|
||||||
tt_int_op(buf_get_total_allocation(), ==, 16384); /* that chunk went onto
|
tt_int_op(buf_get_total_allocation(), ==, 16384); /* that chunk went onto
|
||||||
the freelist. */
|
the freelist. */
|
||||||
|
#else
|
||||||
|
tt_int_op(buf_get_total_allocation(), ==, 12288); /* that chunk was really
|
||||||
|
freed. */
|
||||||
|
#endif
|
||||||
|
|
||||||
write_to_buf(junk, 4000, buf2);
|
write_to_buf(junk, 4000, buf2);
|
||||||
tt_int_op(buf_allocation(buf2), ==, 4096); /* another 4k chunk. */
|
tt_int_op(buf_allocation(buf2), ==, 4096); /* another 4k chunk. */
|
||||||
tt_int_op(buf_get_total_allocation(), ==, 16384); /* that chunk came from
|
/*
|
||||||
the freelist. */
|
* If we're using freelists, size stays at 16384 because we just pulled a
|
||||||
|
* chunk from the freelist. If we aren't, we bounce back up to 16384 by
|
||||||
|
* allocating a new chunk.
|
||||||
|
*/
|
||||||
|
tt_int_op(buf_get_total_allocation(), ==, 16384);
|
||||||
write_to_buf(junk, 4000, buf2);
|
write_to_buf(junk, 4000, buf2);
|
||||||
tt_int_op(buf_allocation(buf2), ==, 8192); /* another 4k chunk. */
|
tt_int_op(buf_allocation(buf2), ==, 8192); /* another 4k chunk. */
|
||||||
tt_int_op(buf_get_total_allocation(), ==, 5*4096); /* that chunk was new. */
|
tt_int_op(buf_get_total_allocation(), ==, 5*4096); /* that chunk was new. */
|
||||||
|
Loading…
Reference in New Issue
Block a user