Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pwritev/pwritev01.c: add new testcase
Test pwritev(2) with some basic functions. Pwritev(2) should succeed to write the expected content of data and the file offset is not changed after writing the file. Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
- Loading branch information
Showing
9 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,5 +182,6 @@ LTP_CHECK_IF_LINK | |
LTP_CHECK_KCMP | ||
LTP_CHECK_KCMP_TYPE | ||
LTP_CHECK_PREADV | ||
LTP_CHECK_PWRITEV | ||
|
||
AC_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
dnl | ||
dnl Copyright (c) 2015 Fujitsu Ltd. | ||
dnl Author: Xiao Yang <yangx.jy@cn.fujitsu.com> | ||
dnl | ||
dnl This program is free software; you can redistribute it and/or modify it | ||
dnl under the terms of version 2 of the GNU General Public License as | ||
dnl published by the Free Software Foundation. | ||
dnl | ||
dnl This program is distributed in the hope that it would be useful, but | ||
dnl WITHOUT ANY WARRANTY; without even the implied warranty of | ||
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
dnl | ||
dnl You should have received a copy of the GNU General Public License | ||
dnl alone with this program. | ||
dnl | ||
|
||
dnl | ||
dnl LTP_CHECK_PWRITEV | ||
dnl ---------------------------- | ||
dnl | ||
AC_DEFUN([LTP_CHECK_PWRITEV],[ | ||
AC_CHECK_FUNCS(pwritev,,) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# Copyright (c) 2015 Fujitsu Ltd. | ||
# Author: Xiao Yang <yangx.jy@cn.fujitsu.com> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
# the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. | ||
# | ||
# | ||
|
||
top_srcdir ?= ../../../.. | ||
|
||
include $(top_srcdir)/include/mk/testcases.mk | ||
|
||
include $(abs_srcdir)/../utils/newer_64.mk | ||
|
||
%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 | ||
|
||
include $(top_srcdir)/include/mk/generic_leaf_target.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2015 Fujitsu Ltd. | ||
* Author: Xiao Yang <yangx.jy@cn.fujitsu.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it would be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* alone with this program. | ||
*/ | ||
|
||
#ifndef PWRITEV_H | ||
#define PWRITEV_H | ||
|
||
#include <sys/types.h> | ||
#include "config.h" | ||
#include "linux_syscall_numbers.h" | ||
|
||
#if !defined(HAVE_PWRITEV) | ||
int pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) | ||
{ | ||
return ltp_syscall(__NR_pwritev, fd, iov, iovcnt, offset); | ||
} | ||
#endif | ||
|
||
#endif /* PWRITEV_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright (c) 2015 Fujitsu Ltd. | ||
* Author: Xiao Yang <yangx.jy@cn.fujitsu.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it would be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* alone with this program. | ||
*/ | ||
|
||
/* | ||
* Test Name: pwritev01 | ||
* | ||
* Test Description: | ||
* Testcase to check the basic functionality of the pwritev(2). | ||
* pwritev(2) should succeed to write the expected content of data | ||
* and after writing the file, the file offset is not changed. | ||
*/ | ||
|
||
#include <errno.h> | ||
|
||
#include "test.h" | ||
#include "pwritev.h" | ||
#include "safe_macros.h" | ||
|
||
#define CHUNK 64 | ||
|
||
static char buf[CHUNK]; | ||
static char initbuf[CHUNK * 2]; | ||
static char preadbuf[CHUNK]; | ||
static int fd; | ||
|
||
static struct iovec wr_iovec[] = { | ||
{buf, CHUNK}, | ||
{NULL, 0}, | ||
}; | ||
|
||
static struct test_case_t { | ||
int count; | ||
off_t offset; | ||
ssize_t size; | ||
} tc[] = { | ||
{1, 0, CHUNK}, | ||
{2, 0, CHUNK}, | ||
{1, CHUNK/2, CHUNK}, | ||
}; | ||
|
||
void verify_pwritev(struct test_case_t *); | ||
void setup(void); | ||
void cleanup(void); | ||
|
||
char *TCID = "pwritev01"; | ||
int TST_TOTAL = ARRAY_SIZE(tc); | ||
|
||
int main(int ac, char **av) | ||
{ | ||
int lc; | ||
int i; | ||
|
||
tst_parse_opts(ac, av, NULL, NULL); | ||
|
||
setup(); | ||
|
||
for (lc = 0; TEST_LOOPING(lc); lc++) { | ||
tst_count = 0; | ||
|
||
for (i = 0; i < TST_TOTAL; i++) | ||
verify_pwritev(&tc[i]); | ||
} | ||
cleanup(); | ||
tst_exit(); | ||
} | ||
|
||
void verify_pwritev(struct test_case_t *tc) | ||
{ | ||
int i; | ||
|
||
SAFE_PWRITE(cleanup, 1, fd, initbuf, sizeof(initbuf), 0); | ||
|
||
SAFE_LSEEK(cleanup, fd, 0, SEEK_SET); | ||
|
||
TEST(pwritev(fd, wr_iovec, tc->count, tc->offset)); | ||
if (TEST_RETURN < 0) { | ||
tst_resm(TFAIL | TTERRNO, "Pwritev(2) failed"); | ||
return; | ||
} | ||
|
||
if (TEST_RETURN != tc->size) { | ||
tst_resm(TFAIL, "Pwritev(2) write %li bytes, expected %li", | ||
TEST_RETURN, tc->size); | ||
return; | ||
} | ||
|
||
if (SAFE_LSEEK(cleanup, fd, 0, SEEK_CUR) != 0) { | ||
tst_resm(TFAIL, "Pwritev(2) has changed file offset"); | ||
return; | ||
} | ||
|
||
SAFE_PREAD(cleanup, 1, fd, preadbuf, tc->size, tc->offset); | ||
|
||
for (i = 0; i < tc->size; i++) { | ||
if (preadbuf[i] != 0x61) | ||
break; | ||
} | ||
|
||
if (i != tc->size) { | ||
tst_resm(TFAIL, "Buffer wrong at %i have %02x expected 61", | ||
i, preadbuf[i]); | ||
return; | ||
} | ||
|
||
tst_resm(TPASS, "Pwritev(2) write %li bytes successfully " | ||
"with content 'a' expectedly ", tc->size); | ||
} | ||
|
||
void setup(void) | ||
{ | ||
if ((tst_kvercmp(2, 6, 30)) < 0) { | ||
tst_brkm(TCONF, NULL, "This test can only run on kernels " | ||
"that are 2.6.30 and higher"); | ||
} | ||
|
||
tst_sig(NOFORK, DEF_HANDLER, cleanup); | ||
|
||
TEST_PAUSE; | ||
|
||
tst_tmpdir(); | ||
|
||
memset(&buf, 0x61, CHUNK); | ||
|
||
fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); | ||
} | ||
|
||
void cleanup(void) | ||
{ | ||
if (fd > 0 && close(fd)) | ||
tst_resm(TWARN | TERRNO, "Failed to close file"); | ||
|
||
tst_rmdir(); | ||
} |