Skip to content

Commit

Permalink
Added assertion of all function arguments in the kernel.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed May 31, 2016
1 parent dfe7cfa commit 05bcaf6
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/drivers/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ int uart_init(struct uart_driver_t *self_p,
sem_init(&self_p->sem, 1);

chan_init(&self_p->chout,
NULL,
chan_read_null,
(ssize_t (*)(chan_t *, const void *, size_t))uart_port_write_cb,
NULL);
chan_size_null);

if (size > 0) {
queue_init(&self_p->chin, rxbuf_p, size);
Expand Down
23 changes: 17 additions & 6 deletions src/kernel/binary_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ static int node_height(struct binary_tree_node_t *node_p)
return (node_p ? node_p->height : 0);
}

void node_recalc(struct binary_tree_node_t *node_p)
static void node_recalc(struct binary_tree_node_t *node_p)
{
node_p->height = (1 + MAX(node_height(node_p->left_p),
node_height(node_p->right_p)));
}

struct binary_tree_node_t *
static struct binary_tree_node_t *
node_rotate_right(struct binary_tree_node_t *node_p)
{
struct binary_tree_node_t *left_p = node_p->left_p;
Expand Down Expand Up @@ -100,8 +100,8 @@ node_balance(struct binary_tree_node_t *node_p)
return (node_p);
}

int node_insert(struct binary_tree_node_t **parent_pp,
struct binary_tree_node_t *node_p)
static int node_insert(struct binary_tree_node_t **parent_pp,
struct binary_tree_node_t *node_p)
{
int res = 0;
struct binary_tree_node_t *parent_p = *parent_pp;
Expand Down Expand Up @@ -146,8 +146,8 @@ node_delete_min(struct binary_tree_node_t *node_p)
return (node_balance(node_p));
}

int node_delete_item(struct binary_tree_node_t **node_pp,
int key)
static int node_delete_item(struct binary_tree_node_t **node_pp,
int key)
{
int res = 0;
struct binary_tree_node_t *left_p;
Expand Down Expand Up @@ -205,6 +205,8 @@ node_search(struct binary_tree_node_t *node_p, int key)

int binary_tree_init(struct binary_tree_t *self_p)
{
ASSERTN(self_p != NULL, EINVAL);

self_p->root_p = NULL;

return (0);
Expand All @@ -213,6 +215,9 @@ int binary_tree_init(struct binary_tree_t *self_p)
int binary_tree_insert(struct binary_tree_t *self_p,
struct binary_tree_node_t *node_p)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(node_p != NULL, EINVAL);

node_p->height = 1;
node_p->left_p = NULL;
node_p->right_p= NULL;
Expand All @@ -223,18 +228,24 @@ int binary_tree_insert(struct binary_tree_t *self_p,
int binary_tree_delete(struct binary_tree_t *self_p,
int key)
{
ASSERTN(self_p != NULL, EINVAL);

return (node_delete_item(&self_p->root_p, key));
}

struct binary_tree_node_t *
binary_tree_search(struct binary_tree_t *self_p,
int key)
{
ASSERTN(self_p != NULL, EINVAL);

return (node_search(self_p->root_p, key));
}

void binary_tree_print(struct binary_tree_t *self_p)
{
ASSERTN(self_p != NULL, EINVAL);

if (self_p->root_p == NULL) {
std_printf(FSTR("empty\r\n"));
} else {
Expand Down
15 changes: 15 additions & 0 deletions src/kernel/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int bus_module_init()

int bus_init(struct bus_t *self_p)
{
ASSERTN(self_p != NULL, EINVAL);

binary_tree_init(&self_p->listeners);
rwlock_init(&self_p->rwlock);

Expand All @@ -37,6 +39,9 @@ int bus_listener_init(struct bus_listener_t *self_p,
int id,
chan_t *chan_p)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(chan_p != NULL, EINVAL);

self_p->base.key = id;
self_p->id = id;
self_p->chan_p = chan_p;
Expand All @@ -48,6 +53,9 @@ int bus_listener_init(struct bus_listener_t *self_p,
int bus_attach(struct bus_t *self_p,
struct bus_listener_t *listener_p)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(listener_p != NULL, EINVAL);

struct bus_listener_t *head_p;

rwlock_writer_get(&self_p->rwlock, NULL);
Expand All @@ -70,6 +78,9 @@ int bus_attach(struct bus_t *self_p,
int bus_detatch(struct bus_t *self_p,
struct bus_listener_t *listener_p)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(listener_p != NULL, EINVAL);

int res = 0;
struct bus_listener_t *head_p, *curr_p, *prev_p;

Expand Down Expand Up @@ -114,6 +125,10 @@ int bus_write(struct bus_t *self_p,
const void *buf_p,
size_t size)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(buf_p != NULL, EINVAL);
ASSERTN(size > 0, EINVAL);

int number_of_receivers;
struct bus_listener_t *curr_p;

Expand Down
52 changes: 50 additions & 2 deletions src/kernel/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ int chan_init(struct chan_t *self_p,
thrd_write_fn_t write,
thrd_size_fn_t size)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(read != NULL, EINVAL);
ASSERTN(write != NULL, EINVAL);
ASSERTN(size != NULL, EINVAL);

self_p->read = read;
self_p->write = write;
self_p->size = size;
Expand All @@ -46,6 +51,10 @@ int chan_list_init(struct chan_list_t *list_p,
void *workspace_p,
size_t size)
{
ASSERTN(list_p != NULL, EINVAL);
ASSERTN(workspace_p != NULL, EINVAL);
ASSERTN(size > 0, EINVAL);

list_p->max = (size / sizeof(list_p->chans_pp[0]));

if (list_p->max == 0) {
Expand All @@ -61,6 +70,8 @@ int chan_list_init(struct chan_list_t *list_p,

int chan_list_destroy(struct chan_list_t *list_p)
{
ASSERTN(list_p != NULL, EINVAL);

struct chan_t *chan_p = NULL;
size_t i;

Expand All @@ -80,23 +91,36 @@ ssize_t chan_read(chan_t *self_p,
void *buf_p,
size_t size)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(buf_p != NULL, EINVAL);
ASSERTN(size > 0, EINVAL);

return (((struct chan_t *)self_p)->read(self_p, buf_p, size));
}

ssize_t chan_write(chan_t *self_p,
const void *buf_p,
size_t size)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(buf_p != NULL, EINVAL);
ASSERTN(size > 0, EINVAL);

return (((struct chan_t *)self_p)->write(self_p, buf_p, size));
}

size_t chan_size(chan_t *self_p)
{
ASSERTN(self_p != NULL, EINVAL);

return (((struct chan_t *)self_p)->size(self_p));
}

int chan_list_add(struct chan_list_t *list_p, chan_t *chan_p)
{
ASSERTN(list_p != NULL, EINVAL);
ASSERTN(chan_p != NULL, EINVAL);

if (list_p->len == list_p->max) {
return (-ENOMEM);
}
Expand All @@ -107,16 +131,21 @@ int chan_list_add(struct chan_list_t *list_p, chan_t *chan_p)
return (0);
}

int chan_list_remove(struct chan_list_t *list, chan_t *chan_p)
int chan_list_remove(struct chan_list_t *list_p, chan_t *chan_p)
{
ASSERT(0, "chan_list_remove not implemented\n");
ASSERTN(list_p != NULL, EINVAL);
ASSERTN(chan_p != NULL, EINVAL);

ASSERTN(0, ENOSYS, "chan_list_remove not implemented\n");

return (0);
}

chan_t *chan_list_poll(struct chan_list_t *list_p,
struct time_t *timeout_p)
{
ASSERTN(list_p != NULL, EINVAL);

struct chan_t *chan_p = NULL;
size_t i;

Expand Down Expand Up @@ -155,6 +184,25 @@ chan_t *chan_list_poll(struct chan_list_t *list_p,
return (chan_p);
}

ssize_t chan_read_null(chan_t *self_p,
void *buf_p,
size_t size)
{
return (0);
}

ssize_t chan_write_null(chan_t *self_p,
const void *buf_p,
size_t size)
{
return (0);
}

size_t chan_size_null(chan_t *self_p)
{
return (0);
}

int chan_is_polled_isr(struct chan_t *self_p)
{
if (self_p->list_p != NULL) {
Expand Down
12 changes: 12 additions & 0 deletions src/kernel/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

int event_init(struct event_t *self_p)
{
ASSERTN(self_p != NULL, EINVAL);

chan_init(&self_p->base,
(ssize_t (*)(void *, void *, size_t))event_read,
(ssize_t (*)(void *, const void *, size_t))event_write,
Expand All @@ -36,6 +38,10 @@ ssize_t event_read(struct event_t *self_p,
void *buf_p,
size_t size)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(buf_p != NULL, EINVAL);
ASSERTN(size == sizeof(uint32_t), EINVAL);

uint32_t *mask_p, mask;

mask_p = (uint32_t *)buf_p;
Expand Down Expand Up @@ -65,6 +71,10 @@ ssize_t event_write(struct event_t *self_p,
const void *buf_p,
size_t size)
{
ASSERTN(self_p != NULL, EINVAL);
ASSERTN(buf_p != NULL, EINVAL);
ASSERTN(size == sizeof(uint32_t), EINVAL);

sys_lock();
size = event_write_isr(self_p, buf_p, size);
sys_unlock();
Expand Down Expand Up @@ -94,5 +104,7 @@ ssize_t event_write_isr(struct event_t *self_p,

ssize_t event_size(struct event_t *self_p)
{
ASSERTN(self_p != NULL, EINVAL);

return (self_p->mask != 0);
}
Loading

0 comments on commit 05bcaf6

Please sign in to comment.