Skip to contentSkip to conversation

ftest cleanup II

PATCH In review Cyril Hrubis 1 participant 3 messages Sep 9, 2009 – Sep 17, 2009 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftest cleanup II

Hi,
this is ftest cleanup part II. Most of the functions that were copy & pasted again and again in every file are now in libftest library. Also ftest04, ftest05, ftest06, ftest07 and ftest08 are cleaned.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/kernel/fs/ftest/ftest01.c +32 -106
Index: ltp/testcases/kernel/fs/ftest/ftest01.c
===================================================================
@@ -1,6 +1,7 @@
 /*
  *
  *   Copyright (c) International Business Machines  Corp., 2002
+ *   Copyright (c) Cyril Hrubis [email protected] 2009
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -58,6 +59,7 @@
 #include <inttypes.h>
 #include "test.h"
 #include "usctest.h"
+#include "libftest.h"
 
 char *TCID = "ftest01";
 int TST_TOTAL = 1;
@@ -66,12 +68,8 @@ static void setup(void);
 static void runtest(void);
 static void dotest(int, int, int);
 static void domisc(int, int, char*);
-static void bfill(char*, char, int);
-static void dumpbuf(char*);
-static void dumpbits(char*, int);
-static void orbits(char*, char*, int);
 static void cleanup(void);
-static void term(int);
+static void term(int sig);
 
 #define PASSED 1
 #define FAILED 0
@@ -81,26 +79,23 @@ static void term(int);
 #define K_2		2048
 #define K_4		4096
 
-char progname[]= "ftest1()";	/* replace ++ with test name	*/
+static int csize;             /* chunk size */
+static int iterations;        /* # total iterations */
+static int max_size;          /* max file size */
+static int misc_intvl;        /* for doing misc things; 0 ==> no */
+static int nchild;            /* how many children */
+static int nwait;
+static int fd;                /* file descriptor used by child */
+static int parent_pid;
+static int pidlist[MAXCHILD];
+static char test_name[2];
 
-int	csize;				/* chunk size */
-int	iterations;			/* # total iterations */
-int	max_size;			/* max file size */
-int	misc_intvl;			/* for doing misc things; 0 ==> no */
-int	nchild;				/* how many children */
-int	nwait;
-int	fd;				/* file descriptor used by child */
-int	parent_pid;
-int	pidlist[MAXCHILD];
-char	test_name[2];
-char	*prog;
+static char fuss[40];         /* directory to do this in */
+static char homedir[200];     /* where we started */
 
-char	fuss[40] = "";		/* directory to do this in */
-char	homedir[200]= "";	/* where we started */
+static int local_flag;
 
-int 	local_flag;
-
-int main (int ac, char *av[])
+int main(int ac, char *av[])
 {
 	int lc;
         char *msg;
@@ -108,7 +103,7 @@ int main (int ac, char *av[])
         /*
          * parse standard options
          */
-        if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != NULL)
+        if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
                 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
 
 	setup();
@@ -326,7 +321,6 @@ static void dotest(int testers, int me, 
 	 *		repeat until count = nchunks.
 	 *	++val.
 	 */
-
 	srand(getpid());
 
 	if (misc_intvl)
@@ -337,10 +331,10 @@ static void dotest(int testers, int me, 
 			misc_cnt[i] = 0;
 		ftruncate(fd, 0);
 		file_max = 0;
-		bfill(bits, 0, (nchunks+7)/8);
-		bfill(hold_bits, 0, (nchunks+7)/8);
-		bfill(val_buf, val, csize);
-		bfill(zero_buf, 0, csize);
+		memset(bits, 0, (nchunks+7)/8);
+		memset(hold_bits, 0, (nchunks+7)/8);
+		memset(val_buf, val, csize);
+		memset(zero_buf, 0, csize);
 		count = 0;
 		collide = 0;
 		while (count < nchunks) {
@@ -381,11 +375,11 @@ static void dotest(int testers, int me, 
 					tst_resm(TFAIL, "Test[%d]: last_trunc = 0x%x.",
 						me, last_trunc);
 					sync();
-					dumpbuf(buf);
-					dumpbits(bits, (nchunks+7)/8);
-					orbits(hold_bits, bits, (nchunks+7)/8);
+					ft_dumpbuf(buf, csize);
+					ft_dumpbits(bits, (nchunks+7)/8);
+					ft_orbits(hold_bits, bits, (nchunks+7)/8);
 					tst_resm(TINFO, "Hold ");
-					dumpbits(hold_bits, (nchunks+7)/8);
+					ft_dumpbits(hold_bits, (nchunks+7)/8);
 					tst_exit();
 				}
 				bits[chunk/8] |= (1<<(chunk%8));
@@ -404,11 +398,11 @@ static void dotest(int testers, int me, 
 					tst_resm(TFAIL, "Test[%d]: last_trunc = 0x%x.",
 						me, last_trunc);
 					sync();
-					dumpbuf(buf);
-					dumpbits(bits, (nchunks+7)/8);
-					orbits(hold_bits, bits, (nchunks+7)/8);
+					ft_dumpbuf(buf, csize);
+					ft_dumpbits(bits, (nchunks+7)/8);
+					ft_orbits(hold_bits, bits, (nchunks+7)/8);
 					tst_resm(TINFO, "Hold ");
-					dumpbits(hold_bits, (nchunks+7)/8);
+					ft_dumpbits(hold_bits, (nchunks+7)/8);
 					tst_exit();
 				}
 			}
@@ -436,7 +430,7 @@ static void dotest(int testers, int me, 
 			 * If hit "misc" interval, do it.
 			 */
 			if (misc_intvl && --whenmisc <= 0) {
-				orbits(hold_bits, bits, (nchunks+7)/8);
+				ft_orbits(hold_bits, bits, (nchunks+7)/8);
 				domisc(me, fd, bits);
 				whenmisc = NEXTMISC;
 			}
@@ -519,78 +513,10 @@ static void domisc(int me, int fd, char 
 	++type;
 }
 
-static void bfill(char *buf, char val, int size)
-{
-	int i;
-
-	for (i = 0; i < size; i++)
-		buf[i] = val;
-}
-
-/*
- * dumpbuf
- *	Dump the buffer.
- */
-static void dumpbuf(char *buf)
-{
-	char val;
-	int idx, nout, i;
-
-	tst_resm(TINFO, "\tBuf:");
-	nout = 0;
-	idx = 0;
-	val = buf[0];
-
-	for (i = 0; i < csize; i++) {
-		if (buf[i] != val) {
-			if (i == idx+1)
-				tst_resm(TINFO, "\t%x, ", buf[idx] & 0xff);
-			else
-				tst_resm(TINFO, "\t%d*%x, ", i-idx, buf[idx] & 0xff);
-			idx = i;
-			++nout;
-		}
-		if (nout > 10) {
-			tst_resm(TINFO, "\t ... more");
-			return;
-		}
-	}
-
-	if (i == idx+1)
-		tst_resm(TINFO, "\t%x", buf[idx] & 0xff);
-	else
-		tst_resm(TINFO, "\t%d*%x", i-idx, buf[idx]);
-}
-
-/*
- * dumpbits
- *	Dump the bit-map.
- */
-static void dumpbits(char *bits, int size)
-{
-	char *buf;
-
-	tst_resm(TINFO, "\tBits array:");
-
-	for (buf = bits; size > 0; --size, ++buf) {
-		if ((buf-bits) % 16 == 0)
-			tst_resm(TINFO, "\t%04x:\t", 8*(buf-bits));
-		tst_resm(TINFO, "\t%02x ", *buf & 0xff);
-	}
-
-	tst_resm(TINFO, "\t");
-}
-
-static void orbits(char *hold, char *bits, int count)
-{
-	while (count-- > 0)
-		*hold++ |= *bits++;
-}
-
 /*
  * SIGTERM signal handler.
  */
-static void term(int sig)
+static void term(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	int i;
 
testcases/kernel/fs/ftest/ftest02.c +39 -59

208 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest03.c +30 -103

205 lines not on this page · raw message

testcases/kernel/fs/ftest/libftest.c new file +139 -0

139 lines not on this page · raw message

testcases/kernel/fs/ftest/libftest.h new file +55 -0

55 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest05.c +124 -242

624 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest06.c +92 -149

482 lines not on this page · raw message

include/compiler.h +1 -0
Index: ltp/include/compiler.h
===================================================================
@@ -8,6 +8,7 @@
 #define __LTP_COMPILER_H__
 
 #define LTP_ATTRIBUTE_NORETURN __attribute__((noreturn))
+#define LTP_ATTRIBUTE_UNUSED __attribute__((unused))
 
 #ifndef ARRAY_SIZE
 	#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
testcases/kernel/fs/ftest/ftest07.c +122 -238

611 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest08.c +112 -225

456 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Part of the diff is not shown here. View the raw message.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi!
The previous patch had missing changes in Makefile and ftest04.c. Fixed patch (that was tested on ltp cvs checkout) is attched.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/kernel/fs/ftest/ftest01.c +32 -106
Index: ltp/testcases/kernel/fs/ftest/ftest01.c
===================================================================
@@ -1,6 +1,7 @@
 /*
  *
  *   Copyright (c) International Business Machines  Corp., 2002
+ *   Copyright (c) Cyril Hrubis [email protected] 2009
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -58,6 +59,7 @@
 #include <inttypes.h>
 #include "test.h"
 #include "usctest.h"
+#include "libftest.h"
 
 char *TCID = "ftest01";
 int TST_TOTAL = 1;
@@ -66,12 +68,8 @@ static void setup(void);
 static void runtest(void);
 static void dotest(int, int, int);
 static void domisc(int, int, char*);
-static void bfill(char*, char, int);
-static void dumpbuf(char*);
-static void dumpbits(char*, int);
-static void orbits(char*, char*, int);
 static void cleanup(void);
-static void term(int);
+static void term(int sig);
 
 #define PASSED 1
 #define FAILED 0
@@ -81,26 +79,23 @@ static void term(int);
 #define K_2		2048
 #define K_4		4096
 
-char progname[]= "ftest1()";	/* replace ++ with test name	*/
+static int csize;             /* chunk size */
+static int iterations;        /* # total iterations */
+static int max_size;          /* max file size */
+static int misc_intvl;        /* for doing misc things; 0 ==> no */
+static int nchild;            /* how many children */
+static int nwait;
+static int fd;                /* file descriptor used by child */
+static int parent_pid;
+static int pidlist[MAXCHILD];
+static char test_name[2];
 
-int	csize;				/* chunk size */
-int	iterations;			/* # total iterations */
-int	max_size;			/* max file size */
-int	misc_intvl;			/* for doing misc things; 0 ==> no */
-int	nchild;				/* how many children */
-int	nwait;
-int	fd;				/* file descriptor used by child */
-int	parent_pid;
-int	pidlist[MAXCHILD];
-char	test_name[2];
-char	*prog;
+static char fuss[40];         /* directory to do this in */
+static char homedir[200];     /* where we started */
 
-char	fuss[40] = "";		/* directory to do this in */
-char	homedir[200]= "";	/* where we started */
+static int local_flag;
 
-int 	local_flag;
-
-int main (int ac, char *av[])
+int main(int ac, char *av[])
 {
 	int lc;
         char *msg;
@@ -108,7 +103,7 @@ int main (int ac, char *av[])
         /*
          * parse standard options
          */
-        if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != NULL)
+        if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
                 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
 
 	setup();
@@ -326,7 +321,6 @@ static void dotest(int testers, int me, 
 	 *		repeat until count = nchunks.
 	 *	++val.
 	 */
-
 	srand(getpid());
 
 	if (misc_intvl)
@@ -337,10 +331,10 @@ static void dotest(int testers, int me, 
 			misc_cnt[i] = 0;
 		ftruncate(fd, 0);
 		file_max = 0;
-		bfill(bits, 0, (nchunks+7)/8);
-		bfill(hold_bits, 0, (nchunks+7)/8);
-		bfill(val_buf, val, csize);
-		bfill(zero_buf, 0, csize);
+		memset(bits, 0, (nchunks+7)/8);
+		memset(hold_bits, 0, (nchunks+7)/8);
+		memset(val_buf, val, csize);
+		memset(zero_buf, 0, csize);
 		count = 0;
 		collide = 0;
 		while (count < nchunks) {
@@ -381,11 +375,11 @@ static void dotest(int testers, int me, 
 					tst_resm(TFAIL, "Test[%d]: last_trunc = 0x%x.",
 						me, last_trunc);
 					sync();
-					dumpbuf(buf);
-					dumpbits(bits, (nchunks+7)/8);
-					orbits(hold_bits, bits, (nchunks+7)/8);
+					ft_dumpbuf(buf, csize);
+					ft_dumpbits(bits, (nchunks+7)/8);
+					ft_orbits(hold_bits, bits, (nchunks+7)/8);
 					tst_resm(TINFO, "Hold ");
-					dumpbits(hold_bits, (nchunks+7)/8);
+					ft_dumpbits(hold_bits, (nchunks+7)/8);
 					tst_exit();
 				}
 				bits[chunk/8] |= (1<<(chunk%8));
@@ -404,11 +398,11 @@ static void dotest(int testers, int me, 
 					tst_resm(TFAIL, "Test[%d]: last_trunc = 0x%x.",
 						me, last_trunc);
 					sync();
-					dumpbuf(buf);
-					dumpbits(bits, (nchunks+7)/8);
-					orbits(hold_bits, bits, (nchunks+7)/8);
+					ft_dumpbuf(buf, csize);
+					ft_dumpbits(bits, (nchunks+7)/8);
+					ft_orbits(hold_bits, bits, (nchunks+7)/8);
 					tst_resm(TINFO, "Hold ");
-					dumpbits(hold_bits, (nchunks+7)/8);
+					ft_dumpbits(hold_bits, (nchunks+7)/8);
 					tst_exit();
 				}
 			}
@@ -436,7 +430,7 @@ static void dotest(int testers, int me, 
 			 * If hit "misc" interval, do it.
 			 */
 			if (misc_intvl && --whenmisc <= 0) {
-				orbits(hold_bits, bits, (nchunks+7)/8);
+				ft_orbits(hold_bits, bits, (nchunks+7)/8);
 				domisc(me, fd, bits);
 				whenmisc = NEXTMISC;
 			}
@@ -519,78 +513,10 @@ static void domisc(int me, int fd, char 
 	++type;
 }
 
-static void bfill(char *buf, char val, int size)
-{
-	int i;
-
-	for (i = 0; i < size; i++)
-		buf[i] = val;
-}
-
-/*
- * dumpbuf
- *	Dump the buffer.
- */
-static void dumpbuf(char *buf)
-{
-	char val;
-	int idx, nout, i;
-
-	tst_resm(TINFO, "\tBuf:");
-	nout = 0;
-	idx = 0;
-	val = buf[0];
-
-	for (i = 0; i < csize; i++) {
-		if (buf[i] != val) {
-			if (i == idx+1)
-				tst_resm(TINFO, "\t%x, ", buf[idx] & 0xff);
-			else
-				tst_resm(TINFO, "\t%d*%x, ", i-idx, buf[idx] & 0xff);
-			idx = i;
-			++nout;
-		}
-		if (nout > 10) {
-			tst_resm(TINFO, "\t ... more");
-			return;
-		}
-	}
-
-	if (i == idx+1)
-		tst_resm(TINFO, "\t%x", buf[idx] & 0xff);
-	else
-		tst_resm(TINFO, "\t%d*%x", i-idx, buf[idx]);
-}
-
-/*
- * dumpbits
- *	Dump the bit-map.
- */
-static void dumpbits(char *bits, int size)
-{
-	char *buf;
-
-	tst_resm(TINFO, "\tBits array:");
-
-	for (buf = bits; size > 0; --size, ++buf) {
-		if ((buf-bits) % 16 == 0)
-			tst_resm(TINFO, "\t%04x:\t", 8*(buf-bits));
-		tst_resm(TINFO, "\t%02x ", *buf & 0xff);
-	}
-
-	tst_resm(TINFO, "\t");
-}
-
-static void orbits(char *hold, char *bits, int count)
-{
-	while (count-- > 0)
-		*hold++ |= *bits++;
-}
-
 /*
  * SIGTERM signal handler.
  */
-static void term(int sig)
+static void term(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	int i;
 
testcases/kernel/fs/ftest/ftest02.c +39 -59

208 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest03.c +30 -103

205 lines not on this page · raw message

testcases/kernel/fs/ftest/libftest.c new file +139 -0

139 lines not on this page · raw message

testcases/kernel/fs/ftest/libftest.h new file +55 -0

55 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest05.c +124 -242

624 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest06.c +92 -149

482 lines not on this page · raw message

include/compiler.h +1 -0
Index: ltp/include/compiler.h
===================================================================
@@ -8,6 +8,7 @@
 #define __LTP_COMPILER_H__
 
 #define LTP_ATTRIBUTE_NORETURN __attribute__((noreturn))
+#define LTP_ATTRIBUTE_UNUSED __attribute__((unused))
 
 #ifndef ARRAY_SIZE
 	#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
testcases/kernel/fs/ftest/ftest07.c +122 -238

611 lines not on this page · raw message

testcases/kernel/fs/ftest/ftest08.c +112 -225

456 lines not on this page · raw message

testcases/kernel/fs/ftest/Makefile +6 -7
Index: ltp/testcases/kernel/fs/ftest/Makefile
===================================================================

Lines of this file are not shown. View the raw message.

testcases/kernel/fs/ftest/ftest04.c +90 -205

295 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Part of the diff is not shown here. View the raw message.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hi!

Quoted 14 lines
Quoted 4 lines

The previous patch had missing changes in Makefile and ftest04.c. Fixed patch (that was tested on ltp cvs checkout) is attched.

This Fixes the earlier issues, but introduced a new one.

# make
will work fine, but
# make -j4
will not,

because,

Quoted 8 lines

ltp/testcases/kernel/fs/ftest/libftest.o

may not have been created when:

# gcc ... libftest.o ftest01.c
or,
# gcc ... libftest.o ftest02.c

Attached patch should fix this.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/kernel/fs/ftest/Makefile +4 -2
Index: ltp/testcases/kernel/fs/ftest/Makefile
===================================================================
@@ -22,12 +22,14 @@
 # description	: make(1) description file for the send(2) tests.	  #
 ###########################################################################
 CFLAGS+=	-I../../../../include -W -Wall -g
-LOADLIBES+=	-L../../../../lib libftest.o -lltp
+LOADLIBES+=	-L../../../../lib -lltp
 
 SRCS=$(wildcard ftest*.c)
 TARGETS=$(patsubst %.c,%,$(SRCS))
 
-all: libftest.o $(TARGETS)
+all: $(TARGETS)
+
+$(TARGETS): libftest.o
 
 install:
 	@set -e; for i in $(TARGETS) ; do ln -f $$i ../../../bin/$$i ; done ;

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list