File: test_pktbuf.c

package info (click to toggle)
rat 4.2.22-2.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,896 kB
  • ctags: 3,717
  • sloc: ansic: 36,542; tcl: 2,740; sh: 2,675; makefile: 295
file content (58 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "config_unix.h"

#include "pktbuf.h"
#include "rtp.h"
#include "debug.h"

#define PKTBUF_SIZE 23

static int 		buf_est;

static void 
add_thing(pktbuf_t *pb, rtp_packet *pp) {
	pktbuf_enqueue(pb, pp);
	if (buf_est < PKTBUF_SIZE) {
		buf_est++;
	}
	assert(buf_est == pktbuf_get_count(pb));
	xmemchk();
}

static void
remove_thing(pktbuf_t *pb) {
	rtp_packet *pp;
	if (pktbuf_dequeue(pb, &pp)) {
		xfree(pp);
		buf_est --;
	}
	assert(buf_est == pktbuf_get_count(pb));
	xmemchk();
}

int main() {
	static rtp_packet	*pp;
	static pktbuf_t		*pb;
	int32_t			i, j, n,ts;

	if (pktbuf_create(&pb, PKTBUF_SIZE) == 0) {
		printf("Failed to create buffer\n");
		exit(-1);
	}
	xmemchk();
	for(i = 0; i < 100000; i++) {
		n = lrand48() % 16;
		for(j = 0; j <= n; j++) {
			pp = (rtp_packet*)xmalloc(sizeof(rtp_packet));
			pp->ts = ts ++;
			add_thing(pb, pp);
		}
		n = lrand48() % 16;
		for(j = 0; j < n; j++) {
			remove_thing(pb);
		}
	}
	pktbuf_destroy(&pb);
	xmemdmp();
	printf("Okay\n");
	return 0;
}