14c87aefeSPatrick Mooney /*
24c87aefeSPatrick Mooney  * This file and its contents are supplied under the terms of the
34c87aefeSPatrick Mooney  * Common Development and Distribution License ("CDDL"), version 1.0.
44c87aefeSPatrick Mooney  * You may only use this file in accordance with the terms of version
54c87aefeSPatrick Mooney  * 1.0 of the CDDL.
64c87aefeSPatrick Mooney  *
74c87aefeSPatrick Mooney  * A full copy of the text of the CDDL should have accompanied this
84c87aefeSPatrick Mooney  * source.  A copy of the CDDL is also available via the Internet at
94c87aefeSPatrick Mooney  * http://www.illumos.org/license/CDDL.
104c87aefeSPatrick Mooney  */
114c87aefeSPatrick Mooney 
124c87aefeSPatrick Mooney /*
134c87aefeSPatrick Mooney  * Copyright 2018 Joyent, Inc.
144c87aefeSPatrick Mooney  */
154c87aefeSPatrick Mooney 
164c87aefeSPatrick Mooney #include "../../../mevent.c"
174c87aefeSPatrick Mooney #include "testlib.h"
184c87aefeSPatrick Mooney 
194c87aefeSPatrick Mooney /*
204c87aefeSPatrick Mooney  * Returns by reference the number of events on the global and change lists.
214c87aefeSPatrick Mooney  *
224c87aefeSPatrick Mooney  * Used by tests that wish to ensure that the event count changes as suggested
234c87aefeSPatrick Mooney  * by mevent_add() and mevent_delete().  Note that a delete does not immediately
244c87aefeSPatrick Mooney  * delete an event.  Events that are pending delete are included in the change
254c87aefeSPatrick Mooney  * list until the next pass through the change list to process pending changes.
264c87aefeSPatrick Mooney  */
274c87aefeSPatrick Mooney void
test_mevent_count_lists(int * ret_global,int * ret_change,int * ret_del_pending)284c87aefeSPatrick Mooney test_mevent_count_lists(int *ret_global, int *ret_change, int *ret_del_pending)
294c87aefeSPatrick Mooney {
304c87aefeSPatrick Mooney 	struct mevent *mevp;
314c87aefeSPatrick Mooney 	int global = 0;
324c87aefeSPatrick Mooney 	int change = 0;
334c87aefeSPatrick Mooney 	int del_pending = 0;
344c87aefeSPatrick Mooney 
354c87aefeSPatrick Mooney 	mevent_qlock();
364c87aefeSPatrick Mooney 
374c87aefeSPatrick Mooney 	LIST_FOREACH(mevp, &global_head, me_list) {
384c87aefeSPatrick Mooney 		global++;
394c87aefeSPatrick Mooney 		VERBOSE(("on global: type %d fd %d state %d", mevp->me_type,
404c87aefeSPatrick Mooney 		    mevp->me_fd, mevp->me_state));
414c87aefeSPatrick Mooney 	}
424c87aefeSPatrick Mooney 
434c87aefeSPatrick Mooney 	LIST_FOREACH(mevp, &change_head, me_list) {
444c87aefeSPatrick Mooney 		change++;
45*154972afSPatrick Mooney 		if (mevp->me_state == EV_DELETE) {
464c87aefeSPatrick Mooney 			del_pending++;
474c87aefeSPatrick Mooney 		}
484c87aefeSPatrick Mooney 		VERBOSE(("on change: type %d fd %d state %d", mevp->me_type,
494c87aefeSPatrick Mooney 		    mevp->me_fd, mevp->me_state));
504c87aefeSPatrick Mooney 	}
514c87aefeSPatrick Mooney 
524c87aefeSPatrick Mooney 	mevent_qunlock();
534c87aefeSPatrick Mooney 
544c87aefeSPatrick Mooney 	*ret_global = global;
554c87aefeSPatrick Mooney 	*ret_change = change;
564c87aefeSPatrick Mooney 	*ret_del_pending = del_pending;
574c87aefeSPatrick Mooney }
58