blob: 4caa69440e0b5db3ffaf99ded4ba74a34e4d0469 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
vapierd13d74b2006-02-11 07:24:00 +000019 * TEST IDENTIFIER : fdatasync01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : Any user
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Basic test for fdatasync(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
vapierd13d74b2006-02-11 07:24:00 +000027 * AUTHOR : Madhu T L <madhu.tarikere@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
vapierd13d74b2006-02-11 07:24:00 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the fdatasync(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
vapierd13d74b2006-02-11 07:24:00 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
40 * Create a temp directory and cd to it
41 * Initialize filename and open it in write mode for each child process.
subrata_modak4bb656a2009-02-26 12:02:09 +000042 *
vapierd13d74b2006-02-11 07:24:00 +000043 * Test:
44 * Loop if the proper options are given.
45 * Execute system call
46 * Check return code, if system call failed (return=-1)
47 * Issue FAIL message with errno.
48 * Otherwise, Issue PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
vapierd13d74b2006-02-11 07:24:00 +000050 * Cleanup:
51 * Print errno log and/or timing stats if options given
52 * Remove temporary directory and all files in it.
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
vapierd13d74b2006-02-11 07:24:00 +000054 * USAGE: <for command-line>
55 * fdatasync01 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
56 * where, -c n : Run n copies concurrently.
57 * -e : Turn on errno logging.
58 * -f : Turn off functional testing
59 * -h : Show help screen
60 * -i n : Execute test n times.
61 * -I x : Execute test for x seconds.
62 * -p : Pause for SIGUSR1 before starting
63 * -P x : Pause for x seconds between iterations.
64 * -t : Turn on syscall timing.
subrata_modak4bb656a2009-02-26 12:02:09 +000065 *
vapierd13d74b2006-02-11 07:24:00 +000066 ****************************************************************/
67#include <errno.h>
68#include <sys/types.h>
69#include <sys/stat.h>
70#include <fcntl.h>
71#include <unistd.h>
72#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000073
vapierd13d74b2006-02-11 07:24:00 +000074static int fd;
75static char filename[30];
76static void setup(void);
77static void cleanup(void);
78
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020079char *TCID = "fdatasync01";
80int TST_TOTAL = 1;
vapierd13d74b2006-02-11 07:24:00 +000081
subrata_modak56207ce2009-03-23 13:35:39 +000082int main(int argc, char **argv)
vapierd13d74b2006-02-11 07:24:00 +000083{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020084 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020085 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000086
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080088 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000089 }
90
vapierd13d74b2006-02-11 07:24:00 +000091 setup();
92
vapierd13d74b2006-02-11 07:24:00 +000093 for (lc = 0; TEST_LOOPING(lc); lc++) {
94
Caspar Zhangd59a6592013-03-07 14:59:12 +080095 /* reset tst_count in case we are looping */
96 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000097
98 /* Test the system call */
99 TEST(fdatasync(fd));
100
101 /* check return code */
102 if (TEST_RETURN == -1) {
103 tst_resm(TFAIL, "fdatasync() failed, errno=%d : %s",
subrata_modak56207ce2009-03-23 13:35:39 +0000104 TEST_ERRNO, strerror(TEST_ERRNO));
vapierd13d74b2006-02-11 07:24:00 +0000105 } else {
106 /* No Functional verification yet */
107 tst_resm(TPASS, "fdatasync() successful");
108 }
109 }
110
111 /* perform global cleanup and exit */
112 cleanup();
113
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800114 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000115
Garrett Cooper2c282152010-12-16 00:55:50 -0800116}
vapierd13d74b2006-02-11 07:24:00 +0000117
118/* setup() - performs all ONE TIME setup for this test */
subrata_modak56207ce2009-03-23 13:35:39 +0000119void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000120{
Garrett Cooper2c282152010-12-16 00:55:50 -0800121
vapierd13d74b2006-02-11 07:24:00 +0000122 tst_sig(NOFORK, DEF_HANDLER, cleanup);
123
124 /* Pause if that option was specified
125 * TEST_PAUSE contains the code to fork the test with the -c option.
126 */
127 TEST_PAUSE;
128
vapierd13d74b2006-02-11 07:24:00 +0000129 tst_tmpdir();
130
131 /* Initialize unique filename for each child process */
subrata_modak56207ce2009-03-23 13:35:39 +0000132 if (sprintf(filename, "fdatasync_%d", getpid()) <= 0) {
subrata_modak814e03c2008-11-11 06:44:51 +0000133 tst_brkm(TBROK, cleanup, "Failed to initialize filename");
Wanlong Gao354ebb42012-12-07 10:10:04 +0800134 }
subrata_modak56207ce2009-03-23 13:35:39 +0000135 if ((fd = open(filename, O_CREAT | O_WRONLY, 0777)) == -1) { //mode must be specified when O_CREATE is in the flag
subrata_modak814e03c2008-11-11 06:44:51 +0000136 tst_brkm(TBROK, cleanup, "open() failed");
Wanlong Gao354ebb42012-12-07 10:10:04 +0800137 }
subrata_modak56207ce2009-03-23 13:35:39 +0000138 if ((write(fd, filename, strlen(filename) + 1)) == -1) {
subrata_modak814e03c2008-11-11 06:44:51 +0000139 tst_brkm(TBROK, cleanup, "write() failed");
Wanlong Gao354ebb42012-12-07 10:10:04 +0800140 }
vapierd13d74b2006-02-11 07:24:00 +0000141}
142
143/*
144 * cleanup()
145 * performs all ONE TIME cleanup for this test at
146 * completion or premature exit
147 */
subrata_modak56207ce2009-03-23 13:35:39 +0000148void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000149{
150 /*
151 * print timing stats if that option was specified.
152 * print errno log if that option was specified.
153 */
subrata_modak56207ce2009-03-23 13:35:39 +0000154 close(fd);
vapierd13d74b2006-02-11 07:24:00 +0000155
vapierd13d74b2006-02-11 07:24:00 +0000156 tst_rmdir();
157
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158}