#include <pj/pool_buf.h>
#include "test.h"
#if INCLUDE_POOL_TEST
#define SIZE 4096
{
}
#define GET_FREE(p) (pj_pool_get_capacity(p)-pj_pool_get_used_size(p))
static int capacity_test(void)
{
PJ_LOG(3,(
"test",
"...capacity_test()"));
if (!pool)
return -200;
freesize = GET_FREE(pool);
PJ_LOG(3,(
"test",
"...error: wrong freesize %u reported",
freesize));
return -210;
}
return 0;
}
static int pool_alignment_test(void)
{
void *ptr;
enum { MEMSIZE = 64, LOOP = 100 };
unsigned i;
PJ_LOG(3,(
"test",
"...alignment test"));
if (!pool)
return -300;
#define IS_ALIGNED(p) ((((unsigned long)(pj_ssize_t)p) & \
(PJ_POOL_ALIGNMENT-1)) == 0)
for (i=0; i<LOOP; ++i) {
if (!IS_ALIGNED(ptr)) {
return -310;
}
if (!IS_ALIGNED(ptr)) {
return -320;
}
if (!IS_ALIGNED(ptr)) {
return -330;
}
}
return 0;
}
static int pool_buf_alignment_test(void)
{
char buf[512];
void *ptr;
enum { LOOP = 100 };
unsigned i;
PJ_LOG(3,(
"test",
"...pool_buf alignment test"));
if (!pool)
return -400;
for (i=0; i<LOOP; ++i) {
if (!IS_ALIGNED(ptr)) {
return -410;
}
if (!IS_ALIGNED(ptr)) {
return -420;
}
}
return 0;
}
{
&null_callback);
void *p;
int status = 0;
PJ_LOG(3,(
"test",
"...drain_test(%d,%d)", size, increment));
if (!pool)
return -10;
freesize = GET_FREE(pool);
if (freesize < 1) {
status=-15;
goto on_error;
}
while (freesize > 0) {
int size2;
if (freesize > 255)
else
size2 = (int)freesize;
if (!p) {
status=-20; goto on_error;
}
freesize -= size2;
}
if (GET_FREE(pool) != 0) {
PJ_LOG(3,(
"test",
"....error: returned free=%u (expecting 0)",
GET_FREE(pool)));
status=-30; goto on_error;
}
if (!p) {
status=-40; goto on_error;
}
if (GET_FREE(pool) == 0) {
status=-50; goto on_error;
}
on_error:
return status;
}
static int pool_buf_test(void)
{
enum { STATIC_BUF_SIZE = 40 };
static char buf[ STATIC_BUF_SIZE +
sizeof(
pj_pool_t) +
void *p;
PJ_LOG(3,(
"test",
"...pool_buf test"));
if (!pool)
return -70;
return -75;
return -76;
}
return -77;
}
if (p != NULL) {
return -78;
}
}
}
return 0;
}
int pool_test(void)
{
enum { LOOP = 2 };
int loop;
int rc;
rc = capacity_test();
if (rc) return rc;
rc = pool_alignment_test();
if (rc) return rc;
rc = pool_buf_alignment_test();
if (rc) return rc;
for (loop=0; loop<LOOP; ++loop) {
rc = drain_test(SIZE, SIZE);
if (rc != 0) return rc;
rc = drain_test(SIZE, 0);
if (rc != -40) return rc;
}
rc = pool_buf_test();
if (rc != 0)
return rc;
return 0;
}
#else
int dummy_pool_test;
#endif
#define PJ_CATCH_ANY
Definition: except.h:388
#define PJ_TRY
Definition: except.h:373
#define PJ_END
Definition: except.h:394
#define PJ_USE_EXCEPTION
Definition: except.h:367
size_t pj_size_t
Definition: types.h:58
#define PJ_LOG(level, arg)
Definition: log.h:106
pj_pool_t * pj_pool_create_on_buf(const char *name, void *buf, pj_size_t size)
void * pj_pool_alloc(pj_pool_t *pool, pj_size_t size)
#define PJ_POOL_SIZE
Definition: pool.h:340
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
#define PJ_POOL_ALIGNMENT
Definition: pool.h:346
void pj_pool_reset(pj_pool_t *pool)
void pj_pool_release(pj_pool_t *pool)
#define PJ_UNUSED_ARG(arg)
Definition: config.h:1343