/* * bmm_test.c * * Buffer Management Module * * User test application * * Li Li (lea.li@marvell.com) *(C) Copyright 2007 Marvell International Ltd. * All Rights Reserved */ #include #include #include #include #include #include #include #include #include "bmm_lib.h" static int debug = 0; int test_count = 0; int pass_count = 0; int fail_count = 0; #define PRINT_TEST_NAME printf("Testing %d: %s()\n", test_count++, __FUNCTION__) #define PRINT_TEST_RESULT(x) \ do { \ if(!x) \ pass_count++, printf("\tPassed.\n"); \ else \ fail_count++, printf("\tFailed.\n"); \ } while(0) #define PRINT_TEST_RESULTS() printf("Passed/Failed = %d/%d\n", pass_count, fail_count) int test_bmm_init() { int ret; PRINT_TEST_NAME; ret = bmm_init(); printf("\tbmm_init() return %d\n", ret); return (ret <= 0); } int test_bmm_get_space() { unsigned long total_size; unsigned long free_size; PRINT_TEST_NAME; total_size = bmm_get_total_space(); free_size = bmm_get_free_space(); printf("\tbmm_get_total_space() return %ldKB\n", total_size/1024); printf("\tbmm_get_free_space() return %ldKB\n", free_size/1024); return (total_size <= 0 || total_size != free_size); } int test_bmm_malloc(unsigned long size, int attr) { void *vaddr; unsigned long allocated_size1, free_size1; unsigned long allocated_size2, free_size2; unsigned long allocated_size3, free_size3; int off = 0; PRINT_TEST_NAME; allocated_size1 = bmm_get_allocated_space(); free_size1 = bmm_get_free_space(); vaddr = bmm_malloc(size, attr); if(vaddr == NULL) { printf("\tno enough memory\n"); return -1; } for(off = 0; off < size; off += 1024*1024){ void *get_paddr = bmm_get_paddr(vaddr+off); void *get_vaddr = bmm_get_vaddr(get_paddr); int get_attr = bmm_get_mem_attr(get_vaddr); printf("\toff = 0x%x, vaddr=0x%p, get_vaddr=0x%p, get_paddr=0x%p\n", off, vaddr+off, get_vaddr, get_paddr); printf("\tset_attr=0x%x, get_attr=0x%x\n", attr, get_attr); if(vaddr+off != get_vaddr) return -1; } allocated_size2 = bmm_get_allocated_space(); free_size2 = bmm_get_free_space(); bmm_free(vaddr); allocated_size3 = bmm_get_allocated_space(); free_size3 = bmm_get_free_space(); printf("\tbmm_malloc(%ldKB) return 0x%08lx\n", size/1024, (unsigned long)vaddr); printf("\tbmm_get_allocated_space() return %ldKB %ldKB %ldKB\n", allocated_size1/1024, allocated_size2/1024, allocated_size3/1024); printf("\tbmm_get_free_space() return %ldKB %ldKB %ldKB\n", free_size1/1024, free_size2/1024, free_size3/1024); return ((int)vaddr <= 0 || allocated_size2 - allocated_size1 != size || allocated_size1 != allocated_size3 || free_size1 - free_size2 != size || free_size1 != free_size3); } int test_bmm_dma_memcpy(unsigned long size) { char *src; char *dst; unsigned long i; unsigned long free_size1; unsigned long free_size2; unsigned long free_size3; int ret = 0; PRINT_TEST_NAME; free_size1 = bmm_get_free_space(); src = bmm_malloc(size, BMM_ATTR_DEFAULT); dst = bmm_malloc(size, BMM_ATTR_DEFAULT); memset(src, 0, size); memset(dst, 0, size); free_size2 = bmm_get_free_space(); if(src == NULL) { printf("\tno enough memory\n"); return -1; } if(dst == NULL) { printf("\tno enough memory\n"); bmm_free(src); return -2; } for(i=0; i 1) { debug = 1; if(!strcmp(argv[1], "dump")) { ret = test_bmm_get_space(); PRINT_TEST_RESULT(ret); bmm_dump(); return 0; } } printf("%s running with pid=%d/%x\n", argv[0], pid, pid); if(debug) bmm_dump(); ret = test_bmm_init(); PRINT_TEST_RESULT(ret); ret = test_bmm_get_space(); PRINT_TEST_RESULT(ret); n = 8; for(i=1; i<=n; i++) { ret = test_bmm_malloc(i*1024*1024, BMM_ATTR_DEFAULT); PRINT_TEST_RESULT(ret); } for(i=n; i>=1; i--) { ret = test_bmm_malloc(i*1024*1024, BMM_ATTR_NONCACHED); PRINT_TEST_RESULT(ret); } n = 8; for(i=1; i<=n; i++) { ret = test_bmm_share(i*1024*1024); PRINT_TEST_RESULT(ret); } #if 0 n = 128; for(i=1; i<=n; i++) { ret = test_bmm_dma_memcpy(i*4096); PRINT_TEST_RESULT(ret); } n = 4; for(i=1; i<=n; i++) { ret = test_bmm_dma_memcpy(i*1024*1024); PRINT_TEST_RESULT(ret); } n = 128; for(i=1; i<=n; i++) { ret = test_bmm_dma_memcpy_range(i*4096); PRINT_TEST_RESULT(ret); } #endif n = 1; ret = test_bmm_flush_user(n*1024*1024); PRINT_TEST_RESULT(ret); PRINT_TEST_RESULTS(); if(debug) bmm_dump(); bmm_exit(); if(debug) bmm_dump(); return 0; }