diff options
Diffstat (limited to 'src/tests/memblock-test.c')
-rw-r--r-- | src/tests/memblock-test.c | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index c2dd2efa..6da1b1e9 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. - + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -23,11 +21,11 @@ #include <config.h> #endif -#include <assert.h> #include <stdio.h> #include <unistd.h> #include <pulsecore/memblock.h> +#include <pulsecore/macro.h> #include <pulse/xmalloc.h> static void release_cb(pa_memimport *i, uint32_t block_id, void *userdata) { @@ -46,24 +44,24 @@ static void print_stats(pa_mempool *p, const char *text) { "n_accumulated = %u\n" "n_imported = %u\n" "n_exported = %u\n" - "allocated_size = %lu\n" - "accumulated_size = %lu\n" - "imported_size = %lu\n" - "exported_size = %lu\n" + "allocated_size = %u\n" + "accumulated_size = %u\n" + "imported_size = %u\n" + "exported_size = %u\n" "n_too_large_for_pool = %u\n" "n_pool_full = %u\n" "}\n", text, - (unsigned) AO_load_acquire_read((AO_t*) &s->n_allocated), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_accumulated), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_imported), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_exported), - (unsigned long) AO_load_acquire_read((AO_t*) &s->allocated_size), - (unsigned long) AO_load_acquire_read((AO_t*) &s->accumulated_size), - (unsigned long) AO_load_acquire_read((AO_t*) &s->imported_size), - (unsigned long) AO_load_acquire_read((AO_t*) &s->exported_size), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_too_large_for_pool), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_pool_full)); + (unsigned) pa_atomic_load(&s->n_allocated), + (unsigned) pa_atomic_load(&s->n_accumulated), + (unsigned) pa_atomic_load(&s->n_imported), + (unsigned) pa_atomic_load(&s->n_exported), + (unsigned) pa_atomic_load(&s->allocated_size), + (unsigned) pa_atomic_load(&s->accumulated_size), + (unsigned) pa_atomic_load(&s->imported_size), + (unsigned) pa_atomic_load(&s->exported_size), + (unsigned) pa_atomic_load(&s->n_too_large_for_pool), + (unsigned) pa_atomic_load(&s->n_pool_full)); } int main(int argc, char *argv[]) { @@ -79,7 +77,7 @@ int main(int argc, char *argv[]) { char *x; const char txt[] = "This is a test!"; - + pool_a = pa_mempool_new(1); pool_b = pa_mempool_new(1); pool_c = pa_mempool_new(1); @@ -87,20 +85,20 @@ int main(int argc, char *argv[]) { pa_mempool_get_shm_id(pool_a, &id_a); pa_mempool_get_shm_id(pool_b, &id_b); pa_mempool_get_shm_id(pool_c, &id_c); - - assert(pool_a && pool_b && pool_c); - + + pa_assert(pool_a && pool_b && pool_c); + blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1); blocks[1] = pa_memblock_new(pool_a, sizeof(txt)); x = pa_memblock_acquire(blocks[1]); snprintf(x, pa_memblock_get_length(blocks[1]), "%s", txt); pa_memblock_release(blocks[1]); - + blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt)); x = pa_memblock_acquire(blocks[2]); snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt); - pa_memblock_release(blocks[1]); + pa_memblock_release(blocks[2]); blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt)); blocks[4] = NULL; @@ -109,35 +107,35 @@ int main(int argc, char *argv[]) { printf("Memory block %u\n", i); mb_a = blocks[i]; - assert(mb_a); - + pa_assert(mb_a); + export_a = pa_memexport_new(pool_a, revoke_cb, (void*) "A"); export_b = pa_memexport_new(pool_b, revoke_cb, (void*) "B"); - - assert(export_a && export_b); - + + pa_assert(export_a && export_b); + import_b = pa_memimport_new(pool_b, release_cb, (void*) "B"); import_c = pa_memimport_new(pool_c, release_cb, (void*) "C"); - - assert(import_b && import_c); - + + pa_assert(import_b && import_c); + r = pa_memexport_put(export_a, mb_a, &id, &shm_id, &offset, &size); - assert(r >= 0); - assert(shm_id == id_a); + pa_assert(r >= 0); + pa_assert(shm_id == id_a); printf("A: Memory block exported as %u\n", id); - + mb_b = pa_memimport_get(import_b, id, shm_id, offset, size); - assert(mb_b); + pa_assert(mb_b); r = pa_memexport_put(export_b, mb_b, &id, &shm_id, &offset, &size); - assert(r >= 0); - assert(shm_id == id_a || shm_id == id_b); + pa_assert(r >= 0); + pa_assert(shm_id == id_a || shm_id == id_b); pa_memblock_unref(mb_b); printf("B: Memory block exported as %u\n", id); - + mb_c = pa_memimport_get(import_c, id, shm_id, offset, size); - assert(mb_c); + pa_assert(mb_c); x = pa_memblock_acquire(mb_c); printf("1 data=%s\n", x); pa_memblock_release(mb_c); @@ -145,23 +143,23 @@ int main(int argc, char *argv[]) { print_stats(pool_a, "A"); print_stats(pool_b, "B"); print_stats(pool_c, "C"); - + pa_memexport_free(export_b); x = pa_memblock_acquire(mb_c); printf("2 data=%s\n", x); pa_memblock_release(mb_c); pa_memblock_unref(mb_c); - + pa_memimport_free(import_b); - + pa_memblock_unref(mb_a); - + pa_memimport_free(import_c); pa_memexport_free(export_a); } printf("vaccuuming...\n"); - + pa_mempool_vacuum(pool_a); pa_mempool_vacuum(pool_b); pa_mempool_vacuum(pool_c); |