Пример #1
0
static void *
thd_start(void *varg)
{
    unsigned thd_ind = *(unsigned *)varg;
    size_t bt_count_prev, bt_count;
    unsigned i_prev, i;

    i_prev = 0;
    bt_count_prev = 0;
    for (i = 0; i < NALLOCS_PER_THREAD; i++) {
        void *p = alloc_from_permuted_backtrace(thd_ind, i);
        dallocx(p, 0);
        if (i % DUMP_INTERVAL == 0) {
            assert_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0),
                        0, "Unexpected error while dumping heap profile");
        }

        if (i % BT_COUNT_CHECK_INTERVAL == 0 ||
                i+1 == NALLOCS_PER_THREAD) {
            bt_count = prof_bt_count();
            assert_zu_le(bt_count_prev+(i-i_prev), bt_count,
                         "Expected larger backtrace count increase");
            i_prev = i;
            bt_count_prev = bt_count;
        }
    }

    return (NULL);
}
Пример #2
0
TEST_END

TEST_BEGIN(test_stats_chunks)
{
	size_t current, high;
	uint64_t total;
	size_t sz;
	int expected = config_stats ? 0 : ENOENT;

	sz = sizeof(size_t);
	assert_d_eq(mallctl("pool.0.stats.chunks.current", &current, &sz, NULL, 0),
	    expected, "Unexpected mallctl() result");
	sz = sizeof(uint64_t);
	assert_d_eq(mallctl("pool.0.stats.chunks.total", &total, &sz, NULL, 0),
	    expected, "Unexpected mallctl() result");
	sz = sizeof(size_t);
	assert_d_eq(mallctl("pool.0.stats.chunks.high", &high, &sz, NULL, 0), expected,
	    "Unexpected mallctl() result");

	if (config_stats) {
		assert_zu_le(current, high,
		    "current should be no larger than high");
		assert_u64_le((uint64_t)high, total,
		    "high should be no larger than total");
	}
}
Пример #3
0
TEST_END

TEST_BEGIN(test_monotonic)
{
    unsigned nbins, nlruns, i;
    size_t sz, floor_prev, ceil_prev;

    /*
     * Iterate over all run sizes and verify that
     * run_quantize_{floor,ceil}() are monotonic.
     */

    sz = sizeof(unsigned);
    assert_d_eq(mallctl("arenas.nbins", &nbins, &sz, NULL, 0), 0,
                "Unexpected mallctl failure");

    sz = sizeof(unsigned);
    assert_d_eq(mallctl("arenas.nlruns", &nlruns, &sz, NULL, 0), 0,
                "Unexpected mallctl failure");

    floor_prev = 0;
    ceil_prev = 0;
    for (i = 1; i < run_quantize_max >> LG_PAGE; i++) {
        size_t run_size, floor, ceil;

        run_size = i << LG_PAGE;
        floor = run_quantize_floor(run_size);
        ceil = run_quantize_ceil(run_size);

        assert_zu_le(floor, run_size,
                     "Floor should be <= (floor=%zu, run_size=%zu, ceil=%zu)",
                     floor, run_size, ceil);
        assert_zu_ge(ceil, run_size,
                     "Ceiling should be >= (floor=%zu, run_size=%zu, ceil=%zu)",
                     floor, run_size, ceil);

        assert_zu_le(floor_prev, floor, "Floor should be monotonic "
                     "(floor_prev=%zu, floor=%zu, run_size=%zu, ceil=%zu)",
                     floor_prev, floor, run_size, ceil);
        assert_zu_le(ceil_prev, ceil, "Ceiling should be monotonic "
                     "(floor=%zu, run_size=%zu, ceil_prev=%zu, ceil=%zu)",
                     floor, run_size, ceil_prev, ceil);

        floor_prev = floor;
        ceil_prev = ceil;
    }
}
Пример #4
0
TEST_END

TEST_BEGIN(test_size_extra_overflow)
{
	size_t small0, hugemax;
	void *p;

	/* Get size classes. */
	small0 = get_small_size(0);
	hugemax = get_huge_size(get_nhuge()-1);

	p = mallocx(small0, 0);
	assert_ptr_not_null(p, "Unexpected mallocx() error");

	/* Test overflows that can be resolved by clamping extra. */
	assert_zu_le(xallocx(p, hugemax-1, 2, 0), hugemax,
	    "Unexpected xallocx() behavior");
	assert_zu_le(xallocx(p, hugemax, 1, 0), hugemax,
	    "Unexpected xallocx() behavior");

	/* Test overflow such that hugemax-size underflows. */
	assert_zu_le(xallocx(p, hugemax+1, 2, 0), hugemax,
	    "Unexpected xallocx() behavior");
	assert_zu_le(xallocx(p, hugemax+2, 3, 0), hugemax,
	    "Unexpected xallocx() behavior");
	assert_zu_le(xallocx(p, SIZE_T_MAX-2, 2, 0), hugemax,
	    "Unexpected xallocx() behavior");
	assert_zu_le(xallocx(p, SIZE_T_MAX-1, 1, 0), hugemax,
	    "Unexpected xallocx() behavior");

	dallocx(p, 0);
}
Пример #5
0
TEST_END

TEST_BEGIN(test_extra_huge)
{
	int flags = MALLOCX_ARENA(arena_ind());
	size_t largemax, huge1, huge2, huge3, hugemax;
	void *p;

	/* Get size classes. */
	largemax = get_large_size(get_nlarge()-1);
	huge1 = get_huge_size(1);
	huge2 = get_huge_size(2);
	huge3 = get_huge_size(3);
	hugemax = get_huge_size(get_nhuge()-1);

	p = mallocx(huge3, flags);
	assert_ptr_not_null(p, "Unexpected mallocx() error");

	assert_zu_eq(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	/* Test size decrease with zero extra. */
	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	assert_zu_ge(xallocx(p, largemax, 0, flags), huge1,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	/* Test size decrease with non-zero extra. */
	assert_zu_eq(xallocx(p, huge1, huge3 - huge1, flags), huge3,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, huge2, huge3 - huge2, flags), huge3,
	    "Unexpected xallocx() behavior");
	assert_zu_eq(xallocx(p, huge1, huge2 - huge1, flags), huge2,
	    "Unexpected xallocx() behavior");
	assert_zu_ge(xallocx(p, largemax, huge1 - largemax, flags), huge1,
	    "Unexpected xallocx() behavior");

	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	/* Test size increase with zero extra. */
	assert_zu_le(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	assert_zu_le(xallocx(p, hugemax+1, 0, flags), huge3,
	    "Unexpected xallocx() behavior");

	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	/* Test size increase with non-zero extra. */
	assert_zu_le(xallocx(p, huge1, SIZE_T_MAX - huge1, flags), hugemax,
	    "Unexpected xallocx() behavior");

	assert_zu_ge(xallocx(p, huge1, 0, flags), huge1,
	    "Unexpected xallocx() behavior");
	/* Test size increase with non-zero extra. */
	assert_zu_le(xallocx(p, huge1, huge3 - huge1, flags), huge3,
	    "Unexpected xallocx() behavior");

	assert_zu_eq(xallocx(p, huge3, 0, flags), huge3,
	    "Unexpected xallocx() behavior");
	/* Test size+extra overflow. */
	assert_zu_le(xallocx(p, huge3, hugemax - huge3 + 1, flags), hugemax,
	    "Unexpected xallocx() behavior");

	dallocx(p, flags);
}