[prev in list] [next in list] [prev in thread] [next in thread]
List: ltp-cvs
Subject: [Ltp-cvs] ltp/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel 1-1.c,NONE,1.1 10-1.c
From: Robert Williamson <robbiew () users ! sourceforge ! net>
Date: 2004-12-20 17:04:20
Message-ID: E1CgQxI-00082e-JJ () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]
Update of /cvsroot/ltp/ltp/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30688/conformance/interfaces/aio_cancel
Added Files:
1-1.c 10-1.c 2-1.c 2-2.c 3-1.c 4-1.c 5-1.c 6-1.c 7-1.c 8-1.c
9-1.c assertions.xml coverage.txt
Log Message:
Update to Version 1.5.0
--- NEW FILE: assertions.xml ---
<assertions>
<assertion id="1" tag="ef:XSH6TC2:3966:3967">
The aiocbp argument points to the AIO control block to be canceled.
</assertion>
<assertion id="2" tag="ef:XSH6TC2:3967:3968">
if aiobcp is NULL, all outstanding cancelable AIO against fildes
shall be canceled.
</assertion>
<assertion id="3" tag="ef:XSH6TC2:3969:3970">
Asynchronous notification shall occur for AIO that are successfully
cancelled.
</assertion>
<assertion id="4" tag="ef:XSH6TC2:3972:3973">
Error status should be set to [ECANCELED] and return shall be -1 for
successfully canceled AIO.
</assertion>
<assertion id="5" tag="ef:XSH6TC2:3973:3974">
aiocbp not successfully canceled shall not be modified
</assertion>
<assertion id="6" tag="ef:XSH6TC2:3979:3980">
aio_cancel() shall return AIO_CANCELED if the requested operations
were canceled.
</assertion>
<assertion id="7" tag="ef:XSH6TC2:3980:3981">
aio_cancel() shall return AIO_NOTCANCELED if at least one of the
requested operations cannot be canceled because it is in progress.
</assertion>
<assertion id="8" tag="ef:XSH6TC2:3984:3985">
aio_cancel() shall return AIO_ALLDONE if all operation have already
completed
</assertion>
<assertion id="9" tag="ef:XSH6TC2:3985:3985">
aio_cancel() shall return -1 and set errno in all other case.
</assertion>
<assertion id="10" tag="ef:XSH6TC2:3988:3988">
aio_cancel() shall fail if:
[EBADF] The fildes argument is not a valid descriptor.
</assertion>
</assertions>
--- NEW FILE: 1-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* The aiocbp argument points to the AIO control block to be canceled.
*
* method:
*
* - create a valid aiocb with a call to aio_write()
* - call aio_cancel() with this aiocb and check return value is not -1
* -> aio_cancel() works with a valid (finished or not) aiocb
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/1-1.c"
int main()
{
char tmpfname[256];
#define BUF_SIZE 1024
char buf[BUF_SIZE];
int fd;
struct aiocb aiocb;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_1_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
memset(buf, 0xaa, BUF_SIZE);
memset(&aiocb, 0, sizeof(aiocb));
aiocb.aio_fildes = fd;
aiocb.aio_buf = buf;
aiocb.aio_nbytes = BUF_SIZE;
if (aio_write(&aiocb) == -1)
{
printf(TNAME " Error at aio_write(): %s\n",
strerror(errno));
return PTS_FAIL;
}
if (aio_cancel(fd, &aiocb) == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 2-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* if aiobcp is NULL, all outstanding cancelable AIO against fildes
* shall be canceled.
*
* method:
*
* open a file and queue a write to it with aio_write()
* execute aio_cancel() on this file
* check aio_cancel() is not -1
* -> aio_cancel() works on fildes used with an aio command
*
* we have no way to assert we generate "cancelable" AIO and thus to check
* if it has been really canceled
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/2-1.c"
int main()
{
char tmpfname[256];
#define BUF_SIZE 1024
char buf[BUF_SIZE];
int fd;
struct aiocb aiocb;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_2_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
memset(buf, 0xaa, BUF_SIZE);
memset(&aiocb, 0, sizeof(aiocb));
aiocb.aio_fildes = fd;
aiocb.aio_buf = buf;
aiocb.aio_nbytes = BUF_SIZE;
if (aio_write(&aiocb) == -1)
{
printf(TNAME " Error at aio_write(): %s\n",
strerror(errno));
return PTS_FAIL;
}
if (aio_cancel(fd, NULL) == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 2-2.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* if aiobcp is NULL, all outstanding cancelable AIO against fildes
* shall be canceled.
*
* method:
*
* open a file
* execute aio_cancel() on this file
* check aio_cancel() is not -1
* -> aio_cancel() works on standard fildes
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/2-2.c"
int main()
{
char tmpfname[256];
int fd;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_2_2_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
if (aio_cancel(fd, NULL) == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 6-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* aio_cancel() shall return AIO_CANCELED if the requested operations
* were canceled.
*
* method:
*
* queue a lot of aio_write() to a given fildes.
* try to cancel the last one submited
* if aio_error() is ECANCELED and aio_cancel() is AIO_CANCELED
* test is passed
* if aio_error() is ECANCELED and aio_cancel() is NOT AIO_CANCELED
* test is failed
* if there is no aio_error() with ECANCELED and
* aio_cancel() is AIO_CANCELED
* test is failed
* otherwise test is unresolved
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <malloc.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/6-1.c"
#define BUF_NB 128
#define BUF_SIZE 1024
int main()
{
char tmpfname[256];
int fd;
struct aiocb *aiocb[BUF_NB];
int i;
int in_progress;
int gret;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_6_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
/* create AIO req */
for (i = 0; i < BUF_NB; i++)
{
aiocb[i] = malloc(sizeof(struct aiocb));
if (aiocb[i] == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_fildes = fd;
aiocb[i]->aio_buf = malloc(BUF_SIZE);
if (aiocb[i]->aio_buf == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_nbytes = BUF_SIZE;
aiocb[i]->aio_offset = 0;
aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
if (aio_write(aiocb[i]) == -1)
{
printf(TNAME " loop %d: Error at aio_write(): %s\n",
i, strerror(errno));
return PTS_FAIL;
}
}
/* try to cancel the last one queued */
gret = aio_cancel(fd, aiocb[i-1]);
if (gret == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
do {
in_progress = 0;
for (i = 0; i < BUF_NB; i++)
{
int ret;
ret = (aio_error(aiocb[i]));
if (ret == -1)
{
printf(TNAME " Error at aio_error(): %s\n",
strerror(errno));
return PTS_FAIL;
}
else if (ret == EINPROGRESS)
in_progress = 1;
else if (ret == ECANCELED)
{
if (gret == AIO_CANCELED)
{
printf ("Test PASSED\n");
return PTS_PASS;
}
printf(TNAME " aio_cancel() is not AIO_CANCELED\n");
return PTS_FAIL;
}
}
} while (in_progress);
if (gret == AIO_CANCELED)
{
printf(TNAME " aio_cancel() is AIO_CANCELED without ECANCELED\n");
return PTS_FAIL;
}
return PTS_UNRESOLVED;
}
--- NEW FILE: 9-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* io_cancel() shall return -1 and set errno in all other case.
*
* method:
*
* call aio_cancel() with invalid parameter and check result is -1
* and errno is not 0
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/9-1.c"
int main()
{
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
if (aio_cancel(-1, NULL) != -1)
{
printf(TNAME " bad aio_cancel return value()\n");
return PTS_FAIL;
}
if (errno == 0)
{
printf(TNAME " bad errno value()\n");
return PTS_FAIL;
}
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 10-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/* assertion:
*
* aio_cancel() shall fail if:
* [EBADF] The fildes argument is not a valid descriptor.
*
* method:
*
* use -1 as fildes and check return value is -1 and errno is EBADF
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/10-1.c"
int main()
{
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
if (aio_cancel(-1, NULL) != -1)
{
printf(TNAME " bad aio_cancel return value()\n");
return PTS_FAIL;
}
if (errno != EBADF)
{
printf(TNAME " errno is not EBADF %s\n", strerror(errno));
return PTS_FAIL;
}
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 5-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* iocbp not successfully canceled shall not be modified
*
* method:
*
* queue a some aio_write() to a file descriptor
* cancel all operations for this file descriptor
* for all operations not canceled at end of operations
* verify that values in aiocb is the good ones
* if all operations are canceled, result is unresolved
* if some operation not canceled are modified, test fails
* if all operations not canceled (at least one) are good
* result is pass
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <malloc.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/5-1.c"
#define BUF_NB 128
#define BUF_SIZE 1024
int main()
{
char tmpfname[256];
int fd;
struct aiocb *aiocb[BUF_NB];
char *buf[BUF_NB];
int i;
int in_progress;
static int check_one;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_5_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
/* create AIO req */
for (i = 0; i < BUF_NB; i++)
{
aiocb[i] = malloc(sizeof(struct aiocb));
if (aiocb[i] == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
buf[i] = malloc(BUF_SIZE);
if (buf[i] == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_fildes = fd;
aiocb[i]->aio_buf = buf[i];
aiocb[i]->aio_nbytes = BUF_SIZE;
aiocb[i]->aio_offset = 0;
aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
if (aio_write(aiocb[i]) == -1)
{
printf(TNAME " loop %d: Error at aio_write(): %s\n",
i, strerror(errno));
return PTS_FAIL;
}
}
/* try to cancel all
* we hope to have enough time to cancel at least one
*/
if (aio_cancel(fd, NULL) == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
check_one = 0;
do {
in_progress = 0;
for (i = 0; i < BUF_NB; i++)
{
int ret;
ret = (aio_error(aiocb[i]));
if (ret == -1)
{
printf(TNAME " Error at aio_error(): %s\n",
strerror(errno));
return PTS_FAIL;
}
else if ((ret == EINPROGRESS) || (ret == 0))
{
if (ret == EINPROGRESS)
in_progress = 1;
check_one = 1;
/* check iocb is not modified */
if ( (aiocb[i]->aio_fildes != fd) ||
(aiocb[i]->aio_buf != buf[i]) ||
(aiocb[i]->aio_nbytes != BUF_SIZE) ||
(aiocb[i]->aio_offset != 0) ||
(aiocb[i]->aio_sigevent.sigev_notify
!= SIGEV_NONE) )
{
printf(TNAME " aiocbp modified\n");
return PTS_FAIL;
}
}
}
} while (in_progress);
if (!check_one)
return PTS_UNRESOLVED;
return PTS_PASS;
}
--- NEW FILE: coverage.txt ---
this file defines the coverage for the aio_cancel() function testing.
Assertion Covered?
1 YES
2 YES
3 YES *
4 YES *
5 YES +
6 YES *
7 YES *
8 YES
9 YES
10 YES
* can be unresolved, because:
- cancelable operations are implementation specific
- we have no way to be sure we try to cancel an operation that is not
already done or is in progress.
+ can be unresolved, because we must have at least one not canceled.
--- NEW FILE: 7-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* aio_cancel() shall return AIO_NOTCANCELED if at least one of the
* requested operations cannot be canceled because it is in progress.
*
* method:
*
* queue a lot of aio_write() to a given file descriptor
* then cancel all operation belonging to this file descriptor
* check result of each operation:
* - if aio_error() is EINPROGRESS and aio_cancel() is not AIO_NOTCANCELED
* result is failed
* - if aio_error() is succes (0) and aio_cancel() is AIO_NOTCANCELED
* result is susccess
* - otherwise result is unresolved
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <malloc.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/7-1.c"
#define BUF_NB 128
#define BUF_SIZE 1024
int main()
{
char tmpfname[256];
int fd;
struct aiocb *aiocb[BUF_NB];
int i;
int in_progress;
int gret;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_7_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
/* create AIO req */
for (i = 0; i < BUF_NB; i++)
{
aiocb[i] = malloc(sizeof(struct aiocb));
if (aiocb[i] == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_fildes = fd;
aiocb[i]->aio_buf = malloc(BUF_SIZE);
if (aiocb[i]->aio_buf == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_nbytes = BUF_SIZE;
aiocb[i]->aio_offset = 0;
aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
if (aio_write(aiocb[i]) == -1)
{
printf(TNAME " loop %d: Error at aio_write(): %s\n",
i, strerror(errno));
return PTS_FAIL;
}
}
/* try to cancel all
* we hope to have enough time to cancel at least one
*/
gret = aio_cancel(fd, NULL);
if (gret == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
do {
in_progress = 0;
for (i = 0; i < BUF_NB; i++)
{
int ret;
ret = (aio_error(aiocb[i]));
if (ret == -1)
{
printf(TNAME " Error at aio_error(): %s\n",
strerror(errno));
return PTS_FAIL;
}
else if (ret == EINPROGRESS)
{
/* at this point, all operations should be:
* canceled
* or in progress
* with aio_cancel() == AIO_NOTCANCELED
*/
if (gret != AIO_NOTCANCELED)
{
printf(TNAME " Error at aio_error(): %s\n", strerror(errno));
return PTS_FAIL;
}
in_progress = 1;
}
else if (ret == 0)
{
/* we seek one not canceled and check why.
* (perhaps) it has not been canceled
* because it was in progress
* during the cancel operation
*/
if (gret == AIO_NOTCANCELED)
{
printf ("Test PASSED\n");
return PTS_PASS;
}
}
}
} while (in_progress);
return PTS_UNRESOLVED;
}
--- NEW FILE: 8-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* aio_cancel() shall return AIO_ALLDONE if all operation have already
* completed
*
* method:
*
* execute one aio_write(), wait it is finished
* execute aio_cancel
* if result is AIO_ALLDONE, test is passed
* otherwise it is failed
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/1-1.c"
int main()
{
char tmpfname[256];
#define BUF_SIZE 1024
char buf[BUF_SIZE];
int fd;
struct aiocb aiocb;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_1_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
memset(buf, 0xaa, BUF_SIZE);
memset(&aiocb, 0, sizeof(aiocb));
aiocb.aio_fildes = fd;
aiocb.aio_buf = buf;
aiocb.aio_nbytes = BUF_SIZE;
if (aio_write(&aiocb) == -1)
{
printf(TNAME " Error at aio_write(): %s\n",
strerror(errno));
return PTS_FAIL;
}
while (aio_error(&aiocb) == EINPROGRESS);
if (aio_cancel(fd, &aiocb) != AIO_ALLDONE)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 3-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* Asynchronous notification shall occur for AIO that are successfully
* cancelled.
*
* method:
*
* we queue a lot of aio_write() with a valid sigevent to a file descriptor
* next we try to cancel all operations on this file descriptor
* we guess some have been finished, other are in progress,
* other are waiting
* we guess we can cancel all operations waiting
* then we analyze aio_error() in the event handler
* if aio_error() is ECANCELED, the test is passed
* otherwise, we don't know (perhaps we haven't cancel any operation ?)
* if number of sig event is not equal to number of aio_write()
* the test fails (in fact it hangs).
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <malloc.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/3-1.c"
#define BUF_NB 128
#define BUF_SIZE 1024
static volatile int countdown = BUF_NB;
static volatile int canceled = 0;
void sigusr1_handler(int signum, siginfo_t *info, void *context)
{
struct aiocb *a = info->si_value.sival_ptr;
if (aio_error(a) == ECANCELED)
canceled++;
aio_return(a); /* free entry */
free((void*)a->aio_buf);
free(a);
countdown--;
}
int main()
{
char tmpfname[256];
int fd;
struct aiocb *aiocb;
struct sigaction action;
int i;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_3_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
/* install signal handler */
action.sa_sigaction = sigusr1_handler;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO|SA_RESTART;
if (sigaction(SIGRTMIN+1, &action, NULL))
{
printf(TNAME " Error at sigaction(): %s\n",
strerror(errno));
return PTS_FAIL;
}
/* create AIO req */
for (i = 0; i < BUF_NB; i++)
{
aiocb = malloc(sizeof(struct aiocb));
if (aiocb == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_FAIL;
}
aiocb->aio_fildes = fd;
aiocb->aio_buf = malloc(BUF_SIZE);
if (aiocb->aio_buf == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_FAIL;
}
aiocb->aio_nbytes = BUF_SIZE;
aiocb->aio_offset = 0;
aiocb->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
aiocb->aio_sigevent.sigev_signo = SIGRTMIN+1;
aiocb->aio_sigevent.sigev_value.sival_ptr = aiocb;
if (aio_write(aiocb) == -1)
{
printf(TNAME " loop %d: Error at aio_write(): %s\n",
i, strerror(errno));
return PTS_FAIL;
}
}
/* try to cancel all
* we hope to have enough time to cancel at least one
*/
if (aio_cancel(fd, NULL) == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
while(countdown);
if (!canceled)
return PTS_UNRESOLVED;
printf ("Test PASSED\n");
return PTS_PASS;
}
--- NEW FILE: 4-1.c ---
/*
* Copyright (c) 2004, IBM Corporation. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/*
* assertion:
*
* Error status should be set to [ECANCELED] and return shall be -1 for
* successfully canceled AIO.
*
* method:
*
* we queue a lot of aio_write() operation to a file descriptor
* then we try to cancel all aio operation of this file descriptor
* we check with aio_error() state of each operation
* if aio_error() is ECANCELED and aio_return() is -1
* test is passed
* if aio_error() is ECANCELED and aio_return() is NOT -1
* test fails
* otherwise
* test is unresolved
*
*/
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <malloc.h>
#include <aio.h>
#include "posixtest.h"
#define TNAME "aio_cancel/4-1.c"
#define BUF_NB 128
#define BUF_SIZE 1024
int main()
{
char tmpfname[256];
int fd;
struct aiocb *aiocb[BUF_NB];
int i;
int in_progress;
#if _POSIX_ASYNCHRONOUS_IO != 200112L
return PTS_UNSUPPORTED;
#endif
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_4_1_%d",
getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
unlink(tmpfname);
/* create AIO req */
for (i = 0; i < BUF_NB; i++)
{
aiocb[i] = malloc(sizeof(struct aiocb));
if (aiocb[i] == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_fildes = fd;
aiocb[i]->aio_buf = malloc(BUF_SIZE);
if (aiocb[i]->aio_buf == NULL)
{
printf(TNAME " Error at malloc(): %s\n",
strerror(errno));
return PTS_UNRESOLVED;
}
aiocb[i]->aio_nbytes = BUF_SIZE;
aiocb[i]->aio_offset = 0;
aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
if (aio_write(aiocb[i]) == -1)
{
printf(TNAME " loop %d: Error at aio_write(): %s\n",
i, strerror(errno));
return PTS_FAIL;
}
}
/* try to cancel all
* we hope to have enough time to cancel at least one
*/
if (aio_cancel(fd, NULL) == -1)
{
printf(TNAME " Error at aio_cancel(): %s\n",
strerror(errno));
return PTS_FAIL;
}
close(fd);
do {
in_progress = 0;
for (i = 0; i < BUF_NB; i++)
{
int ret;
ret = (aio_error(aiocb[i]));
if (ret == -1)
{
printf(TNAME " Error at aio_error(): %s\n",
strerror(errno));
return PTS_FAIL;
}
else if (ret == EINPROGRESS)
in_progress = 1;
else if (ret == ECANCELED)
{
if (aio_return(aiocb[i]) == -1)
{
printf ("Test PASSED\n");
return PTS_PASS;
}
printf(TNAME " aio_return is not -1\n");
return PTS_FAIL;
}
}
} while (in_progress);
return PTS_UNRESOLVED;
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Ltp-cvs mailing list
Ltp-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic