Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Add additional tests/profiling #4

Merged
merged 8 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
script:
- cd events-c

# Strict compilation of library
- CFLAGS='-pedantic -Werror' make

# Runtime tests
- make test

# Relative profiling with current master
- if ( git clone https://github.com/armmbed/mbed-events tests/master &&
make -s -C tests/master/$(basename $(pwd)) prof | tee tests/results.txt ) ;
then
cat tests/results.txt | make prof ;
else
make prof ;
fi
13 changes: 13 additions & 0 deletions events-c/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
script:
# Strict compilation of library
- CFLAGS='-pedantic -Werror' make

# Runtime tests
- make test

# Relative profiling with current master
- if ( git clone https://github.com/geky/events tests/master &&
make -s -C tests/master prof | tee tests/results.txt ) ;
then
cat tests/results.txt | make prof ;
else
make prof ;
fi
24 changes: 11 additions & 13 deletions events-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
ASM := $(SRC:.c=.s)

TESTS = tests/tests
TSRC += $(wildcard tests/*.c)
TOBJ := $(TSRC:.c=.o)
TDEP := $(TSRC:.c=.d)

ifdef DEBUG
CFLAGS += -O0 -g3 -DMU_DEBUG
CFLAGS += -fkeep-inline-functions
CFLAGS += -O0 -g3
else
CFLAGS += -O2
endif
Expand All @@ -25,17 +19,21 @@ CFLAGS += -m$(WORD)
endif
CFLAGS += -I.
CFLAGS += -std=c99
CFLAGS += -Wall -Winline
CFLAGS += -Wall
CFLAGS += -D_XOPEN_SOURCE=500

LFLAGS += -lpthread


all: $(TARGET)

test: $(TOBJ) $(OBJ)
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $(TESTS)
$(TESTS)
test: tests/tests.o $(OBJ)
$(CC) $(CFLAGS) $^ $(LFLAGS) -o tests/tests
tests/tests

prof: tests/prof.o $(OBJ)
$(CC) $(CFLAGS) $^ $(LFLAGS) -o tests/prof
tests/prof

asm: $(ASM)

Expand All @@ -55,8 +53,8 @@ size: $(OBJ)

clean:
rm -f $(TARGET)
rm -f $(TESTS)
rm -f $(TOBJ) $(TDEP)
rm -f tests/tests tests/tests.o tests/tests.d
rm -f tests/prof tests/prof.o tests/prof.d
rm -f $(OBJ)
rm -f $(DEP)
rm -f $(ASM)
35 changes: 27 additions & 8 deletions events-c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,32 @@ supports multithreaded environments. More information on the idea
behind composable event loops
[here](https://gist.github.com/geky/4969d940f1bd5596bdc10e79093e2553).

## Porting ##
## Tests ##

The events library uses a set of local tests based on the posix implementation.

Runtime tests are located in [tests.c](tests/tests.c):

``` bash
make test
```

Profiling tests based on rdtsc are located in [prof.c](tests/prof.c):

The events library only requires the following:
- monotonic counter
- non-recursive mutex
- binary semaphore
``` bash
make prof
```

To make profiling results more tangible, the profiler also supports percentage
comparison with previous runs:
``` bash
make prof | tee results.txt
cat results.txt | make prof
```

## Porting ##

Supported implementations are hosted as branches on this repo:
- Posix
- mbed
The events library requires a small porting layer:
- [events_tick](events_tick.h) - monotonic counter
- [events_mutex](events_mutex.h) - non-recursive mutex
- [events_sema](events_sema.h) - binary semaphore
15 changes: 10 additions & 5 deletions events-c/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ static inline int equeue_tickdiff(unsigned a, unsigned b) {
return (int)(a - b);
}

static int equeue_enqueue(equeue_t *q, struct event *e, int ms) {
e->target = events_tick() + (unsigned)ms;
static void equeue_enqueue(equeue_t *q, struct event *e, unsigned ms) {
e->target = events_tick() + ms;

struct event **p = &q->queue;
while (*p && equeue_tickdiff((*p)->target, e->target) <= 0) {
Expand All @@ -167,8 +167,6 @@ static int equeue_enqueue(equeue_t *q, struct event *e, int ms) {

e->next = *p;
*p = e;

return e->id;
}

static struct event *equeue_dequeue(equeue_t *q, int id) {
Expand All @@ -184,9 +182,16 @@ static struct event *equeue_dequeue(equeue_t *q, int id) {
}

static int equeue_post(equeue_t *q, struct event *e, int ms) {
int id = e->id;
if (ms < 0) {
event_dealloc(q, e+1);
return id;
}

events_mutex_lock(&q->queuelock);
int id = equeue_enqueue(q, e, ms);
equeue_enqueue(q, e, ms);
events_mutex_unlock(&q->queuelock);

events_sema_release(&q->eventsema);
return id;
}
Expand Down
Loading