blob: d2f843ae735f4d9c43c3beaa237a94cf567d9827 [file] [log] [blame]
subrata_modakad1d5d42009-04-15 06:25:58 +00001/******************************************************************************/
Garrett Cooper2c282152010-12-16 00:55:50 -08002/* Copyright (c) Jens Axboe <axboe@kernel.dk>, 2009 */
subrata_modakad1d5d42009-04-15 06:25:58 +00003/* */
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 Hrubis42840062014-06-03 13:45:46 +020017/* 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_modakad1d5d42009-04-15 06:25:58 +000019/* */
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 Hrubis42840062014-06-03 13:45:46 +020035
subrata_modakad1d5d42009-04-15 06:25:58 +000036#include <stdio.h>
37#include <stdlib.h>
38#include <unistd.h>
39#include <fcntl.h>
40
subrata_modakad1d5d42009-04-15 06:25:58 +000041#include "test.h"
Cyril Hrubis42840062014-06-03 13:45:46 +020042#include "safe_macros.h"
Cyril Hrubis6bd56e62014-06-03 11:09:35 +020043#include "lapi/splice.h"
subrata_modakad1d5d42009-04-15 06:25:58 +000044
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020045char *TCID = "splice02";
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020046int TST_TOTAL = 1;
subrata_modakad1d5d42009-04-15 06:25:58 +000047
Cyril Hrubis42840062014-06-03 13:45:46 +020048static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080049{
Wanlong Gao354ebb42012-12-07 10:10:04 +080050 tst_rmdir();
subrata_modakad1d5d42009-04-15 06:25:58 +000051}
52
Cyril Hrubis42840062014-06-03 13:45:46 +020053static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080054{
Cyril Hrubis42840062014-06-03 13:45:46 +020055 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 Gao354ebb42012-12-07 10:10:04 +080060 TEST_PAUSE;
61 tst_tmpdir();
subrata_modakad1d5d42009-04-15 06:25:58 +000062}
63
64#define SPLICE_SIZE (64*1024)
65
Wanlong Gao354ebb42012-12-07 10:10:04 +080066int main(int ac, char **av)
67{
Cyril Hrubis42840062014-06-03 13:45:46 +020068 int fd;
subrata_modak5210c012009-05-29 12:42:35 +000069
Wanlong Gao354ebb42012-12-07 10:10:04 +080070 setup();
subrata_modakad1d5d42009-04-15 06:25:58 +000071
Wanlong Gao354ebb42012-12-07 10:10:04 +080072 if (ac < 2) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010073 tst_brkm(TFAIL, NULL, "%s failed - Usage: %s outfile", TCID,
74 av[0]);
Wanlong Gao354ebb42012-12-07 10:10:04 +080075 }
Cyril Hrubis42840062014-06-03 13:45:46 +020076
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 Gao354ebb42012-12-07 10:10:04 +080085 }
86
Cyril Hrubis42840062014-06-03 13:45:46 +020087 SAFE_CLOSE(cleanup, fd);
88
89 cleanup();
90 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -070091}