[PATCH 1/2] test-message: add message quota test

John de la Garza john at jjdev.com
Sun Nov 2 16:15:11 PST 2014


Signed-off-by: John de la Garza <john at jjdev.com>
---
 test/kdbus-test.c   |  6 ++++++
 test/kdbus-test.h   |  1 +
 test/test-message.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/test/kdbus-test.c b/test/kdbus-test.c
index 56a0ff9..d9e6a89 100644
--- a/test/kdbus-test.c
+++ b/test/kdbus-test.c
@@ -106,6 +106,12 @@ static const struct kdbus_test tests[] = {
 		.flags	= TEST_CREATE_BUS,
 	},
 	{
+		.name	= "message-quota",
+		.desc	= "message quotas are enforced",
+		.func	= kdbus_test_message_quota,
+		.flags	= TEST_CREATE_BUS,
+	},
+	{
 		.name	= "timeout",
 		.desc	= "timeout",
 		.func	= kdbus_test_timeout,
diff --git a/test/kdbus-test.h b/test/kdbus-test.h
index bb9b372..e267182 100644
--- a/test/kdbus-test.h
+++ b/test/kdbus-test.h
@@ -61,6 +61,7 @@ int kdbus_test_match_name_change(struct kdbus_test_env *env);
 int kdbus_test_match_name_remove(struct kdbus_test_env *env);
 int kdbus_test_message_basic(struct kdbus_test_env *env);
 int kdbus_test_message_prio(struct kdbus_test_env *env);
+int kdbus_test_message_quota(struct kdbus_test_env *env);
 int kdbus_test_metadata_ns(struct kdbus_test_env *env);
 int kdbus_test_monitor(struct kdbus_test_env *env);
 int kdbus_test_name_basic(struct kdbus_test_env *env);
diff --git a/test/test-message.c b/test/test-message.c
index 93b9d9c..e7980a1 100644
--- a/test/test-message.c
+++ b/test/test-message.c
@@ -13,6 +13,9 @@
 #include "kdbus-util.h"
 #include "kdbus-enum.h"
 #include "kdbus-test.h"
+#include "../limits.h"
+#include <sys/capability.h>
+
 
 int kdbus_test_message_basic(struct kdbus_test_env *env)
 {
@@ -124,3 +127,33 @@ int kdbus_test_message_prio(struct kdbus_test_env *env)
 
 	return TEST_OK;
 }
+
+int kdbus_test_message_quota(struct kdbus_test_env *env)
+{
+	struct kdbus_conn *a, *b;
+	uint64_t cookie = 0;
+	int ret;
+	int i;
+
+	if (geteuid() == 0) {
+		kdbus_printf("error geteuid() == 0, %s() can't be root\n",
+			     __func__);
+		return TEST_SKIP;
+	}
+
+	a = kdbus_hello(env->buspath, 0, NULL, 0);
+	b = kdbus_hello(env->buspath, 0, NULL, 0);
+
+	for (i = 0; i <= KDBUS_CONN_MAX_MSGS_PER_USER; i++) {
+		ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 0, a->id);
+		ASSERT_RETURN(ret == 0);
+	}
+
+	ret = kdbus_msg_send(b, NULL, ++cookie, 0, 0, 0, a->id);
+	ASSERT_RETURN(ret == -ENOBUFS);
+
+	kdbus_conn_free(a);
+	kdbus_conn_free(b);
+
+	return TEST_OK;
+}
-- 
2.1.1



More information about the dbus mailing list