xref: /freebsd/tests/sys/fs/fusefs/dev_fuse_poll.cc (revision 3429092cd1b112b33d78385d2f02e59cadf173e6)
1*3429092cSAlan Somers /*-
2*3429092cSAlan Somers  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*3429092cSAlan Somers  *
4*3429092cSAlan Somers  * Copyright (c) 2019 The FreeBSD Foundation
5*3429092cSAlan Somers  *
6*3429092cSAlan Somers  * This software was developed by BFF Storage Systems, LLC under sponsorship
7*3429092cSAlan Somers  * from the FreeBSD Foundation.
8*3429092cSAlan Somers  *
9*3429092cSAlan Somers  * Redistribution and use in source and binary forms, with or without
10*3429092cSAlan Somers  * modification, are permitted provided that the following conditions
11*3429092cSAlan Somers  * are met:
12*3429092cSAlan Somers  * 1. Redistributions of source code must retain the above copyright
13*3429092cSAlan Somers  *    notice, this list of conditions and the following disclaimer.
14*3429092cSAlan Somers  * 2. Redistributions in binary form must reproduce the above copyright
15*3429092cSAlan Somers  *    notice, this list of conditions and the following disclaimer in the
16*3429092cSAlan Somers  *    documentation and/or other materials provided with the distribution.
17*3429092cSAlan Somers  *
18*3429092cSAlan Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*3429092cSAlan Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*3429092cSAlan Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*3429092cSAlan Somers  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*3429092cSAlan Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*3429092cSAlan Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*3429092cSAlan Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*3429092cSAlan Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*3429092cSAlan Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*3429092cSAlan Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*3429092cSAlan Somers  * SUCH DAMAGE.
29*3429092cSAlan Somers  */
30*3429092cSAlan Somers 
31*3429092cSAlan Somers /*
32*3429092cSAlan Somers  * This file tests different polling methods for the /dev/fuse device
33*3429092cSAlan Somers  */
34*3429092cSAlan Somers 
35*3429092cSAlan Somers extern "C" {
36*3429092cSAlan Somers #include <fcntl.h>
37*3429092cSAlan Somers #include <unistd.h>
38*3429092cSAlan Somers }
39*3429092cSAlan Somers 
40*3429092cSAlan Somers #include "mockfs.hh"
41*3429092cSAlan Somers #include "utils.hh"
42*3429092cSAlan Somers 
43*3429092cSAlan Somers using namespace testing;
44*3429092cSAlan Somers 
45*3429092cSAlan Somers const char FULLPATH[] = "mountpoint/some_file.txt";
46*3429092cSAlan Somers const char RELPATH[] = "some_file.txt";
47*3429092cSAlan Somers const uint64_t ino = 42;
48*3429092cSAlan Somers const mode_t access_mode = R_OK;
49*3429092cSAlan Somers 
50*3429092cSAlan Somers /*
51*3429092cSAlan Somers  * Translate a poll method's string representation to the enum value.
52*3429092cSAlan Somers  * Using strings with ::testing::Values gives better output with
53*3429092cSAlan Somers  * --gtest_list_tests
54*3429092cSAlan Somers  */
55*3429092cSAlan Somers enum poll_method poll_method_from_string(const char *s)
56*3429092cSAlan Somers {
57*3429092cSAlan Somers 	if (0 == strcmp("BLOCKING", s))
58*3429092cSAlan Somers 		return BLOCKING;
59*3429092cSAlan Somers 	else if (0 == strcmp("KQ", s))
60*3429092cSAlan Somers 		return KQ;
61*3429092cSAlan Somers 	else if (0 == strcmp("POLL", s))
62*3429092cSAlan Somers 		return POLL;
63*3429092cSAlan Somers 	else
64*3429092cSAlan Somers 		return SELECT;
65*3429092cSAlan Somers }
66*3429092cSAlan Somers 
67*3429092cSAlan Somers class DevFusePoll: public FuseTest, public WithParamInterface<const char *> {
68*3429092cSAlan Somers 	virtual void SetUp() {
69*3429092cSAlan Somers 		m_pm = poll_method_from_string(GetParam());
70*3429092cSAlan Somers 		FuseTest::SetUp();
71*3429092cSAlan Somers 	}
72*3429092cSAlan Somers };
73*3429092cSAlan Somers 
74*3429092cSAlan Somers TEST_P(DevFusePoll, access)
75*3429092cSAlan Somers {
76*3429092cSAlan Somers 	expect_access(1, X_OK, 0);
77*3429092cSAlan Somers 	expect_lookup(RELPATH, ino, S_IFREG | 0644, 0, 1);
78*3429092cSAlan Somers 	expect_access(ino, access_mode, 0);
79*3429092cSAlan Somers 
80*3429092cSAlan Somers 	ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno);
81*3429092cSAlan Somers }
82*3429092cSAlan Somers 
83*3429092cSAlan Somers /* Ensure that we wake up pollers during unmount */
84*3429092cSAlan Somers TEST_P(DevFusePoll, destroy)
85*3429092cSAlan Somers {
86*3429092cSAlan Somers 	expect_forget(1, 1);
87*3429092cSAlan Somers 	expect_destroy(0);
88*3429092cSAlan Somers 
89*3429092cSAlan Somers 	m_mock->unmount();
90*3429092cSAlan Somers }
91*3429092cSAlan Somers 
92*3429092cSAlan Somers INSTANTIATE_TEST_CASE_P(PM, DevFusePoll,
93*3429092cSAlan Somers 		::testing::Values("BLOCKING", "KQ", "POLL", "SELECT"));
94