Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/fs/ffs New extended attributes test (does not work unt...



details:   https://anonhg.NetBSD.org/src/rev/cafdbef849f0
branches:  trunk
changeset: 971011:cafdbef849f0
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Apr 10 22:58:47 2020 +0000

description:
New extended attributes test (does not work until we commit kernel changes)

diffstat:

 tests/fs/ffs/Makefile    |    3 +-
 tests/fs/ffs/t_extattr.c |  176 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 178 insertions(+), 1 deletions(-)

diffs (197 lines):

diff -r 3bba42c75879 -r cafdbef849f0 tests/fs/ffs/Makefile
--- a/tests/fs/ffs/Makefile     Fri Apr 10 22:34:36 2020 +0000
+++ b/tests/fs/ffs/Makefile     Fri Apr 10 22:58:47 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.20 2020/03/01 18:08:13 christos Exp $
+#      $NetBSD: Makefile,v 1.21 2020/04/10 22:58:47 christos Exp $
 #
 
 .include <bsd.own.mk>
@@ -20,6 +20,7 @@
 TESTS_SH_SRC_${name}=  ffs_common.sh quotas_common.sh ${name}.sh
 .endfor
 
+TESTS_C+=      t_extattr
 TESTS_C+=      t_fifos
 TESTS_C+=      t_snapshot
 TESTS_C+=      t_snapshot_log
diff -r 3bba42c75879 -r cafdbef849f0 tests/fs/ffs/t_extattr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fs/ffs/t_extattr.c  Fri Apr 10 22:58:47 2020 +0000
@@ -0,0 +1,176 @@
+/*     $NetBSD: t_extattr.c,v 1.1 2020/04/10 22:58:47 christos Exp $   */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_extattr.c,v 1.1 2020/04/10 22:58:47 christos Exp $");
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/extattr.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include "h_macros.h"
+
+ATF_TC_WITH_CLEANUP(extattr);
+ATF_TC_HEAD(extattr, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "test extended attribute support in "
+           "ffsv2");
+       atf_tc_set_md_var(tc, "timeout", "5");
+}
+
+#define IMGNAME "extattr.img"
+
+#define G "/garage"
+#define M "mercedes"
+#define C "carburator"
+#define E "engine"
+#define T "trunk"
+#define S "suitcase"
+
+static const char *attrs[] = { E, T };
+
+static void
+check_list(const char *buf, ssize_t nr)
+{
+       size_t p = 0;
+       for (size_t i = 0; i < __arraycount(attrs); i++) {
+               size_t l = buf[p++];
+               if (l != strlen(attrs[i]))
+                   atf_tc_fail("got invalid len %zu expected %zu", l,
+                       strlen(attrs[i]));
+               if (strncmp(&buf[p], attrs[i], l) != 0)
+                       atf_tc_fail("got invalid str %.*s expected %s", (int)l,
+                           &buf[p], attrs[i]);
+               p += l;
+       }
+}
+
+// Make it ffsv2
+const char *newfs = "newfs -O 2 -F -s 10000 " IMGNAME;
+#define FAKEBLK "/dev/formula1"
+
+ATF_TC_BODY(extattr, tc)
+{
+       struct ufs_args args;
+       ssize_t nr;
+       int fd;
+       char buf[512];
+
+       if (system(newfs) == -1)
+               atf_tc_fail_errno("newfs failed");
+
+       memset(&args, 0, sizeof(args));
+       args.fspec = __UNCONST(FAKEBLK);
+
+       rump_init();
+       if (rump_sys_mkdir(G, 0777) == -1)
+               atf_tc_fail_errno("cannot create mountpoint");
+       rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK);
+       if (rump_sys_mount(MOUNT_FFS, G, 0, &args, sizeof(args))==-1)
+               atf_tc_fail_errno("rump_sys_mount failed");
+
+       /* create extattr */
+       if (rump_sys_chdir(G) == 1)
+               atf_tc_fail_errno("chdir");
+       if ((fd = rump_sys_open(M, O_RDWR | O_CREAT, 0600)) == -1)
+               atf_tc_fail_errno("open");
+       if (rump_sys_write(fd, "hi mom\n", 7) != 7)
+               atf_tc_fail_errno("write");
+
+       if (rump_sys_extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, E, C, 11) == -1)
+               atf_tc_fail_errno("exattr_set_fd");
+       if ((nr = rump_sys_extattr_get_file(M, EXTATTR_NAMESPACE_USER,
+           E, buf, sizeof(buf))) != 11)
+               atf_tc_fail_errno("extattr_get_file");
+       if (strcmp(buf, C) != 0)
+               atf_tc_fail("got invalid str %s expected %s", buf, C);
+
+       if (rump_sys_extattr_set_file(M, EXTATTR_NAMESPACE_USER, T, S, 9) == -1)
+               atf_tc_fail_errno("extattr_set_file");
+       if ((nr = rump_sys_extattr_get_fd(fd, EXTATTR_NAMESPACE_USER,
+           T, buf, sizeof(buf))) != 9)
+               atf_tc_fail_errno("extattr_get_fd");
+       if (strcmp(buf, S) != 0)
+               atf_tc_fail("got invalid str %s expected %s", buf, S);
+
+       if ((nr = rump_sys_extattr_list_fd(fd, EXTATTR_NAMESPACE_USER,
+           buf, sizeof(buf))) != 13)
+               atf_tc_fail_errno("extattr_list_fd %zd", nr);
+       check_list(buf, __arraycount(attrs));
+
+       if ((nr = rump_sys_extattr_list_file(M, EXTATTR_NAMESPACE_USER,
+           buf, sizeof(buf))) != 13)
+               atf_tc_fail_errno("extattr_list_file %zd", nr);
+       check_list(buf, __arraycount(attrs));
+
+       if (rump_sys_extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, T) == -1)
+               atf_tc_fail_errno("extattr_delete_fd");
+       if ((nr = rump_sys_extattr_list_fd(fd, EXTATTR_NAMESPACE_USER,
+           buf, sizeof(buf))) != 7)
+               atf_tc_fail_errno("extattr_list_fd %zd", nr);
+       check_list(buf, 1);
+
+       if (rump_sys_extattr_delete_file(M, EXTATTR_NAMESPACE_USER, E) == -1)
+               atf_tc_fail_errno("extattr_delete_file");
+       if ((nr = rump_sys_extattr_list_fd(fd, EXTATTR_NAMESPACE_USER,
+           buf, sizeof(buf))) != 0)
+               atf_tc_fail_errno("extattr_list_fd %zd", nr);
+
+       if (rump_sys_close(fd) == -1)
+               atf_tc_fail_errno("close");
+       if (rump_sys_unlink(M) == -1)
+               atf_tc_fail_errno("unlink");
+}
+
+ATF_TC_CLEANUP(extattr, tc)
+{
+
+       unlink(IMGNAME);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+       ATF_TP_ADD_TC(tp, extattr);
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index