blob: d240ed79840d311480b641c703d72e57b669170d [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 */
17/* along with this program; if not, write to the Free Software */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018/* Foundation, 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
35#include <stdio.h>
36#include <stdlib.h>
37#include <unistd.h>
38#include <fcntl.h>
39
subrata_modakad1d5d42009-04-15 06:25:58 +000040/* Harness Specific Include Files. */
41#include "test.h"
42#include "usctest.h"
43#include "linux_syscall_numbers.h"
44
45/* Extern Global Variables */
subrata_modakad1d5d42009-04-15 06:25:58 +000046
47/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080048char *TCID = "splice02"; /* Test program identifier. */
49int testno;
50int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modakad1d5d42009-04-15 06:25:58 +000051
Wanlong Gao354ebb42012-12-07 10:10:04 +080052static 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_modak5210c012009-05-29 12:42:35 +000055{
Jan Stancek359980f2013-02-15 10:16:05 +010056 return ltp_syscall(__NR_splice, fd_in, off_in, fd_out, off_out,
57 len, flags);
subrata_modak5210c012009-05-29 12:42:35 +000058}
59
subrata_modakad1d5d42009-04-15 06:25:58 +000060/* 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 Gao354ebb42012-12-07 10:10:04 +080078extern void cleanup()
79{
Garrett Cooper2c282152010-12-16 00:55:50 -080080
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 TEST_CLEANUP;
82 tst_rmdir();
subrata_modakad1d5d42009-04-15 06:25:58 +000083
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 tst_exit();
subrata_modakad1d5d42009-04-15 06:25:58 +000085}
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 Gao354ebb42012-12-07 10:10:04 +0800105void setup()
106{
107 /* Capture signals if any */
108 /* Create temporary directories */
109 TEST_PAUSE;
110 tst_tmpdir();
subrata_modakad1d5d42009-04-15 06:25:58 +0000111}
112
113#define SPLICE_SIZE (64*1024)
114
Wanlong Gao354ebb42012-12-07 10:10:04 +0800115int main(int ac, char **av)
116{
subrata_modakad1d5d42009-04-15 06:25:58 +0000117 int fd = 0;
subrata_modak5210c012009-05-29 12:42:35 +0000118 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 Gao354ebb42012-12-07 10:10:04 +0800127 setup();
subrata_modakad1d5d42009-04-15 06:25:58 +0000128
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 if (ac < 2) {
130 tst_resm(TFAIL, "%s failed - Usage: %s outfile", TCID, av[0]);
subrata_modakad1d5d42009-04-15 06:25:58 +0000131 tst_exit();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800132 }
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 Cooperdf3eb162010-11-28 22:44:32 -0800154 } while (1);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700155}