following are the some of test cases if anyone has (idea) more test cases then plz share it
Three Test Cases
test case 1:
Give Bad file descriptor as input to the read and expect EBADF ,read return -1
test case 2:
Give descriptor of directory as input to the read and excpect EISDIR,read reurns -1
test case 3:
Give Bad address input to the read and excpect EFAULT,read reurns -1
Code for these test cases
/*
MIS NO-121122019
Testing Read System call
*/
#include
#include
#include
#include
int badfd=-1;
int fd2,fd3;
char buffer[1024];
struct test_case_t {
int *fd;
char *buf;
int error;
}TC[] = {
{&badfd,buffer,EBADF},
{&fd2,buffer,EISDIR},
{&fd3,(void *)-1,EFAULT}
};
int TST_TOTAL=sizeof(TC)/sizeof(*TC);
int main(int argc,char *argv[])
{
//badfd=-1 holding bad file descriptor
//fd2 for holding directory
//fd3 for holding normal file
int retval,i;
char ch;
if(argc < 2){
printf("\n Check arguments ..");
exit(1);
}
fd2=open(argv[1],O_RDONLY);
if(fd2 < 0) {
printf("\n Cant open directory ");
exit(1);
}
fd3=open(argv[2],O_RDONLY);
if(fd3 < 0) {
printf("\n Cant open directory ");
exit(1);
}
for(i = 0; i < TST_TOTAL; i++){
retval=read(*TC[i].fd,TC[i].buf,1);
if(retval != -1 && errno != TC[i].error)
{
return i+1;
} /*else {
printf("\n For test %d ---> retval = %d errno =%d",i+1,retval,errno);
}*/
}
return 0;
}
#shell file
#!/bin/bash
#test2 prepration create regular file
touch file
ls -l > file
#test3 prepration create directory
mkdir dir
# cc read01.c -o bad_fd_dir_addr
./bad_fd_dir_addr dir file
a=$?
if [ $a -eq 0 ] ; then
echo "TEST_CASE_SUCESS"
else
echo "TEST_CASE_FAILURE"
fi
rm file
rmdir dir
Thank You.
No comments:
Post a Comment