From d65686ac2ca5c930372a9d141bbe185477c935f5 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Sat, 1 Apr 2023 16:45:46 +0100 Subject: Add unit tests for setxattr() et al Hopefully, this will catch issues as in commit 024eccbf3 --- example/hello_ll.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++----- test/test_examples.py | 14 +++++++++--- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/example/hello_ll.c b/example/hello_ll.c index 1db5eff..96afd0f 100644 --- a/example/hello_ll.c +++ b/example/hello_ll.c @@ -153,12 +153,61 @@ static void hello_ll_read(fuse_req_t req, fuse_ino_t ino, size_t size, reply_buf_limited(req, hello_str, strlen(hello_str), off, size); } +static void hello_ll_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size) +{ + (void)size; + assert(ino == 2); + if (strcmp(name, "hello_ll_getxattr_name") == 0) + { + char *buf = "hello_ll_getxattr_value"; + fuse_reply_buf(req, buf, strlen(buf)); + } + else + { + fuse_reply_err(req, ENOTSUP); + } +} + +static void hello_ll_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags) +{ + (void)flags; + (void)size; + assert(ino == 2); + if (strcmp(name, "hello_ll_setxattr_name") == 0 && + strcmp(value, "hello_ll_setxattr_value") == 0) + { + fuse_reply_err(req, 0); + } + else + { + fuse_reply_err(req, ENOTSUP); + } +} + +static void hello_ll_removexattr(fuse_req_t req, fuse_ino_t ino, const char *name) +{ + assert(ino == 2); + if (strcmp(name, "hello_ll_removexattr_name") == 0) + { + fuse_reply_err(req, 0); + } + else + { + fuse_reply_err(req, ENOTSUP); + } +} + static const struct fuse_lowlevel_ops hello_ll_oper = { - .lookup = hello_ll_lookup, - .getattr = hello_ll_getattr, - .readdir = hello_ll_readdir, - .open = hello_ll_open, - .read = hello_ll_read, + .lookup = hello_ll_lookup, + .getattr = hello_ll_getattr, + .readdir = hello_ll_readdir, + .open = hello_ll_open, + .read = hello_ll_read, + .setxattr = hello_ll_setxattr, + .getxattr = hello_ll_getxattr, + .removexattr = hello_ll_removexattr, }; int main(int argc, char *argv[]) diff --git a/test/test_examples.py b/test/test_examples.py index c63ac11..7df9ba4 100755 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -104,6 +104,8 @@ def test_hello(tmpdir, name, options, cmdline_builder, output_checker): with pytest.raises(IOError) as exc_info: open(filename + 'does-not-exist', 'r+') assert exc_info.value.errno == errno.ENOENT + if name == 'hello_ll': + tst_xattr(mnt_dir) except: cleanup(mount_process, mnt_dir) raise @@ -760,7 +762,13 @@ def tst_passthrough(src_dir, mnt_dir): assert name in os.listdir(mnt_dir) assert os.stat(src_name) == os.stat(mnt_name) -# avoid warning about unused import -test_printcap - +def tst_xattr(mnt_dir): + path = os.path.join(mnt_dir, 'hello') + os.setxattr(path, b'hello_ll_setxattr_name', b'hello_ll_setxattr_value') + assert os.getxattr(path, b'hello_ll_getxattr_name') == b'hello_ll_getxattr_value' + os.removexattr(path, b'hello_ll_removexattr_name') + + +# avoid warning about unused import +assert test_printcap -- cgit v1.2.1