git » libfilo » commit 2385c35

Add another stupid test case.

author Alberto Bertogli
2005-04-27 20:52:03 UTC
committer Alberto Bertogli
2005-04-27 20:52:03 UTC
parent f984989f0af0ba356dd047d1bcc8e91c77a71130

Add another stupid test case.

tests/test4.c +51 -0

diff --git a/tests/test4.c b/tests/test4.c
new file mode 100644
index 0000000..ce34f61
--- /dev/null
+++ b/tests/test4.c
@@ -0,0 +1,51 @@
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include "libfilo.h"
+
+#define LOCK(start, len, mode)	 			\
+	do {						\
+		printf("%lu: about to lock\n", pthread_self()); \
+		if (!filo_lock(&l, start, len, mode)) printf("F\n"); \
+		printf("%lu: lock\t %d %d %d\n", pthread_self(), start, len, mode); \
+	} while(0);
+
+#define UNLOCK(start, len)	 			\
+	do {						\
+		printf("%lu: about to unlock\n", pthread_self()); \
+		if (!filo_unlock(&l, start, len)) printf("F\n"); \
+		printf("%lu: unlock\t %d %d\n", pthread_self(), start, len); \
+	} while(0);
+
+#define LU_S(start, len, mode, sl)			\
+	do {						\
+		LOCK(start, len, mode);			\
+		sleep(sl);				\
+		UNLOCK(start, len);			\
+	} while(0);
+
+filock_t l;
+
+int main(void) {
+
+	filo_init(&l);
+
+	LOCK(10, 1, FL_WR_MODE);
+	UNLOCK(10, 1);
+
+	LOCK(0, 1, FL_RD_MODE);
+	LOCK(0, 1, FL_WR_MODE);
+	UNLOCK(0, 1);
+
+	LOCK(0, 2, FL_RD_MODE);
+	UNLOCK(0, 1);
+	UNLOCK(1, 1);
+
+	filo_free(&l);
+
+	printf("done static\n\n");
+	return 0;
+
+}
+