• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * Description:
20  * The testcase checks the basic functionality of the unlink(2).
21  * 1) unlink() can delete regular file successfully.
22  * 2) unlink() can delete fifo file successfully.
23  */
24 
25 #include <errno.h>
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <stdio.h>
29 #include "tst_test.h"
30 
31 static void file_create(char *);
32 static void fifo_create(char *);
33 
34 static struct test_case_t {
35 	void (*setupfunc)(char *);
36 	char *desc;
37 } tcases[] = {
38 	{file_create, "file"},
39 	{fifo_create, "fifo"},
40 };
41 
file_create(char * name)42 static void file_create(char *name)
43 {
44 	sprintf(name, "tfile_%d", getpid());
45 	SAFE_TOUCH(name, 0777, NULL);
46 }
47 
fifo_create(char * name)48 static void fifo_create(char *name)
49 {
50 	sprintf(name, "tfifo_%d", getpid());
51 	SAFE_MKFIFO(name, 0777);
52 }
53 
verify_unlink(unsigned int n)54 static void verify_unlink(unsigned int n)
55 {
56 	char fname[255];
57 	struct test_case_t *tc = &tcases[n];
58 
59 	tc->setupfunc(fname);
60 
61 	TEST(unlink(fname));
62 	if (TST_RET == -1) {
63 		tst_res(TFAIL | TTERRNO, "unlink(%s) failed", tc->desc);
64 		return;
65 	}
66 
67 	if (!access(fname, F_OK)) {
68 		tst_res(TFAIL, "unlink(%s) succeeded, but %s still existed",
69 			tc->desc, tc->desc);
70 		return;
71 	}
72 
73 	tst_res(TPASS, "unlink(%s) succeeded", tc->desc);
74 }
75 
76 static struct tst_test test = {
77 	.needs_tmpdir = 1,
78 	.tcnt = ARRAY_SIZE(tcases),
79 	.test = verify_unlink,
80 };
81