vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : fdatasync01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 21 | * EXECUTED BY : Any user |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for fdatasync(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 27 | * AUTHOR : Madhu T L <madhu.tarikere@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 29 | * 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 36 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 37 | * 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 42 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 43 | * 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 50 | * Cleanup: |
| 51 | * Print errno log and/or timing stats if options given |
| 52 | * Remove temporary directory and all files in it. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 54 | * 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 65 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 66 | ****************************************************************/ |
| 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" |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 73 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 74 | static int fd; |
| 75 | static char filename[30]; |
| 76 | static void setup(void); |
| 77 | static void cleanup(void); |
| 78 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 79 | char *TCID = "fdatasync01"; |
| 80 | int TST_TOTAL = 1; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | int main(int argc, char **argv) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 83 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 84 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 85 | const char *msg; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 86 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 87 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 88 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 89 | } |
| 90 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 91 | setup(); |
| 92 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 93 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 94 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 95 | /* reset tst_count in case we are looping */ |
| 96 | tst_count = 0; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 97 | |
| 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | TEST_ERRNO, strerror(TEST_ERRNO)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 105 | } 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 Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 114 | tst_exit(); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 115 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 116 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 117 | |
| 118 | /* setup() - performs all ONE TIME setup for this test */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | void setup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 120 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 121 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 122 | 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 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 129 | tst_tmpdir(); |
| 130 | |
| 131 | /* Initialize unique filename for each child process */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | if (sprintf(filename, "fdatasync_%d", getpid()) <= 0) { |
subrata_modak | 814e03c | 2008-11-11 06:44:51 +0000 | [diff] [blame] | 133 | tst_brkm(TBROK, cleanup, "Failed to initialize filename"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 134 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 135 | if ((fd = open(filename, O_CREAT | O_WRONLY, 0777)) == -1) { //mode must be specified when O_CREATE is in the flag |
subrata_modak | 814e03c | 2008-11-11 06:44:51 +0000 | [diff] [blame] | 136 | tst_brkm(TBROK, cleanup, "open() failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | if ((write(fd, filename, strlen(filename) + 1)) == -1) { |
subrata_modak | 814e03c | 2008-11-11 06:44:51 +0000 | [diff] [blame] | 139 | tst_brkm(TBROK, cleanup, "write() failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 140 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* |
| 144 | * cleanup() |
| 145 | * performs all ONE TIME cleanup for this test at |
| 146 | * completion or premature exit |
| 147 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | void cleanup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 149 | { |
| 150 | /* |
| 151 | * print timing stats if that option was specified. |
| 152 | * print errno log if that option was specified. |
| 153 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | close(fd); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 155 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 156 | tst_rmdir(); |
| 157 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 158 | } |