From owner-svn-src-projects@freebsd.org Thu May 9 18:23:11 2019 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 28A111589F27 for ; Thu, 9 May 2019 18:23:11 +0000 (UTC) (envelope-from asomers@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C141873729; Thu, 9 May 2019 18:23:10 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9A88E20C36; Thu, 9 May 2019 18:23:10 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x49INALw081735; Thu, 9 May 2019 18:23:10 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x49IN9BU081731; Thu, 9 May 2019 18:23:09 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201905091823.x49IN9BU081731@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Thu, 9 May 2019 18:23:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r347403 - projects/fuse2/tests/sys/fs/fusefs X-SVN-Group: projects X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: projects/fuse2/tests/sys/fs/fusefs X-SVN-Commit-Revision: 347403 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C141873729 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.970,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 May 2019 18:23:11 -0000 Author: asomers Date: Thu May 9 18:23:09 2019 New Revision: 347403 URL: https://svnweb.freebsd.org/changeset/base/347403 Log: fusefs: shorten and consolidate sleeps Some fusefs tests must sleep because they deliberately trigger a race, or because they're testing the cache timeout functionality. Consolidate the sleep interval in a single place so it will be easy to adjust. Shorten it from either 500ms or 250ms to 100ms. From experiment I find that 10ms works every time, so 100ms should be fairly safe. Sponsored by: The FreeBSD Foundation Modified: projects/fuse2/tests/sys/fs/fusefs/getattr.cc projects/fuse2/tests/sys/fs/fusefs/interrupt.cc projects/fuse2/tests/sys/fs/fusefs/lookup.cc projects/fuse2/tests/sys/fs/fusefs/read.cc projects/fuse2/tests/sys/fs/fusefs/utils.hh Modified: projects/fuse2/tests/sys/fs/fusefs/getattr.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/getattr.cc Thu May 9 18:06:11 2019 (r347402) +++ projects/fuse2/tests/sys/fs/fusefs/getattr.cc Thu May 9 18:23:09 2019 (r347403) @@ -100,11 +100,6 @@ TEST_F(Getattr, attr_cache_timeout) const char RELPATH[] = "some_file.txt"; const uint64_t ino = 42; struct stat sb; - /* - * The timeout should be longer than the longest plausible time the - * daemon would take to complete a write(2) to /dev/fuse, but no longer. - */ - long timeout_ns = 250'000'000; expect_lookup(RELPATH, ino, S_IFREG | 0644, 0, 1, 0, 0); EXPECT_CALL(*m_mock, process( @@ -116,14 +111,14 @@ TEST_F(Getattr, attr_cache_timeout) ).Times(2) .WillRepeatedly(Invoke(ReturnImmediate([=](auto i __unused, auto out) { SET_OUT_HEADER_LEN(out, attr); - out->body.attr.attr_valid_nsec = timeout_ns; + out->body.attr.attr_valid_nsec = NAP_NS / 2; out->body.attr.attr_valid = 0; out->body.attr.attr.ino = ino; // Must match nodeid out->body.attr.attr.mode = S_IFREG | 0644; }))); EXPECT_EQ(0, stat(FULLPATH, &sb)); - usleep(2 * timeout_ns / 1000); + nap(); /* Timeout has expired. stat(2) should requery the daemon */ EXPECT_EQ(0, stat(FULLPATH, &sb)); } Modified: projects/fuse2/tests/sys/fs/fusefs/interrupt.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/interrupt.cc Thu May 9 18:06:11 2019 (r347402) +++ projects/fuse2/tests/sys/fs/fusefs/interrupt.cc Thu May 9 18:23:09 2019 (r347403) @@ -69,7 +69,7 @@ void sigusr2_handler(int __unused sig) { void* killer(void* target) { /* Wait until the main thread is blocked in fdisp_wait_answ */ if (killer_should_sleep) - usleep(250'000); + nap(); else sem_wait(blocked_semaphore); if (verbosity > 1) @@ -478,7 +478,7 @@ TEST_F(Interrupt, in_kernel_restartable) ASSERT_EQ(0, sem_post(&sem0)) << strerror(errno); /* Wait awhile to make sure the signal generates no FUSE_INTERRUPT */ - usleep(250'000); + nap(); pthread_join(th1, &thr1_value); pthread_join(th0, &thr0_value); @@ -548,7 +548,7 @@ TEST_F(Interrupt, in_kernel_nonrestartable) ASSERT_EQ(0, sem_post(&sem0)) << strerror(errno); /* Wait awhile to make sure the signal generates no FUSE_INTERRUPT */ - usleep(250'000); + nap(); pthread_join(th0, &thr0_value); EXPECT_EQ(0, (intptr_t)thr0_value); @@ -700,7 +700,7 @@ TEST_F(Interrupt, priority) ASSERT_EQ(0, mkdir(FULLDIRPATH1, MODE)) << strerror(errno); /* Wait awhile to make sure the signal generates no FUSE_INTERRUPT */ - usleep(250'000); + nap(); pthread_join(th0, NULL); sem_destroy(&sem1); Modified: projects/fuse2/tests/sys/fs/fusefs/lookup.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/lookup.cc Thu May 9 18:06:11 2019 (r347402) +++ projects/fuse2/tests/sys/fs/fusefs/lookup.cc Thu May 9 18:23:09 2019 (r347403) @@ -110,18 +110,13 @@ TEST_F(Lookup, attr_cache_timeout) const char RELPATH[] = "some_file.txt"; const uint64_t ino = 42; struct stat sb; - /* - * The timeout should be longer than the longest plausible time the - * daemon would take to complete a write(2) to /dev/fuse, but no longer. - */ - long timeout_ns = 250'000'000; EXPECT_LOOKUP(1, RELPATH) .Times(2) .WillRepeatedly(Invoke(ReturnImmediate([=](auto in __unused, auto out) { SET_OUT_HEADER_LEN(out, entry); out->body.entry.nodeid = ino; - out->body.entry.attr_valid_nsec = timeout_ns; + out->body.entry.attr_valid_nsec = NAP_NS / 2; out->body.entry.attr.ino = ino; // Must match nodeid out->body.entry.attr.mode = S_IFREG | 0644; }))); @@ -129,7 +124,7 @@ TEST_F(Lookup, attr_cache_timeout) /* access(2) will issue a VOP_LOOKUP and fill the attr cache */ ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno); /* Next access(2) will use the cached attributes */ - usleep(2 * timeout_ns / 1000); + nap(); /* The cache has timed out; VOP_GETATTR should query the daemon*/ ASSERT_EQ(0, stat(FULLPATH, &sb)) << strerror(errno); } @@ -247,11 +242,7 @@ TEST_F(Lookup, entry_cache_negative_timeout) { const char *RELPATH = "does_not_exist"; const char *FULLPATH = "mountpoint/does_not_exist"; - /* - * The timeout should be longer than the longest plausible time the - * daemon would take to complete a write(2) to /dev/fuse, but no longer. - */ - struct timespec entry_valid = {.tv_sec = 0, .tv_nsec = 250'000'000}; + struct timespec entry_valid = {.tv_sec = 0, .tv_nsec = NAP_NS / 2}; EXPECT_LOOKUP(1, RELPATH).Times(2) .WillRepeatedly(Invoke(ReturnNegativeCache(&entry_valid))); @@ -259,7 +250,7 @@ TEST_F(Lookup, entry_cache_negative_timeout) EXPECT_NE(0, access(FULLPATH, F_OK)); EXPECT_EQ(ENOENT, errno); - usleep(2 * entry_valid.tv_nsec / 1000); + nap(); /* The cache has timed out; VOP_LOOKUP should requery the daemon*/ EXPECT_NE(0, access(FULLPATH, F_OK)); @@ -274,17 +265,12 @@ TEST_F(Lookup, entry_cache_timeout) { const char FULLPATH[] = "mountpoint/some_file.txt"; const char RELPATH[] = "some_file.txt"; - /* - * The timeout should be longer than the longest plausible time the - * daemon would take to complete a write(2) to /dev/fuse, but no longer. - */ - long timeout_ns = 250'000'000; EXPECT_LOOKUP(1, RELPATH) .Times(2) .WillRepeatedly(Invoke(ReturnImmediate([=](auto in __unused, auto out) { SET_OUT_HEADER_LEN(out, entry); - out->body.entry.entry_valid_nsec = timeout_ns; + out->body.entry.entry_valid_nsec = NAP_NS / 2; out->body.entry.attr.mode = S_IFREG | 0644; out->body.entry.nodeid = 14; }))); @@ -293,7 +279,7 @@ TEST_F(Lookup, entry_cache_timeout) ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno); /* Next access(2) will use the cached entry */ ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno); - usleep(2 * timeout_ns / 1000); + nap(); /* The cache has timed out; VOP_LOOKUP should requery the daemon*/ ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno); } Modified: projects/fuse2/tests/sys/fs/fusefs/read.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/read.cc Thu May 9 18:06:11 2019 (r347402) +++ projects/fuse2/tests/sys/fs/fusefs/read.cc Thu May 9 18:23:09 2019 (r347403) @@ -200,7 +200,7 @@ TEST_F(AioRead, async_read_disabled) * Sleep for awhile to make sure the kernel has had a chance to issue * the second read, even though the first has not yet returned */ - usleep(250'000); + nap(); /* Deliberately leak iocbs */ /* Deliberately leak fd. close(2) will be tested in release.cc */ @@ -278,7 +278,7 @@ TEST_F(AsyncRead, DISABLED_async_read) * Sleep for awhile to make sure the kernel has had a chance to issue * both reads. */ - usleep(250'000); + nap(); /* Deliberately leak iocbs */ /* Deliberately leak fd. close(2) will be tested in release.cc */ Modified: projects/fuse2/tests/sys/fs/fusefs/utils.hh ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/utils.hh Thu May 9 18:06:11 2019 (r347402) +++ projects/fuse2/tests/sys/fs/fusefs/utils.hh Thu May 9 18:23:09 2019 (r347403) @@ -37,7 +37,14 @@ #define FUSE_WRITE_CACHE 1 #endif +/* Nanoseconds to sleep, for tests that must */ +#define NAP_NS (100'000'000) + void get_unprivileged_id(uid_t *uid, gid_t *gid); +inline void nap() +{ + usleep(NAP_NS / 1000); +} class FuseTest : public ::testing::Test { protected: