* Added a test application that show that BFS does not care to fill the space
between the former end of the file and the position of a write with zeros as required. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36262 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,155 +2,52 @@ SubDir HAIKU_TOP src tests system libroot posix ;
|
||||
|
||||
UsePrivateHeaders libroot syslog_daemon ;
|
||||
|
||||
SimpleTest abort_test
|
||||
: abort_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest SyslogTest
|
||||
: SyslogTest.cpp syslog.cpp
|
||||
;
|
||||
|
||||
SimpleTest clearenv
|
||||
: clearenv.cpp
|
||||
;
|
||||
|
||||
SimpleTest dirent_test
|
||||
: dirent_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest flock_test
|
||||
: flock_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest memalign_test
|
||||
: memalign_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest mprotect_test
|
||||
: mprotect_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest realtime_sem_test1
|
||||
: realtime_sem_test1.cpp
|
||||
;
|
||||
|
||||
# POSIX/libc tests
|
||||
SimpleTest abort_test : abort_test.cpp ;
|
||||
SimpleTest SyslogTest : SyslogTest.cpp syslog.cpp ;
|
||||
SimpleTest clearenv : clearenv.cpp ;
|
||||
SimpleTest dirent_test : dirent_test.cpp ;
|
||||
SimpleTest flock_test : flock_test.cpp ;
|
||||
SimpleTest memalign_test : memalign_test.cpp ;
|
||||
SimpleTest mprotect_test : mprotect_test.cpp ;
|
||||
SimpleTest realtime_sem_test1 : realtime_sem_test1.cpp ;
|
||||
SimpleTest seek_and_write_test : seek_and_write_test.cpp ;
|
||||
SimpleTest setpgid_test : setpgid_test.cpp ;
|
||||
SimpleTest setjmp_test : setjmp_test.c ;
|
||||
SimpleTest setjmp_test2 : setjmp_test2.S ;
|
||||
SimpleTest signal_in_allocator_test : signal_in_allocator_test.cpp ;
|
||||
SimpleTest signal_in_allocator_test2 : signal_in_allocator_test2.cpp ;
|
||||
SimpleTest signal_test : signal_test.cpp ;
|
||||
SimpleTest sigsetjmp_test : sigsetjmp_test.c ;
|
||||
SimpleTest <test>truncate : truncate.cpp ;
|
||||
SimpleTest init_rld_after_fork_test : init_rld_after_fork_test.cpp ;
|
||||
|
||||
SimpleTest setjmp_test
|
||||
: setjmp_test.c
|
||||
;
|
||||
# XSI tests
|
||||
SimpleTest xsi_msg_queue_test1 : xsi_msg_queue_test1.cpp ;
|
||||
SimpleTest xsi_sem_test1 : xsi_sem_test1.cpp ;
|
||||
|
||||
SimpleTest setjmp_test2
|
||||
: setjmp_test2.S
|
||||
;
|
||||
# wide character tests
|
||||
SimpleTest mbtest : mbtest.c ;
|
||||
SimpleTest testmb : testmb.c ;
|
||||
SimpleTest tst-btowc : tst-btowc.c ;
|
||||
SimpleTest tst-fgetws : tst-fgetws.c ;
|
||||
SimpleTest tst-getwc : tst-getwc.c ;
|
||||
SimpleTest tst-mbrtowc : tst-mbrtowc.c ;
|
||||
SimpleTest tst-swprintf : tst-swprintf.c ;
|
||||
SimpleTest tst-swscanf : tst-swscanf.c ;
|
||||
SimpleTest tst-swscanf2 : tst-swscanf2.c ;
|
||||
SimpleTest tst-ungetwc1 : tst-ungetwc1.c ;
|
||||
SimpleTest tst-ungetwc2 : tst-ungetwc2.c ;
|
||||
SimpleTest tst-wcrtomb : tst-wcrtomb.c ;
|
||||
SimpleTest tst-wcsnlen : tst-wcsnlen.c ;
|
||||
SimpleTest tst-wcstof : tst-wcstof.c ;
|
||||
SimpleTest tst-wprintf : tst-wprintf.c ;
|
||||
SimpleTest tst-wprintf2 : tst-wprintf2.c ;
|
||||
SimpleTest tst-wscanf : tst-wscanf.c ;
|
||||
SimpleTest test_wcfuncs : test_wcfuncs.c ;
|
||||
SimpleTest test_wctype : test_wctype.c ;
|
||||
|
||||
SimpleTest signal_in_allocator_test
|
||||
: signal_in_allocator_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest signal_in_allocator_test2
|
||||
: signal_in_allocator_test2.cpp
|
||||
;
|
||||
|
||||
SimpleTest signal_test
|
||||
: signal_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest sigsetjmp_test
|
||||
: sigsetjmp_test.c
|
||||
;
|
||||
|
||||
SimpleTest <test>truncate
|
||||
: truncate.cpp
|
||||
;
|
||||
|
||||
SimpleTest init_rld_after_fork_test
|
||||
: init_rld_after_fork_test.cpp
|
||||
;
|
||||
|
||||
SimpleTest xsi_msg_queue_test1
|
||||
: xsi_msg_queue_test1.cpp
|
||||
;
|
||||
|
||||
SimpleTest xsi_sem_test1
|
||||
: xsi_sem_test1.cpp
|
||||
;
|
||||
|
||||
SimpleTest mbtest
|
||||
: mbtest.c
|
||||
;
|
||||
|
||||
SimpleTest testmb
|
||||
: testmb.c
|
||||
;
|
||||
|
||||
SimpleTest tst-btowc
|
||||
: tst-btowc.c
|
||||
;
|
||||
|
||||
SimpleTest tst-fgetws
|
||||
: tst-fgetws.c
|
||||
;
|
||||
|
||||
SimpleTest tst-getwc
|
||||
: tst-getwc.c
|
||||
;
|
||||
|
||||
SimpleTest tst-mbrtowc
|
||||
: tst-mbrtowc.c
|
||||
;
|
||||
|
||||
SimpleTest tst-swprintf
|
||||
: tst-swprintf.c
|
||||
;
|
||||
|
||||
SimpleTest tst-swscanf
|
||||
: tst-swscanf.c
|
||||
;
|
||||
|
||||
SimpleTest tst-swscanf2
|
||||
: tst-swscanf2.c
|
||||
;
|
||||
|
||||
SimpleTest tst-ungetwc1
|
||||
: tst-ungetwc1.c
|
||||
;
|
||||
|
||||
SimpleTest tst-ungetwc2
|
||||
: tst-ungetwc2.c
|
||||
;
|
||||
|
||||
SimpleTest tst-wcrtomb
|
||||
: tst-wcrtomb.c
|
||||
;
|
||||
|
||||
SimpleTest tst-wcsnlen
|
||||
: tst-wcsnlen.c
|
||||
;
|
||||
|
||||
SimpleTest tst-wcstof
|
||||
: tst-wcstof.c
|
||||
;
|
||||
|
||||
SimpleTest tst-wprintf
|
||||
: tst-wprintf.c
|
||||
;
|
||||
|
||||
SimpleTest tst-wprintf2
|
||||
: tst-wprintf2.c
|
||||
;
|
||||
|
||||
SimpleTest tst-wscanf
|
||||
: tst-wscanf.c
|
||||
;
|
||||
|
||||
SimpleTest test_wcfuncs
|
||||
: test_wcfuncs.c
|
||||
;
|
||||
|
||||
SimpleTest test_wctype
|
||||
: test_wctype.c
|
||||
;
|
||||
|
||||
# Tell Jam where to find these sources
|
||||
SEARCH on [ FGristFiles
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2010, Axel Dörfler, [email protected].
|
||||
* This file may be used under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
void
|
||||
test_for_content(int fd, off_t start, const char* contents, size_t length)
|
||||
{
|
||||
char buffer[4096];
|
||||
while (length > 0) {
|
||||
size_t toRead = std::min(length, sizeof(buffer));
|
||||
|
||||
if (pread(fd, buffer, toRead, start) != (ssize_t)toRead) {
|
||||
perror("reading failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (memcmp(contents, buffer, toRead)) {
|
||||
fprintf(stderr, "Contents at %lld differ!\n", start);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
contents += toRead;
|
||||
start += toRead;
|
||||
length -= toRead;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
test_for_zero(int fd, off_t start, off_t end)
|
||||
{
|
||||
while (start < end) {
|
||||
char buffer[4096];
|
||||
size_t length = std::min((size_t)(end - start), sizeof(buffer));
|
||||
|
||||
if (pread(fd, buffer, length, start) != (ssize_t)length) {
|
||||
perror("reading failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
if (buffer[i] != 0) {
|
||||
fprintf(stderr, "Buffer at %lld is not empty (%#x)!\n",
|
||||
start + i, buffer[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
start += length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
const char* name = "/tmp/seek_and_write";
|
||||
bool prefill = true;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
if (argv[i][1] == 'n')
|
||||
prefill = false;
|
||||
else {
|
||||
fprintf(stderr, "Unknown option\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
name = argv[i];
|
||||
}
|
||||
|
||||
int fd = open(name, O_RDWR | O_TRUNC | O_CREAT, 0644);
|
||||
if (fd < 0) {
|
||||
perror("failed to open file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[256];
|
||||
for (size_t i = 0; i < 256; i++)
|
||||
buffer[i] = i;
|
||||
|
||||
if (prefill) {
|
||||
// Write test data to file to make sure it's not empty
|
||||
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
if (write(fd, buffer, sizeof(buffer)) != (ssize_t)sizeof(buffer)) {
|
||||
perror("writing failed");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Truncate it again in order to remove its contents
|
||||
|
||||
ftruncate(fd, 0);
|
||||
|
||||
// Seek past its end, and write something
|
||||
|
||||
pwrite(fd, "---", 3, 100 * 1024);
|
||||
pwrite(fd, "+++", 3, 200 * 1024);
|
||||
|
||||
// Test contents
|
||||
|
||||
test_for_zero(fd, 0, 100 * 1024);
|
||||
test_for_content(fd, 100 * 1024, "---", 3);
|
||||
test_for_zero(fd, 100 * 1024 + 256, 200 * 1024);
|
||||
test_for_content(fd, 200 * 1024, "+++", 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user