bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] [PATCH] Add `tftpd' and `tftp' test.


From: Ludovic Courtès
Subject: [bug-inetutils] [PATCH] Add `tftpd' and `tftp' test.
Date: Mon, 18 Oct 2010 22:59:25 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hello!

The attached patch (based on the one that started this thread) adds a
unit test for inetd/tftpd/tftp.

Interestingly, ‘inetd’ now fails if the path to ‘inetd.conf’ and to
‘tftpd’ isn’t absolute, because it chdirs to / before opening the files.
I suspect this is due to recent inetd changes, but I didn’t find
anything obvious.

Thanks,
Ludo’.

From dcdcf4af19b2d657cf86be5f942dfa9bc27dc472 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
Date: Mon, 18 Oct 2010 22:27:07 +0200
Subject: [PATCH] Add `tftpd' and `tftp' test.

* tests/Makefile.am (dist_check_SCRIPTS)[ENABLE_inetd && ENABLE_tftpd &&
  ENABLE_tftp]: Add `tftp.sh'.

* tests/tftp.sh: New file.
---
 ChangeLog         |    8 +++++
 tests/Makefile.am |    9 ++++++
 tests/tftp.sh     |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 0 deletions(-)
 create mode 100755 tests/tftp.sh

diff --git a/ChangeLog b/ChangeLog
index 2ab8b07..d3b7bb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-10-18  Ludovic Courtès  <address@hidden>
+
+       Add `tftpd' and `tftp' test.
+
+       * tests/Makefile.am (dist_check_SCRIPTS)[ENABLE_inetd &&
+       ENABLE_tftpd && ENABLE_tftp]: Add `tftp.sh'.
+       * tests/tftp.sh: New file.
+
 2010-10-18  Alfred M. Szmidt  <address@hidden>
 
        Always use <termios.h> interface.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f64a066..4f4610a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,6 +28,15 @@ endif
 if ENABLE_traceroute
 dist_check_SCRIPTS += traceroute-localhost.sh
 endif
+
+if ENABLE_inetd
+if ENABLE_tftpd
+if ENABLE_tftp
+dist_check_SCRIPTS += tftp.sh
+endif
+endif
+endif
+
 TESTS = $(check_PROGRAMS) $(dist_check_SCRIPTS)
 
 TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT)
diff --git a/tests/tftp.sh b/tests/tftp.sh
new file mode 100755
index 0000000..f7cc16a
--- /dev/null
+++ b/tests/tftp.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This file is part of GNU Inetutils.
+#
+# GNU Inetutils is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or (at
+# your option) any later version.
+#
+# GNU Inetutils 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see `http://www.gnu.org/licenses/'.
+
+# Run `inetd' with `tftpd' and try to fetch a file from there using `tftp'.
+
+TFTP="${TFTP:-../src/tftp$EXEEXT}"
+TFTPD="${TFTPD:-$PWD/../src/tftpd$EXEEXT}"
+INETD="${INETD:-../src/inetd$EXEEXT}"
+IFCONFIG="${IFCONFIG:-../ifconfig/ifconfig$EXEEXT}"
+
+PORT=7777
+INETD_CONF="$PWD/inetd.conf.tmp"
+
+ADDRESSES="`$IFCONFIG | grep 'inet addr:' | \
+  sed -e's/inet addr:\([^ ]\+\)[[:blank:]].*$/\1/g'`"
+
+if [ "$VERBOSE" ]; then
+    set -x
+    "$TFTP" --version
+    "$TFTPD" --version
+    "$INETD" --version
+fi
+
+# Create `inetd.conf'.  Note: We want $TFTPD to be an absolute path
+# because `inetd' chdirs to `/' in daemon mode; ditto for $INETD_CONF.
+cat > "$INETD_CONF" <<EOF
+$PORT dgram udp wait $USER $TFTPD   tftpd -l `pwd`/tftp-test
+EOF
+
+# Launch `inetd', assuming it's reachable at all $ADDRESSES.
+$INETD "${VERBOSE:+-d}" "$INETD_CONF" &
+inetd_pid="$!"
+
+if [ -f /dev/urandom ]; then
+    input="/dev/urandom"
+else
+    input="/dev/zero"
+fi
+
+rm -fr tftp-test tftp-test-file
+mkdir tftp-test && \
+    dd if="$input" of="tftp-test/tftp-test-file" bs=1024 count=170
+
+for addr in $ADDRESSES
+do
+    echo "trying with address \`$addr'..." >&2
+
+    rm -f tftp-test-file
+    echo "get tftp-test-file" | "$TFTP" $addr $PORT
+
+    cmp tftp-test/tftp-test-file tftp-test-file
+    result=$?
+
+    if [ "$result" -ne 0 ]; then
+       # Failure.
+       break
+    fi
+done
+
+kill "$inetd_pid"
+
+rm -rf tftp-test tftp-test-file "$INETD_CONF"
+
+exit $result
-- 
1.7.0

Attachment: pgpGkJaChnUWG.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]