Ejemplo n.º 1
0
static void get_some(int times)
{
    if( times == 0 ) return;
    get_some(times-1);

    int sz = random() % 20;
    int cnt = IGS;

	if( sz <= 0 ) sz = 1;

    while(cnt--)
    {
        if( igp >= IGS-1 ) igp = -1;

        if( igot[++igp].size )
            continue;

        physalloc_item_t 	ret;
        if( phantom_phys_alloc_region( &pm_map, &ret, sz ) )
            return;

        igot[igp].size = sz;
        igot[igp].pos = ret;

        SHOW_FLOW( 10, "get %7d @ %7d", igot[igp].size, igot[igp].pos);

        return;
    }
}
Ejemplo n.º 2
0
int do_test_physalloc_gen(const char *test_parm)
{
    (void) test_parm;

    physalloc_item_t 	ret;

    memset( &igot, 0, sizeof(igot) );

    SHOW_FLOW( 0, "physalloc test arena %d, initial free %d", PA_PAGES, PA_PAGES/2 );

    phantom_phys_alloc_init( &pm_map, PA_PAGES ); 

    SHOW_FLOW( 0, "physalloc test allocable_size %d, n_used_pages %d", pm_map.allocable_size, pm_map.n_used_pages );
    // Free half at strange position

    pm_map.allocable_size = PA_PAGES/2;
    pm_map.n_used_pages = PA_PAGES/2; // init sets it to PA_PAGES
    phantom_phys_free_region(&pm_map, 100, PA_PAGES/2);

    SHOW_FLOW( 0, "physalloc test allocable_size %d, n_used_pages %d", pm_map.allocable_size, pm_map.n_used_pages );

    cfree(PA_PAGES/2);

    test_check_false( phantom_phys_alloc_region( &pm_map, &ret, 20 ) );

    cfree(PA_PAGES/2-20);

    phantom_phys_free_region( &pm_map, ret, 20 );

    cfree(PA_PAGES/2);

    SHOW_FLOW0( 0, "loop mem a/f" );

    get_some(10);
    put_some(5);
    get_some(10);
    put_some(5);
    get_some(10);
    put_some(10);

    put_some(25); // cleanup

    cfree(PA_PAGES/2);

    return 0;
}
Ejemplo n.º 3
0
extern int printf(const char *str, ...);

static int counter;

int get_some(void)
{
	return counter++;
}

int main(void)
{
	printf("%d\n", get_some() ? : 42);
	printf("%d\n", get_some() ? : 42);
	printf("%d\n", get_some() && get_some() ? : 42);
	printf("%d\n", get_some() || get_some() ? : 42);
	printf("%d\n", !get_some() ? : 42);
	printf("%d\n", get_some() ? get_some() : 42);

	return 0;
}