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

Commit 6be60bf

Browse files
authored
Merge pull request #4 from ARMmbed/tests
Add additional tests/profiling
2 parents ff8ad3b + efd3259 commit 6be60bf

File tree

6 files changed

+429
-26
lines changed

6 files changed

+429
-26
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
script:
22
- cd events-c
3+
4+
# Strict compilation of library
5+
- CFLAGS='-pedantic -Werror' make
6+
7+
# Runtime tests
38
- make test
9+
10+
# Relative profiling with current master
11+
- if ( git clone https://github.com/armmbed/mbed-events tests/master &&
12+
make -s -C tests/master/$(basename $(pwd)) prof | tee tests/results.txt ) ;
13+
then
14+
cat tests/results.txt | make prof ;
15+
else
16+
make prof ;
17+
fi

events-c/.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
script:
2+
# Strict compilation of library
3+
- CFLAGS='-pedantic -Werror' make
4+
5+
# Runtime tests
26
- make test
7+
8+
# Relative profiling with current master
9+
- if ( git clone https://github.com/geky/events tests/master &&
10+
make -s -C tests/master prof | tee tests/results.txt ) ;
11+
then
12+
cat tests/results.txt | make prof ;
13+
else
14+
make prof ;
15+
fi

events-c/Makefile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ OBJ := $(SRC:.c=.o)
99
DEP := $(SRC:.c=.d)
1010
ASM := $(SRC:.c=.s)
1111

12-
TESTS = tests/tests
13-
TSRC += $(wildcard tests/*.c)
14-
TOBJ := $(TSRC:.c=.o)
15-
TDEP := $(TSRC:.c=.d)
16-
1712
ifdef DEBUG
18-
CFLAGS += -O0 -g3 -DMU_DEBUG
19-
CFLAGS += -fkeep-inline-functions
13+
CFLAGS += -O0 -g3
2014
else
2115
CFLAGS += -O2
2216
endif
@@ -25,17 +19,21 @@ CFLAGS += -m$(WORD)
2519
endif
2620
CFLAGS += -I.
2721
CFLAGS += -std=c99
28-
CFLAGS += -Wall -Winline
22+
CFLAGS += -Wall
2923
CFLAGS += -D_XOPEN_SOURCE=500
3024

3125
LFLAGS += -lpthread
3226

3327

3428
all: $(TARGET)
3529

36-
test: $(TOBJ) $(OBJ)
37-
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $(TESTS)
38-
$(TESTS)
30+
test: tests/tests.o $(OBJ)
31+
$(CC) $(CFLAGS) $^ $(LFLAGS) -o tests/tests
32+
tests/tests
33+
34+
prof: tests/prof.o $(OBJ)
35+
$(CC) $(CFLAGS) $^ $(LFLAGS) -o tests/prof
36+
tests/prof
3937

4038
asm: $(ASM)
4139

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

5654
clean:
5755
rm -f $(TARGET)
58-
rm -f $(TESTS)
59-
rm -f $(TOBJ) $(TDEP)
56+
rm -f tests/tests tests/tests.o tests/tests.d
57+
rm -f tests/prof tests/prof.o tests/prof.d
6058
rm -f $(OBJ)
6159
rm -f $(DEP)
6260
rm -f $(ASM)

events-c/README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,32 @@ supports multithreaded environments. More information on the idea
3737
behind composable event loops
3838
[here](https://gist.github.com/geky/4969d940f1bd5596bdc10e79093e2553).
3939
40-
## Porting ##
40+
## Tests ##
41+
42+
The events library uses a set of local tests based on the posix implementation.
43+
44+
Runtime tests are located in [tests.c](tests/tests.c):
45+
46+
``` bash
47+
make test
48+
```
49+
50+
Profiling tests based on rdtsc are located in [prof.c](tests/prof.c):
4151

42-
The events library only requires the following:
43-
- monotonic counter
44-
- non-recursive mutex
45-
- binary semaphore
52+
``` bash
53+
make prof
54+
```
55+
56+
To make profiling results more tangible, the profiler also supports percentage
57+
comparison with previous runs:
58+
``` bash
59+
make prof | tee results.txt
60+
cat results.txt | make prof
61+
```
62+
63+
## Porting ##
4664

47-
Supported implementations are hosted as branches on this repo:
48-
- Posix
49-
- mbed
65+
The events library requires a small porting layer:
66+
- [events_tick](events_tick.h) - monotonic counter
67+
- [events_mutex](events_mutex.h) - non-recursive mutex
68+
- [events_sema](events_sema.h) - binary semaphore

events-c/events.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ static inline int equeue_tickdiff(unsigned a, unsigned b) {
157157
return (int)(a - b);
158158
}
159159

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

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

168168
e->next = *p;
169169
*p = e;
170-
171-
return e->id;
172170
}
173171

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

186184
static int equeue_post(equeue_t *q, struct event *e, int ms) {
185+
int id = e->id;
186+
if (ms < 0) {
187+
event_dealloc(q, e+1);
188+
return id;
189+
}
190+
187191
events_mutex_lock(&q->queuelock);
188-
int id = equeue_enqueue(q, e, ms);
192+
equeue_enqueue(q, e, ms);
189193
events_mutex_unlock(&q->queuelock);
194+
190195
events_sema_release(&q->eventsema);
191196
return id;
192197
}

0 commit comments

Comments
 (0)