0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1998-2001, 2004, 2005, 2007, 2009, 2011, 2013-2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews/* $Id: t_tasks.c,v 1.49 2011/07/27 07:45:55 marka Exp $ */
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrencet1_callback(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (i = 0; i < 1000000; i++)
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("task %s\n", (char *)event->ev_arg);
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt1_shutdown(isc_task_t *task, isc_event_t *event) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("shutdown %s\n", (char *)event->ev_arg);
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrencemy_tick(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King * Adapted from RTH's original task_test program
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Bad config value for ISC_TASK_WORKERS, %d\n", workers);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &manager);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %d\n", isc_result);
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task2);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task3);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task4);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task1, t1_shutdown, one);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task2, t1_shutdown, two);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task3, t1_shutdown, three);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task4, t1_shutdown, four);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_timermgr_create(mctx, &timgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_timermgr_create %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_timer_create(timgr, isc_timertype_ticker,
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_timer_create(timgr, isc_timertype_ticker,
99e207809793732e3e47da3a1cab6925b6eee8e9William King * Note: (void *)1 is used as a sender here, since some compilers
99e207809793732e3e47da3a1cab6925b6eee8e9William King * don't like casting a function pointer to a (void *).
99e207809793732e3e47da3a1cab6925b6eee8e9William King * In a real use, it is more likely the sender would be a
99e207809793732e3e47da3a1cab6925b6eee8e9William King * structure (socket, timer, task, etc) but this is just a test
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, two,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, three,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, four,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, two,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, three,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, four,
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a1 = "The task subsystem can create and manage tasks";
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt2_shutdown(isc_task_t *task, isc_event_t *event) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff isc_task_destroy((isc_task_t**) &event->ev_arg);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %d\n", isc_result);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencet2_callback(isc_task_t *task, isc_event_t *event) {
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews event->ev_arg = (void *)(((uintptr_t) event->ev_arg) - 1);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Create a new task and forward the message.
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(T2_manager, 0, &newtask);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(newtask, t2_shutdown,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Time to unwind, shutdown should perc back up.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Bad config value for ISC_TASK_WORKERS, %d\n", workers);
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews t_info("Bad config value for ISC_TASKS_MIN, %lu\n",
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews (unsigned long)ntasks);
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews t_info("Testing with %lu tasks\n", (unsigned long)ntasks);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(T2_mctx, workers, 0, &T2_manager);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_event = isc_event_allocate(T2_mctx, (void *)1, 1, t2_callback,
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T2_done == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_wait(&T2_cv, &T2_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_wait failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (T2_nfails != 0)
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a2 = "The task subsystem can create ISC_TASKS_MIN tasks";
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Shutdown events not processed in LIFO order\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Shutdown events not processed in LIFO order\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3_event2(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * This event causes the task to wait on T3_cv.
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type, t3_event1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now we fill up the task's event queue with some events.
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now we register two shutdown events.
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t3_sde1, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t3_sde2, NULL);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now we free the task by signaling T3_cv.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("T3_nsdevents == %d, expected 2\n", T3_nsdevents);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a3 = "When isc_task_shutdown() is called, any shutdown "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "events that have been requested via prior "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "isc_task_onshutdown() calls are posted in "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "LIFO order.";
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt4_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * This event causes the task to wait on T4_cv.
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type, t4_event1,
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_task_onshutdown(task, t4_sde, NULL);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Release the task.
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "After isc_task_shutdown() has been called, any call to "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "isc_task_onshutdown() will return ISC_R_SHUTTINGDOWN.";
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_task_onshutdown(task, t7_sde, NULL);
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type, t7_event1,
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley while (T7_sdflag == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_time_nowplusinterval(&now, &interval);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_condition_waituntil(&T7_cv, &T7_mx, &now);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_waituntil returned %s\n",
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a7 = "A call to isc_task_create() creates a task that can "
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley "receive events.";
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T10_NEVENTS (T10_SENDERCNT*T10_TYPECNT*T10_TAGCNT)
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt10_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_wait(&T10_cv, &T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt10_event2(isc_task_t *task, isc_event_t *event) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_attributes & ISC_EVENTATTR_NOPURGE ?
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if ((T10_purge_type_first <= event->ev_type) &&
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (event->ev_attributes & ISC_EVENTATTR_NOPURGE) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("event %p,%d,%p matched but was not purgable\n",
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("*** event %p,%d,%p not purged\n",
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrewst_taskpurge_x(int sender, int type, int tag, void *purge_sender,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence int purge_type_first, int purge_type_last, void *purge_tag,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence int exp_nevents, int *nfails, int *nprobs, int testrange)
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_purge_type_first = (isc_eventtype_t) purge_type_first;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_purge_type_last = (isc_eventtype_t) purge_type_last;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t10_sde, NULL);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Block the task on T10_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)T_CONTROL,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Fill the task's queue with some messages with varying
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * sender, type, tag, and purgable attribute values.
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (sender_cnt = 0; sender_cnt < T10_SENDERCNT; ++sender_cnt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (type_cnt = 0; type_cnt < T10_TYPECNT; ++type_cnt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (tag_cnt = 0; tag_cnt < T10_TAGCNT; ++tag_cnt) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Make all odd message non-purgable.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * We're testing isc_task_purge.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("*** isc_task_purge returned %d, expected %d\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_purge returned %d\n", nevents);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * We're testing isc_task_purgerange.
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews nevents = isc_task_purgerange(task, purge_sender,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t_info("*** isc_task_purgerange returned %d, "
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_purgerange returned %d\n", nevents);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Unblock the task, allowing event processing.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Wait for shutdown processing to complete.
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_time_nowplusinterval(&now, &interval);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_waituntil(&T10_cv, &T10_mx, &now);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_waituntil returned %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("task processed %d events\n", T10_eventcnt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("*** processed %d, purged %d, total %d\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specific sender.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 2,4,8 expecting 1\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[2], 4, 4, (void *)8, 1, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,8 expecting 3\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, (void *)8, 3, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders, specified type, all tags.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,0 expecting 15\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, NULL, 15, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specified tag, no such type.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,99,8 expecting 0\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 99, 99, (void *)8, 0, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on specified sender, type, all tags.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,5,0 expecting 5\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[3], 5, 5, NULL, 5, &T10_nfails,
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (T10_nfails != 0)
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "A call to isc_task_purge(task, sender, type, tag) "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "purges all events of type 'type' and with tag 'tag' "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "not marked as unpurgable from sender from the task's "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "queue and returns the number of events purged.";
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt11_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_wait(&T11_cv, &T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt11_event2(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t11_sde, NULL);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Block the task on T11_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event1 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event2 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff event2->ev_attributes &= ~ISC_EVENTATTR_NOPURGE;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff event2->ev_attributes |= ISC_EVENTATTR_NOPURGE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (rval != (purgable ? ISC_TRUE : ISC_FALSE)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_purgeevent returned %s, expected %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Unblock the task, allowing event processing.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Wait for shutdown processing to complete.
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_time_nowplusinterval(&now, &interval);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_waituntil(&T11_cv, &T11_mx, &now);
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_waituntil returned %s\n",
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "When the event is marked as purgable, a call to "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "isc_task_purgeevent(task, event) purges the event 'event' "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "from the task's queue and returns ISC_TRUE.";
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "When the event is not marked as purgable, a call to "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "isc_task_purgeevent(task, event) does not purge the "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "event 'event' from the task's queue and returns "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "ISC_FALSE.";
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "isc_event_purgerange(task, sender, first, last, tag) "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "purges all events not marked unpurgable from "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "sender 'sender' and of type within the range 'first' "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "to 'last' inclusive from the task's event queue and "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "returns the number of tasks purged.";
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * First let's try the same cases we used in t10.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specific sender.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 2,4,8 expecting 1\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[2], 4, 4, (void *)8, 1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,8 expecting 3\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, (void *)8, 3,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders, specified type, all tags.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,0 expecting 15\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, NULL, 15, &T13_nfails, &T13_nprobs, 1);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specified tag, no such type.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,99,8 expecting 0\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 99, 99, (void *)8, 0,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on specified sender, type, all tags.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 3,5,0 expecting 5\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[3], 5, 5, 0, 5, &T13_nfails, &T13_nprobs, 1);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now let's try some ranges.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purgerange on 2,4-5,8 expecting 2\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[2], 4, 5, (void *)8, 1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4-5,8 expecting 5\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 5, (void *)8, 5,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders, specified type, all tags.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,5-6,0 expecting 28\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 5, 6, NULL, 28, &T13_nfails, &T13_nprobs, 1);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specified tag, no such type.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,99-101,8 expecting 0\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 99, 101, (void *)8, 0,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on specified sender, type, all tags.
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 3,5-6,0 expecting 10\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[3], 5, 6, NULL, 10, &T13_nfails,
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssont14_callback(isc_task_t *task, isc_event_t *event) {
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t14_exclusiveerror = isc_task_beginexclusive(task);
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t_info("task %d got exclusive access\n", taskno);
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t_info("task %d failed to got exclusive access: %d\n",
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++) {
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater t_info("task %d state %d\n", i , t14_active[i]);
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews isc_mem_put(event->ev_destroy_arg, event->ev_arg, sizeof (int));
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < n; i++) {
54b4a8d3451f65434f9dddec6b252c7e5e0b1624Andreas Gustafsson if (r > 1000000)
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++)
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("Bad config value for ISC_TASK_WORKERS, %d\n", workers);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result = isc_mem_create(0, 0, &mctx);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_mem_create failed %d\n", isc_result);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result = isc_taskmgr_create(mctx, workers, 0, &manager);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_taskmgr_create failed %d\n", isc_result);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result = isc_task_create(manager, 0, &tasks[i]);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_task_create failed %d\n", isc_result);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence event = isc_event_allocate(mctx, NULL, 1, t14_callback,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews v, sizeof(*event));
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++) {
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews if (t14_exclusiveerror != ISC_R_SUCCESS || t14_error) {
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater "isc_task_beginexclusive() gets exclusive access");