void hash_command(ostream &out, istream &in) { int threads ; size_t startsize ; size_t maxsize ; size_t cycles ; out << "Parallel (threaded) FrObject Hash Table operations" << endl << endl ; #ifdef FrMULTITHREAD out << "Enter number of threads: " ; in >> threads ; #else out << "Compiled without multi-thread support, will run single-threaded" << endl ; threads = 0 ; #endif /* FrMULTITHREAD */ out << "Enter initial size of hash table: " ; in >> startsize ; out << "Enter number of distinct elements to add: " ; in >> maxsize ; out << "Enter number of iterations: " ; in >> cycles ; if (maxsize > 0) { bool terse = false ; if (threads <= 0) { terse = true ; threads = -threads ; } FrSymbol **keys = FrNewN(FrSymbol*,2*maxsize) ; uint32_t *randnums = FrNewN(uint32_t,2*maxsize) ; out << "\nGenerating random numbers for randomized tests" << endl ; for (size_t i = 0 ; i < 2*maxsize ; i++) { randnums[i] = FrRandomNumber(maxsize) ; } out << "Preparing symbols " << endl ; // speed up symbol creation and avoid memory fragmentation by // expanding the symbol table to hold all the symbols we will // create size_t needed = FrSymbolTable::current()->sizeForCapacity(2*maxsize) ; needed *= 1.33 ; // gensyms tend to cluster in the table, since they are so similar in name FrSymbolTable::current()->expandTo(needed+1000) ; hash_test(0,out,threads,1,(FrObjHashTable*)0,2*maxsize,keys,Op_GENSYM,terse) ; out << "Checking symbols " << endl ; hash_test(0,out,threads,1,(FrObjHashTable*)0,2*maxsize,keys,Op_CHECKSYMS,terse) ; run_tests<FrObjHashTable>(threads,startsize,maxsize,cycles,keys,randnums,out,terse) ; FrFree(randnums) ; FrFree(keys) ; }
/*---------------------------------------------------------------------------*/ void zrtp_test_crypto(zrtp_global_t* zrtp) { ZRTP_LOG(3, (_ZTU_,"====================CIPHERS TESTS====================\n")); cipher_test(zrtp); ZRTP_LOG(3, (_ZTU_,"=====================HASHES TESTS====================\n")); hash_test(zrtp); ZRTP_LOG(3, (_ZTU_,"================PUBLIC KEY SCHEMES TESTS==============\n")); dh_test(zrtp); ecdh_test(zrtp); ZRTP_LOG(3, (_ZTU_,"===============SRTP Key derivation TESTS==============\n")); dk_test(zrtp); ZRTP_LOG(3, (_ZTU_,"==============SRTP Replay protection TESTS============\n")) ; srtp_replay_protection_test(zrtp); }
int main(int argc, char ** argv) { lt_type_init(); array_test(); hash_test(); module_test(); base64_test(); set_test(); object_test(); return 0; }
/** Performs all tests of the util library */ static void test_util() { int i; say( L"Testing utility library" ); for( i=0; i<18; i++ ) { long t1, t2; pq_test( 1<<i ); stack_test( 1<<i ); t1 = get_time(); hash_test( 1<<i ); t2 = get_time(); if( i > 8 ) say( L"Hashtable uses %f microseconds per element at size %d", ((double)(t2-t1))/(1<<i), 1<<i ); al_test( 1<<i ); } sb_test(); /* int i; for( i=2; i<10000000; i*=2 ) { printf( "%d", i ); t1 = get_time(); if(!hash_test(i)) exit(0); t2 = get_time(); printf( " %d\n", (t2-t1)/i ); } */ }
void various_tests() { printf("Finished initializing\n"); checkTest(); illegal_move_test(); test_get_legal_moves(); make_test_suite(); see_test_suite(); check_test(); isLegal_test(); eval_test(); run_perft_test(); check_evasion_test(); hash_test(); do_eval(); //bookTest(); }
static void run_tests(size_t threads, size_t startsize, size_t maxsize, size_t cycles, KeyT *keys, uint32_t *randnums, ostream &out, bool terse) { if_SHOW_CHAINS(size_t *chains[6]); if_SHOW_CHAINS(size_t max_chain[6]) ; if_SHOW_NEIGHBORS(size_t *neighborhoods[5]) ; if_SHOW_NEIGHBORS(size_t max_neighbors[5]) ; HashT *ht = new HashT(startsize) ; FrThreadPool tpool(threads) ; #if 1 out << "Filling hash table " << endl ; hash_test(&tpool,out,threads,1,ht,maxsize,keys,Op_ADD,terse) ; if_SHOW_CHAINS(chains[0] = ht->chainLengths(max_chain[0])); if_SHOW_NEIGHBORS(neighborhoods[0] = ht->neighborhoodDensities(max_neighbors[0])) ; out << "Lookups (100% present) " << endl ; hash_test(&tpool,out,threads,cycles,ht,maxsize,keys,Op_CHECK,terse) ; out << "Lookups (50% present) " << endl ; size_t half_cycles = (cycles + 1) / 2 ; swap_segments(keys,2*maxsize,threads) ; hash_test(&tpool,out,threads,half_cycles,ht,2*maxsize,keys,Op_CHECK,terse,false) ; swap_segments(keys,2*maxsize,threads) ; out << "Lookups (0% present) " << endl ; hash_test(&tpool,out,threads,cycles,ht,maxsize,keys+maxsize,Op_CHECKMISS,terse) ; out << "Emptying hash table " << endl ; hash_test(&tpool,out,threads,1,ht,maxsize,keys,Op_REMOVE,terse) ; out << "Lookups in empty table " << endl ; hash_test(&tpool,out,threads,cycles,ht,maxsize,keys,Op_CHECKMISS,terse) ; delete ht ; ht = new HashT(startsize) ; out << "Random additions " << endl ; hash_test(&tpool,out,threads,half_cycles,ht,maxsize,keys,Op_RANDOM_ADDONLY,terse,true, randnums) ; if_SHOW_CHAINS(chains[1] = ht->chainLengths(max_chain[1])) ; out << "Emptying hash table " << endl ; hash_test(&tpool,out,threads,1,ht,maxsize,keys,Op_REMOVE,terse,false) ; delete ht ; ht = new HashT(startsize) ; out << "Random ops (del=1) " << endl ; hash_test(&tpool,out,threads,half_cycles,ht,maxsize,keys,Op_RANDOM_LOWREMOVE,terse,true, randnums + maxsize/2 - 1) ; if_SHOW_CHAINS(chains[2] = ht->chainLengths(max_chain[2])) ; out << "Random ops (del=1,full) " << endl ; hash_test(&tpool,out,threads,half_cycles,ht,maxsize,keys,Op_RANDOM_LOWREMOVE,terse,true, randnums + maxsize/2 - 1) ; if_SHOW_CHAINS(chains[2] = ht->chainLengths(max_chain[2])) ; out << "Emptying hash table " << endl ; hash_test(&tpool,out,threads,1,ht,maxsize,keys,Op_REMOVE,terse,false) ; delete ht ; ht = new HashT(startsize) ; #else if_SHOW_CHAINS(chains[0] = chains[1] = chains[2] = chains[3] = 0) ; if_SHOW_NEIGHBORS(neighborhoods[0] = neighborhoods[1] = 0) ; #endif /* 0 */ out << "Random ops (del=3) " << endl ; hash_test(&tpool,out,threads,cycles,ht,maxsize,keys,Op_RANDOM,terse,true, randnums + maxsize - 1) ; if_SHOW_CHAINS(chains[3] = ht->chainLengths(max_chain[3])) ; if_SHOW_NEIGHBORS(neighborhoods[1] = ht->neighborhoodDensities(max_neighbors[1])) ; out << "Emptying hash table " << endl ; hash_test(&tpool,out,threads,1,ht,maxsize,keys,Op_REMOVE,terse,false) ; delete ht ; ht = new HashT(startsize) ; out << "Random ops (del=7) " << endl ; hash_test(&tpool,out,threads,cycles,ht,maxsize,keys,Op_RANDOM,terse,true, randnums + maxsize - 1) ; if_SHOW_CHAINS(chains[4] = ht->chainLengths(max_chain[4])) ; if_SHOW_NEIGHBORS(neighborhoods[1] = ht->neighborhoodDensities(max_neighbors[1])) ; out << "Emptying hash table " << endl ; hash_test(&tpool,out,threads,1,ht,maxsize,keys,Op_REMOVE,terse,false) ; if_SHOW_CHAINS(chains[5] = ht->chainLengths(max_chain[5])) ; #ifdef SHOW_CHAINS for (size_t i = 0 ; i < 6 ; i++) { print_chain_lengths(out,i,chains[i],max_chain[i]) ; delete [] chains[i] ; } #if defined(SHOW_LOST_CHAINS) if (chains[5] && max_chain[5] > 0) { // try to display the lost deletions out << "lost keys:" << endl ; size_t count = 0 ; ht->iterate(show_lost_keys,&out,&count) ; out << "(end of list)" << endl ; } #endif /* SHOW_LOST_CHAINS */ #endif /* SHOW_CHAINS */ delete ht ; #ifdef SHOW_NEIGHBORHOODS for (size_t i = 0 ; i < 2 ; i++) { print_neighborhoods(out,i,neighborhoods[i],max_neighbors[i]) ; delete [] neighborhoods[i] ; } #endif /* SHOW_NEIGHBORHOODS */ return ; }
int test_inner(void) { pj_caching_pool caching_pool; const char *filename; int line; int rc = 0; mem = &caching_pool.factory; pj_log_set_level(3); pj_log_set_decor(param_log_decor); rc = pj_init(); if (rc != 0) { app_perror("pj_init() error!!", rc); return rc; } //pj_dump_config(); pj_caching_pool_init( &caching_pool, NULL, 0 ); #if INCLUDE_ERRNO_TEST DO_TEST( errno_test() ); #endif #if INCLUDE_EXCEPTION_TEST DO_TEST( exception_test() ); #endif #if INCLUDE_OS_TEST DO_TEST( os_test() ); #endif #if INCLUDE_RAND_TEST DO_TEST( rand_test() ); #endif #if INCLUDE_LIST_TEST DO_TEST( list_test() ); #endif #if INCLUDE_POOL_TEST DO_TEST( pool_test() ); #endif #if INCLUDE_POOL_PERF_TEST DO_TEST( pool_perf_test() ); #endif #if INCLUDE_STRING_TEST DO_TEST( string_test() ); #endif #if INCLUDE_FIFOBUF_TEST DO_TEST( fifobuf_test() ); #endif #if INCLUDE_RBTREE_TEST DO_TEST( rbtree_test() ); #endif #if INCLUDE_HASH_TEST DO_TEST( hash_test() ); #endif #if INCLUDE_TIMESTAMP_TEST DO_TEST( timestamp_test() ); #endif #if INCLUDE_ATOMIC_TEST DO_TEST( atomic_test() ); #endif #if INCLUDE_MUTEX_TEST DO_TEST( mutex_test() ); #endif #if INCLUDE_TIMER_TEST DO_TEST( timer_test() ); #endif #if INCLUDE_SLEEP_TEST DO_TEST( sleep_test() ); #endif #if INCLUDE_THREAD_TEST DO_TEST( thread_test() ); #endif #if INCLUDE_SOCK_TEST DO_TEST( sock_test() ); #endif #if INCLUDE_SOCK_PERF_TEST DO_TEST( sock_perf_test() ); #endif #if INCLUDE_SELECT_TEST DO_TEST( select_test() ); #endif #if INCLUDE_UDP_IOQUEUE_TEST DO_TEST( udp_ioqueue_test() ); #endif #if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST DO_TEST( tcp_ioqueue_test() ); #endif #if INCLUDE_IOQUEUE_PERF_TEST DO_TEST( ioqueue_perf_test() ); #endif #if INCLUDE_IOQUEUE_UNREG_TEST DO_TEST( udp_ioqueue_unreg_test() ); #endif #if INCLUDE_ACTIVESOCK_TEST DO_TEST( activesock_test() ); #endif #if INCLUDE_FILE_TEST DO_TEST( file_test() ); #endif #if INCLUDE_SSLSOCK_TEST DO_TEST( ssl_sock_test() ); #endif #if INCLUDE_ECHO_SERVER //echo_server(); //echo_srv_sync(); udp_echo_srv_ioqueue(); #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) param_echo_sock_type = pj_SOCK_DGRAM(); echo_client( param_echo_sock_type, param_echo_server, param_echo_port); #endif goto on_return; on_return: pj_caching_pool_destroy( &caching_pool ); PJ_LOG(3,("test", "")); pj_thread_get_stack_info(pj_thread_this(), &filename, &line); PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", pj_thread_get_stack_max_usage(pj_thread_this()), filename, line)); if (rc == 0) PJ_LOG(3,("test", "Looks like everything is okay!..")); else PJ_LOG(3,("test", "Test completed with error(s)")); pj_shutdown(); return 0; }
int main() { hash_test(); return boost::report_errors(); }
int get_sha1_threshold() { return hash_test(CRYPTO_SHA1, sha_hash); }