[sheepdog] [PATCH 6/6] tests/dynamorio: add a new DR based tester for EMFILE handling

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Aug 13 18:27:41 CEST 2013


From: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

DR is suitable for testing EMFILE handling because it can open files
transparently and consume fds. This patch adds a new DR client for
this purpose. We can enhance this client for inserting fd consuming at
arbital timing.

This patch also adds a test scinario for testing sockfd_shrink()
(01.sh). With this script, we can confirm that sockfd_shrink() is
actually called and does it work.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 tests/dynamorio/emfile/01.sh          | 26 +++++++++++++++++++
 tests/dynamorio/emfile/CMakeLists.txt |  9 +++++++
 tests/dynamorio/emfile/emfile.c       | 47 +++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100755 tests/dynamorio/emfile/01.sh
 create mode 100644 tests/dynamorio/emfile/CMakeLists.txt
 create mode 100644 tests/dynamorio/emfile/emfile.c

diff --git a/tests/dynamorio/emfile/01.sh b/tests/dynamorio/emfile/01.sh
new file mode 100755
index 0000000..ae4390f
--- /dev/null
+++ b/tests/dynamorio/emfile/01.sh
@@ -0,0 +1,26 @@
+#! /bin/bash
+
+# testing sockfd shrink with transparent fd consuming
+
+sudo killall -KILL sheep
+sudo killall -KILL shepherd
+
+sudo rm -rf /tmp/sheepdog/dynamorio/*
+
+sudo shepherd
+
+sudo ~/dynamorio/build/bin64/drrun -c libemfile.so 990 -- \
+    sheep -d -c shepherd:127.0.0.1 -p 7000 -z 0 /tmp/sheepdog/dynamorio/0
+
+for i in `seq 1 5`;
+do
+    sudo sheep -d -c shepherd:127.0.0.1 -p 700$i -z $i\
+        /tmp/sheepdog/dynamorio/$i
+done
+
+sleep 3
+collie cluster format
+
+collie vdi create -P test1 100M &
+collie vdi create -P test2 100M &
+collie vdi create -P test3 100M
diff --git a/tests/dynamorio/emfile/CMakeLists.txt b/tests/dynamorio/emfile/CMakeLists.txt
new file mode 100644
index 0000000..3a548df
--- /dev/null
+++ b/tests/dynamorio/emfile/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.8)
+
+SET(DynamoRIO_DIR "~/dynamorio/exports/cmake")
+find_package(DynamoRIO)
+
+add_library(emfile SHARED emfile.c ../common.c)
+configure_DynamoRIO_client(emfile)
+
+use_DynamoRIO_extension(emfile drwrap)
diff --git a/tests/dynamorio/emfile/emfile.c b/tests/dynamorio/emfile/emfile.c
new file mode 100644
index 0000000..cb7dce2
--- /dev/null
+++ b/tests/dynamorio/emfile/emfile.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * ToDos
+ * 1. consume fd at arbital timing with some messaging mechanisms
+ * 2. test ENFILE case
+ */
+
+#include "dr_api.h"
+
+#include "../common.h"
+#include <stdint.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+static int nr_consumed_fds;
+
+DR_EXPORT void dr_init(client_id_t id)
+{
+	int i;
+	const char *option;
+
+	init_log_file();
+
+	option = dr_get_options(id);
+	fi_printf("the passed option to this client: %s\n", option);
+	nr_consumed_fds = atoi(option);
+	fi_printf("number of consumed file descriptors: %d\n", nr_consumed_fds);
+
+	for (i = 0; i < nr_consumed_fds; i++) {
+		int fd = open("/dev/null", O_RDONLY);
+		if (fd < 0)
+			die("opening /dev/null failed: %m");
+	}
+}
-- 
1.8.1.2




More information about the sheepdog mailing list