void st_memory(void) { enum { P = N/2/sizeof(void*) }; static OBJ arr[P]; useclass(Counter, AutoRelease); OBJ ar = gnew(AutoRelease); size_t sz = gsize(Counter); size_t i; int lvl; // allocator warm up for (i = 0; i < P; i++) arr[i++] = malloc(sz); for (i = 0; i < P; i++) free(arr[i++]); i = 0; STEST( "malloc", P, arr[i++] = malloc(sz) ); i = 0; STEST( "free", P, free(arr[i++]) ); i = 0; STEST( "alloc + init", P, arr[i++] = ginit(galloc(Counter)) ); i = 0; STEST( "retain", P, gretain(arr[i++]) ); i = 0; lvl = cos_logmsg_setLevel(COS_LOGMSG_WARN); STEST( "autoRelease", P, gautoRelease(arr[i++]) ); cos_logmsg_setLevel(lvl); i = 0; STEST( "release", P, grelease(arr[i++]) ); STEST( "alloc + init + release", P, grelease(ginit(galloc(Counter))) ); grelease(ar); }
int main(int argc, char *argv[]) { enum { bits = CHAR_BIT*sizeof(void*) }; int init_time = NO; int speed_tst = NO; int debug_sym = NO; int alloc_trc = NO; int cache_trc = NO; int i; cos_logmsg_setLevel(COS_LOGMSG_DEBUG); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d")) debug_sym = YES; if (!strcmp(argv[i], "-ds")) debug_sym = YES+YES; if (!strcmp(argv[i], "-da")) alloc_trc = YES; if (!strcmp(argv[i], "-dc")) cache_trc = YES; if (!strcmp(argv[i], "-i")) init_time = YES; if (!strcmp(argv[i], "-s")) speed_tst = YES; if (!strcmp(argv[i], "-t")) cos_logmsg_setLevel(COS_LOGMSG_TRACE); if (!strcmp(argv[i], "-m")) cos_logmsg_setLevel(COS_LOGMSG_TRALL); } if (init_time) { // must be loaded before COS is initialized (and first message is sent) atexit(on_exit); cos_init(); // explicit initialization for measurement printf("** COS init duration: %.3f s\n", cos_initDuration()); } else cos_init(); // convert signal to exception cos_signal_std(); // for debugging if (debug_sym) cos_symbol_showSummary(0); if (debug_sym > 1) { cos_symbol_showClasses(0); cos_symbol_showProperties(0); cos_symbol_showGenerics(0); cos_symbol_showMethods(0); cos_symbol_showClassProperties(0,YES); } // testsuites printf("\n** C Object System Testsuite (%d bits) **\n", bits); ut_methods(); ut_classes(); ut_properties(); ut_nextmethod(); ut_unrecognized(); ut_forwardmessage(); ut_variadics(); ut_proxy(); ut_exception(); ut_contract(); ut_autorelease(); cos_utest_stat(); // speed testsuites if (speed_tst) { printf("\n** C Object System Speed Testsuite (%d bits) **\n", bits); st_methods(); st_nextmethods(); st_multimethods(); st_methods_ptr(); st_multimethods_ptr(); st_pxymethods(); st_pxynextmethods(); st_pxymultimethods(); st_memory(); st_exception(); cos_stest_stat(); } if (cache_trc) { printf("\n** COS caches statistics\n"); cos_method_statCache1(0); cos_method_statCache2(0); cos_method_statCache3(0); cos_method_statCache4(0); cos_method_statCache5(0); } if (alloc_trc) cos_deinit(); return EXIT_SUCCESS; }