test_sorcery_memory_cache_thrash.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2015, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file
  20. * \brief Sorcery Unit Tests
  21. *
  22. * \author Joshua Colp <jcolp@digium.com>
  23. *
  24. */
  25. /*** MODULEINFO
  26. <depend>TEST_FRAMEWORK</depend>
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. #include "asterisk/test.h"
  31. #include "asterisk/module.h"
  32. #include "asterisk/sorcery.h"
  33. #include "asterisk/logger.h"
  34. #include "asterisk/vector.h"
  35. #include "asterisk/cli.h"
  36. /*! \brief The default amount of time (in seconds) that thrash unit tests execute for */
  37. #define TEST_THRASH_TIME 3
  38. /*! \brief The number of threads to use for retrieving for applicable tests */
  39. #define TEST_THRASH_RETRIEVERS 25
  40. /*! \brief The number of threads to use for updating for applicable tests*/
  41. #define TEST_THRASH_UPDATERS 25
  42. /*! \brief Structure for a memory cache thras thread */
  43. struct sorcery_memory_cache_thrash_thread {
  44. /*! \brief The thread thrashing the cache */
  45. pthread_t thread;
  46. /*! \brief Sorcery instance being tested */
  47. struct ast_sorcery *sorcery;
  48. /*! \brief The number of unique objects we should restrict ourself to */
  49. unsigned int unique_objects;
  50. /*! \brief Set when the thread should stop */
  51. unsigned int stop;
  52. /*! \brief Average time spent executing sorcery operation in this thread */
  53. unsigned int average_execution_time;
  54. };
  55. /*! \brief Structure for memory cache thrasing */
  56. struct sorcery_memory_cache_thrash {
  57. /*! \brief The sorcery instance being tested */
  58. struct ast_sorcery *sorcery;
  59. /*! \brief The number of threads which are updating */
  60. unsigned int update_threads;
  61. /*! \brief The average execution time of sorcery update operations */
  62. unsigned int average_update_execution_time;
  63. /*! \brief The number of threads which are retrieving */
  64. unsigned int retrieve_threads;
  65. /*! \brief The average execution time of sorcery retrieve operations */
  66. unsigned int average_retrieve_execution_time;
  67. /*! \brief Threads which are updating or reading from the cache */
  68. AST_VECTOR(, struct sorcery_memory_cache_thrash_thread *) threads;
  69. };
  70. /*!
  71. * \brief Sorcery object created based on backend data
  72. */
  73. struct test_data {
  74. SORCERY_OBJECT(details);
  75. };
  76. /*!
  77. * \brief Allocation callback for test_data sorcery object
  78. */
  79. static void *test_data_alloc(const char *id)
  80. {
  81. return ast_sorcery_generic_alloc(sizeof(struct test_data), NULL);
  82. }
  83. /*!
  84. * \brief Callback for retrieving sorcery object by ID
  85. *
  86. * \param sorcery The sorcery instance
  87. * \param data Unused
  88. * \param type The object type. Will always be "test".
  89. * \param id The object id. Will always be "test".
  90. *
  91. * \retval NULL Backend data successfully allocated
  92. * \retval non-NULL Backend data could not be successfully allocated
  93. */
  94. static void *mock_retrieve_id(const struct ast_sorcery *sorcery, void *data,
  95. const char *type, const char *id)
  96. {
  97. return ast_sorcery_alloc(sorcery, type, id);
  98. }
  99. /*!
  100. * \brief Callback for updating a sorcery object
  101. *
  102. * \param sorcery The sorcery instance
  103. * \param data Unused
  104. * \param object The object to update.
  105. *
  106. */
  107. static int mock_update(const struct ast_sorcery *sorcery, void *data,
  108. void *object)
  109. {
  110. return 0;
  111. }
  112. /*!
  113. * \brief A mock sorcery wizard used for the stale test
  114. */
  115. static struct ast_sorcery_wizard mock_wizard = {
  116. .name = "mock",
  117. .retrieve_id = mock_retrieve_id,
  118. .update = mock_update,
  119. };
  120. /*!
  121. * \internal
  122. * \brief Destructor for sorcery memory cache thrasher
  123. *
  124. * \param obj The sorcery memory cache thrash structure
  125. */
  126. static void sorcery_memory_cache_thrash_destroy(void *obj)
  127. {
  128. struct sorcery_memory_cache_thrash *thrash = obj;
  129. int idx;
  130. if (thrash->sorcery) {
  131. ast_sorcery_unref(thrash->sorcery);
  132. }
  133. for (idx = 0; idx < AST_VECTOR_SIZE(&thrash->threads); ++idx) {
  134. struct sorcery_memory_cache_thrash_thread *thread;
  135. thread = AST_VECTOR_GET(&thrash->threads, idx);
  136. ast_free(thread);
  137. }
  138. AST_VECTOR_FREE(&thrash->threads);
  139. ast_sorcery_wizard_unregister(&mock_wizard);
  140. }
  141. /*!
  142. * \internal
  143. * \brief Set up thrasing against a memory cache on a sorcery instance
  144. *
  145. * \param cache_configuration The sorcery memory cache configuration to use
  146. * \param update_threads The number of threads which should be constantly updating sorcery
  147. * \param retrieve_threads The number of threads which should be constantly retrieving from sorcery
  148. * \param unique_objects The number of unique objects that can exist
  149. *
  150. * \retval non-NULL success
  151. * \retval NULL failure
  152. */
  153. static struct sorcery_memory_cache_thrash *sorcery_memory_cache_thrash_create(const char *cache_configuration,
  154. unsigned int update_threads, unsigned int retrieve_threads, unsigned int unique_objects)
  155. {
  156. struct sorcery_memory_cache_thrash *thrash;
  157. struct sorcery_memory_cache_thrash_thread *thread;
  158. unsigned int total_threads = update_threads + retrieve_threads;
  159. thrash = ao2_alloc_options(sizeof(*thrash), sorcery_memory_cache_thrash_destroy,
  160. AO2_ALLOC_OPT_LOCK_NOLOCK);
  161. if (!thrash) {
  162. return NULL;
  163. }
  164. thrash->update_threads = update_threads;
  165. thrash->retrieve_threads = retrieve_threads;
  166. ast_sorcery_wizard_register(&mock_wizard);
  167. thrash->sorcery = ast_sorcery_open();
  168. if (!thrash->sorcery) {
  169. ao2_ref(thrash, -1);
  170. return NULL;
  171. }
  172. ast_sorcery_apply_wizard_mapping(thrash->sorcery, "test", "memory_cache",
  173. !strcmp(cache_configuration, "default") ? "" : cache_configuration, 1);
  174. ast_sorcery_apply_wizard_mapping(thrash->sorcery, "test", "mock", NULL, 0);
  175. ast_sorcery_internal_object_register(thrash->sorcery, "test", test_data_alloc, NULL, NULL);
  176. if (AST_VECTOR_INIT(&thrash->threads, update_threads + retrieve_threads)) {
  177. ao2_ref(thrash, -1);
  178. return NULL;
  179. }
  180. while (AST_VECTOR_SIZE(&thrash->threads) != total_threads) {
  181. thread = ast_calloc(1, sizeof(*thread));
  182. if (!thread) {
  183. ao2_ref(thrash, -1);
  184. return NULL;
  185. }
  186. thread->thread = AST_PTHREADT_NULL;
  187. thread->unique_objects = unique_objects;
  188. /* This purposely holds no ref as the main thrash structure does */
  189. thread->sorcery = thrash->sorcery;
  190. if (AST_VECTOR_APPEND(&thrash->threads, thread)) {
  191. ast_free(thread);
  192. ao2_ref(thrash, -1);
  193. return NULL;
  194. }
  195. }
  196. return thrash;
  197. }
  198. /*!
  199. * \internal
  200. * \brief Thrashing cache update thread
  201. *
  202. * \param data The sorcery memory cache thrash thread
  203. */
  204. static void *sorcery_memory_cache_thrash_update(void *data)
  205. {
  206. struct sorcery_memory_cache_thrash_thread *thread = data;
  207. struct timeval start;
  208. unsigned int object_id;
  209. char object_id_str[AST_UUID_STR_LEN];
  210. void *object;
  211. while (!thread->stop) {
  212. object_id = ast_random() % thread->unique_objects;
  213. snprintf(object_id_str, sizeof(object_id_str), "%u", object_id);
  214. object = ast_sorcery_alloc(thread->sorcery, "test", object_id_str);
  215. ast_assert(object != NULL);
  216. start = ast_tvnow();
  217. ast_sorcery_update(thread->sorcery, object);
  218. thread->average_execution_time = (thread->average_execution_time + ast_tvdiff_ms(ast_tvnow(), start)) / 2;
  219. ao2_ref(object, -1);
  220. }
  221. return NULL;
  222. }
  223. /*!
  224. * \internal
  225. * \brief Thrashing cache retrieve thread
  226. *
  227. * \param data The sorcery memory cache thrash thread
  228. */
  229. static void *sorcery_memory_cache_thrash_retrieve(void *data)
  230. {
  231. struct sorcery_memory_cache_thrash_thread *thread = data;
  232. struct timeval start;
  233. unsigned int object_id;
  234. char object_id_str[AST_UUID_STR_LEN];
  235. void *object;
  236. while (!thread->stop) {
  237. object_id = ast_random() % thread->unique_objects;
  238. snprintf(object_id_str, sizeof(object_id_str), "%u", object_id);
  239. start = ast_tvnow();
  240. object = ast_sorcery_retrieve_by_id(thread->sorcery, "test", object_id_str);
  241. thread->average_execution_time = (thread->average_execution_time + ast_tvdiff_ms(ast_tvnow(), start)) / 2;
  242. ast_assert(object != NULL);
  243. ao2_ref(object, -1);
  244. }
  245. return NULL;
  246. }
  247. /*!
  248. * \internal
  249. * \brief Stop thrashing against a sorcery memory cache
  250. *
  251. * \param thrash The sorcery memory cache thrash structure
  252. */
  253. static void sorcery_memory_cache_thrash_stop(struct sorcery_memory_cache_thrash *thrash)
  254. {
  255. int idx;
  256. for (idx = 0; idx < AST_VECTOR_SIZE(&thrash->threads); ++idx) {
  257. struct sorcery_memory_cache_thrash_thread *thread;
  258. thread = AST_VECTOR_GET(&thrash->threads, idx);
  259. if (thread->thread == AST_PTHREADT_NULL) {
  260. continue;
  261. }
  262. thread->stop = 1;
  263. }
  264. for (idx = 0; idx < AST_VECTOR_SIZE(&thrash->threads); ++idx) {
  265. struct sorcery_memory_cache_thrash_thread *thread;
  266. thread = AST_VECTOR_GET(&thrash->threads, idx);
  267. if (thread->thread == AST_PTHREADT_NULL) {
  268. continue;
  269. }
  270. pthread_join(thread->thread, NULL);
  271. if (idx < thrash->update_threads) {
  272. thrash->average_update_execution_time += thread->average_execution_time;
  273. } else {
  274. thrash->average_retrieve_execution_time += thread->average_execution_time;
  275. }
  276. }
  277. if (thrash->update_threads) {
  278. thrash->average_update_execution_time /= thrash->update_threads;
  279. }
  280. if (thrash->retrieve_threads) {
  281. thrash->average_retrieve_execution_time /= thrash->retrieve_threads;
  282. }
  283. }
  284. /*!
  285. * \internal
  286. * \brief Start thrashing against a sorcery memory cache
  287. *
  288. * \param thrash The sorcery memory cache thrash structure
  289. *
  290. * \retval 0 success
  291. * \retval -1 failure
  292. */
  293. static int sorcery_memory_cache_thrash_start(struct sorcery_memory_cache_thrash *thrash)
  294. {
  295. int idx;
  296. for (idx = 0; idx < AST_VECTOR_SIZE(&thrash->threads); ++idx) {
  297. struct sorcery_memory_cache_thrash_thread *thread;
  298. thread = AST_VECTOR_GET(&thrash->threads, idx);
  299. if (ast_pthread_create(&thread->thread, NULL, idx < thrash->update_threads ?
  300. sorcery_memory_cache_thrash_update : sorcery_memory_cache_thrash_retrieve, thread)) {
  301. sorcery_memory_cache_thrash_stop(thrash);
  302. return -1;
  303. }
  304. }
  305. return 0;
  306. }
  307. /*!
  308. * \internal
  309. * \brief CLI command implementation for 'sorcery memory cache thrash'
  310. */
  311. static char *sorcery_memory_cache_cli_thrash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  312. {
  313. struct sorcery_memory_cache_thrash *thrash;
  314. unsigned int thrash_time, unique_objects, retrieve_threads, update_threads;
  315. switch (cmd) {
  316. case CLI_INIT:
  317. e->command = "sorcery memory cache thrash";
  318. e->usage =
  319. "Usage: sorcery memory cache thrash <cache configuration> <amount of time to thrash the cache> <number of unique objects> <number of retrieve threads> <number of update threads>\n"
  320. " Create a sorcery instance with a memory cache using the provided configuration and thrash it.\n";
  321. return NULL;
  322. case CLI_GENERATE:
  323. return NULL;
  324. }
  325. if (a->argc != 9) {
  326. return CLI_SHOWUSAGE;
  327. }
  328. if (sscanf(a->argv[5], "%30u", &thrash_time) != 1) {
  329. ast_cli(a->fd, "An invalid value of '%s' has been provided for the thrashing time\n", a->argv[5]);
  330. return CLI_FAILURE;
  331. } else if (sscanf(a->argv[6], "%30u", &unique_objects) != 1) {
  332. ast_cli(a->fd, "An invalid value of '%s' has been provided for number of unique objects\n", a->argv[6]);
  333. return CLI_FAILURE;
  334. } else if (sscanf(a->argv[7], "%30u", &retrieve_threads) != 1) {
  335. ast_cli(a->fd, "An invalid value of '%s' has been provided for the number of retrieve threads\n", a->argv[7]);
  336. return CLI_FAILURE;
  337. } else if (sscanf(a->argv[8], "%30u", &update_threads) != 1) {
  338. ast_cli(a->fd, "An invalid value of '%s' has been provided for the number of update threads\n", a->argv[8]);
  339. return CLI_FAILURE;
  340. }
  341. thrash = sorcery_memory_cache_thrash_create(a->argv[4], update_threads, retrieve_threads, unique_objects);
  342. if (!thrash) {
  343. ast_cli(a->fd, "Could not create a sorcery memory cache thrash test using the provided arguments\n");
  344. return CLI_FAILURE;
  345. }
  346. ast_cli(a->fd, "Starting cache thrash test.\n");
  347. ast_cli(a->fd, "Memory cache configuration: %s\n", a->argv[4]);
  348. ast_cli(a->fd, "Amount of time to perform test: %u seconds\n", thrash_time);
  349. ast_cli(a->fd, "Number of unique objects: %u\n", unique_objects);
  350. ast_cli(a->fd, "Number of retrieve threads: %u\n", retrieve_threads);
  351. ast_cli(a->fd, "Number of update threads: %u\n", update_threads);
  352. sorcery_memory_cache_thrash_start(thrash);
  353. while ((thrash_time = sleep(thrash_time)));
  354. sorcery_memory_cache_thrash_stop(thrash);
  355. ast_cli(a->fd, "Stopped cache thrash test\n");
  356. ast_cli(a->fd, "Average retrieve execution time (in milliseconds): %u\n", thrash->average_retrieve_execution_time);
  357. ast_cli(a->fd, "Average update execution time (in milliseconds): %u\n", thrash->average_update_execution_time);
  358. ao2_ref(thrash, -1);
  359. return CLI_SUCCESS;
  360. }
  361. static struct ast_cli_entry cli_memory_cache_thrash[] = {
  362. AST_CLI_DEFINE(sorcery_memory_cache_cli_thrash, "Thrash a sorcery memory cache"),
  363. };
  364. /*!
  365. * \internal
  366. * \brief Perform a thrash test against a cache
  367. *
  368. * \param test The unit test being run
  369. * \param cache_configuration The underlying cache configuration
  370. * \param thrash_time How long (in seconds) to thrash the cache for
  371. * \param unique_objects The number of unique objects
  372. * \param retrieve_threads The number of threads constantly doing a retrieve
  373. * \param update_threads The number of threads constantly doing an update
  374. *
  375. * \retval AST_TEST_PASS success
  376. * \retval AST_TEST_FAIL failure
  377. */
  378. static enum ast_test_result_state nominal_thrash(struct ast_test *test, const char *cache_configuration,
  379. unsigned int thrash_time, unsigned int unique_objects, unsigned int retrieve_threads,
  380. unsigned int update_threads)
  381. {
  382. struct sorcery_memory_cache_thrash *thrash;
  383. thrash = sorcery_memory_cache_thrash_create(cache_configuration, update_threads, retrieve_threads, unique_objects);
  384. if (!thrash) {
  385. return AST_TEST_FAIL;
  386. }
  387. sorcery_memory_cache_thrash_start(thrash);
  388. while ((thrash_time = sleep(thrash_time)));
  389. sorcery_memory_cache_thrash_stop(thrash);
  390. ao2_ref(thrash, -1);
  391. return AST_TEST_PASS;
  392. }
  393. AST_TEST_DEFINE(low_unique_object_count_immediately_stale)
  394. {
  395. switch (cmd) {
  396. case TEST_INIT:
  397. info->name = "low_unique_object_count_immediately_stale";
  398. info->category = "/res/res_sorcery_memory_cache/thrash/";
  399. info->summary = "Thrash a cache with low number of unique objects that are immediately stale";
  400. info->description = "This test creates a cache with objects that are stale\n"
  401. "after 1 second. It also creates 25 threads which are constantly attempting\n"
  402. "to retrieve the objects. This test confirms that the background refreshes\n"
  403. "being done as a result of going stale do not conflict or cause problems with\n"
  404. "the large number of retrieve threads.";
  405. return AST_TEST_NOT_RUN;
  406. case TEST_EXECUTE:
  407. break;
  408. }
  409. return nominal_thrash(test, "object_lifetime_stale=1", TEST_THRASH_TIME, 10, TEST_THRASH_RETRIEVERS, 0);
  410. }
  411. AST_TEST_DEFINE(low_unique_object_count_immediately_expire)
  412. {
  413. switch (cmd) {
  414. case TEST_INIT:
  415. info->name = "low_unique_object_count_immediately_expire";
  416. info->category = "/res/res_sorcery_memory_cache/thrash/";
  417. info->summary = "Thrash a cache with low number of unique objects that are immediately expired";
  418. info->description = "This test creates a cache with objects that are expired\n"
  419. "after 1 second. It also creates 25 threads which are constantly attempting\n"
  420. "to retrieve the objects. This test confirms that the expiration process does\n"
  421. "not cause a problem as the retrieve threads execute.";
  422. return AST_TEST_NOT_RUN;
  423. case TEST_EXECUTE:
  424. break;
  425. }
  426. return nominal_thrash(test, "object_lifetime_maximum=1", TEST_THRASH_TIME, 10, TEST_THRASH_RETRIEVERS, 0);
  427. }
  428. AST_TEST_DEFINE(low_unique_object_count_high_concurrent_updates)
  429. {
  430. switch (cmd) {
  431. case TEST_INIT:
  432. info->name = "low_unique_object_count_high_concurrent_updates";
  433. info->category = "/res/res_sorcery_memory_cache/thrash/";
  434. info->summary = "Thrash a cache with low number of unique objects that are updated frequently";
  435. info->description = "This test creates a cache with objects that are being constantly\n"
  436. "updated and retrieved at the same time. This will create contention between all\n"
  437. "of the threads as the write lock is held for the updates. This test confirms that\n"
  438. "no problems occur in this situation.";
  439. return AST_TEST_NOT_RUN;
  440. case TEST_EXECUTE:
  441. break;
  442. }
  443. return nominal_thrash(test, "default", TEST_THRASH_TIME, 10, TEST_THRASH_RETRIEVERS, TEST_THRASH_UPDATERS);
  444. }
  445. AST_TEST_DEFINE(unique_objects_exceeding_maximum)
  446. {
  447. switch (cmd) {
  448. case TEST_INIT:
  449. info->name = "unique_objects_exceeding_maximum";
  450. info->category = "/res/res_sorcery_memory_cache/thrash/";
  451. info->summary = "Thrash a cache with a fixed maximum object count";
  452. info->description = "This test creates a cache with a maximum number of objects\n"
  453. "allowed in it. The maximum number of unique objects, however, far exceeds the\n"
  454. "the maximum number allowed in the cache. This test confirms that the cache does\n"
  455. "not exceed the maximum and that the removal of older objects does not cause\n"
  456. "a problem.";
  457. return AST_TEST_NOT_RUN;
  458. case TEST_EXECUTE:
  459. break;
  460. }
  461. return nominal_thrash(test, "maximum_objects=10", TEST_THRASH_TIME, 100, TEST_THRASH_RETRIEVERS, 0);
  462. }
  463. AST_TEST_DEFINE(unique_objects_exceeding_maximum_with_expire_and_stale)
  464. {
  465. switch (cmd) {
  466. case TEST_INIT:
  467. info->name = "unique_objects_exceeding_maximum_with_expire_and_stale";
  468. info->category = "/res/res_sorcery_memory_cache/thrash/";
  469. info->summary = "Thrash a cache with a fixed maximum object count with objects that expire and go stale";
  470. info->description = "This test creates a cache with a maximum number of objects\n"
  471. "allowed in it with objects that also go stale after a period of time and expire.\n"
  472. "A number of threads are created that constantly retrieve from the cache, causing\n"
  473. "both stale refresh and expiration to occur. This test confirms that the combination\n"
  474. "of these do not present a problem.";
  475. return AST_TEST_NOT_RUN;
  476. case TEST_EXECUTE:
  477. break;
  478. }
  479. return nominal_thrash(test, "maximum_objects=10,object_lifetime_maximum=2,object_lifetime_stale=1",
  480. TEST_THRASH_TIME * 2, 100, TEST_THRASH_RETRIEVERS, 0);
  481. }
  482. AST_TEST_DEFINE(conflicting_expire_and_stale)
  483. {
  484. switch (cmd) {
  485. case TEST_INIT:
  486. info->name = "conflicting_expire_and_stale";
  487. info->category = "/res/res_sorcery_memory_cache/thrash/";
  488. info->summary = "Thrash a cache with a large number of objects that expire and go stale";
  489. info->description = "This test creates a cache with a large number of objects that expire\n"
  490. "and go stale. As there is such a large number this ensures that both operations occur.\n"
  491. "This test confirms that stale refreshing and expiration do not conflict.";
  492. return AST_TEST_NOT_RUN;
  493. case TEST_EXECUTE:
  494. break;
  495. }
  496. return nominal_thrash(test, "object_lifetime_maximum=2,object_lifetime_stale=1", TEST_THRASH_TIME * 2, 5000,
  497. TEST_THRASH_RETRIEVERS, 0);
  498. }
  499. AST_TEST_DEFINE(high_object_count_without_expiration)
  500. {
  501. switch (cmd) {
  502. case TEST_INIT:
  503. info->name = "high_object_count_without_expiration";
  504. info->category = "/res/res_sorcery_memory_cache/thrash/";
  505. info->summary = "Thrash a cache with a large number of objects";
  506. info->description = "This test creates a cache with a large number of objects that persist.\n"
  507. "A large number of threads are created which constantly retrieve from the cache.\n"
  508. "This test confirms that the large number of retrieves do not cause a problem.";
  509. return AST_TEST_NOT_RUN;
  510. case TEST_EXECUTE:
  511. break;
  512. }
  513. return nominal_thrash(test, "default", TEST_THRASH_TIME, 5000, TEST_THRASH_RETRIEVERS, 0);
  514. }
  515. static int unload_module(void)
  516. {
  517. ast_cli_unregister_multiple(cli_memory_cache_thrash, ARRAY_LEN(cli_memory_cache_thrash));
  518. AST_TEST_UNREGISTER(low_unique_object_count_immediately_stale);
  519. AST_TEST_UNREGISTER(low_unique_object_count_immediately_expire);
  520. AST_TEST_UNREGISTER(low_unique_object_count_high_concurrent_updates);
  521. AST_TEST_UNREGISTER(unique_objects_exceeding_maximum);
  522. AST_TEST_UNREGISTER(unique_objects_exceeding_maximum_with_expire_and_stale);
  523. AST_TEST_UNREGISTER(conflicting_expire_and_stale);
  524. AST_TEST_UNREGISTER(high_object_count_without_expiration);
  525. return 0;
  526. }
  527. static int load_module(void)
  528. {
  529. ast_cli_register_multiple(cli_memory_cache_thrash, ARRAY_LEN(cli_memory_cache_thrash));
  530. AST_TEST_REGISTER(low_unique_object_count_immediately_stale);
  531. AST_TEST_REGISTER(low_unique_object_count_immediately_expire);
  532. AST_TEST_REGISTER(low_unique_object_count_high_concurrent_updates);
  533. AST_TEST_REGISTER(unique_objects_exceeding_maximum);
  534. AST_TEST_REGISTER(unique_objects_exceeding_maximum_with_expire_and_stale);
  535. AST_TEST_REGISTER(conflicting_expire_and_stale);
  536. AST_TEST_REGISTER(high_object_count_without_expiration);
  537. return AST_MODULE_LOAD_SUCCESS;
  538. }
  539. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Sorcery Cache Thrasing test module");