lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 31 Jan 2013 23:47:34 -0500
From:	Sasha Levin <sasha.levin@...cle.com>
To:	mingo@...hat.com, peterz@...radead.org
Cc:	paulus@...ba.org, acme@...stprotocols.net, penberg@...nel.org,
	linux-kernel@...r.kernel.org, Sasha Levin <sasha.levin@...cle.com>
Subject: [PATCH 3/7] liblock: mutex test suite

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@...cle.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ