task_test.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2011, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*! \file */
#include <config.h>
#include <atf-c.h>
#include <unistd.h>
#include "../task_p.h"
#include "isctest.h"
/*
* Helper functions
*/
/* task event handler, sets a boolean to true */
int counter = 0;
static void
}
static void
counter++;
}
/*
* Individual unit tests
*/
/* Create a task */
}
isc_test_end();
}
/* Process events */
}
int a = 0, b = 0;
int i = 0;
counter = 1;
/* First event */
set, &a, sizeof (isc_event_t));
ATF_CHECK_EQ(a, 0);
set, &b, sizeof (isc_event_t));
ATF_CHECK_EQ(b, 0);
while ((a == 0 || b == 0) && i++ < 5000) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
#endif
isc_test_nap(1000);
}
ATF_CHECK(a != 0);
ATF_CHECK(b != 0);
isc_test_end();
}
/* Privileged events */
}
int a = 0, b = 0, c = 0, d = 0, e = 0;
int i = 0;
counter = 1;
#ifdef ISC_PLATFORM_USETHREADS
/*
* Pause the task manager so we can fill up the work queue
* without things happening while we do it.
*/
#endif
/* First event: privileged */
set, &a, sizeof (isc_event_t));
ATF_CHECK_EQ(a, 0);
/* Second event: not privileged */
set, &b, sizeof (isc_event_t));
ATF_CHECK_EQ(b, 0);
/* Third event: privileged */
set, &c, sizeof (isc_event_t));
ATF_CHECK_EQ(c, 0);
/* Fourth event: privileged */
set, &d, sizeof (isc_event_t));
ATF_CHECK_EQ(d, 0);
/* Fifth event: not privileged */
set, &e, sizeof (isc_event_t));
ATF_CHECK_EQ(e, 0);
#ifdef ISC_PLATFORM_USETHREADS
#endif
/* We're waiting for *all* variables to be set */
while ((a == 0 || b == 0 || c == 0 || d == 0 || e == 0) && i++ < 5000) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
#endif
isc_test_nap(1000);
}
/*
* We can't guarantee what order the events fire, but
* we do know the privileged tasks that set a, c, and d
* would have fired first.
*/
ATF_CHECK(a <= 3);
ATF_CHECK(c <= 3);
ATF_CHECK(d <= 3);
/* ...and the non-privileged tasks that set b and e, last */
ATF_CHECK(b >= 4);
ATF_CHECK(e >= 4);
isc_test_end();
}
/*
* Edge case: this tests that the task manager behaves as expected when
* we explicitly set it into normal mode *while* running privileged.
*/
}
int a = -1, b = -1, c = -1, d = -1, e = -1; /* non valid states */
int i = 0;
counter = 1;
#ifdef ISC_PLATFORM_USETHREADS
/*
* Pause the task manager so we can fill up the work queue
* without things happening while we do it.
*/
#endif
/* First event: privileged */
set_and_drop, &a, sizeof (isc_event_t));
ATF_CHECK_EQ(a, -1);
/* Second event: not privileged */
set_and_drop, &b, sizeof (isc_event_t));
ATF_CHECK_EQ(b, -1);
/* Third event: privileged */
set_and_drop, &c, sizeof (isc_event_t));
ATF_CHECK_EQ(c, -1);
/* Fourth event: privileged */
set_and_drop, &d, sizeof (isc_event_t));
ATF_CHECK_EQ(d, -1);
/* Fifth event: not privileged */
set_and_drop, &e, sizeof (isc_event_t));
ATF_CHECK_EQ(e, -1);
#ifdef ISC_PLATFORM_USETHREADS
#endif
/* We're waiting for all variables to be set. */
while ((a == -1 || b == -1 || c == -1 || d == -1 || e == -1) &&
i++ < 5000) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
#endif
isc_test_nap(1000);
}
/*
* We can't guarantee what order the events fire, but
* we do know *exactly one* of the privileged tasks will
* have run in privileged mode...
*/
ATF_CHECK(a == isc_taskmgrmode_privileged ||
c == isc_taskmgrmode_privileged ||
d == isc_taskmgrmode_privileged);
ATF_CHECK(a + c + d == isc_taskmgrmode_privileged);
/* ...and neither of the non-privileged tasks did... */
/* ...but all five of them did run. */
isc_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
return (atf_no_error());
}