Commit a2c14dfe authored by 's avatar
Browse files

added extra error checkings & a new test in test suite

git-svn-id: file:///home/svn/mapi/trunk@1290 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 944d1d19
......@@ -2758,9 +2758,9 @@ int mapi_get_next_function_info(int fd,int fid, mapi_function_info_t *info)
host_flow* hflow;
flist_node_t* fnode;
function_data* fdata;
flowdescr_t* flow;
#endif
#ifdef RECONNECT
flowdescr_t* flow;
functdescr_t *f;
#endif
......@@ -2822,13 +2822,13 @@ int mapi_get_next_function_info(int fd,int fid, mapi_function_info_t *info)
}
#endif
#ifdef RECONNECT
if((flow = flist_get(flowlist, fd)) == NULL){
DEBUG_CMD(printf("Invalid flow: %d [%s:%d]\n", fd, __FILE__, __LINE__));
local_err = MAPI_INIT_ERROR;
return -1;
}
#ifdef RECONNECT
if((f = flist_get(flow->flist, fid)) == NULL){
local_err = MAPI_INVALID_FID_FUNCID;
return -1;
......@@ -2872,14 +2872,12 @@ int mapi_get_next_function_info(int fd,int fid, mapi_function_info_t *info)
int mapi_get_flow_info(int fd, mapi_flow_info_t *info)
{
struct mapiipcbuf qbuf;
flowdescr_t* flow;
#ifdef DIMAPI
remote_flowdescr_t* rflow;
host_flow* hflow;
flist_node_t* fnode;
#endif
#ifdef RECONNECT
flowdescr_t* flow;
#endif
if (!minit) {
DEBUG_CMD(printf("Not initialized! [%s:%d]\n",__FILE__,__LINE__));
......@@ -2933,13 +2931,11 @@ int mapi_get_flow_info(int fd, mapi_flow_info_t *info)
}
#endif
#ifdef RECONNECT
if((flow = flist_get(flowlist, fd)) == NULL){
DEBUG_CMD(printf("Invalid flow: %d [%s:%d]\n", fd, __FILE__, __LINE__));
local_err = MAPI_INVALID_FLOW;
return -1;
}
#endif
qbuf.mtype=1;
qbuf.cmd=GET_FLOW_INFO;
......@@ -2976,15 +2972,12 @@ int mapi_get_flow_info(int fd, mapi_flow_info_t *info)
int mapi_get_next_flow_info(int fd, mapi_flow_info_t *info)
{
struct mapiipcbuf qbuf;
flowdescr_t* flow;
#ifdef DIMAPI
remote_flowdescr_t* rflow;
host_flow* hflow;
flist_node_t* fnode;
#endif
#ifdef RECONNECT
flowdescr_t* flow;
#endif
// pthread_once(&mapi_is_initialized, (void*)mapi_init);
......@@ -3036,13 +3029,11 @@ int mapi_get_next_flow_info(int fd, mapi_flow_info_t *info)
}
#endif
#ifdef RECONNECT
if((flow = flist_get(flowlist, fd)) == NULL){
DEBUG_CMD(printf("Invalid flow: %d [%s:%d]\n", fd, __FILE__, __LINE__));
local_err = MAPI_INVALID_FLOW;
return -1;
}
#endif
qbuf.mtype=1;
qbuf.cmd=GET_NEXT_FLOW_INFO;
......
......@@ -161,6 +161,15 @@ DOT;
flag = 1;
}
}
DOT;
if(mapi_get_flow_info(12345, &info)<0){
mapi_read_error( &err_no, error);
printf("Testing error case2. Errorcode :%d description: %s \n" ,err_no, error);
if(err_no != 6145){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
}
DOT;
if ((fd = mapi_create_offline_flow("./tracefile" , MFF_PCAP))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
......
#include <stdio.h>
#include <unistd.h>
#include "mapi.h"
#include "test.h"
int main(MAPI_UNUSED int argc, char *argv[]){
int fd, fd_, ok;
mapi_flow_info_t info;
int err_no =0 , flag=0;
char error[512];
if(!argv[1]){
printf("\nwrong arguments\n");
return -1;
}
if ((fd_ = mapi_create_flow(argv[1]))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if ((fd = mapi_create_flow(argv[1]))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode:%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_connect(fd_)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd_);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_connect(fd)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_get_next_flow_info(fd_, &info))<0){
fprintf(stderr, "Getting flow info failed on fd:%d\n", fd_);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
printf("\nnext flow info : ");
printf("\n\t uid = %d", info.uid);
printf("\n\t fd = %d", info.fd);
printf("\n\t device = %s", info.device);
printf("\n\t num_functions: %u", info.num_functions);
printf("\n\t start = %lu", info.start);
printf("\n\t end = %lu", info.end);
printf("\n");
/*
* Sanity checks
*/
if(info.num_functions != 10)
fprintf(stderr, "WARNING: Sanity check failed %d functions found\n" , info.num_functions);
DOT;
if(mapi_close_flow(fd_)<0){
fprintf(stderr,"Close flow failed\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_close_flow(fd)<0){
fprintf(stderr,"Close flow failed\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
/*
* Wrong argument error checking
*/
fd = 0;
if(mapi_get_next_flow_info(fd, &info)<0){
mapi_read_error( &err_no, error);
printf("Testing error case0. Errorcode: %d description: %s \n" ,err_no, error);
if(err_no != 6145){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
}
DOT;
if ((fd = mapi_create_flow(argv[1]))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_get_next_flow_info(fd, NULL)<0){
mapi_read_error( &err_no, error);
printf("Testing error case1. Errorcode: %d description: %s \n" ,err_no, error);
if(err_no != 7002){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
}
DOT;
if(mapi_get_next_flow_info(12345, &info)<0){
mapi_read_error( &err_no, error);
printf("Testing error case2. Errorcode: %d description: %s \n" ,err_no, error);
if(err_no != 6145){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
}
DOT;
if(mapi_get_next_flow_info(fd, &info)<0){
mapi_read_error( &err_no, error);
printf("Testing error case3. Errorcode: %d description: %s \n" ,err_no, error);
if(err_no != 6149){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
}
DOT;
if ((fd_ = mapi_create_offline_flow("./tracefile" , MFF_PCAP))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if ((fd = mapi_create_offline_flow("./tracefile" , MFF_PCAP))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr,"Could not apply function PKT_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((ok = mapi_apply_function(fd, "BYTE_COUNTER"))<0){
fprintf(stderr,"Could not apply function BYTE_COUNTER\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_connect(fd)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_connect(fd_)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd_);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
info.num_functions=0;
DOT;
if((ok = mapi_get_next_flow_info(fd_, &info))<0){
fprintf(stderr, "Getting flow info failed on fd:%d\n", fd_);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
printf("\nnext flow info : ");
printf("\n\t uid = %d", info.uid);
printf("\n\t fd = %d", info.fd);
printf("\n\t device = %s", info.device);
printf("\n\t num_functions: %u", info.num_functions);
printf("\n\t start = %lu", info.start);
printf("\n\t end = %lu", info.end);
printf("\n");
/*
* Sanity checks
*/
if(info.num_functions != 4)
fprintf(stderr, "WARNING: Sanity check failed %d functions found\n" , info.num_functions);
DOT;
/*
* Wrong argument error checking
*/
if(mapi_get_next_flow_info(fd, &info)<0){
mapi_read_error( &err_no, error);
printf("Testing error case4. Errorcode: %d description: %s \n" ,err_no, error);
if(err_no != 6149){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
}
DOT;
if(mapi_close_flow(fd)<0){
fprintf(stderr,"Close flow failed\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_close_flow(fd_)<0){
fprintf(stderr,"Close flow failed\n");
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode: %d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(!flag)
printf("\nGet Next Flow Info Error Checking OK\n");
else
printf("\nGet Next Flow Info Error Checking FAILED\n");
return 0;
}
......@@ -112,7 +112,7 @@ DOT;
if( (res = mapi_get_next_function_info(12375, fid, &info)) !=0 ){
mapi_read_error( &err_no, error);
printf("Testing error case1: Errorcode :%d description: %s \n" ,err_no, error);
if(err_no != 6150){
if(err_no != 6141){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
......@@ -189,7 +189,7 @@ DOT;
printf("\n\t libname: %s", info.libname);
printf("\n\t devoid: %s", info.devtype);
printf("\n\t pkts: %llu", -info.pkts);
printf("\n\t passed_pkts: %llu", info.passed_pkts);
printf("\n\t passed_pkts: %llu\n", info.passed_pkts);
}
}
else{
......@@ -235,7 +235,7 @@ DOT;
if( (res = mapi_get_next_function_info(12375, fid, &info)) !=0 ){
mapi_read_error( &err_no, error);
printf("Testing error case4: Errorcode :%d description: %s \n" ,err_no, error);
if(err_no != 6150){
if(err_no != 6141){
printf(" Wrong ERRORCODE returned\n");
flag = 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment