* winsup.api/mmaptest01.c: Add several tests on mmaps. Use libltp.
* winsup.api/winsup.exp: Link all tests agains libltp.
This commit is contained in:
parent
97405ef5b0
commit
d7f6398556
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Oct 8 14:15:00 2001 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* winsup.api/mmaptest01.c: Add several tests on mmaps. Use libltp.
|
||||||
|
* winsup.api/winsup.exp: Link all tests agains libltp.
|
||||||
|
|
||||||
Fri Oct 5 11:15:55 2001 Christopher Faylor <cgf@cygnus.com>
|
Fri Oct 5 11:15:55 2001 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
* winsup.api/nullgetcwd.c: New file. Check that NULL first argument to
|
* winsup.api/nullgetcwd.c: New file. Check that NULL first argument to
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2001 Free Software Foundation, Inc.
|
Copyright 2001 Free Software Foundation, Inc.
|
||||||
Written by Michael Chastain, <chastain@redhat.com>
|
Written by Michael Chastain, <chastain@redhat.com>
|
||||||
|
Changes by Corinna Vinschen, <corinna@vinschen.de>:
|
||||||
|
- Using mkstemp to generate filenames.
|
||||||
|
- Adding tests
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -50,6 +53,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
|
#include "usctest.h"
|
||||||
|
|
||||||
|
char *TCID = "mmaptest01"; /* Test program identifier. */
|
||||||
|
int TST_TOTAL = 7; /* Total number of test cases. */
|
||||||
|
extern int Tst_count; /* Test Case counter for tst_* routines */
|
||||||
|
|
||||||
/* some systems have O_BINARY and some do not */
|
/* some systems have O_BINARY and some do not */
|
||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
|
@ -67,43 +77,100 @@ char const line2 [] = "y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2 y2\n";
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
char fnam1[32];
|
||||||
|
char fnam2[32];
|
||||||
|
|
||||||
int fd1;
|
int fd1;
|
||||||
char * buf1;
|
char * buf1;
|
||||||
|
|
||||||
int fd2;
|
int fd2;
|
||||||
char * buf2;
|
char * buf2;
|
||||||
|
|
||||||
|
char buf3[20];
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
strcpy (fnam1, "mmaptest01.1.XXXXXX");
|
||||||
|
strcpy (fnam2, "mmaptest01.2.XXXXXX");
|
||||||
|
|
||||||
/* create file 1 */
|
/* create file 1 */
|
||||||
fd1 = open ("y1.txt", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
|
//fd1 = open (fnam1, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
|
||||||
|
fd1 = mkstemp (fnam1);
|
||||||
for (i = 0; i < count1; i++)
|
for (i = 0; i < count1; i++)
|
||||||
write (fd1, line1, size1);
|
write (fd1, line1, size1);
|
||||||
close (fd1);
|
close (fd1);
|
||||||
|
|
||||||
/* create file 2 */
|
/* create file 2 */
|
||||||
fd2 = open ("y2.txt", O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
|
//fd2 = open (fnam2, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
|
||||||
|
fd2 = mkstemp (fnam2);
|
||||||
for (i = 0; i < count2; i++)
|
for (i = 0; i < count2; i++)
|
||||||
write (fd2, line2, size2);
|
write (fd2, line2, size2);
|
||||||
close (fd2);
|
close (fd2);
|
||||||
|
|
||||||
/* mmap file 1 */
|
/* mmap file 1 */
|
||||||
fd1 = open ("y1.txt", O_RDONLY | O_BINARY, 0644);
|
fd1 = open (fnam1, O_RDONLY | O_BINARY, 0644);
|
||||||
buf1 = mmap (0, 4096, PROT_READ, MAP_PRIVATE, fd1, 0);
|
buf1 = mmap (0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd1, 0);
|
||||||
close (fd1);
|
close (fd1);
|
||||||
|
|
||||||
/* mmap file 2 */
|
/* mmap file 2 */
|
||||||
fd2 = open ("y2.txt", O_RDONLY | O_BINARY, 0644);
|
fd2 = open (fnam2, O_RDONLY | O_BINARY, 0644);
|
||||||
buf2 = mmap (0, 4096, PROT_READ, MAP_PRIVATE, fd2, 0);
|
buf2 = mmap (0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd2, 0);
|
||||||
close (fd2);
|
close (fd2);
|
||||||
|
|
||||||
/* the buffers have to be different */
|
/* the buffers have to be different */
|
||||||
if (buf1 == buf2 || !memcmp (buf1, buf2, 20))
|
Tst_count = 0;
|
||||||
{
|
tst_resm (buf1 == buf2 || !memcmp (buf1, buf2, 20) ? TFAIL : TPASS,
|
||||||
printf ("buffers are not different!\n");
|
"mmap uses unique buffers when mapping different already closed files");
|
||||||
return 1;
|
munmap (buf2, 4096);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
/* mmap file 1 twice with MAP_PRIVATE */
|
||||||
|
fd2 = open (fnam1, O_RDONLY | O_BINARY, 0644);
|
||||||
|
buf2 = mmap (0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd2, 0);
|
||||||
|
close (fd2);
|
||||||
|
|
||||||
|
tst_resm (buf1 == buf2 ? TFAIL : TPASS,
|
||||||
|
"mmap uses different buffers on MAP_PRIVATE mapping");
|
||||||
|
|
||||||
|
tst_resm (memcmp (buf1, buf2, 20) ? TFAIL : TPASS,
|
||||||
|
"two private buffers of the same file are identical");
|
||||||
|
|
||||||
|
buf1[0] = 0x7f;
|
||||||
|
tst_resm (!memcmp (buf1, buf2, 20) ? TFAIL : TPASS,
|
||||||
|
"changes are private in MAP_PRIVATE mappings");
|
||||||
|
|
||||||
|
munmap (buf1, 4096);
|
||||||
|
munmap (buf2, 4096);
|
||||||
|
|
||||||
|
/* mmap file 1 twice with MAP_SHARED */
|
||||||
|
fd1 = open (fnam1, O_RDWR | O_BINARY, 0644);
|
||||||
|
buf1 = mmap (0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd1, 0);
|
||||||
|
close (fd1);
|
||||||
|
|
||||||
|
fd2 = open (fnam1, O_RDWR | O_BINARY, 0644);
|
||||||
|
buf2 = mmap (0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd2, 0);
|
||||||
|
close (fd2);
|
||||||
|
|
||||||
|
tst_resm (memcmp (buf1, buf2, 20) ? TFAIL : TPASS,
|
||||||
|
"two shared buffers of the same file are identical");
|
||||||
|
|
||||||
|
buf1[0] = 0x7f;
|
||||||
|
tst_resm (memcmp (buf1, buf2, 20) ? TFAIL : TPASS,
|
||||||
|
"changes are shared between MAP_SHARED mappings of the same file");
|
||||||
|
munmap (buf2, 4096);
|
||||||
|
|
||||||
|
fd2 = open (fnam1, O_RDWR | O_BINARY, 0644);
|
||||||
|
memset (buf3, 0, 20);
|
||||||
|
read (fd2, buf3, 20);
|
||||||
|
close (fd2);
|
||||||
|
|
||||||
|
tst_resm (memcmp (buf1, buf3, 20) ? TFAIL : TPASS,
|
||||||
|
"changes are propagated to the mapped file on MAP_SHARED mapping");
|
||||||
|
|
||||||
|
munmap (buf1, 4096);
|
||||||
|
unlink (fnam1);
|
||||||
|
unlink (fnam2);
|
||||||
|
tst_exit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,13 @@ if { ! [isnative] } {
|
||||||
}
|
}
|
||||||
|
|
||||||
set rv ""
|
set rv ""
|
||||||
set add_includes ""
|
|
||||||
set add_libs ""
|
|
||||||
|
|
||||||
set ltp_includes "-I$ltp_includes"
|
set ltp_includes "-I$ltp_includes"
|
||||||
set ltp_libs "$rootme/libltp.a"
|
set ltp_libs "$rootme/libltp.a"
|
||||||
|
|
||||||
|
set add_includes $ltp_includes
|
||||||
|
set add_libs $ltp_libs
|
||||||
|
|
||||||
set test_filter ""
|
set test_filter ""
|
||||||
|
|
||||||
if { [info exists env(CYGWIN_TESTSUITE_TESTS)] } {
|
if { [info exists env(CYGWIN_TESTSUITE_TESTS)] } {
|
||||||
|
@ -47,11 +48,6 @@ foreach src [glob -nocomplain $srcdir/$subdir/*.c $srcdir/$subdir/*/*.c] {
|
||||||
clear_xfail
|
clear_xfail
|
||||||
}
|
}
|
||||||
|
|
||||||
if { [regexp "^ltp/" $testcase ] } {
|
|
||||||
set add_includes $ltp_includes
|
|
||||||
set add_libs $ltp_libs
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_spawn "$CC -g3 $CFLAGS $src $add_includes $add_libs $runtime_root/binmode.o $runtime_root/new-libcygwin.a -o $base.exe"
|
ws_spawn "$CC -g3 $CFLAGS $src $add_includes $add_libs $runtime_root/binmode.o $runtime_root/new-libcygwin.a -o $base.exe"
|
||||||
if { $rv != "" } {
|
if { $rv != "" } {
|
||||||
verbose -log "$rv"
|
verbose -log "$rv"
|
||||||
|
|
Loading…
Reference in New Issue