• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) Cyril Hrubis chrubis@suse.cz 2009
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  *   the GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program;  if not, write to the Free Software
16  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <sys/uio.h>
20 #include <inttypes.h>
21 #include <limits.h>
22 #include <assert.h>
23 #include "test.h"
24 #include "libftest.h"
25 
26 /*
27  * Dump content of iov structure.
28  */
ft_dumpiov(struct iovec * iov)29 void ft_dumpiov(struct iovec *iov)
30 {
31 	char *buf, val;
32 	int idx, nout, i;
33 
34 	tst_resm(TINFO, "\tBuf:");
35 
36 	nout = 0;
37 	idx = 0;
38 	buf = (char *)iov->iov_base;
39 	val = *((char *)buf);
40 
41 	for (i = 0; (unsigned int)i < iov->iov_len; i++) {
42 
43 		if (buf[i] != val) {
44 			if (i == idx + 1)
45 				tst_resm(TINFO, "\t%" PRIx32 "x,",
46 					 buf[idx] & 0xff);
47 			else
48 				tst_resm(TINFO, "\t%d*%" PRIx32 "x, ", i - idx,
49 					 buf[idx] & 0xff);
50 			idx = i;
51 			++nout;
52 		}
53 
54 		if (nout > 10) {
55 			tst_resm(TINFO, "\t ... more");
56 			return;
57 		}
58 	}
59 
60 	if (i == idx + 1)
61 		tst_resm(TINFO, "\t%" PRIx32 "x", buf[idx] & 0xff);
62 	else
63 		tst_resm(TINFO, "\t%d*%" PRIx32 "x", i - idx, buf[idx]);
64 }
65 
66 /*
67  * Dump bits string.
68  */
ft_dumpbits(void * bits,size_t size)69 void ft_dumpbits(void *bits, size_t size)
70 {
71 	void *buf;
72 
73 	tst_resm(TINFO, "\tBits array:");
74 
75 	for (buf = bits; size > 0; --size, ++buf) {
76 		tst_resm(TINFO, "\t%td:\t", 8 * (buf - bits));
77 		if ((buf - bits) % 16 == 0) {
78 			assert(0 < (buf - bits));
79 			tst_resm(TINFO, "\t%td:\t", 8 * (buf - bits));
80 		}
81 		tst_resm(TINFO, "\t%02" PRIx32 "x ", *((char *)buf) & 0xff);
82 	}
83 
84 	tst_resm(TINFO, "\t");
85 }
86 
87 /*
88  * Do logical or of hold and bits (of size)
89  * fields and store result into hold field.
90  */
ft_orbits(char * hold,char * bits,int size)91 void ft_orbits(char *hold, char *bits, int size)
92 {
93 	while (size-- > 0)
94 		*hold++ |= *bits++;
95 }
96 
97 /*
98  * Dumps buffer in hexadecimal format.
99  */
ft_dumpbuf(char * buf,int csize)100 void ft_dumpbuf(char *buf, int csize)
101 {
102 	char val;
103 	int idx, nout, i;
104 
105 	tst_resm(TINFO, "\tBuf:");
106 	nout = 0;
107 	idx = 0;
108 	val = buf[0];
109 
110 	for (i = 0; i < csize; i++) {
111 		if (buf[i] != val) {
112 			if (i == idx + 1)
113 				tst_resm(TINFO, "\t%x, ", buf[idx] & 0xff);
114 			else
115 				tst_resm(TINFO, "\t%d*%x, ", i - idx,
116 					 buf[idx] & 0xff);
117 			idx = i;
118 			++nout;
119 		}
120 		if (nout > 10) {
121 			tst_resm(TINFO, "\t ... more");
122 			return;
123 		}
124 	}
125 
126 	if (i == idx + 1)
127 		tst_resm(TINFO, "\t%x", buf[idx] & 0xff);
128 	else
129 		tst_resm(TINFO, "\t%d*%x", i - idx, buf[idx]);
130 }
131 
132 /*
133  * Creates filename from path and numbers.
134  *
135  * TODO: name is big enough?
136  */
ft_mkname(char * name,char * dirname,int me,int idx)137 void ft_mkname(char *name, char *dirname, int me, int idx)
138 {
139 	char a, b;
140 
141 	a = 'A' + (me % 26);
142 	b = 'a' + (idx % 26);
143 
144 	if (dirname[0] != '\0')
145 		snprintf(name, PATH_MAX, "%s/%c%c", dirname, a, b);
146 	else
147 		snprintf(name, PATH_MAX, "%c%c", a, b);
148 }
149