1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3*49cdfc7eSAndroid Build Coastguard Worker *
4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify it
5*49cdfc7eSAndroid Build Coastguard Worker * under the terms of version 2 of the GNU General Public License as
6*49cdfc7eSAndroid Build Coastguard Worker * published by the Free Software Foundation.
7*49cdfc7eSAndroid Build Coastguard Worker *
8*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it would be useful, but
9*49cdfc7eSAndroid Build Coastguard Worker * WITHOUT ANY WARRANTY; without even the implied warranty of
10*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11*49cdfc7eSAndroid Build Coastguard Worker *
12*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License along
13*49cdfc7eSAndroid Build Coastguard Worker * with this program; if not, write the Free Software Foundation, Inc.,
14*49cdfc7eSAndroid Build Coastguard Worker * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15*49cdfc7eSAndroid Build Coastguard Worker *
16*49cdfc7eSAndroid Build Coastguard Worker */
17*49cdfc7eSAndroid Build Coastguard Worker /**********************************************************
18*49cdfc7eSAndroid Build Coastguard Worker *
19*49cdfc7eSAndroid Build Coastguard Worker * TEST IDENTIFIER : fdatasync01
20*49cdfc7eSAndroid Build Coastguard Worker *
21*49cdfc7eSAndroid Build Coastguard Worker * EXECUTED BY : Any user
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * TEST TITLE : Basic test for fdatasync(2)
24*49cdfc7eSAndroid Build Coastguard Worker *
25*49cdfc7eSAndroid Build Coastguard Worker * TEST CASE TOTAL : 1
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR : Madhu T L <[email protected]>
28*49cdfc7eSAndroid Build Coastguard Worker *
29*49cdfc7eSAndroid Build Coastguard Worker * SIGNALS
30*49cdfc7eSAndroid Build Coastguard Worker * Uses SIGUSR1 to pause before test if option set.
31*49cdfc7eSAndroid Build Coastguard Worker * (See the parse_opts(3) man page).
32*49cdfc7eSAndroid Build Coastguard Worker *
33*49cdfc7eSAndroid Build Coastguard Worker * DESCRIPTION
34*49cdfc7eSAndroid Build Coastguard Worker * This is a Phase I test for the fdatasync(2) system call.
35*49cdfc7eSAndroid Build Coastguard Worker * It is intended to provide a limited exposure of the system call.
36*49cdfc7eSAndroid Build Coastguard Worker *
37*49cdfc7eSAndroid Build Coastguard Worker * Setup:
38*49cdfc7eSAndroid Build Coastguard Worker * Setup signal handling.
39*49cdfc7eSAndroid Build Coastguard Worker * Pause for SIGUSR1 if option specified.
40*49cdfc7eSAndroid Build Coastguard Worker * Create a temp directory and cd to it
41*49cdfc7eSAndroid Build Coastguard Worker * Initialize filename and open it in write mode for each child process.
42*49cdfc7eSAndroid Build Coastguard Worker *
43*49cdfc7eSAndroid Build Coastguard Worker * Test:
44*49cdfc7eSAndroid Build Coastguard Worker * Loop if the proper options are given.
45*49cdfc7eSAndroid Build Coastguard Worker * Execute system call
46*49cdfc7eSAndroid Build Coastguard Worker * Check return code, if system call failed (return=-1)
47*49cdfc7eSAndroid Build Coastguard Worker * Issue FAIL message with errno.
48*49cdfc7eSAndroid Build Coastguard Worker * Otherwise, Issue PASS message.
49*49cdfc7eSAndroid Build Coastguard Worker *
50*49cdfc7eSAndroid Build Coastguard Worker * Cleanup:
51*49cdfc7eSAndroid Build Coastguard Worker * Print errno log and/or timing stats if options given
52*49cdfc7eSAndroid Build Coastguard Worker * Remove temporary directory and all files in it.
53*49cdfc7eSAndroid Build Coastguard Worker *
54*49cdfc7eSAndroid Build Coastguard Worker * USAGE: <for command-line>
55*49cdfc7eSAndroid Build Coastguard Worker * fdatasync01 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
56*49cdfc7eSAndroid Build Coastguard Worker * where, -c n : Run n copies concurrently.
57*49cdfc7eSAndroid Build Coastguard Worker * -e : Turn on errno logging.
58*49cdfc7eSAndroid Build Coastguard Worker * -f : Turn off functional testing
59*49cdfc7eSAndroid Build Coastguard Worker * -h : Show help screen
60*49cdfc7eSAndroid Build Coastguard Worker * -i n : Execute test n times.
61*49cdfc7eSAndroid Build Coastguard Worker * -I x : Execute test for x seconds.
62*49cdfc7eSAndroid Build Coastguard Worker * -p : Pause for SIGUSR1 before starting
63*49cdfc7eSAndroid Build Coastguard Worker * -P x : Pause for x seconds between iterations.
64*49cdfc7eSAndroid Build Coastguard Worker * -t : Turn on syscall timing.
65*49cdfc7eSAndroid Build Coastguard Worker *
66*49cdfc7eSAndroid Build Coastguard Worker ****************************************************************/
67*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
68*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
69*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
70*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
71*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
72*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
73*49cdfc7eSAndroid Build Coastguard Worker
74*49cdfc7eSAndroid Build Coastguard Worker static int fd;
75*49cdfc7eSAndroid Build Coastguard Worker static char filename[30];
76*49cdfc7eSAndroid Build Coastguard Worker static void setup(void);
77*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void);
78*49cdfc7eSAndroid Build Coastguard Worker
79*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "fdatasync01";
80*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
81*49cdfc7eSAndroid Build Coastguard Worker
main(int argc,char ** argv)82*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char **argv)
83*49cdfc7eSAndroid Build Coastguard Worker {
84*49cdfc7eSAndroid Build Coastguard Worker int lc;
85*49cdfc7eSAndroid Build Coastguard Worker
86*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(argc, argv, NULL, NULL);
87*49cdfc7eSAndroid Build Coastguard Worker
88*49cdfc7eSAndroid Build Coastguard Worker setup();
89*49cdfc7eSAndroid Build Coastguard Worker
90*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
91*49cdfc7eSAndroid Build Coastguard Worker
92*49cdfc7eSAndroid Build Coastguard Worker /* reset tst_count in case we are looping */
93*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker /* Test the system call */
96*49cdfc7eSAndroid Build Coastguard Worker TEST(fdatasync(fd));
97*49cdfc7eSAndroid Build Coastguard Worker
98*49cdfc7eSAndroid Build Coastguard Worker /* check return code */
99*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN == -1) {
100*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fdatasync() failed, errno=%d : %s",
101*49cdfc7eSAndroid Build Coastguard Worker TEST_ERRNO, strerror(TEST_ERRNO));
102*49cdfc7eSAndroid Build Coastguard Worker } else {
103*49cdfc7eSAndroid Build Coastguard Worker /* No Functional verification yet */
104*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "fdatasync() successful");
105*49cdfc7eSAndroid Build Coastguard Worker }
106*49cdfc7eSAndroid Build Coastguard Worker }
107*49cdfc7eSAndroid Build Coastguard Worker
108*49cdfc7eSAndroid Build Coastguard Worker /* perform global cleanup and exit */
109*49cdfc7eSAndroid Build Coastguard Worker cleanup();
110*49cdfc7eSAndroid Build Coastguard Worker
111*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
112*49cdfc7eSAndroid Build Coastguard Worker
113*49cdfc7eSAndroid Build Coastguard Worker }
114*49cdfc7eSAndroid Build Coastguard Worker
115*49cdfc7eSAndroid Build Coastguard Worker /* setup() - performs all ONE TIME setup for this test */
setup(void)116*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
117*49cdfc7eSAndroid Build Coastguard Worker {
118*49cdfc7eSAndroid Build Coastguard Worker
119*49cdfc7eSAndroid Build Coastguard Worker tst_sig(NOFORK, DEF_HANDLER, cleanup);
120*49cdfc7eSAndroid Build Coastguard Worker
121*49cdfc7eSAndroid Build Coastguard Worker /* Pause if that option was specified
122*49cdfc7eSAndroid Build Coastguard Worker * TEST_PAUSE contains the code to fork the test with the -c option.
123*49cdfc7eSAndroid Build Coastguard Worker */
124*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
125*49cdfc7eSAndroid Build Coastguard Worker
126*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
127*49cdfc7eSAndroid Build Coastguard Worker
128*49cdfc7eSAndroid Build Coastguard Worker /* Initialize unique filename for each child process */
129*49cdfc7eSAndroid Build Coastguard Worker if (sprintf(filename, "fdatasync_%d", getpid()) <= 0) {
130*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup, "Failed to initialize filename");
131*49cdfc7eSAndroid Build Coastguard Worker }
132*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open(filename, O_CREAT | O_WRONLY, 0777)) == -1) { //mode must be specified when O_CREATE is in the flag
133*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup, "open() failed");
134*49cdfc7eSAndroid Build Coastguard Worker }
135*49cdfc7eSAndroid Build Coastguard Worker if ((write(fd, filename, strlen(filename) + 1)) == -1) {
136*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup, "write() failed");
137*49cdfc7eSAndroid Build Coastguard Worker }
138*49cdfc7eSAndroid Build Coastguard Worker }
139*49cdfc7eSAndroid Build Coastguard Worker
140*49cdfc7eSAndroid Build Coastguard Worker /*
141*49cdfc7eSAndroid Build Coastguard Worker * cleanup()
142*49cdfc7eSAndroid Build Coastguard Worker * performs all ONE TIME cleanup for this test at
143*49cdfc7eSAndroid Build Coastguard Worker * completion or premature exit
144*49cdfc7eSAndroid Build Coastguard Worker */
cleanup(void)145*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
146*49cdfc7eSAndroid Build Coastguard Worker {
147*49cdfc7eSAndroid Build Coastguard Worker /*
148*49cdfc7eSAndroid Build Coastguard Worker * print timing stats if that option was specified.
149*49cdfc7eSAndroid Build Coastguard Worker * print errno log if that option was specified.
150*49cdfc7eSAndroid Build Coastguard Worker */
151*49cdfc7eSAndroid Build Coastguard Worker close(fd);
152*49cdfc7eSAndroid Build Coastguard Worker
153*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
154*49cdfc7eSAndroid Build Coastguard Worker
155*49cdfc7eSAndroid Build Coastguard Worker }
156