Date: Fri, 3 Aug 2018 14:13:15 +0000 (UTC) From: Alan Somers <asomers@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r337246 - in stable/10: etc/mtree libexec/tftpd libexec/tftpd/tests Message-ID: <201808031413.w73EDFkq069991@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: asomers Date: Fri Aug 3 14:13:15 2018 New Revision: 337246 URL: https://svnweb.freebsd.org/changeset/base/337246 Log: MFC r330696, r330709, r330742, r331358 r330696: Add some functional tests for tftpd(8) tftpd(8) is difficult to test in isolation due to its relationship with inetd. Create a test program that mimics the behavior of tftp(1) and inetd(8) and verifies tftpd's response in several different scenarios. These test cases cover all of the basic TFTP protocol, but not the optional parts. PR: 157700 PR: 225996 PR: 226004 PR: 226005 Differential Revision: https://reviews.freebsd.org/D14310 r330709: Commit missing file from r330696 X-MFC-With: 330696 r330742: tftpd: fix the build of tests on i386 after 330696 It's those darn printf format specifiers again Reported by: cy, kibab X-MFC-With: 330696 r331358: tftpd: misc Coverity cleanup in the tests A bunch of unchecked return values from open(2) and read(2) Reported by: Coverity CID: 1386900, 1386911, 1386926, 1386928, 1386932, 1386942 CID: 1386961, 1386979 X-MFC-With: 330696 Added: stable/10/libexec/tftpd/tests/ - copied from r330696, head/libexec/tftpd/tests/ Modified: stable/10/etc/mtree/BSD.tests.dist stable/10/libexec/tftpd/Makefile stable/10/libexec/tftpd/tests/functional.c Directory Properties: stable/10/ (props changed) Modified: stable/10/etc/mtree/BSD.tests.dist ============================================================================== --- stable/10/etc/mtree/BSD.tests.dist Fri Aug 3 14:12:37 2018 (r337245) +++ stable/10/etc/mtree/BSD.tests.dist Fri Aug 3 14:13:15 2018 (r337246) @@ -350,6 +350,8 @@ atf-sh .. .. + tftpd + .. .. sbin dhclient Modified: stable/10/libexec/tftpd/Makefile ============================================================================== --- stable/10/libexec/tftpd/Makefile Fri Aug 3 14:12:37 2018 (r337245) +++ stable/10/libexec/tftpd/Makefile Fri Aug 3 14:13:15 2018 (r337246) @@ -15,4 +15,7 @@ DPADD+= ${LIBWRAP} LDADD+= -lwrap .endif +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include <bsd.prog.mk> Modified: stable/10/libexec/tftpd/tests/functional.c ============================================================================== --- head/libexec/tftpd/tests/functional.c Fri Mar 9 15:30:20 2018 (r330696) +++ stable/10/libexec/tftpd/tests/functional.c Fri Aug 3 14:13:15 2018 (r337246) @@ -224,19 +224,17 @@ do { \ static void cleanup(void) { - int fd = -1; - char buffer[80] = {0}; + FILE *f; pid_t pid; - fd = open(pidfile, O_RDONLY); - if (fd < 0) + f = fopen(pidfile, "r"); + if (f == NULL) return; - if (read(fd, buffer, sizeof(buffer)) > 0) { - sscanf(buffer, "%d", &pid); + if (fscanf(f, "%d", &pid) == 1) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); } - close(fd); + fclose(f); unlink(pidfile); } @@ -248,10 +246,10 @@ require_bufeq(const char *expected, ssize_t expected_l ssize_t i; ATF_REQUIRE_EQ_MSG(expected_len, len, - "Expected %ld bytes but got %ld", expected_len, len); + "Expected %zd bytes but got %zd", expected_len, len); for (i = 0; i < len; i++) { ATF_REQUIRE_EQ_MSG(actual[i], expected[i], - "Expected %#hhx at position %ld; got %hhx instead", + "Expected %#hhx at position %zd; got %hhx instead", expected[i], i, actual[i]); } } @@ -696,6 +694,7 @@ TFTPD_TC_DEFINE(w_flag,, w_flag = 1;) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("small.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq(contents, contents_len, buffer, r); @@ -733,6 +732,7 @@ TFTPD_TC_DEFINE(wrq_dropped_ack,) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("medium.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq((const char*)contents, 768, buffer, r); @@ -766,6 +766,7 @@ TFTPD_TC_DEFINE(wrq_dropped_data,) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("small.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq(contents, contents_len, buffer, r); @@ -800,6 +801,7 @@ TFTPD_TC_DEFINE(wrq_duped_data,) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("medium.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq((const char*)contents, 768, buffer, r); @@ -867,6 +869,7 @@ TFTPD_TC_DEFINE(wrq_medium,) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("medium.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq((const char*)contents, 768, buffer, r); @@ -900,6 +903,7 @@ TFTPD_TC_DEFINE(wrq_netascii,) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("unix.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq(expected, sizeof(expected), buffer, r); @@ -940,6 +944,7 @@ TFTPD_TC_DEFINE(wrq_small,) atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF"); fd = open("small.txt", O_RDONLY); + ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); close(fd); require_bufeq(contents, contents_len, buffer, r);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808031413.w73EDFkq069991>