HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- test_system_conn
- test_shutdown
- test_sys_shutdown_complete
- test_sys_shutdown_failed
#include <async.h>
#include <errno.h>
#include <fibril_synch.h>
#include <loc.h>
#include <pcut/pcut.h>
#include <str.h>
#include <system.h>
#include <system_srv.h>
#include "../private/system.h"
PCUT_INIT;
PCUT_TEST_SUITE(system);
static const char *test_system_server = "test-system";
static const char *test_system_svc = "test/system";
void test_system_conn(ipc_call_t *, void *);
static errno_t test_shutdown(void *);
static void test_sys_shutdown_complete(void *);
static void test_sys_shutdown_failed(void *);
static system_ops_t test_system_srv_ops = {
.shutdown = test_shutdown
};
system_cb_t test_system_cb = {
.shutdown_complete = test_sys_shutdown_complete,
.shutdown_failed = test_sys_shutdown_failed
};
typedef struct {
errno_t rc;
bool shutdown_called;
bool shutdown_complete_called;
bool shutdown_failed_called;
fibril_condvar_t event_cv;
fibril_mutex_t event_lock;
system_srv_t *srv;
} test_response_t;
PCUT_TEST(open_close)
{
errno_t rc;
service_id_t sid;
system_t *system = NULL;
test_response_t resp;
loc_srv_t *srv;
async_set_fallback_port_handler(test_system_conn, &resp);
rc = loc_server_register(test_system_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_system_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = system_open(test_system_svc, NULL, NULL, &system);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(system);
system_close(system);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(shutdown_failure)
{
errno_t rc;
service_id_t sid;
system_t *system = NULL;
test_response_t resp;
loc_srv_t *srv;
async_set_fallback_port_handler(test_system_conn, &resp);
rc = loc_server_register(test_system_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_system_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = system_open(test_system_svc, NULL, NULL, &system);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(system);
resp.rc = ENOMEM;
resp.shutdown_called = false;
rc = system_shutdown(system);
PCUT_ASSERT_TRUE(resp.shutdown_called);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
system_close(system);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(shutdown_success)
{
errno_t rc;
service_id_t sid;
system_t *system = NULL;
test_response_t resp;
loc_srv_t *srv;
async_set_fallback_port_handler(test_system_conn, &resp);
rc = loc_server_register(test_system_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_system_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = system_open(test_system_svc, NULL, NULL, &system);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(system);
resp.rc = EOK;
resp.shutdown_called = false;
rc = system_shutdown(system);
PCUT_ASSERT_TRUE(resp.shutdown_called);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
system_close(system);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(shutdown_complete)
{
errno_t rc;
service_id_t sid;
system_t *system = NULL;
test_response_t resp;
loc_srv_t *srv;
async_set_fallback_port_handler(test_system_conn, &resp);
rc = loc_server_register(test_system_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_system_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = system_open(test_system_svc, &test_system_cb, &resp, &system);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(system);
PCUT_ASSERT_NOT_NULL(resp.srv);
resp.shutdown_complete_called = false;
fibril_mutex_initialize(&resp.event_lock);
fibril_condvar_initialize(&resp.event_cv);
system_srv_shutdown_complete(resp.srv);
fibril_mutex_lock(&resp.event_lock);
while (!resp.shutdown_complete_called) {
fibril_condvar_wait(&resp.event_cv, &resp.event_lock);
}
fibril_mutex_unlock(&resp.event_lock);
system_close(system);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
PCUT_TEST(shutdown_failed)
{
errno_t rc;
service_id_t sid;
system_t *system = NULL;
test_response_t resp;
loc_srv_t *srv;
async_set_fallback_port_handler(test_system_conn, &resp);
rc = loc_server_register(test_system_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = loc_service_register(srv, test_system_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = system_open(test_system_svc, &test_system_cb, &resp, &system);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(system);
PCUT_ASSERT_NOT_NULL(resp.srv);
resp.shutdown_failed_called = false;
fibril_mutex_initialize(&resp.event_lock);
fibril_condvar_initialize(&resp.event_cv);
system_srv_shutdown_failed(resp.srv);
fibril_mutex_lock(&resp.event_lock);
while (!resp.shutdown_failed_called) {
fibril_condvar_wait(&resp.event_cv, &resp.event_lock);
}
fibril_mutex_unlock(&resp.event_lock);
system_close(system);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}
void test_system_conn(ipc_call_t *icall, void *arg)
{
test_response_t *resp = (test_response_t *)arg;
system_srv_t srv;
system_srv_initialize(&srv);
srv.ops = &test_system_srv_ops;
srv.arg = arg;
resp->srv = &srv;
system_conn(icall, &srv);
resp->srv = NULL;
}
static errno_t test_shutdown(void *arg)
{
test_response_t *resp = (test_response_t *)arg;
resp->shutdown_called = true;
return resp->rc;
}
static void test_sys_shutdown_complete(void *arg)
{
test_response_t *resp = (test_response_t *)arg;
resp->shutdown_complete_called = true;
fibril_condvar_signal(&resp->event_cv);
}
static void test_sys_shutdown_failed(void *arg)
{
test_response_t *resp = (test_response_t *)arg;
resp->shutdown_failed_called = true;
}
PCUT_EXPORT(system);
HelenOS homepage, sources at GitHub