]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/rump/rumpvfs/t_p2kifs.c
MFC r314450,r313439:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / rump / rumpvfs / t_p2kifs.c
1 /*      $NetBSD: t_p2kifs.c,v 1.6 2017/01/13 21:30:43 christos Exp $    */
2
3 /*-
4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <sys/types.h>
31 #include <sys/mount.h>
32 #include <sys/sysctl.h>
33
34 #include <rump/rump.h>
35 #include <rump/rumpvnode_if.h>
36 #include <rump/rump_syscalls.h>
37
38 #include <atf-c.h>
39 #include <fcntl.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43
44 #include "h_macros.h"
45
46 ATF_TC(makecn);
47 ATF_TC_HEAD(makecn, tc)
48 {
49
50         atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
51 }
52
53 #define TESTFILE "testi"
54
55 ATF_TC_BODY(makecn, tc)
56 {
57         struct componentname *cn;
58         char pathstr[MAXPATHLEN] = TESTFILE;
59         struct vnode *vp;
60         extern struct vnode *rumpns_rootvnode;
61
62         rump_init();
63
64         /*
65          * Strategy is to create a componentname, edit the passed
66          * string, and then do a lookup with the componentname.
67          */
68         RL(rump_sys_mkdir("/" TESTFILE, 0777));
69
70         /* need stable lwp for componentname */
71         RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
72
73         /* try it once with the right path */
74         cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
75             rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
76         RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
77         rump_pub_freecn(cn, RUMPCN_FREECRED);
78
79         /* and then with modification-in-the-middle */
80         cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
81             rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
82         strcpy(pathstr, "/muuta");
83         RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
84         rump_pub_freecn(cn, RUMPCN_FREECRED);
85 }
86
87 ATF_TP_ADD_TCS(tp)
88 {
89
90         ATF_TP_ADD_TC(tp, makecn);
91
92         return atf_no_error();
93 }