1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <small/region.h>
#include <small/quota.h>
#include <stdio.h>
#include "unit.h"
struct slab_cache cache;
struct slab_arena arena;
struct quota quota;
void
region_basic()
{
header();
struct region region;
region_create(®ion, &cache);
fail_unless(region_used(®ion) == 0);
void *ptr = region_alloc(®ion, 10);
fail_unless(ptr);
fail_unless(region_used(®ion) == 10);
ptr = region_alloc(®ion, 10000000);
fail_unless(ptr);
fail_unless(region_used(®ion) == 10000010);
region_free(®ion);
fail_unless(region_used(®ion) == 0);
printf("name of a new region: %s.\n", region_name(®ion));
region_set_name(®ion, "region");
printf("set new region name: %s.\n", region_name(®ion));
region_set_name(®ion, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
printf("region name is truncated: %s.\n", region_name(®ion));
footer();
}
void
region_test_truncate()
{
header();
struct region region;
region_create(®ion, &cache);
void *ptr = region_alloc(®ion, 10);
fail_unless(ptr);
size_t used = region_used(®ion);
region_alloc(®ion, 10000);
region_alloc(®ion, 10000000);
region_truncate(®ion, used);
fail_unless(region_used(®ion) == used);
region_free(®ion);
footer();
}
int main()
{
quota_init("a, UINT_MAX);
slab_arena_create(&arena, "a, 0,
4000000, MAP_PRIVATE);
slab_cache_create(&cache, &arena);
region_basic();
region_test_truncate();
slab_cache_destroy(&cache);
}
|