subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 2 | /* Copyright (c) Jens Axboe <axboe@kernel.dk>, 2009 */ |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 3 | /* */ |
| 4 | /* LKML Reference: http://lkml.org/lkml/2009/4/2/55 */ |
| 5 | /* */ |
| 6 | /* This program is free software; you can redistribute it and/or modify */ |
| 7 | /* it under the terms of the GNU General Public License as published by */ |
| 8 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 9 | /* (at your option) any later version. */ |
| 10 | /* */ |
| 11 | /* This program is distributed in the hope that it will be useful, */ |
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 14 | /* the GNU General Public License for more details. */ |
| 15 | /* */ |
| 16 | /* You should have received a copy of the GNU General Public License */ |
| 17 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: splice02.c */ |
| 24 | /* */ |
| 25 | /* Description: This tests the splice() syscall */ |
| 26 | /* */ |
| 27 | /* Usage: <for command-line> */ |
| 28 | /* echo "Test splice()" > <outfile>; splice02 <outfile> */ |
| 29 | /* */ |
| 30 | /* Total Tests: 1 */ |
| 31 | /* */ |
| 32 | /* Test Name: splice02 */ |
| 33 | /******************************************************************************/ |
| 34 | #define _GNU_SOURCE |
| 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
| 37 | #include <unistd.h> |
| 38 | #include <fcntl.h> |
| 39 | |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 40 | /* Harness Specific Include Files. */ |
| 41 | #include "test.h" |
| 42 | #include "usctest.h" |
| 43 | #include "linux_syscall_numbers.h" |
| 44 | |
| 45 | /* Extern Global Variables */ |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 46 | |
| 47 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 48 | char *TCID = "splice02"; /* Test program identifier. */ |
| 49 | int testno; |
| 50 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 51 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 52 | static inline long ltp_splice(int fd_in, loff_t * off_in, |
| 53 | int fd_out, loff_t * off_out, |
| 54 | size_t len, unsigned int flags) |
subrata_modak | 5210c01 | 2009-05-29 12:42:35 +0000 | [diff] [blame] | 55 | { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 56 | return ltp_syscall(__NR_splice, fd_in, off_in, fd_out, off_out, |
| 57 | len, flags); |
subrata_modak | 5210c01 | 2009-05-29 12:42:35 +0000 | [diff] [blame] | 58 | } |
| 59 | |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 60 | /* Extern Global Functions */ |
| 61 | /******************************************************************************/ |
| 62 | /* */ |
| 63 | /* Function: cleanup */ |
| 64 | /* */ |
| 65 | /* Description: Performs all one time clean up for this test on successful */ |
| 66 | /* completion, premature exit or failure. Closes all temporary */ |
| 67 | /* files, removes all temporary directories exits the test with */ |
| 68 | /* appropriate return code by calling tst_exit() function. */ |
| 69 | /* */ |
| 70 | /* Input: None. */ |
| 71 | /* */ |
| 72 | /* Output: None. */ |
| 73 | /* */ |
| 74 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 75 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 76 | /* */ |
| 77 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 78 | extern void cleanup() |
| 79 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 80 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | TEST_CLEANUP; |
| 82 | tst_rmdir(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 83 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 84 | tst_exit(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* Local Functions */ |
| 88 | /******************************************************************************/ |
| 89 | /* */ |
| 90 | /* Function: setup */ |
| 91 | /* */ |
| 92 | /* Description: Performs all one time setup for this test. This function is */ |
| 93 | /* typically used to capture signals, create temporary dirs */ |
| 94 | /* and temporary files that may be used in the course of this */ |
| 95 | /* test. */ |
| 96 | /* */ |
| 97 | /* Input: None. */ |
| 98 | /* */ |
| 99 | /* Output: None. */ |
| 100 | /* */ |
| 101 | /* Return: On failure - Exits by calling cleanup(). */ |
| 102 | /* On success - returns 0. */ |
| 103 | /* */ |
| 104 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 105 | void setup() |
| 106 | { |
| 107 | /* Capture signals if any */ |
| 108 | /* Create temporary directories */ |
| 109 | TEST_PAUSE; |
| 110 | tst_tmpdir(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | #define SPLICE_SIZE (64*1024) |
| 114 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 115 | int main(int ac, char **av) |
| 116 | { |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 117 | int fd = 0; |
subrata_modak | 5210c01 | 2009-05-29 12:42:35 +0000 | [diff] [blame] | 118 | int results = 0; |
| 119 | |
| 120 | /* Disable test if the version of the kernel is less than 2.6.17 */ |
| 121 | if (((results = tst_kvercmp(2, 6, 17)) < 0)) { |
| 122 | tst_resm(TINFO, "This test can only run on kernels that are "); |
| 123 | tst_resm(TINFO, "2.6.17 and higher"); |
| 124 | exit(0); |
| 125 | } |
| 126 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | setup(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 128 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 129 | if (ac < 2) { |
| 130 | tst_resm(TFAIL, "%s failed - Usage: %s outfile", TCID, av[0]); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 131 | tst_exit(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 132 | } |
| 133 | fd = open(av[1], O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 134 | if (fd < 0) { |
| 135 | tst_resm(TFAIL, "open(%s) failed - errno = %d : %s", av[1], |
| 136 | errno, strerror(errno)); |
| 137 | cleanup(); |
| 138 | tst_exit(); |
| 139 | } |
| 140 | |
| 141 | do { |
| 142 | TEST(ltp_splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, 0)); |
| 143 | if (TEST_RETURN < 0) { |
| 144 | tst_resm(TFAIL, "splice failed - errno = %d : %s", |
| 145 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 146 | cleanup(); |
| 147 | tst_exit(); |
| 148 | } else if (TEST_RETURN == 0) { |
| 149 | tst_resm(TPASS, "splice() system call Passed"); |
| 150 | close(fd); |
| 151 | cleanup(); |
| 152 | tst_exit(); |
| 153 | } |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 154 | } while (1); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 155 | } |