[Ocfs2-test-devel] [PATCH 3/3] Splice had a limit of 1000 bytes to write through the pipe.

Marcos Matsunaga Marcos.Matsunaga at oracle.com
Wed Oct 29 12:26:04 PDT 2008


I've increased the size to 10,000,000 bytes to make it more flexible.

Also, made the splice lenght to be printed to stderr instead of
stdout. This is to make the splice_read work as it was piping everything
and causing error in the splice_test.py script that is being added here.

Added the script splice_test.py

Makefile was changed to install splice_test.py

Signed-off-by: Marcos Matsunaga <Marcos.Matsunaga at oracle.com>
---
 programs/splice/Makefile       |    4 +-
 programs/splice/splice_read.c  |    6 +-
 programs/splice/splice_test.py |  195 ++++++++++++++++++++++++++++++++++++++++
 programs/splice/splice_write.c |    6 +-
 4 files changed, 204 insertions(+), 7 deletions(-)
 create mode 100644 programs/splice/splice_test.py

diff --git a/programs/splice/Makefile b/programs/splice/Makefile
index 6a0bd41..dadbdf6 100644
--- a/programs/splice/Makefile
+++ b/programs/splice/Makefile
@@ -13,10 +13,12 @@ SPLICE_WRITE_OBJECTS = $(patsubst %.c,%.o,$(SPLICE_WRITE_SOURCES))
 
 SOURCES = $(SPLICE_WRITE_SOURCES) $(SPLICE_READ_SOURCES)
 
-DIST_FILES = $(SOURCES)
+DIST_FILES = $(SOURCES) splice_test.py
 
 BIN_PROGRAMS = splice_read splice_write
 
+BIN_EXTRA = splice_test.py
+
 splice_read: $(SPLICE_READ_OBJECTS)
 	$(LINK) 
 splice_write: $(SPLICE_WRITE_OBJECTS)
diff --git a/programs/splice/splice_read.c b/programs/splice/splice_read.c
index ad4af0f..c25522e 100644
--- a/programs/splice/splice_read.c
+++ b/programs/splice/splice_read.c
@@ -16,11 +16,11 @@ int main(int argc, char *argv[])
 		printf("open file failed.\n");
 		exit(-1);
 	}
-	slen = splice(fd, NULL, STDOUT_FILENO, NULL, 1000, 0);
+	slen = splice(fd, NULL, STDOUT_FILENO, NULL, 10000000, 0);
 	if (slen < 0)
-		printf("splice failed.\n");
+		fprintf(stderr, "splice failed.\n");
 	else
-		printf("spliced length = %d\n",slen);
+		fprintf(stderr, "spliced length = %d\n",slen);
 	close(fd);
 	if (slen <0)
 		exit(-1);
diff --git a/programs/splice/splice_test.py b/programs/splice/splice_test.py
new file mode 100644
index 0000000..435fef6
--- /dev/null
+++ b/programs/splice/splice_test.py
@@ -0,0 +1,195 @@
+#!/usr/bin/env python
+#
+# * vim: noexpandtab sw=8 ts=8 sts=0:
+# *
+# * splice_test.py
+# *
+# * Test splice on ocfs2.
+# *
+# * Copyright (C) 2004, 2008 Oracle.  All rights reserved.
+# *
+# * 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.
+# *
+# * This program is distributed in the hope that it will be useful,
+# * but WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# * General Public License for more details.
+#
+#
+#	 
+# Program	: splice_test.py
+# Description 	: This program will just test the splice feature on ocfs2.
+# Author	: Marcos E. Matsunaga 
+
+#
+import os, sys, time, optparse, socket, string, o2tf, config, pdb, timing
+import time, config
+#
+MD5SUM = '/usr/bin/md5sum'
+#
+DEBUGON = os.getenv('DEBUG',0)
+PID = os.getpid()
+node_dirs = {}
+#
+logfile = config.LOGFILE
+filename = 'splice_test.dat'
+SPLICEWRITE_BIN = config.BINDIR + '/splice_write'
+SPLICEREAD_BIN = config.BINDIR + '/splice_read'
+count = 5
+uname = os.uname()
+lhostname = str(socket.gethostname())
+BASEMD5SUM=''
+TEMPMD5SUM=''
+SCRIPT_STATUS=0
+#
+# FUNCTIONS
+#
+def Cleanup():
+	from os import access, F_OK
+	if access(os.path.join(directory, filename), F_OK) ==1:
+		os.system('rm -fr ' + os.path.join(directory, filename))
+	if access(os.path.join('/tmp', filename), F_OK) ==1:
+		os.system('rm -fr ' + os.path.join('/tmp', filename))
+def CreateBaseFile():
+	from commands import getoutput
+	global BASEMD5SUM
+	os.system('ps -efl > %s' % os.path.join('/tmp', filename))
+	BASEMD5SUM=getoutput('%s %s|cut -f1 -d" "' % \
+		(MD5SUM, os.path.join('/tmp', filename)))
+	if DEBUGON:
+		o2tf.printlog('splice_test: Running CreateBaseFile',
+			logfile, 0, '')
+		o2tf.printlog('splice_test: BASEMD5SUM %s' % BASEMD5SUM,
+			logfile, 0, '')
+def SpliceWrite():
+	from commands import getoutput
+	print('Testing splice_write ........')
+	from os import access, F_OK
+	if access(os.path.join(directory, filename), F_OK) ==1:
+		os.system('rm -fr ' + os.path.join(directory, filename))
+	os.system('cat %s | %s %s' % (os.path.join('/tmp', filename), \
+		SPLICEWRITE_BIN, os.path.join(directory, filename)))
+	TEMPMD5SUM=getoutput('%s %s|cut -f1 -d" "' % \
+		(MD5SUM, os.path.join(directory, filename)))
+	if BASEMD5SUM == TEMPMD5SUM:
+		print('PASSED')
+	else:
+		SCRIPT_STATUS=-1
+		print('FAILED')
+		o2tf.printlog('splice_test: BASEMD5SUM %s' % BASEMD5SUM,
+			logfile, 0, '')
+		o2tf.printlog('splice_test: TEMPMD5SUM %s' % TEMPMD5SUM,
+			logfile, 0, '')
+def SpliceRead():
+	from commands import getoutput
+	from os import access, F_OK
+	print('Testing splice_read ........')
+	if access(os.path.join(directory, filename), F_OK) ==1:
+		os.system('rm -fr ' + os.path.join(directory, filename))
+	os.system('%s %s | cat > %s' % (SPLICEREAD_BIN, \
+		os.path.join('/tmp', filename), \
+		os.path.join(directory, filename)))
+	TEMPMD5SUM=getoutput('%s %s|cut -f1 -d" "' % \
+		(MD5SUM, os.path.join(directory, filename)))
+	if BASEMD5SUM == TEMPMD5SUM:
+		print('PASSED')
+	else:
+		SCRIPT_STATUS=-1
+		print('FAILED')
+		o2tf.printlog('splice_test: BASEMD5SUM %s' % BASEMD5SUM,
+			logfile, 0, '')
+		o2tf.printlog('splice_test: TEMPMD5SUM %s' % TEMPMD5SUM,
+			logfile, 0, '')
+#
+# MAIN
+#
+Usage = 'usage: %prog [-d|--directory directory] \
+[-c| --count] \
+[-D| --debug] \
+[-f|--filename filename] \
+[-l|-logfile logfilename] \
+[-h|--help]'
+if __name__=='__main__':
+	parser = optparse.OptionParser(Usage)
+#
+	parser.add_option('-d',
+		'--directory',
+		dest='directory',
+		type='string',
+		help='Directory where the file will be created.')
+#
+	parser.add_option('-c',
+		'--count',
+		dest='count',
+		type='int',
+		help='Number of times the test will be repeated.')
+#
+        parser.add_option('-D',
+                '--debug',
+                action="store_true",
+                dest='debug',
+                default=False,
+                help='Turn the debug option on. Default=False.')
+#
+	parser.add_option('-l',
+		'--logfile',
+		dest='logfile',
+		type='string',
+		help='Logfile used by the process.')
+#
+	parser.add_option('-f',
+		'--filename',
+		dest='filename',
+		type='string',
+		help='Test filename.')
+#
+	(options, args) = parser.parse_args()
+	if len(args) != 0:
+		parser.error('incorrect number of arguments')
+#
+        if options.debug:
+                DEBUGON=1
+#
+	if options.filename:
+		filename = options.filename
+#
+	if not options.directory:
+		parser.error('Please specify working directory.')
+	else:
+		if not isdir(options.directory):
+			makedirs(options.directory, 0755)
+	directory = options.directory
+	if options.logfile:
+		logfile = options.logfile+'_'+lhostname
+	if options.count:
+		count = options.count
+#
+# Make nproc at least the number of nodes
+#
+# End or arguments parsing
+#
+if DEBUGON:
+	o2tf.printlog('splice_test: directory = (%s)' % directory,
+		logfile, 0, '')
+	o2tf.printlog('splice_test: filename = (%s)' % filename,
+		logfile, 0, '')
+	o2tf.printlog('splice_test: logfile = (%s)' % logfile,
+		logfile, 0, '')
+#
+for i in range(count):
+	CreateBaseFile()
+	SpliceWrite()
+	SpliceRead()
+	if SCRIPT_STATUS:
+		break
+#
+if SCRIPT_STATUS:
+	o2tf.printlog('splice_test: Job ',
+		logfile, 3, '=')
+else:
+	o2tf.printlog('splice_test: Job completed successfully',
+		logfile, 3, '=')
+Cleanup();
+sys.exit()
diff --git a/programs/splice/splice_write.c b/programs/splice/splice_write.c
index 5c92bbb..a4d8c1a 100644
--- a/programs/splice/splice_write.c
+++ b/programs/splice/splice_write.c
@@ -15,11 +15,11 @@ int main(int argc, char *argv[])
 		printf("open file failed.\n");
 		exit(-1);
 	}
-	slen = splice(STDIN_FILENO, NULL, fd, NULL, 1000, 0);
+	slen = splice(STDIN_FILENO, NULL, fd, NULL, 10000000, 0);
 	if (slen < 0)
-		printf("splice failed.\n");
+		fprintf(stderr, "splice failed.\n");
 	else
-		printf("spliced length = %d\n",slen);
+		fprintf(stderr, "spliced length = %d\n",slen);
 	close(fd);
 	if (slen < 0)
 		exit(-1);
-- 
1.5.6.3




More information about the Ocfs2-test-devel mailing list