From: Sasha Levin <sasha.levin@oracle.com>
To: mingo@redhat.com, peterz@infradead.org
Cc: paulus@samba.org, acme@ghostprotocols.net, penberg@kernel.org,
linux-kernel@vger.kernel.org,
Sasha Levin <sasha.levin@oracle.com>
Subject: [PATCH 3/7] liblock: mutex test suite
Date: Thu, 31 Jan 2013 23:47:34 -0500 [thread overview]
Message-ID: <1359694058-24452-4-git-send-email-sasha.levin@oracle.com> (raw)
In-Reply-To: <1359694058-24452-1-git-send-email-sasha.levin@oracle.com>
This is a rather simple and basic test suite to test common locking
issues.
Beyond tests, it also shows how to use the library.
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
tools/lib/liblock/run_tests.sh | 16 ++++++++++++++++
tools/lib/liblock/tests/AA.c | 16 ++++++++++++++++
tools/lib/liblock/tests/ABBA.c | 16 ++++++++++++++++
tools/lib/liblock/tests/ABBCCA.c | 18 ++++++++++++++++++
tools/lib/liblock/tests/ABBCCDDA.c | 20 ++++++++++++++++++++
tools/lib/liblock/tests/ABCABC.c | 18 ++++++++++++++++++
tools/lib/liblock/tests/ABCDBCDA.c | 20 ++++++++++++++++++++
tools/lib/liblock/tests/ABCDBDDA.c | 20 ++++++++++++++++++++
tools/lib/liblock/tests/common.h | 11 +++++++++++
tools/lib/liblock/tests/unlock_balance.c | 15 +++++++++++++++
10 files changed, 170 insertions(+)
create mode 100755 tools/lib/liblock/run_tests.sh
create mode 100644 tools/lib/liblock/tests/AA.c
create mode 100644 tools/lib/liblock/tests/ABBA.c
create mode 100644 tools/lib/liblock/tests/ABBCCA.c
create mode 100644 tools/lib/liblock/tests/ABBCCDDA.c
create mode 100644 tools/lib/liblock/tests/ABCABC.c
create mode 100644 tools/lib/liblock/tests/ABCDBCDA.c
create mode 100644 tools/lib/liblock/tests/ABCDBDDA.c
create mode 100644 tools/lib/liblock/tests/common.h
create mode 100644 tools/lib/liblock/tests/unlock_balance.c
diff --git a/tools/lib/liblock/run_tests.sh b/tools/lib/liblock/run_tests.sh
new file mode 100755
index 0000000..bbf5281
--- /dev/null
+++ b/tools/lib/liblock/run_tests.sh
@@ -0,0 +1,16 @@
+#! /bin/bash
+
+make &> /dev/null
+
+for i in `ls tests/*.c`; do
+ testname=$(basename -s .c "$i")
+ gcc -o tests/$testname -lpthread $i liblock.a -Iinclude &> /dev/null
+ echo -ne "$testname... "
+ if [ $(timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then
+ echo "PASSED!"
+ else
+ echo "FAILED!"
+ fi
+ rm tests/$testname
+done
+
diff --git a/tools/lib/liblock/tests/AA.c b/tools/lib/liblock/tests/AA.c
new file mode 100644
index 0000000..558109c
--- /dev/null
+++ b/tools/lib/liblock/tests/AA.c
@@ -0,0 +1,16 @@
+#include <liblock/mutex.h>
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+
+ liblock_pthread_mutex_lock(&a);
+ liblock_pthread_mutex_unlock(&b);
+ liblock_pthread_mutex_lock(&a);
+}
diff --git a/tools/lib/liblock/tests/ABBA.c b/tools/lib/liblock/tests/ABBA.c
new file mode 100644
index 0000000..b5070fd
--- /dev/null
+++ b/tools/lib/liblock/tests/ABBA.c
@@ -0,0 +1,16 @@
+#include <liblock/mutex.h>
+#include "common.h"
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+
+ LOCK_UNLOCK_2(a, b);
+ LOCK_UNLOCK_2(b, a);
+}
diff --git a/tools/lib/liblock/tests/ABBCCA.c b/tools/lib/liblock/tests/ABBCCA.c
new file mode 100644
index 0000000..5fc5fa2
--- /dev/null
+++ b/tools/lib/liblock/tests/ABBCCA.c
@@ -0,0 +1,18 @@
+#include <liblock/mutex.h>
+#include "common.h"
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b, c;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+ liblock_pthread_mutex_init(&c, NULL);
+
+ LOCK_UNLOCK_2(a, b);
+ LOCK_UNLOCK_2(b, c);
+ LOCK_UNLOCK_2(c, a);
+}
diff --git a/tools/lib/liblock/tests/ABBCCDDA.c b/tools/lib/liblock/tests/ABBCCDDA.c
new file mode 100644
index 0000000..5cf05bb
--- /dev/null
+++ b/tools/lib/liblock/tests/ABBCCDDA.c
@@ -0,0 +1,20 @@
+#include <liblock/mutex.h>
+#include "common.h"
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b, c, d;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+ liblock_pthread_mutex_init(&c, NULL);
+ liblock_pthread_mutex_init(&d, NULL);
+
+ LOCK_UNLOCK_2(a, b);
+ LOCK_UNLOCK_2(b, c);
+ LOCK_UNLOCK_2(c, d);
+ LOCK_UNLOCK_2(d, a);
+}
diff --git a/tools/lib/liblock/tests/ABCABC.c b/tools/lib/liblock/tests/ABCABC.c
new file mode 100644
index 0000000..eab71ff
--- /dev/null
+++ b/tools/lib/liblock/tests/ABCABC.c
@@ -0,0 +1,18 @@
+#include <liblock/mutex.h>
+#include "common.h"
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b, c;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+ liblock_pthread_mutex_init(&c, NULL);
+
+ LOCK_UNLOCK_2(a, b);
+ LOCK_UNLOCK_2(c, a);
+ LOCK_UNLOCK_2(b, c);
+}
diff --git a/tools/lib/liblock/tests/ABCDBCDA.c b/tools/lib/liblock/tests/ABCDBCDA.c
new file mode 100644
index 0000000..3250f0f
--- /dev/null
+++ b/tools/lib/liblock/tests/ABCDBCDA.c
@@ -0,0 +1,20 @@
+#include <liblock/mutex.h>
+#include "common.h"
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b, c, d;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+ liblock_pthread_mutex_init(&c, NULL);
+ liblock_pthread_mutex_init(&d, NULL);
+
+ LOCK_UNLOCK_2(a, b);
+ LOCK_UNLOCK_2(c, d);
+ LOCK_UNLOCK_2(b, c);
+ LOCK_UNLOCK_2(d, a);
+}
diff --git a/tools/lib/liblock/tests/ABCDBDDA.c b/tools/lib/liblock/tests/ABCDBDDA.c
new file mode 100644
index 0000000..b49c5d9
--- /dev/null
+++ b/tools/lib/liblock/tests/ABCDBDDA.c
@@ -0,0 +1,20 @@
+#include <liblock/mutex.h>
+#include "common.h"
+
+void main(void)
+{
+ liblock_pthread_mutex_t a, b, c, d;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+ liblock_pthread_mutex_init(&b, NULL);
+ liblock_pthread_mutex_init(&c, NULL);
+ liblock_pthread_mutex_init(&d, NULL);
+
+ LOCK_UNLOCK_2(a, b);
+ LOCK_UNLOCK_2(c, d);
+ LOCK_UNLOCK_2(b, d);
+ LOCK_UNLOCK_2(d, a);
+}
diff --git a/tools/lib/liblock/tests/common.h b/tools/lib/liblock/tests/common.h
new file mode 100644
index 0000000..d5f6d5e
--- /dev/null
+++ b/tools/lib/liblock/tests/common.h
@@ -0,0 +1,11 @@
+#ifndef _LIBLOCK_TEST_COMMON_H
+#define _LIBLOCK_TEST_COMMON_H
+
+#define LOCK_UNLOCK_2(a, b) \
+ liblock_pthread_mutex_lock(&(a)); \
+ liblock_pthread_mutex_lock(&(b)); \
+ liblock_pthread_mutex_unlock(&(b)); \
+ liblock_pthread_mutex_unlock(&(a));
+
+
+#endif
diff --git a/tools/lib/liblock/tests/unlock_balance.c b/tools/lib/liblock/tests/unlock_balance.c
new file mode 100644
index 0000000..e68ca99
--- /dev/null
+++ b/tools/lib/liblock/tests/unlock_balance.c
@@ -0,0 +1,15 @@
+#include <liblock/mutex.h>
+
+void main(void)
+{
+ liblock_pthread_mutex_t a;
+
+ liblock_init();
+ liblock_set_thread();
+
+ liblock_pthread_mutex_init(&a, NULL);
+
+ liblock_pthread_mutex_lock(&a);
+ liblock_pthread_mutex_unlock(&a);
+ liblock_pthread_mutex_unlock(&a);
+}
--
1.8.1.1
next prev parent reply other threads:[~2013-02-01 4:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 4:47 [PATCH 0/7] liblock: userspace lockdep Sasha Levin
2013-02-01 4:47 ` [PATCH 1/7] liblock: wrap kernel/lockdep.c to allow usage from userspace Sasha Levin
2013-02-01 4:47 ` [PATCH 2/7] liblock: public headers for mutex implementation Sasha Levin
2013-02-01 9:57 ` Ingo Molnar
2013-02-01 14:20 ` Sasha Levin
2013-02-01 4:47 ` Sasha Levin [this message]
2013-02-01 4:47 ` [PATCH 4/7] liblock: public headers for rwlock implementation Sasha Levin
2013-02-01 4:47 ` [PATCH 5/7] liblock: rwlock test suite Sasha Levin
2013-02-01 4:47 ` [PATCH 6/7] liblock: add a MAINTAINERS entry Sasha Levin
2013-02-01 4:47 ` [PATCH 7/7] perf: integrate liblock support into perf Sasha Levin
2013-02-01 7:35 ` [PATCH 0/7] liblock: userspace lockdep Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359694058-24452-4-git-send-email-sasha.levin@oracle.com \
--to=sasha.levin@oracle.com \
--cc=acme@ghostprotocols.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=penberg@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®