int aim_main(int argc, char* argv[]) { int i; { const char* tstStrings[] = { "This", "is", "a", "complete", "sentence." }; char* join = aim_strjoin(" ", tstStrings, AIM_ARRAYSIZE(tstStrings)); if(strcmp(join, "This is a complete sentence.")) { printf("fail: join='%s'\n", join); } AIM_FREE(join); } for(i = 0; i < argc; i++) { aim_printf(&aim_pvs_stdout, "arg%d: '%s'\n", i, argv[i]); } { /* Test data */ char data[2500]; memset(data, 0xFF, sizeof(data)); aim_printf(&aim_pvs_stdout, "data is %{data}", data, sizeof(data)); } { char* sdata = "DEADBEEFCAFE"; char* data; int size; aim_sparse(&sdata, &aim_pvs_stdout, "{data}", &data, &size); aim_printf(&aim_pvs_stdout, "data is %{data}\n", data, size); aim_free(data); } utest_list(); AIM_LOG_MSG("Should print 1-27"); AIM_LOG_MSG("%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); aim_printf(&aim_pvs_stdout, "aim_pvs_stdout from %s:%d\n", __FILE__, __LINE__); { char c; aim_pvs_t* pvs = aim_pvs_buffer_create(); aim_printf(pvs, "\nConsider "); aim_printf(pvs, "%s ", "the"); aim_printf(pvs, "alphabet: "); for(c = 'A'; c <= 'Z'; c++) { aim_printf(pvs, "%c", c); } aim_printf(pvs, "\n"); { char* s = aim_pvs_buffer_get(pvs); aim_printf(&aim_pvs_stdout, "first: %s", s); free(s); aim_printf(pvs, "(second)"); s = aim_pvs_buffer_get(pvs); aim_printf(&aim_pvs_stdout, "second: %s", s); free(s); aim_pvs_destroy(pvs); } { aim_ratelimiter_t rl; aim_ratelimiter_init(&rl, 10, 5, NULL); /* 5 (6?) tokens available at t=0 */ assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) < 0); /* Another token at t=10 */ assert(aim_ratelimiter_limit(&rl, 10) == 0); assert(aim_ratelimiter_limit(&rl, 10) < 0); /* Nothing at t=15 */ assert(aim_ratelimiter_limit(&rl, 15) < 0); /* 4 more tokens granted by t=50 */ assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) < 0); } { aim_printf(&aim_pvs_stdout, "valgrind_status=%d\n", aim_valgrind_status()); } AIM_LOG_MSG("%{aim_error}", AIM_ERROR_PARAM); } return 0; }
static ucli_status_t fme_ucli_utm__perf__(ucli_context_t* uc) { int set_keymask; int table_size; int iterations; int i; fme_key_t mkey; fme_entry_t* match; fme_t* fme; double seconds; int keysize; uint64_t start, end; UCLI_COMMAND_INFO(uc, "perf", 3, "$summary#Run performance matching tests." "$args#<table_size> <iterations> <use_keymask>"); if(aim_valgrind_status() == 1) { ucli_printf(uc, "Skipping performance test while running under valgrind.\n"); return UCLI_STATUS_OK; } UCLI_ARGPARSE_OR_RETURN(uc, "iib", &table_size, &iterations, &set_keymask); fme_create(&fme, "fme_utm", table_size); keysize = sizeof(mkey.values); for(i = 0; i < table_size; i++) { fme_entry_t* entry; fme_key_t key; uint8_t byte = (i == 0 || i & 0xFF) ? i : 0x1; FME_MEMSET(&key, 0, sizeof(key)); FME_MEMSET(&key.values, byte, sizeof(key.values)); FME_MEMSET(&key.masks, byte, sizeof(key.masks)); key.size = keysize; if(set_keymask) { key.keymask = i; } fme_entry_create(&entry); fme_entry_key_set(entry, &key); entry->prio=i; fme_add_entry(fme, entry); } FME_MEMSET(&mkey, 0, sizeof(mkey)); mkey.size = keysize; start = os_time_thread(); for(i = 0; i < iterations; i++) { int rv = fme_match(fme, &mkey, 0, 0, NULL, NULL, &match); /* The lowest priority entry will always match */ if(rv != 1 || match->index != table_size-1){ return ucli_printf(uc, "i=%d error: rv=%d, index=%d\n", i, rv, (match) ? match->index : -1); } } end = os_time_thread(); seconds = (end - start) / (1000.0*1000); ucli_printf(uc, "%d matches in %f seconds (%f matches/sec)\n", iterations, seconds, iterations/seconds); fme_destroy_all(fme); return UCLI_STATUS_OK; }