Beispiel #1
0
int do_test_rectangles(const char *test_parm)
{
    (void) test_parm;

    rect_t out1, out2, oldw, neww;

    oldw.x = 1;
    oldw.y = 1;
    oldw.xsize = 10;
    oldw.ysize = 10;

    neww.x = 2;
    neww.y = 2;
    neww.xsize = 10;
    neww.ysize = 10;

    //int o2 =
    rect_sub( &out1, &out2, &oldw, &neww );

    //rect_dump( &out1 );
    //rect_dump( &out2 );

    test_check_eq(out1.x,1);
    test_check_eq(out1.y,1);
    test_check_eq(out1.xsize,1);
    test_check_eq(out1.ysize,10);

    test_check_eq(out2.x,1);
    test_check_eq(out2.y,1);
    test_check_eq(out2.xsize,10);
    test_check_eq(out2.ysize,1);

    rect_t a, b;

    a.x     = 10; a.y     = 10;
    a.xsize = 10; a.ysize = 10;

    b.x     = 15; b.y     = 15;
    b.xsize = 10; b.ysize = 10;

    test_check_false( rect_includes( &a, &b ) );
    test_check_true( rect_intersects( &a, &b ) );

    b.xsize = 2;  b.ysize = 2;

    test_check_true( rect_includes( &a, &b ) );
    test_check_true( rect_intersects( &a, &b ) );

    b.x     = 35; b.y     = 35;

    test_check_false( rect_includes( &a, &b ) );
    test_check_false( rect_intersects( &a, &b ) );

    return 0;
}
int do_test_amap(const char *test_parm)
{
    (void) test_parm;
    //errno_t ret;
    int modified;

    amap_init( &map, 0, ~0, MAP_UNKNOWN );

    test_check_false(  amap_check_modify( &map, 10, 1, MAP_USED, &modified ) );
    test_check_false(  amap_check_modify( &map, 10, 1, MAP_USED, &modified ) );
    test_check_false( modified );

    test_check_false(  amap_check_modify( &map, 10, 1, MAP_FREE, &modified ) );
    test_check_true( modified );

    // Check if range has these attributes. Return 0 if it has.
    test_check_false( amap_check( &map, 10, 1, MAP_FREE ) );

    counter = 0;
    amap_iterate_flags( &map, count, 0, MAP_FREE );
    test_check_eq( counter, 1 );

    unsigned int i;

    for( i = 20; i < 50; i += 3 )
    {
        test_check_false( amap_check_modify( &map, i, 2, MAP_FREE, &modified ) );
    }

    for( i = 20; i < 50; i += 4 )
    {
        test_check_false( amap_check_modify( &map, i, 4, MAP_USED, &modified ) );
        test_check_true( modified );
    }

    for( i = 20; i < 100; i += 7 )
    {
        test_check_false( amap_check_modify( &map, i, 3, MAP_FREE, &modified ) );
    }


    amap_destroy( &map );
    return 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;
}