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 */ |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 17 | /* along with this program; if not, write to the Free Software Foundation, */ |
| 18 | /* 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 |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 35 | |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <unistd.h> |
| 39 | #include <fcntl.h> |
| 40 | |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 41 | #include "test.h" |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 42 | #include "safe_macros.h" |
Cyril Hrubis | 6bd56e6 | 2014-06-03 11:09:35 +0200 | [diff] [blame] | 43 | #include "lapi/splice.h" |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 44 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 45 | char *TCID = "splice02"; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 46 | int TST_TOTAL = 1; |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 47 | |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 48 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 49 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 50 | tst_rmdir(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 53 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 54 | { |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 55 | if ((tst_kvercmp(2, 6, 17)) < 0) { |
| 56 | tst_brkm(TCONF, cleanup, "This test can only run on kernels " |
| 57 | "that are 2.6.17 or higher"); |
| 58 | } |
| 59 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | TEST_PAUSE; |
| 61 | tst_tmpdir(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | #define SPLICE_SIZE (64*1024) |
| 65 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 66 | int main(int ac, char **av) |
| 67 | { |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 68 | int fd; |
subrata_modak | 5210c01 | 2009-05-29 12:42:35 +0000 | [diff] [blame] | 69 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 70 | setup(); |
subrata_modak | ad1d5d4 | 2009-04-15 06:25:58 +0000 | [diff] [blame] | 71 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 72 | if (ac < 2) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 73 | tst_brkm(TFAIL, NULL, "%s failed - Usage: %s outfile", TCID, |
| 74 | av[0]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 75 | } |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 76 | |
| 77 | fd = SAFE_OPEN(cleanup, av[1], O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 78 | |
| 79 | TEST(splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, 0)); |
| 80 | if (TEST_RETURN < 0) { |
| 81 | tst_resm(TFAIL, "splice failed - errno = %d : %s", |
| 82 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 83 | } else { |
| 84 | tst_resm(TPASS, "splice() system call Passed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | } |
| 86 | |
Cyril Hrubis | 4284006 | 2014-06-03 13:45:46 +0200 | [diff] [blame] | 87 | SAFE_CLOSE(cleanup, fd); |
| 88 | |
| 89 | cleanup(); |
| 90 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 91 | } |