Skip to content

Commit 98d8d3a

Browse files
wangli5665metan-ucw
authored andcommitted
ltp/pounder: Log to stdout instead of /dev/tty
* FILE *tty_fp --> FILE *out * Using out = stdout; instead of fdopen() Signed-off-by: Li Wang <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent 433308e commit 98d8d3a

File tree

6 files changed

+36
-57
lines changed

6 files changed

+36
-57
lines changed

tools/pounder21/Install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ done
6565
# Set up optdir
6666
mkdir -p "$POUNDER_OPTDIR"
6767
if [ ! -d "$POUNDER_OPTDIR" ]; then
68-
echo "Could not create $POUNDER_OPTDIR; aborting." > /dev/tty
68+
echo "Could not create $POUNDER_OPTDIR; aborting."
6969
exit 1
7070
fi
7171

tools/pounder21/fancy_timed_loop.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
static int res = 0;
3333
static char *progname;
3434
static pid_t test_pgrp;
35-
static FILE *tty_fp;
35+
static FILE *out;
3636

3737
static int the_signal = SIGTERM;
3838

3939
static void int_func(int signum)
4040
{
41-
pounder_fprintf(tty_fp,
41+
pounder_fprintf(out,
4242
"%s: Killed by interrupt. Last exit code = %d.\n",
4343
progname, res);
4444
kill(-test_pgrp, the_signal);
@@ -47,7 +47,7 @@ static void int_func(int signum)
4747

4848
static void alarm_func(int signum)
4949
{
50-
pounder_fprintf(tty_fp, "%s: Killed by timer. Last exit code = %d.\n",
50+
pounder_fprintf(out, "%s: Killed by timer. Last exit code = %d.\n",
5151
progname, res);
5252
kill(-test_pgrp, the_signal);
5353
exit(res);
@@ -90,14 +90,7 @@ int main(int argc, char *argv[])
9090
}
9191
}
9292

93-
tty_fp = fdopen(3, "w+");
94-
if (tty_fp == NULL) {
95-
tty_fp = fopen("/dev/tty", "w+");
96-
if (tty_fp == NULL) {
97-
perror("stdout");
98-
exit(2);
99-
}
100-
}
93+
out = stdout;
10194

10295
if (use_max_failures) {
10396
progname = rindex(argv[7], '/');
@@ -142,11 +135,11 @@ int main(int argc, char *argv[])
142135
gid = atoi(argv[3]);
143136
}
144137

145-
pounder_fprintf(tty_fp, "%s: uid = %d, gid = %d, sig = %d\n",
138+
pounder_fprintf(out, "%s: uid = %d, gid = %d, sig = %d\n",
146139
progname, uid, gid, the_signal);
147140

148141
while (1) {
149-
pounder_fprintf(tty_fp, "%s: %s loop #%d.\n", progname,
142+
pounder_fprintf(out, "%s: %s loop #%d.\n", progname,
150143
start_msg, revs++);
151144
pid = fork();
152145
if (pid == 0) {
@@ -196,22 +189,22 @@ int main(int argc, char *argv[])
196189
}
197190
// interrogate it
198191
if (WIFSIGNALED(stat)) {
199-
pounder_fprintf(tty_fp, "%s: %s on signal %d.\n",
192+
pounder_fprintf(out, "%s: %s on signal %d.\n",
200193
progname, fail_msg, WTERMSIG(stat));
201194
res = 255;
202195
} else {
203196
res = WEXITSTATUS(stat);
204197
if (res == 0) {
205-
pounder_fprintf(tty_fp, "%s: %s.\n", progname,
198+
pounder_fprintf(out, "%s: %s.\n", progname,
206199
pass_msg);
207200
} else if (res < 0 || res == 255) {
208-
pounder_fprintf(tty_fp,
201+
pounder_fprintf(out,
209202
"%s: %s with code %d.\n",
210203
progname, abort_msg, res);
211204
exit(-1);
212205
// FIXME: add test to blacklist
213206
} else {
214-
pounder_fprintf(tty_fp,
207+
pounder_fprintf(out,
215208
"%s: %s with code %d.\n",
216209
progname, fail_msg, res);
217210
if (max_failures > 0) {

tools/pounder21/infinite_loop.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
static int res = 0;
3333
static char *progname;
3434
static pid_t test_pgrp;
35-
static FILE *tty_fp;
35+
static FILE *out;
3636

3737
static void int_func(int signum)
3838
{
39-
pounder_fprintf(tty_fp,
39+
pounder_fprintf(out,
4040
"%s: Killed by interrupt. Last exit code = %d.\n",
4141
progname, res);
4242
kill(-test_pgrp, SIGTERM);
@@ -75,14 +75,7 @@ int main(int argc, char *argv[])
7575
}
7676
}
7777

78-
tty_fp = fdopen(3, "w+");
79-
if (tty_fp == NULL) {
80-
tty_fp = fopen("/dev/tty", "w+");
81-
if (tty_fp == NULL) {
82-
perror("stdout");
83-
exit(2);
84-
}
85-
}
78+
out = stdout;
8679

8780
if (use_max_failures) {
8881
progname = rindex(argv[3], '/');
@@ -110,7 +103,7 @@ int main(int argc, char *argv[])
110103
* loop test and descendants easily */
111104

112105
while (1) {
113-
pounder_fprintf(tty_fp, "%s: %s loop #%d.\n", progname,
106+
pounder_fprintf(out, "%s: %s loop #%d.\n", progname,
114107
start_msg, revs++);
115108
pid = fork();
116109
if (pid == 0) {
@@ -149,22 +142,22 @@ int main(int argc, char *argv[])
149142
}
150143
// interrogate it
151144
if (WIFSIGNALED(stat)) {
152-
pounder_fprintf(tty_fp, "%s: %s on signal %d.\n",
145+
pounder_fprintf(out, "%s: %s on signal %d.\n",
153146
progname, fail_msg, WTERMSIG(stat));
154147
res = 255;
155148
} else {
156149
res = WEXITSTATUS(stat);
157150
if (res == 0) {
158-
pounder_fprintf(tty_fp, "%s: %s.\n", progname,
151+
pounder_fprintf(out, "%s: %s.\n", progname,
159152
pass_msg);
160153
} else if (res < 0 || res == 255) {
161-
pounder_fprintf(tty_fp,
154+
pounder_fprintf(out,
162155
"%s: %s with code %d.\n",
163156
progname, abort_msg, res);
164157
exit(-1);
165158
// FIXME: add test to blacklist
166159
} else {
167-
pounder_fprintf(tty_fp,
160+
pounder_fprintf(out,
168161
"%s: %s with code %d.\n",
169162
progname, fail_msg, res);
170163
if (max_failures > 0) {

tools/pounder21/pounder

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ shift `expr $OPTIND - 1`
201201

202202
# Are we already running?
203203
if [ -f "$POUNDER_PIDFILE" ]; then
204-
echo "File $POUNDER_PIDFILE exists; pounder may already be running." > /dev/tty
205-
echo "Either run 'pounder -k' to stop all tests, or remove it." > /dev/tty
204+
echo "File $POUNDER_PIDFILE exists; pounder may already be running."
205+
echo "Either run 'pounder -k' to stop all tests, or remove it."
206206
exit 1
207207
fi
208208

@@ -225,21 +225,21 @@ fi
225225
# Set up log directory
226226
mkdir -p "$POUNDER_LOGDIR" 2> /dev/null
227227
if [ ! -d "$POUNDER_LOGDIR" ]; then
228-
echo "Could not create $POUNDER_LOGDIR; aborting." > /dev/tty
228+
echo "Could not create $POUNDER_LOGDIR; aborting."
229229
exit 1
230230
fi
231231

232232
# Set up dir for optional components
233233
mkdir -p "$POUNDER_OPTDIR"
234234
if [ ! -d "$POUNDER_OPTDIR" ]; then
235-
echo "Could not create $POUNDER_OPTDIR; aborting." > /dev/tty
235+
echo "Could not create $POUNDER_OPTDIR; aborting."
236236
exit 1
237237
fi
238238

239239
# Set up tmpdir
240240
mkdir -p "$POUNDER_TMPDIR"
241241
if [ ! -d "$POUNDER_TMPDIR" ]; then
242-
echo "Could not create $POUNDER_TMPDIR; aborting." > /dev/tty
242+
echo "Could not create $POUNDER_TMPDIR; aborting."
243243
exit 1
244244
fi
245245

@@ -259,8 +259,8 @@ fi
259259
export > "$POUNDER_LOGDIR/environment"
260260

261261
echo "Starting $POUNDER_VERSION"
262-
echo "STARTING TESTS." > /dev/tty
263-
echo "To kill all tests, run 'pounder -k' or press ^C."> /dev/tty
262+
echo "STARTING TESTS."
263+
echo "To kill all tests, run 'pounder -k' or press ^C."
264264

265265
# Handle the duration thing...
266266
function kill_after {

tools/pounder21/test_scripts/memtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# Can we find the script?
2424
if [ ! -f "$POUNDER_OPTDIR/memtest.sh" ]; then
25-
echo "Can't find memtest.sh; did you run Install?" > /dev/tty
25+
echo "Can't find memtest.sh; did you run Install?"
2626
exit -1
2727
fi
2828

tools/pounder21/timed_loop.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
static int res = 0;
3333
static char *progname;
3434
static pid_t test_pgrp;
35-
static FILE *tty_fp;
35+
static FILE *out;
3636

3737
static void int_func(int signum)
3838
{
39-
pounder_fprintf(tty_fp,
39+
pounder_fprintf(out,
4040
"%s: Killed by interrupt. Last exit code = %d.\n",
4141
progname, res);
4242
kill(-test_pgrp, SIGTERM);
@@ -45,7 +45,7 @@ static void int_func(int signum)
4545

4646
static void alarm_func(int signum)
4747
{
48-
pounder_fprintf(tty_fp, "%s: Killed by timer. Last exit code = %d.\n",
48+
pounder_fprintf(out, "%s: Killed by timer. Last exit code = %d.\n",
4949
progname, res);
5050
kill(-test_pgrp, SIGTERM);
5151
exit(res);
@@ -92,14 +92,7 @@ int main(int argc, char *argv[])
9292
}
9393
}
9494

95-
tty_fp = fdopen(3, "w+");
96-
if (tty_fp == NULL) {
97-
tty_fp = fopen("/dev/tty", "w+");
98-
if (tty_fp == NULL) {
99-
perror("stdout");
100-
exit(2);
101-
}
102-
}
95+
out = stdout;
10396

10497
if (use_max_failures) {
10598
progname = rindex(argv[4], '/');
@@ -136,7 +129,7 @@ int main(int argc, char *argv[])
136129
alarm(secs);
137130

138131
while (1) {
139-
pounder_fprintf(tty_fp, "%s: %s loop #%d.\n", progname,
132+
pounder_fprintf(out, "%s: %s loop #%d.\n", progname,
140133
start_msg, revs++);
141134
pid = fork();
142135
if (pid == 0) {
@@ -175,22 +168,22 @@ int main(int argc, char *argv[])
175168
}
176169
// interrogate it
177170
if (WIFSIGNALED(stat)) {
178-
pounder_fprintf(tty_fp, "%s: %s on signal %d.\n",
171+
pounder_fprintf(out, "%s: %s on signal %d.\n",
179172
progname, fail_msg, WTERMSIG(stat));
180173
res = 255;
181174
} else {
182175
res = WEXITSTATUS(stat);
183176
if (res == 0) {
184-
pounder_fprintf(tty_fp, "%s: %s.\n", progname,
177+
pounder_fprintf(out, "%s: %s.\n", progname,
185178
pass_msg);
186179
} else if (res < 0 || res == 255) {
187-
pounder_fprintf(tty_fp,
180+
pounder_fprintf(out,
188181
"CHECK %s: %s with code %d.\n",
189182
progname, abort_msg, res);
190183
exit(-1);
191184
// FIXME: add test to blacklist
192185
} else {
193-
pounder_fprintf(tty_fp,
186+
pounder_fprintf(out,
194187
"%s: %s with code %d.\n",
195188
progname, fail_msg, res);
196189
if (max_failures > 0) {

0 commit comments

Comments
 (0)