From nobody Fri Mar 10 13:29:24 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PY6N45d0kz3xXR9; Fri, 10 Mar 2023 13:29:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PY6N43YWnz3hCn; Fri, 10 Mar 2023 13:29:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wgX1TCo8+6cUXkVIyD82HPeb4yLfNFFNhzI/OOc+NoM=; b=jq+kG+yD0eqG9os1IvC1uqxH5DdqPQz1oFj3M1r+J8PzkU7yjfGwBAH2MU4fClwDwUOXKw WTz+/OAduHEunfcnlRtAM1UaCR4qu8Q4kDCF/EZ8BeeUT025sXfVSLdeGFB3hrXqmuu61R znm561jPCpwMixzQ1u5dMtMpAxgXooFGgRiNIjUWVz5Y3VnYmXqdC63WTOqjrmzUh43g7S AsU4INXngxcQJlyRiBINd2/AiNgKbbdgbKYT/IlrDGNdixfkYMOYzgx+MLyhoOETihFOaQ u6Go4vI3XuRpWntMWYCy/uoCoLIsdXiqU4d0KgBl70dl7L2C5LyHyaz/hQ6HIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wgX1TCo8+6cUXkVIyD82HPeb4yLfNFFNhzI/OOc+NoM=; b=E9EwEhSzBsHAUhO2K6RHH9E4dnR0vPGKhOgduJMfBHb24LmVsQbcMaIkJIBpAvmT/3Td4V n2hGXYRtEU42w3E/LKAOuQRaKyb+MKfhqQ2ZQ1fiVledopGKjMq8cN2gxOT3MeUSJ0cMJV DTjbQLh5mvFQakRGHG6MgwBDKwNQ1RJlGUfZ3hl/I/twYg3NAdufnRyWXASVKJTF+eokMe n1jRB0rocfh9S/1udI7XuahAmsbWEmMgDGcM7hcEplBlVlezeLyaw3tKaJ3grC9dS2egda 4tyDgujToN4+LebBG+6H6K+EJPI6ATyMp7tJD82qupiXvAeMMejSOzMRqkXU5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678454964; a=rsa-sha256; cv=none; b=q4g/O4+qZxGlO8jlf1UbI0G1xAZT5Lo8IQAJtuB+V9AJb8kADk9TPY37tVKnPX8Be1xg/u ZtE3NM1tx9S7ZwGCN0atoR2S4FBoQzn4olMYvVL3+Bw4cwpvFmO0SNgXcKsAU0zWUFjHxD lpqcoyaD9VgyRCpxNyQLBzoWwC6PmQ3UcA4f+bEvBmP1SzIfTgpfhGmkQtx7zfnx2on7X/ X5e02T24eaf/GmEKmIxgyB8o75yZ3vuvB4l95nAUXAQRNoalUATytUsHyCiNKYMVvX6y/E ScpnTvEB8Qourmari9z+f6v9ber9eW9/fN/BxyEpT0ohT80cQ7Ku+WnnP9vdSg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PY6N42SfTzqWQ; Fri, 10 Mar 2023 13:29:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32ADTOI5090208; Fri, 10 Mar 2023 13:29:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32ADTOLJ090207; Fri, 10 Mar 2023 13:29:24 GMT (envelope-from git) Date: Fri, 10 Mar 2023 13:29:24 GMT Message-Id: <202303101329.32ADTOLJ090207@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 64c2a712d661 - main - tftp: Add tests. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 64c2a712d661db9be31f02fe97c3b59710290ae3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=64c2a712d661db9be31f02fe97c3b59710290ae3 commit 64c2a712d661db9be31f02fe97c3b59710290ae3 Author: Dag-Erling Smørgrav AuthorDate: 2023-03-10 13:24:56 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-03-10 13:25:16 +0000 tftp: Add tests. Sponsored by: Klara, Inc. Reviewed by: asomers Differential Revision: https://reviews.freebsd.org/D38969 --- etc/mtree/BSD.tests.dist | 2 + usr.bin/tftp/Makefile | 5 + usr.bin/tftp/tests/Makefile | 10 + usr.bin/tftp/tests/tftp_test.sh | 406 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 423 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index f3420369ad80..c9a13cec193e 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1110,6 +1110,8 @@ .. tar .. + tftp + .. tr .. truncate diff --git a/usr.bin/tftp/Makefile b/usr.bin/tftp/Makefile index b6ad018e03ac..91df4847c629 100644 --- a/usr.bin/tftp/Makefile +++ b/usr.bin/tftp/Makefile @@ -1,6 +1,8 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD$ +.include + .PATH: ${SRCTOP}/libexec/tftpd PROG= tftp @@ -10,4 +12,7 @@ CFLAGS+=-I${SRCTOP}/libexec/tftpd LIBADD= edit +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests + .include diff --git a/usr.bin/tftp/tests/Makefile b/usr.bin/tftp/tests/Makefile new file mode 100644 index 000000000000..ca5d89f92af3 --- /dev/null +++ b/usr.bin/tftp/tests/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +PACKAGE= tests + +ATF_TESTS_SH= tftp_test +BINDIR= ${TESTSDIR} + +TESTS_METADATA.tftp_test+= is_exclusive="true" + +.include diff --git a/usr.bin/tftp/tests/tftp_test.sh b/usr.bin/tftp/tests/tftp_test.sh new file mode 100644 index 000000000000..96e375f51aeb --- /dev/null +++ b/usr.bin/tftp/tests/tftp_test.sh @@ -0,0 +1,406 @@ +# +# Copyright (c) 2023 Klara, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause +# + +tftp_dir="${TMPDIR:-/tmp}/tftp.dir" +inetd_conf="${TMPDIR:-/tmp}/inetd.conf" +inetd_pid="${TMPDIR:-/tmp}/inetd.pid" + +start_tftpd() { + if ! [ -z "$(sockstat -PUDP -p69 -q)" ] ; then + atf_skip "the tftp port is in use" + fi + echo "starting inetd for $(atf_get ident)" >&2 + rm -rf "${tftp_dir}" + mkdir "${tftp_dir}" + cat >"${inetd_conf}" <&2 + # Send SIGTERM to inetd, then SIGKILL until it's gone + local sig=TERM + while pkill -$sig -LF "${inetd_pid}" inetd ; do + echo "waiting for inetd to stop" >&2 + sleep 1 + sig=KILL + done + rm -rf "${tftp_dir}" "${inetd_conf}" "${inetd_pid}" +} + +atf_test_case tftp_get_big cleanup +tftp_get_big_head() { + atf_set "descr" "get command with big file" + atf_set "require.user" "root" +} +tftp_get_big_body() { + start_tftpd + local remote_file="${tftp_dir}/remote.bin" + dd if=/dev/urandom of="${remote_file}" bs=1m count=16 status=none + local local_file="local.bin" + echo "get ${remote_file##*/} ${local_file}" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp localhost "${remote_file}" + local local_file="${remote_file##*/}" + echo "get localhost:${remote_file##*/}" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp "${remote_file}" + local local_file="${remote_file##*/}" + echo "get 127.0.0.1:${remote_file##*/}" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp "${remote_file}" + local local_file="${remote_file##*/}" + echo "get [::1]:${remote_file##*/}" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp "${remote_file}" + local local_file="${remote_file##*/}" + echo "get ${remote_file##*/}" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp localhost "${remote_file}" + local local_file="world.txt" + echo "get ${remote_file##*/} ${local_file}" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp localhost client-script + for f in $(jot -c $n 97) ; do + echo "test file $$/$f/$n" >"${tftp_dir}/${f}.txt" + echo -n " ${f}.txt" >>client-script + rm -f "${f}.txt" + done + echo >>client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp localhost "${tftp_dir}/${f}.txt" + rm -f "${f}.txt" + done + echo "get localhost:a.txt b.txt c.txt" >client-script + atf_check -o match:"Received [0-9]+ bytes" \ + tftp localhost client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp localhost "${local_file}" + local remote_file="${tftp_dir}/remote.txt" + truncate -s 0 "${remote_file}" + chown nobody:nogroup "${remote_file}" + chmod 0666 "${remote_file}" + echo "put ${local_file} localhost:${remote_file##*/}" >client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp "${local_file}" + local remote_file="${tftp_dir}/remote.txt" + truncate -s 0 "${remote_file}" + chown nobody:nogroup "${remote_file}" + chmod 0666 "${remote_file}" + echo "put ${local_file} 127.0.0.1:${remote_file##*/}" >client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp "${local_file}" + local remote_file="${tftp_dir}/remote.txt" + truncate -s 0 "${remote_file}" + chown nobody:nogroup "${remote_file}" + chmod 0666 "${remote_file}" + echo "put ${local_file} [::1]:${remote_file##*/}" >client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp "${local_file}" + local remote_file="${tftp_dir}/${local_file}" + truncate -s 0 "${remote_file}" + chown nobody:nogroup "${remote_file}" + chmod 0666 "${remote_file}" + echo "put ${local_file}" >client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp localhost "${local_file}" + local remote_file="${tftp_dir}/remote.txt" + truncate -s 0 "${remote_file}" + chown nobody:nogroup "${remote_file}" + chmod 0666 "${remote_file}" + echo "put ${local_file} ${remote_file##*/}" >client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp localhost client-script + for f in $(jot -c $n 97) ; do + echo "test file $$/$f/$n" >"${f}.txt" + truncate -s 0 "${tftp_dir}/subdir/${f}.txt" + chown nobody:nogroup "${tftp_dir}/subdir/${f}.txt" + chmod 0666 "${tftp_dir}/subdir/${f}.txt" + echo -n " ${f}.txt" >>client-script + done + echo " subdir" >>client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp localhost client-script + for f in a b c ; do + echo "test file $$/$f" >"${f}.txt" + truncate -s 0 "${tftp_dir}/subdir/${f}.txt" + chown nobody:nogroup "${tftp_dir}/subdir/${f}.txt" + chmod 0666 "${tftp_dir}/subdir/${f}.txt" + echo -n " ${f}.txt" >>client-script + done + echo " localhost:subdir" >>client-script + atf_check -o match:"Sent [0-9]+ bytes" \ + tftp