1314817Sngie/*	$NetBSD: t_p2kifs.c,v 1.6 2017/01/13 21:30:43 christos Exp $	*/
2272343Sngie
3272343Sngie/*-
4272343Sngie * Copyright (c) 2010 The NetBSD Foundation, Inc.
5272343Sngie * All rights reserved.
6272343Sngie *
7272343Sngie * Redistribution and use in source and binary forms, with or without
8272343Sngie * modification, are permitted provided that the following conditions
9272343Sngie * are met:
10272343Sngie * 1. Redistributions of source code must retain the above copyright
11272343Sngie *    notice, this list of conditions and the following disclaimer.
12272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
13272343Sngie *    notice, this list of conditions and the following disclaimer in the
14272343Sngie *    documentation and/or other materials provided with the distribution.
15272343Sngie *
16272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17272343Sngie * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18272343Sngie * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19272343Sngie * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20272343Sngie * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21272343Sngie * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23272343Sngie * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25272343Sngie * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26272343Sngie * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27272343Sngie * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28272343Sngie */
29272343Sngie
30272343Sngie#include <sys/types.h>
31272343Sngie#include <sys/mount.h>
32272343Sngie#include <sys/sysctl.h>
33272343Sngie
34272343Sngie#include <rump/rump.h>
35313498Sngie#include <rump/rumpvnode_if.h>
36272343Sngie#include <rump/rump_syscalls.h>
37272343Sngie
38272343Sngie#include <atf-c.h>
39272343Sngie#include <fcntl.h>
40272343Sngie#include <stdio.h>
41272343Sngie#include <stdlib.h>
42272343Sngie#include <unistd.h>
43272343Sngie
44314817Sngie#include "h_macros.h"
45272343Sngie
46272343SngieATF_TC(makecn);
47272343SngieATF_TC_HEAD(makecn, tc)
48272343Sngie{
49272343Sngie
50272343Sngie	atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
51272343Sngie}
52272343Sngie
53272343Sngie#define TESTFILE "testi"
54272343Sngie
55272343SngieATF_TC_BODY(makecn, tc)
56272343Sngie{
57272343Sngie	struct componentname *cn;
58272343Sngie	char pathstr[MAXPATHLEN] = TESTFILE;
59272343Sngie	struct vnode *vp;
60272343Sngie	extern struct vnode *rumpns_rootvnode;
61272343Sngie
62272343Sngie	rump_init();
63272343Sngie
64272343Sngie	/*
65272343Sngie	 * Strategy is to create a componentname, edit the passed
66272343Sngie	 * string, and then do a lookup with the componentname.
67272343Sngie	 */
68272343Sngie	RL(rump_sys_mkdir("/" TESTFILE, 0777));
69272343Sngie
70272343Sngie	/* need stable lwp for componentname */
71272343Sngie	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
72272343Sngie
73272343Sngie	/* try it once with the right path */
74272343Sngie	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
75272343Sngie	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
76272343Sngie	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
77272343Sngie	rump_pub_freecn(cn, RUMPCN_FREECRED);
78272343Sngie
79272343Sngie	/* and then with modification-in-the-middle */
80272343Sngie	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
81272343Sngie	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
82272343Sngie	strcpy(pathstr, "/muuta");
83272343Sngie	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
84272343Sngie	rump_pub_freecn(cn, RUMPCN_FREECRED);
85272343Sngie}
86272343Sngie
87272343SngieATF_TP_ADD_TCS(tp)
88272343Sngie{
89272343Sngie
90272343Sngie	ATF_TP_ADD_TC(tp, makecn);
91272343Sngie
92272343Sngie	return atf_no_error();
93272343Sngie}
94