1 /******************************************************************************/
2 /* Copyright (c) Jens Axboe <axboe@kernel.dk>, 2009 */
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 Foundation, */
18 /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
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
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <fcntl.h>
40
41 #include "test.h"
42 #include "safe_macros.h"
43 #include "lapi/splice.h"
44
45 char *TCID = "splice02";
46 int TST_TOTAL = 1;
47
cleanup(void)48 static void cleanup(void)
49 {
50 tst_rmdir();
51 }
52
setup(void)53 static void setup(void)
54 {
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
60 TEST_PAUSE;
61 tst_tmpdir();
62 }
63
64 #define SPLICE_SIZE (64*1024)
65
main(int ac,char ** av)66 int main(int ac, char **av)
67 {
68 int fd;
69
70 setup();
71
72 if (ac < 2) {
73 tst_brkm(TFAIL, NULL, "%s failed - Usage: %s outfile", TCID,
74 av[0]);
75 }
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");
85 }
86
87 SAFE_CLOSE(cleanup, fd);
88
89 cleanup();
90 tst_exit();
91 }
92