diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cache.c | 201 | ||||
-rw-r--r-- | test/cache_common.c | 131 | ||||
-rw-r--r-- | test/cache_common.h | 25 |
3 files changed, 347 insertions, 10 deletions
diff --git a/test/cache.c b/test/cache.c index bacd559..a5b5f3a 100644 --- a/test/cache.c +++ b/test/cache.c @@ -126,6 +126,7 @@ static unsigned check_metadata_blizzard_absence(hbool_t fill_via_insertion); static unsigned check_flush_deps(void); static unsigned check_flush_deps_err(void); static unsigned check_flush_deps_order(void); +static unsigned check_notify_cb(void); /**************************************************************************/ @@ -33789,6 +33790,205 @@ done: /*------------------------------------------------------------------------- + * Function: check_notify_cb() + * + * Purpose: Exercise the client 'notify' callback. + * + * Return: 0 on success, non-zero on failure + * + * Programmer: Quincey Koziol + * 4/28/09 + * + *------------------------------------------------------------------------- + */ + +static unsigned +check_notify_cb(void) +{ + H5C_t * cache_ptr = NULL; /* Metadata cache for this test */ + test_entry_t *base_addr; /* Base address of entries for test */ + test_entry_t * entry_ptr; /* Cache entry to examine/manipulate */ + int entry_type = NOTIFY_ENTRY_TYPE; /* Use entry w/notify callback (size of entries doesn't matter) */ + size_t entry_size = NOTIFY_ENTRY_SIZE; /* 1 byte */ + unsigned u; /* Local index variable */ + struct expected_entry_status expected[5] = + { + /* entry entry in at main flush dep flush dep child flush flush flush */ + /* type: index: size: cache: addr: dirty: prot: pinned: loaded: clrd: flshd: dest: par type: par idx: dep ref.count: dep height: order: */ + { entry_type, 0, entry_size, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, -1, -1, {0,0,0,0}, 0, -1 }, + { entry_type, 1, entry_size, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, -1, -1, {0,0,0,0}, 0, -1 }, + { entry_type, 2, entry_size, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, -1, -1, {0,0,0,0}, 0, -1 }, + { entry_type, 3, entry_size, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, -1, -1, {0,0,0,0}, 0, -1 }, + { entry_type, 4, entry_size, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, -1, -1, {0,0,0,0}, 0, -1 } + }; + + TESTING("'notify' callback"); + + pass = TRUE; + + /* Allocate a cache, insert & remove entries, triggering 'notify' callback. + * Verify that all performs as expected. + */ + + reset_entries(); + cache_ptr = setup_cache((size_t)(2 * 1024), (size_t)(1 * 1024)); + base_addr = entries[entry_type]; + + if ( !pass ) CACHE_ERROR("setup_cache failed") + + /* Insert entries to work with into the cache */ + for(u = 0; u < 5; u++) { + insert_entry(cache_ptr, entry_type, (int32_t)u, TRUE, H5C__NO_FLAGS_SET); + if ( !pass ) CACHE_ERROR("insert_entry failed") + + /* Change expected values, and verify the status of the entries + * after each insertion + */ + expected[u].in_cache = TRUE; + expected[u].is_dirty = TRUE; + + /* Verify the status */ + verify_entry_status(cache_ptr, /* H5C_t * cache_ptr */ + (int)u, /* int tag */ + (int)5, /* int num_entries */ + expected); /* struct expected_entry_staus[] */ + if ( !pass ) CACHE_ERROR("verify_entry_status failed") + + /* Check the entry's 'after insert' count */ + entry_ptr = &(base_addr[u]); + if(1 != entry_ptr->notify_after_insert_count) + CACHE_ERROR("invalid notify after insert count") + if(0 != entry_ptr->notify_before_evict_count) + CACHE_ERROR("invalid notify before evict count") + } /* end for */ + + /* Remove entries from the cache */ + for(u = 0; u < 5; u++) { + expunge_entry(cache_ptr, entry_type, (int32_t)u); + if ( !pass ) CACHE_ERROR("expunge_entry failed") + + /* Change expected values, and verify the status of the entries + * after each insertion + */ + expected[u].in_cache = FALSE; + expected[u].is_dirty = FALSE; + expected[u].cleared = TRUE; + expected[u].destroyed = TRUE; + + /* Verify the status */ + verify_entry_status(cache_ptr, /* H5C_t * cache_ptr */ + (int)u, /* int tag */ + (int)5, /* int num_entries */ + expected); /* struct expected_entry_staus[] */ + if ( !pass ) CACHE_ERROR("verify_entry_status failed") + + /* Check the entry's 'before evict' count */ + entry_ptr = &(base_addr[u]); + if(1 != entry_ptr->notify_after_insert_count) + CACHE_ERROR("invalid notify after insert count") + if(1 != entry_ptr->notify_before_evict_count) + CACHE_ERROR("invalid notify before evict count") + } /* end for */ + + /* Protect entries to bring them into the cache */ + for(u = 0; u < 5; u++) { + protect_entry(cache_ptr, entry_type, (int32_t)u); + if ( !pass ) CACHE_ERROR("protect_entry failed") + + /* Change expected values, and verify the status of the entries + * after each insertion + */ + expected[u].in_cache = TRUE; + expected[u].is_dirty = FALSE; + expected[u].is_protected = TRUE; + expected[u].loaded = TRUE; + + /* Verify the status */ + verify_entry_status(cache_ptr, /* H5C_t * cache_ptr */ + (int)u, /* int tag */ + (int)5, /* int num_entries */ + expected); /* struct expected_entry_staus[] */ + if ( !pass ) CACHE_ERROR("verify_entry_status failed") + + /* Check the entry's 'after insert' count */ + entry_ptr = &(base_addr[u]); + if(2 != entry_ptr->notify_after_insert_count) + CACHE_ERROR("invalid notify after insert count") + if(1 != entry_ptr->notify_before_evict_count) + CACHE_ERROR("invalid notify before evict count") + } /* end for */ + + /* Unprotect entries, evicting them from the cache */ + for(u = 0; u < 5; u++) { + unprotect_entry(cache_ptr, entry_type, (int32_t)u, TRUE, H5C__NO_FLAGS_SET); + if ( !pass ) CACHE_ERROR("unprotect_entry failed") + + /* Change expected values, and verify the status of the entries + * after each insertion + */ + expected[u].in_cache = TRUE; + expected[u].is_dirty = TRUE; + expected[u].is_protected = FALSE; + + /* Verify the status */ + verify_entry_status(cache_ptr, /* H5C_t * cache_ptr */ + (int)u, /* int tag */ + (int)5, /* int num_entries */ + expected); /* struct expected_entry_staus[] */ + if ( !pass ) CACHE_ERROR("verify_entry_status failed") + + /* Check the entry's 'after insert' count */ + entry_ptr = &(base_addr[u]); + if(2 != entry_ptr->notify_after_insert_count) + CACHE_ERROR("invalid notify after insert count") + if(1 != entry_ptr->notify_before_evict_count) + CACHE_ERROR("invalid notify before evict count") + } /* end for */ + + /* Remove entries from the cache */ + for(u = 0; u < 5; u++) { + expunge_entry(cache_ptr, entry_type, (int32_t)u); + if ( !pass ) CACHE_ERROR("expunge_entry failed") + + /* Change expected values, and verify the status of the entries + * after each insertion + */ + expected[u].in_cache = FALSE; + expected[u].is_dirty = FALSE; + expected[u].cleared = TRUE; + expected[u].destroyed = TRUE; + + /* Verify the status */ + verify_entry_status(cache_ptr, /* H5C_t * cache_ptr */ + (int)u, /* int tag */ + (int)5, /* int num_entries */ + expected); /* struct expected_entry_staus[] */ + if ( !pass ) CACHE_ERROR("verify_entry_status failed") + + /* Check the entry's 'before evict' count */ + entry_ptr = &(base_addr[u]); + if(2 != entry_ptr->notify_after_insert_count) + CACHE_ERROR("invalid notify after insert count") + if(2 != entry_ptr->notify_before_evict_count) + CACHE_ERROR("invalid notify before evict count") + } /* end for */ + +done: + if(cache_ptr) + takedown_cache(cache_ptr, FALSE, FALSE); + + if ( pass ) + PASSED() + else { + H5_FAILED(); + HDfprintf(stdout, "%s.\n", failure_mssg); + } /* end else */ + + return (unsigned)!pass; +} /* check_notify_cb() */ + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: Run tests on the cache code contained in H5C.c @@ -33867,6 +34067,7 @@ main(void) nerrs += check_flush_deps(); nerrs += check_flush_deps_err(); nerrs += check_flush_deps_order(); + nerrs += check_notify_cb(); return(nerrs > 0); } diff --git a/test/cache_common.c b/test/cache_common.c index 6a9c7e5..4768f53 100644 --- a/test/cache_common.c +++ b/test/cache_common.c @@ -43,6 +43,7 @@ test_entry_t large_entries[NUM_LARGE_ENTRIES], orig_large_entries[NUM_LARGE_ENTR test_entry_t huge_entries[NUM_HUGE_ENTRIES], orig_huge_entries[NUM_HUGE_ENTRIES]; test_entry_t monster_entries[NUM_MONSTER_ENTRIES], orig_monster_entries[NUM_MONSTER_ENTRIES]; test_entry_t variable_entries[NUM_VARIABLE_ENTRIES], orig_variable_entries[NUM_VARIABLE_ENTRIES]; +test_entry_t notify_entries[NUM_NOTIFY_ENTRIES], orig_notify_entries[NUM_NOTIFY_ENTRIES]; hbool_t orig_entry_arrays_init = FALSE; @@ -57,7 +58,8 @@ test_entry_t * entries[NUMBER_OF_ENTRY_TYPES] = large_entries, huge_entries, monster_entries, - variable_entries + variable_entries, + notify_entries }; test_entry_t * orig_entries[NUMBER_OF_ENTRY_TYPES] = @@ -71,7 +73,8 @@ test_entry_t * orig_entries[NUMBER_OF_ENTRY_TYPES] = orig_large_entries, orig_huge_entries, orig_monster_entries, - orig_variable_entries + orig_variable_entries, + orig_notify_entries }; const int32_t max_indices[NUMBER_OF_ENTRY_TYPES] = @@ -85,7 +88,8 @@ const int32_t max_indices[NUMBER_OF_ENTRY_TYPES] = NUM_LARGE_ENTRIES - 1, NUM_HUGE_ENTRIES - 1, NUM_MONSTER_ENTRIES - 1, - NUM_VARIABLE_ENTRIES - 1 + NUM_VARIABLE_ENTRIES - 1, + NUM_NOTIFY_ENTRIES - 1 }; const size_t entry_sizes[NUMBER_OF_ENTRY_TYPES] = @@ -99,7 +103,8 @@ const size_t entry_sizes[NUMBER_OF_ENTRY_TYPES] = LARGE_ENTRY_SIZE, HUGE_ENTRY_SIZE, MONSTER_ENTRY_SIZE, - VARIABLE_ENTRY_SIZE + VARIABLE_ENTRY_SIZE, + NOTIFY_ENTRY_SIZE }; const haddr_t base_addrs[NUMBER_OF_ENTRY_TYPES] = @@ -113,7 +118,8 @@ const haddr_t base_addrs[NUMBER_OF_ENTRY_TYPES] = LARGE_BASE_ADDR, HUGE_BASE_ADDR, MONSTER_BASE_ADDR, - VARIABLE_BASE_ADDR + VARIABLE_BASE_ADDR, + NOTIFY_BASE_ADDR }; const haddr_t alt_base_addrs[NUMBER_OF_ENTRY_TYPES] = @@ -127,7 +133,8 @@ const haddr_t alt_base_addrs[NUMBER_OF_ENTRY_TYPES] = LARGE_ALT_BASE_ADDR, HUGE_ALT_BASE_ADDR, MONSTER_ALT_BASE_ADDR, - VARIABLE_ALT_BASE_ADDR + VARIABLE_ALT_BASE_ADDR, + NOTIFY_ALT_BASE_ADDR }; const char * entry_type_names[NUMBER_OF_ENTRY_TYPES] = @@ -141,7 +148,8 @@ const char * entry_type_names[NUMBER_OF_ENTRY_TYPES] = "large entries -- 4 KB", "huge entries -- 16 KB", "monster entries -- 64 KB", - "variable entries -- 1B - 10KB" + "variable entries -- 1B - 10KB", + "notify entries -- 1B" }; @@ -238,6 +246,15 @@ const H5C_class_t types[NUMBER_OF_ENTRY_TYPES] = (H5C_clear_func_t)variable_clear, (H5C_notify_func_t)NULL, (H5C_size_func_t)variable_size + }, + { + NOTIFY_ENTRY_TYPE, + (H5C_load_func_t)notify_load, + (H5C_flush_func_t)notify_flush, + (H5C_dest_func_t)notify_dest, + (H5C_clear_func_t)notify_clear, + (H5C_notify_func_t)notify_notify, + (H5C_size_func_t)notify_size } }; @@ -248,6 +265,7 @@ static herr_t flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, static void * load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *udata2); static herr_t size(H5F_t * f, void * thing, size_t * size_ptr); +static herr_t notify(H5C_notify_action_t action, void *thing); @@ -542,6 +560,13 @@ variable_clear(H5F_t * f, void * thing, hbool_t dest) return(clear(f, thing, dest)); } +herr_t +notify_clear(H5F_t * f, void * thing, hbool_t dest) +{ + HDassert ( ((test_entry_t *)thing)->type == NOTIFY_ENTRY_TYPE ); + return(clear(f, thing, dest)); +} + /*------------------------------------------------------------------------- @@ -710,6 +735,13 @@ variable_dest(H5F_t * f, void * thing) return(destroy(f, thing)); } +herr_t +notify_dest(H5F_t * f, void * thing) +{ + HDassert ( ((test_entry_t *)thing)->type == NOTIFY_ENTRY_TYPE ); + return(destroy(f, thing)); +} + /*------------------------------------------------------------------------- * Function: flush & friends @@ -888,6 +920,14 @@ variable_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, return(flush(f, dxpl_id, dest, addr, thing, flags_ptr)); } +herr_t +notify_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, + void *thing, unsigned * flags_ptr) +{ + HDassert ( ((test_entry_t *)thing)->type == NOTIFY_ENTRY_TYPE ); + return(flush(f, dxpl_id, dest, addr, thing, flags_ptr)); +} + /*------------------------------------------------------------------------- @@ -1029,6 +1069,13 @@ variable_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, return(load(f, dxpl_id, addr, udata1, udata2)); } +void * +notify_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, + const void *udata1, void *udata2) +{ + return(load(f, dxpl_id, addr, udata1, udata2)); +} + /*------------------------------------------------------------------------- * Function: size & friends @@ -1148,6 +1195,73 @@ variable_size(H5F_t * f, void * thing, size_t * size_ptr) return(size(f, thing, size_ptr)); } +herr_t +notify_size(H5F_t * f, void * thing, size_t * size_ptr) +{ + HDassert ( ((test_entry_t *)thing)->type == NOTIFY_ENTRY_TYPE ); + return(size(f, thing, size_ptr)); +} + + +/*------------------------------------------------------------------------- + * Function: notify & friends + * + * Purpose: Record notifications of cache events for the entry. + * The helper functions verify that the correct version of notify + * is being called, and then call notify proper. + * + * Return: SUCCEED + * + * Programmer: Quincey Koziol + * 4/28/09 + * + *------------------------------------------------------------------------- + */ + +static herr_t +notify(H5C_notify_action_t action, void *thing) +{ + test_entry_t * entry_ptr; + test_entry_t * base_addr; + + HDassert( thing ); + + entry_ptr = (test_entry_t *)thing; + base_addr = entries[entry_ptr->type]; + + HDassert( entry_ptr->index >= 0 ); + HDassert( entry_ptr->index <= max_indices[entry_ptr->type] ); + HDassert( entry_ptr == &(base_addr[entry_ptr->index]) ); + HDassert( entry_ptr == entry_ptr->self ); + HDassert( entry_ptr->header.addr == entry_ptr->addr ); + HDassert( ( entry_ptr->type == VARIABLE_ENTRY_TYPE ) || \ + ( entry_ptr->size == entry_sizes[entry_ptr->type] ) ); + + /* Increment count for appropriate action */ + switch(action) { + case H5C_NOTIFY_ACTION_AFTER_INSERT: /* Entry has been added to the cache */ + entry_ptr->notify_after_insert_count++; + break; + + case H5C_NOTIFY_ACTION_BEFORE_EVICT: /* Entry is about to be evicted from cache */ + entry_ptr->notify_before_evict_count++; + break; + + default: + HDassert(0 && "Unknown notify action!?!"); + } /* end switch */ + + return(SUCCEED); +} /* notify() */ + +herr_t +notify_notify(H5C_notify_action_t action, void *thing) +{ + HDassert ( ((test_entry_t *)thing)->type == NOTIFY_ENTRY_TYPE ); + return(notify(action, thing)); +} + + /**************************************************************************/ @@ -1678,6 +1792,9 @@ reset_entries(void) base_addr[j].flush_order = 0; + base_addr[j].notify_after_insert_count = 0; + base_addr[j].notify_before_evict_count = 0; + addr += (haddr_t)entry_size; alt_addr += (haddr_t)entry_size; } /* end for */ diff --git a/test/cache_common.h b/test/cache_common.h index 37e9e0c..d150f2a 100644 --- a/test/cache_common.h +++ b/test/cache_common.h @@ -51,8 +51,9 @@ #define HUGE_ENTRY_TYPE 7 #define MONSTER_ENTRY_TYPE 8 #define VARIABLE_ENTRY_TYPE 9 +#define NOTIFY_ENTRY_TYPE 10 -#define NUMBER_OF_ENTRY_TYPES 10 +#define NUMBER_OF_ENTRY_TYPES 11 #define PICO_ENTRY_SIZE (size_t)1 #define NANO_ENTRY_SIZE (size_t)4 @@ -64,6 +65,7 @@ #define HUGE_ENTRY_SIZE (size_t)(16 * 1024) #define MONSTER_ENTRY_SIZE (size_t)(64 * 1024) #define VARIABLE_ENTRY_SIZE (size_t)(10 * 1024) +#define NOTIFY_ENTRY_SIZE (size_t)1 #define NUM_PICO_ENTRIES (10 * 1024) #define NUM_NANO_ENTRIES (10 * 1024) @@ -75,6 +77,7 @@ #define NUM_HUGE_ENTRIES (10 * 1024) #define NUM_MONSTER_ENTRIES (10 * 1024) #define NUM_VARIABLE_ENTRIES (10 * 1024) +#define NUM_NOTIFY_ENTRIES (10 * 1024) #define MAX_ENTRIES (10 * 1024) @@ -97,9 +100,11 @@ (HUGE_ENTRY_SIZE * NUM_HUGE_ENTRIES)) #define VARIABLE_BASE_ADDR (haddr_t)(MONSTER_BASE_ADDR + \ (MONSTER_ENTRY_SIZE * NUM_MONSTER_ENTRIES)) +#define NOTIFY_BASE_ADDR (haddr_t)(VARIABLE_BASE_ADDR + \ + (VARIABLE_ENTRY_SIZE * NUM_VARIABLE_ENTRIES)) -#define PICO_ALT_BASE_ADDR (haddr_t)(VARIABLE_BASE_ADDR + \ - (VARIABLE_ENTRY_SIZE * NUM_VARIABLE_ENTRIES)) +#define PICO_ALT_BASE_ADDR (haddr_t)(NOTIFY_BASE_ADDR + \ + (NOTIFY_ENTRY_SIZE * NUM_NOTIFY_ENTRIES)) #define NANO_ALT_BASE_ADDR (haddr_t)(PICO_ALT_BASE_ADDR + \ (PICO_ENTRY_SIZE * NUM_PICO_ENTRIES)) #define MICRO_ALT_BASE_ADDR (haddr_t)(NANO_ALT_BASE_ADDR + \ @@ -118,6 +123,8 @@ (HUGE_ENTRY_SIZE * NUM_HUGE_ENTRIES)) #define VARIABLE_ALT_BASE_ADDR (haddr_t)(MONSTER_ALT_BASE_ADDR + \ (MONSTER_ENTRY_SIZE * NUM_MONSTER_ENTRIES)) +#define NOTIFY_ALT_BASE_ADDR (haddr_t)(VARIABLE_ALT_BASE_ADDR + \ + (VARIABLE_ENTRY_SIZE * NUM_VARIABLE_ENTRIES)) #define MAX_PINS 8 /* Maximum number of entries that can be * directly pinned by a single entry. @@ -309,6 +316,9 @@ typedef struct test_entry_t hbool_t pinned_from_client; /* entry was pinned by client call */ hbool_t pinned_from_cache; /* entry was pinned by cache internally */ unsigned flush_order; /* Order that entry was flushed in */ + + unsigned notify_after_insert_count; /* Count of times that entry was inserted in cache */ + unsigned notify_before_evict_count; /* Count of times that entry was removed in cache */ } test_entry_t; /* The following is a cut down copy of the hash table manipulation @@ -530,6 +540,7 @@ herr_t large_clear(H5F_t * f, void * thing, hbool_t dest); herr_t huge_clear(H5F_t * f, void * thing, hbool_t dest); herr_t monster_clear(H5F_t * f, void * thing, hbool_t dest); herr_t variable_clear(H5F_t * f, void * thing, hbool_t dest); +herr_t notify_clear(H5F_t * f, void * thing, hbool_t dest); herr_t pico_dest(H5F_t * f, void * thing); @@ -542,6 +553,7 @@ herr_t large_dest(H5F_t * f, void * thing); herr_t huge_dest(H5F_t * f, void * thing); herr_t monster_dest(H5F_t * f, void * thing); herr_t variable_dest(H5F_t * f, void * thing); +herr_t notify_dest(H5F_t * f, void * thing); herr_t pico_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, @@ -564,6 +576,8 @@ herr_t monster_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing, unsigned * flags_ptr); herr_t variable_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing, unsigned * flags_ptr); +herr_t notify_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, + haddr_t addr, void *thing, unsigned * flags_ptr); void * pico_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, @@ -586,6 +600,8 @@ void * monster_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *udata2); void * variable_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *udata2); +void * notify_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, + const void *udata1, void *udata2); herr_t pico_size(H5F_t * f, void * thing, size_t * size_ptr); @@ -598,6 +614,9 @@ herr_t large_size(H5F_t * f, void * thing, size_t * size_ptr); herr_t huge_size(H5F_t * f, void * thing, size_t * size_ptr); herr_t monster_size(H5F_t * f, void * thing, size_t * size_ptr); herr_t variable_size(H5F_t * f, void * thing, size_t * size_ptr); +herr_t notify_size(H5F_t * f, void * thing, size_t * size_ptr); + +herr_t notify_notify(H5C_notify_action_t action, void *thing); /* callback table extern */ |