ocs init
This commit is contained in:
429
plat/public/ut/asn.1/asntest.c
Normal file
429
plat/public/ut/asn.1/asntest.c
Normal file
@@ -0,0 +1,429 @@
|
||||
#include "./include/asn1.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
int test1();
|
||||
int test2();
|
||||
int test3();
|
||||
int test4();
|
||||
int test5();
|
||||
int test6();
|
||||
int test7();
|
||||
int test8();
|
||||
int test9();
|
||||
int test10();
|
||||
int test11();
|
||||
int test12();
|
||||
int showtlv(const char *tag_seq,ASN_BUF *asnbuf);
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
if(argc==2)
|
||||
{
|
||||
switch(atoi(argv[1]))
|
||||
{
|
||||
case 1:
|
||||
test1();
|
||||
break;
|
||||
case 2:
|
||||
test2();
|
||||
break;
|
||||
case 3:
|
||||
test3();
|
||||
break;
|
||||
case 4:
|
||||
test4();
|
||||
break;
|
||||
case 5:
|
||||
test5();
|
||||
break;
|
||||
case 6:
|
||||
test6();
|
||||
break;
|
||||
case 7:
|
||||
test7();
|
||||
break;
|
||||
case 8:
|
||||
test8();
|
||||
break;
|
||||
case 9:
|
||||
test9();
|
||||
break;
|
||||
case 10:
|
||||
test10();
|
||||
break;
|
||||
case 11:
|
||||
test11();
|
||||
break;
|
||||
case 12:
|
||||
test12();
|
||||
break;
|
||||
default:
|
||||
printf("Out of range!\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("Usage:asntest number\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test1() //Tag encoding/decoding test
|
||||
{
|
||||
u_char msg_buf[50];
|
||||
int len;
|
||||
ASN_BUF asnbuf;
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
|
||||
len=add_null("2",0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
if(get_null("2",&asnbuf)==1)
|
||||
printf("decoding correctly\n");
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
|
||||
len=add_null("32",0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
if(get_null("32",&asnbuf)==1)
|
||||
printf("decoding correctly\n");
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
|
||||
len=add_null("129",0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
if(get_null("129",&asnbuf)==1)
|
||||
printf("decoding correctly\n");
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
|
||||
len=add_null("2",0x80,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
if(get_null("2",&asnbuf)==1)
|
||||
printf("decoding correctly\n");
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
|
||||
len=add_null("32",0xC0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
if(get_null("32",&asnbuf)==1)
|
||||
printf("decoding correctly\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test2()
|
||||
{
|
||||
u_char msg_buf[1024],pvalue[1024];
|
||||
ASN_BUF asnbuf;
|
||||
|
||||
memset(pvalue,0xFF,1024);
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
add_tlv("1",0,pvalue,0,&asnbuf);
|
||||
showbuf(msg_buf,5);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
add_tlv("1",2,pvalue,0,&asnbuf);
|
||||
showbuf(msg_buf,5);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
add_tlv("1",128,pvalue,0,&asnbuf);
|
||||
showbuf(msg_buf,5);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
add_tlv("1",129,pvalue,0,&asnbuf);
|
||||
showbuf(msg_buf,5);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
add_tlv("1",257,pvalue,0,&asnbuf);
|
||||
showbuf(msg_buf,5);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("len=%d\n",get_tlv("1",pvalue,&asnbuf));
|
||||
return 1;
|
||||
}
|
||||
int test3()
|
||||
{
|
||||
u_char msg_buf[256];
|
||||
ASN_BUF asnbuf;
|
||||
char oid[20];
|
||||
int len;
|
||||
|
||||
//Boolean----->
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_bool("1",0,0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("decoded value:%d\n",get_bool("1",&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_bool("1",1,0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("decoded value:%d\n",get_bool("1",&asnbuf));
|
||||
//Integer----->
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_int("1",2,0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("decoded value:%d\n",get_int("1",&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_int("1",257,0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("decoded value:%d\n",get_int("1",&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_int("1",-2,0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("decoded value:%d\n",get_int("1",&asnbuf));
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_int("1",-259,0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("decoded value:%d\n",get_int("1",&asnbuf));
|
||||
|
||||
//Object Identifier----->
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_oid("1","2.100.6",0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
get_oid("1",oid,&asnbuf);
|
||||
printf("decoded value:%s\n",oid);
|
||||
|
||||
asn_encode(msg_buf,&asnbuf);
|
||||
len=add_oid("1","0.39.6",0,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
get_oid("1",oid,&asnbuf);
|
||||
printf("decoded value:%s\n",oid);
|
||||
return 1;
|
||||
}
|
||||
int test4() //encoding test
|
||||
{
|
||||
u_char msg_buf[256];
|
||||
int c1=0,c2=1;
|
||||
u_char d1[2]={0x22,0x22};
|
||||
u_char d2[2]={0x33,0x33};
|
||||
u_char b3[2]={0x44,0x44};
|
||||
u_char a2[2]={0x55,0x55};
|
||||
u_char a3[2]={0x66,0x66};
|
||||
int len;
|
||||
ASN_BUF asnbuf;
|
||||
|
||||
asn_encode_v3(msg_buf,128,&asnbuf);
|
||||
len=add_int("1.0.2-1",c1,0,&asnbuf);
|
||||
len=add_int("1.0.2-2",c2,0,&asnbuf);
|
||||
len=add_tlv("1.0.1-3.0",2,d1,0x80,&asnbuf);
|
||||
len=add_tlv("1.0.1-3.1",2,d2,0x80,&asnbuf);
|
||||
len=add_tlv("1.1",2,b3,0x80,&asnbuf);
|
||||
len=add_tlv("2",2,a2,0x80,&asnbuf);
|
||||
len=add_tlv("3",2,a3,0x80,&asnbuf);
|
||||
showbuf(msg_buf,len);
|
||||
printf("decode......\n");
|
||||
asn_decode(msg_buf,3,&asnbuf);
|
||||
showtlv("1.0.2-1",&asnbuf);
|
||||
showtlv("1.0.2-2",&asnbuf);
|
||||
showtlv("1.0.1-3.0",&asnbuf);
|
||||
showtlv("1.0.1-3.1",&asnbuf);
|
||||
showtlv("1.1",&asnbuf);
|
||||
showtlv("2",&asnbuf);
|
||||
showtlv("3",&asnbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test5() //decoding test(long length)
|
||||
{
|
||||
u_char msg_buf[256]={0xA5,0x80,
|
||||
0x82,0x80,
|
||||
0x83,0x02,0x00,0x00,
|
||||
0x00,0x00,
|
||||
0x00,0x00,
|
||||
0xA6,0x80,0x82,0x02,0x11,0x11,0x00,0x00};
|
||||
ASN_BUF asnbuf;
|
||||
asn_decode(msg_buf,2,&asnbuf);
|
||||
showtlv("5.2.3",&asnbuf);
|
||||
showtlv("6.2",&asnbuf);
|
||||
showtlv("5.2",&asnbuf);
|
||||
showtlv("6",&asnbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test6() //decoding test(indefinite length)
|
||||
{
|
||||
u_char msg_buf[256]={0xA5,0x80,
|
||||
0xA2,0x81,0x82,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
|
||||
0xA3,0x02,0x01,0x01,
|
||||
0x00,0x00,
|
||||
0xA6,0x80,0x82,0x02,0x11,0x11,0x00,0x00};
|
||||
ASN_BUF asnbuf;
|
||||
int temp;
|
||||
asn_decode_v3(msg_buf,256,&temp,&asnbuf);
|
||||
|
||||
showtlv("5.2",&asnbuf);
|
||||
showtlv("5.3",&asnbuf);
|
||||
showtlv("5",&asnbuf);
|
||||
showtlv("6.2",&asnbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int showtlv(const char *tag_seq,ASN_BUF *asnbuf)
|
||||
{
|
||||
u_char tlvbuf[256];
|
||||
int len;
|
||||
len=get_tlv(tag_seq,tlvbuf,asnbuf);
|
||||
showbuf(tlvbuf,len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test7() //decoding test(long length)
|
||||
{
|
||||
u_char msg_buf[256]={0x60,0x80,
|
||||
0x80,0x02,0x07,0x80,
|
||||
0xa1,0x80,
|
||||
0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x01,0x02,
|
||||
0x00,0x00,
|
||||
0x00,0x00};
|
||||
ASN_BUF asnbuf;
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
showtlv("0",&asnbuf);
|
||||
showtlv("0.0",&asnbuf);
|
||||
showtlv("0.1",&asnbuf);
|
||||
showtlv("0.1.6",&asnbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test8() //decoding test(long length)
|
||||
{
|
||||
u_char msg_buf[256]={0x10,0x03,0xaa,0xbb,0xcc};
|
||||
ASN_BUF asnbuf;
|
||||
asn_decode(msg_buf,1,&asnbuf);
|
||||
printf("tlvcount=%d\n",asnbuf.tlvcount);
|
||||
showtlv("16",&asnbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test9()
|
||||
{
|
||||
u_char msg_buf[256]={0x02,0x01,0xaa,
|
||||
0x04,0x02,0xbb,0xbb,
|
||||
0x04,0x02,0xcc,0xcc,
|
||||
0x04,0x02,0xdd,0xdd,
|
||||
0x02,0x01,0xaa,
|
||||
0x05,0x02,0x55,0xbb,
|
||||
0x05,0x02,0x55,0xcc,
|
||||
0x05,0x02,0x55,0xdd};
|
||||
// u_char mybuf[64];
|
||||
// int len;
|
||||
int temp;
|
||||
ASN_BUF asnbuf;
|
||||
asn_decode_v3(msg_buf,30,&temp,&asnbuf);
|
||||
|
||||
showtlv("2",&asnbuf);
|
||||
showtlv("4-2",&asnbuf);
|
||||
showtlv("4-3",&asnbuf);
|
||||
showtlv("4-4",&asnbuf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test10()
|
||||
{
|
||||
u_char msg_buf[256]={0xA0,0x80,
|
||||
0x04,0x01,0x21,
|
||||
0x30,0x80,
|
||||
0x30,0x80,
|
||||
0x83,0x01,0x11,
|
||||
0x84,0x01,0x07,
|
||||
0x85,0x05,0x81,0x21,0x84,0x00,0x94,
|
||||
0x86,0x01,0x00,
|
||||
0x00,0x00,
|
||||
0x00,0x00,
|
||||
0x00,0x00};
|
||||
u_char mybuf[64];
|
||||
int len;
|
||||
ASN_BUF asnbuf;
|
||||
if(asn_decode(msg_buf,1,&asnbuf)==-1)
|
||||
printf("decode error\n");
|
||||
|
||||
len=get_tlv("0",mybuf,&asnbuf);
|
||||
printf("0:");
|
||||
showbuf(mybuf,len);
|
||||
|
||||
len=get_tlv("0.4",mybuf,&asnbuf);
|
||||
printf("0.4:");
|
||||
showbuf(mybuf,len);
|
||||
|
||||
len=get_tlv("0.16",mybuf,&asnbuf);
|
||||
printf("0.16:");
|
||||
showbuf(mybuf,len);
|
||||
|
||||
len=get_tlv("0.16.16.5",mybuf,&asnbuf);
|
||||
printf("0.16.5:");
|
||||
showbuf(mybuf,len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test11()
|
||||
{
|
||||
u_char msg_buf[256]={0x64,0x6A,0x49
|
||||
,0x04,0x01,0x62,0x00,0x60,0x6B,0x80,0x28,0x80,0x06,0x07,0x00,0x11
|
||||
,0x86,0x05,0x01,0x01,0x01,0xA0,0x80,0x61,0x80,0x80,0x02,0x07,0x80
|
||||
,0xA1,0x80,0x06,0x07,0x04,0x00,0x00,0x01,0x00,0x05,0x02,0x00,0x00
|
||||
,0xA2,0x80,0x02,0x01,0x00,0x00,0x00,0xA3,0x80,0xA1,0x80,0x02,0x01
|
||||
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
,0x6C,0x26,0xA2,0x80,0x02,0x01,0x00,0x30,0x80,0x02,0x01,0x16,0x30
|
||||
,0x80,0x04,0x08,0x64,0x00,0x92,0x00,0x00,0x00,0x00,0xF1,0x04,0x08
|
||||
,0x91,0x44,0x57,0x25,0x31,0x06,0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
};
|
||||
// u_char mybuf[64];
|
||||
// int len;
|
||||
ASN_BUF asnbuf;
|
||||
if(asn_decode(msg_buf,1,&asnbuf)==-1)
|
||||
printf("decode error\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test12()
|
||||
{
|
||||
u_char msg_buf[256]={0xA1,0x0E,
|
||||
0x01,0x01,0x01,
|
||||
0x02,0x80,0x02,0x01,0x01,0x00,0x00,
|
||||
0x02,0x02,0x01,0x02
|
||||
};
|
||||
// u_char mybuf[64];
|
||||
// int len;
|
||||
ASN_BUF asnbuf;
|
||||
if(asn_decode(msg_buf,1,&asnbuf)==-1)
|
||||
printf("decode error\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
149
plat/public/ut/bisearch/bisearch_test.c
Normal file
149
plat/public/ut/bisearch/bisearch_test.c
Normal file
@@ -0,0 +1,149 @@
|
||||
|
||||
/******************************************/
|
||||
/*Title : bisearch.h */
|
||||
/*Descr : BiSearch arithmetic Tester */
|
||||
/*Author : Liu Wei */
|
||||
/*Create : 2006-12-13 */
|
||||
/*Version : R1V00_01 */
|
||||
/*Modify : 2006-12-13 */
|
||||
/******************************************/
|
||||
#include "../../iptrans/src/include/iptrans.h"
|
||||
#include "./include/bisearch.h"
|
||||
|
||||
FILE *fp = NULL;
|
||||
BiSearchArray bsearch_array;
|
||||
|
||||
|
||||
int GetIdleNode(int *nDUIndex)
|
||||
{
|
||||
if( bsearch_array.nArrayCount >= bsearch_array.nArrayTotalLen )
|
||||
return 0;
|
||||
*nDUIndex = (rand()*19)%bsearch_array.nArrayTotalLen;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void logarray ( BiSearchArray * pBiArray, char *op )
|
||||
{
|
||||
BiSearch *pBS;
|
||||
LL lastkey = 0;
|
||||
int nPos = -1;
|
||||
char buf[4096];
|
||||
char tmp_str[512];
|
||||
int i;
|
||||
buf[0] = '\0';
|
||||
|
||||
sprintf ( buf, "Array Contents:[total :%d]\n" , pBiArray->nArrayCount);
|
||||
for ( i = 0; i < pBiArray->nArrayTotalLen; i++ )
|
||||
{
|
||||
pBS = pBiArray->pBiArray + i;
|
||||
sprintf ( tmp_str, "{%-3u,(%-3llu,%-3u)} ", i, pBS->llKey, pBS->nDUPosIndex );
|
||||
strcat ( buf, tmp_str );
|
||||
if( i % 6 == 5 )
|
||||
{
|
||||
strcat ( buf, "\n" );
|
||||
}
|
||||
if( lastkey > pBS->llKey && i < pBiArray->nArrayCount )
|
||||
nPos = i;
|
||||
lastkey = pBS->llKey;
|
||||
}
|
||||
//if( nPos != -1 )
|
||||
{
|
||||
sprintf ( tmp_str, "\nERR Pos: %d\n\n", nPos );
|
||||
strcat ( buf, tmp_str );
|
||||
fprintf ( fp, buf );
|
||||
}
|
||||
}
|
||||
|
||||
#define log() logarray( &bsearch_array , op)
|
||||
|
||||
int main ( int argc, char *argv[] )
|
||||
{
|
||||
|
||||
char op[32];
|
||||
char buff[64];
|
||||
int i;
|
||||
srand((int)time(0));
|
||||
|
||||
if( ( fp = fopen ( "./log.txt", "w" ) ) == NULL )
|
||||
{
|
||||
printf ( "Open File Fail\n" );
|
||||
return 0;
|
||||
}
|
||||
fprintf ( fp, "======================\n" );
|
||||
fprintf ( fp, "|| BiSearch Test ||\n" );
|
||||
fprintf ( fp, "======================\n\n\n" );
|
||||
|
||||
for ( i = 0; i < 32; i++ )
|
||||
{
|
||||
op[i] = 'A' + ( i * 3 + 11 ) % 26;
|
||||
buff[i] = op[i] + ( i * 7 + 19 ) % 26;
|
||||
}
|
||||
|
||||
BISearchReg ( &bsearch_array, 64 ,GetIdleNode );
|
||||
|
||||
for ( i = 0; i < 30; i++ )
|
||||
{
|
||||
int key = ( ( i * 11 ) % 5 ) * ( i % 5 ) - 3 * ( i % 11 ) + 39;
|
||||
int value = (3 * i + 1)%bsearch_array.nArrayTotalLen;
|
||||
|
||||
fprintf ( fp, "Insert(%-3d, %-3d)\n", key, value );
|
||||
BISInsert ( &bsearch_array, key, value );
|
||||
log();
|
||||
}
|
||||
log();
|
||||
|
||||
for ( i = 0; i < 128; i++ )
|
||||
{
|
||||
int k = ( ( i * 11 ) % 7 ) * ( i % 9 ) - 3 * ( i % 13 ) + i * ( rand ( ) % 13 * 19 ) + 61;
|
||||
|
||||
k = k % 999;
|
||||
fprintf ( fp, "=====>>Insert(%d, %d)\n", k, 2 * i );
|
||||
BISInsert ( &bsearch_array, k, (2 * i+rand() % 13 * 19 + i*19)%bsearch_array.nArrayTotalLen);
|
||||
fprintf ( fp, "\n" );
|
||||
log();
|
||||
|
||||
k = ( ( 20 - i ) % 3 ) * 9 - ( 3 * ( 20 - i ) ) + 9*128;
|
||||
k = k % 999;
|
||||
fprintf ( fp, "search index: %d" , k );
|
||||
if( -1 != GetDUIndex( &bsearch_array ,k ) )
|
||||
{
|
||||
fprintf ( fp, "<<=====Delete Key %d\n", k );
|
||||
BISDelete ( &bsearch_array , k );
|
||||
}
|
||||
else
|
||||
fprintf ( fp, "<<=====Delete Fail , not found [%d]", k );
|
||||
fprintf ( fp, "\n" );
|
||||
log();
|
||||
|
||||
}
|
||||
|
||||
for( i = 0 ; i < 128 ; i++ )
|
||||
{
|
||||
int nDUIndex = 0;
|
||||
int k = ( ( i * 11 ) % 7 ) * ( i % 9 ) - 3 * ( i % 13 ) + i * ( rand ( ) % 13 * 19 ) + 61;
|
||||
|
||||
k = k % 999;
|
||||
BISSearchMng( &bsearch_array , BIS_INSERT , k , &nDUIndex );
|
||||
fprintf ( fp, "=====>>Insert(%d, %d)\n", k, nDUIndex );
|
||||
fprintf ( fp, "\n" );
|
||||
log();
|
||||
|
||||
k = ( ( i * 11 ) % 7 ) * ( i % 9 ) - 3 * ( i % 13 ) + i * ( rand ( ) % 13 * 19 ) + 61;
|
||||
k = k % 999;
|
||||
fprintf ( fp, "search index: %d" , k );
|
||||
if( -1 != GetDUIndex( &bsearch_array ,k ) )
|
||||
{
|
||||
fprintf ( fp, "<<=====Delete Key %d\n", k );
|
||||
BISSearchMng( &bsearch_array , BIS_DELETE , k ,&nDUIndex);
|
||||
}
|
||||
else
|
||||
fprintf ( fp, "<<=====Delete Fail , not found [%d]", k );
|
||||
|
||||
fprintf ( fp, "\n" );
|
||||
log();
|
||||
|
||||
}
|
||||
//fclose ( fp );
|
||||
BISearchUnReg ( &bsearch_array);
|
||||
return 0;
|
||||
}
|
||||
BIN
plat/public/ut/debug_api/debug
Normal file
BIN
plat/public/ut/debug_api/debug
Normal file
Binary file not shown.
125
plat/public/ut/debug_api/wxc_debug_test.c
Normal file
125
plat/public/ut/debug_api/wxc_debug_test.c
Normal file
@@ -0,0 +1,125 @@
|
||||
//////////////////////////////////////////////////
|
||||
//Title : wxc_debug.c
|
||||
//Auhtor : Liu Wei
|
||||
//Desc : wxc debug api implemetation
|
||||
//Created : 2007-05-01
|
||||
//Revision :
|
||||
//
|
||||
//Revision :
|
||||
//
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "stdio.h"
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
|
||||
void dump(int signo)
|
||||
{
|
||||
char buf[1024];
|
||||
char cmd[1024];
|
||||
FILE *fh;
|
||||
|
||||
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", getpid());
|
||||
if(!(fh = fopen(buf, "r")))
|
||||
exit(0);
|
||||
if(!fgets(buf, sizeof(buf), fh))
|
||||
exit(0);
|
||||
fclose(fh);
|
||||
if(buf[strlen(buf) - 1] == '\n')
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
snprintf(cmd, sizeof(cmd), "gdb %s %d", buf, getpid());
|
||||
system(cmd);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void WxcBackTrace()
|
||||
{
|
||||
int i;
|
||||
void * array[25];
|
||||
int nSize = backtrace(array, 25);
|
||||
char ** symbols = backtrace_symbols(array, nSize);
|
||||
|
||||
for (i = 0; i < nSize; i++)
|
||||
{
|
||||
printf("%s \n" , symbols[i]);
|
||||
}
|
||||
free(symbols);
|
||||
}
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
#define WxcAssert(uVal,pStr) \
|
||||
if(!(uVal)) \
|
||||
{ \
|
||||
WxcBackTrace(); \
|
||||
} \
|
||||
assert( uVal && pStr ); \
|
||||
|
||||
void sprintf_bcd( const BYTE *pBcdBuff , int nBcdLen , char *pStrBuff , int nStrBuffSize )
|
||||
{
|
||||
int i ,len = 0;
|
||||
int nChar;
|
||||
|
||||
nChar = ( nBcdLen % 8 )* 3 + ( nBcdLen / 8 ) * 25 + 1 ;
|
||||
|
||||
WxcAssert((nChar < nStrBuffSize),"sprint bcd string buffer flow");
|
||||
|
||||
for( i = 1 ; i <= nBcdLen; i ++ )
|
||||
{
|
||||
sprintf ( pStrBuff + len , "%02X ", pBcdBuff[i-1] );
|
||||
len += 3;
|
||||
if( 0 == (i % 16) )
|
||||
{
|
||||
strcat ( pStrBuff , "\n");
|
||||
len++;
|
||||
}
|
||||
else if( 0 == (i % 8) )
|
||||
{
|
||||
strcat ( pStrBuff , " ");
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if( 0 != (len % 50) )
|
||||
{
|
||||
strcat ( pStrBuff , "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void testdump(char *p)
|
||||
{
|
||||
*p =0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
BYTE aBCDBuff[128];
|
||||
char temp[256] ;
|
||||
int i , j;
|
||||
char *p ;
|
||||
|
||||
p = NULL;
|
||||
|
||||
signal(SIGSEGV, &dump);
|
||||
|
||||
for( i = 0 ; i < 128 ; i ++ )
|
||||
{
|
||||
if( i < 80 )
|
||||
aBCDBuff[i] = (BYTE)(1 + i) ;
|
||||
else
|
||||
aBCDBuff[i] = (BYTE)(256 - i*2) ;
|
||||
}
|
||||
|
||||
for( j = 30 ; j < 100 ; j+=7 )
|
||||
{
|
||||
sprintf_bcd(aBCDBuff , j , temp , 256 );
|
||||
printf("BCD:\r\n%s\r\n", temp);
|
||||
}
|
||||
|
||||
testdump(p);
|
||||
getchar();
|
||||
}
|
||||
87
plat/public/ut/function.c
Normal file
87
plat/public/ut/function.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/* public function c file */
|
||||
/* written by Liu Zhiguo 2002-03-26 */
|
||||
/* version 1.0 */
|
||||
/* -------------------------------- */
|
||||
|
||||
#include "./include/includes.h"
|
||||
#include "./include/public.h"
|
||||
#include "./include/pub_debug.h"
|
||||
|
||||
# ifndef S_SPLINT_S
|
||||
/*@ignore@*/
|
||||
/* ++++++++++++++++++++++++++++++++++++++ */
|
||||
/* transfer ascii code to bcd code */
|
||||
/* ++++++++++++++++++++++++++++++++++++++ */
|
||||
/*
|
||||
void AsciiToBcd (BYTE *bcd_buf, const char *ascii_buf, int len)
|
||||
{
|
||||
int i;
|
||||
char ch;
|
||||
char flag=0;
|
||||
|
||||
if (ascii_buf == NULL)
|
||||
{
|
||||
for (i=0;i<len/2;i++)
|
||||
bcd_buf[i] = 0;
|
||||
bcd_buf[len/2] = '\0';
|
||||
return;
|
||||
}
|
||||
if (len & 1)
|
||||
{
|
||||
bcd_buf[0] = 0;
|
||||
flag = 1;
|
||||
}
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
ch = ascii_buf[i];
|
||||
if (ch>='a')
|
||||
ch -= 'a' - 10;
|
||||
else if (ch>='A')
|
||||
ch -= 'A' - 10;
|
||||
else
|
||||
ch -= '0';
|
||||
if (flag)
|
||||
{
|
||||
if (i & 1)
|
||||
*bcd_buf = ch << 4;
|
||||
else
|
||||
*(bcd_buf++) |= ch & 0x0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i & 1)
|
||||
*(bcd_buf++) |= ch & 0x0f;
|
||||
else
|
||||
*bcd_buf = ch << 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
/* ++++++++++++++++++++++++++++++++++++++ */
|
||||
/* transfer bcd code to ascii code */
|
||||
/* ++++++++++++++++++++++++++++++++++++++ */
|
||||
/*
|
||||
void BcdToAscii (char *ascii_buf, const BYTE *bcd_buf, int len)
|
||||
{
|
||||
int i;
|
||||
char ch;
|
||||
|
||||
if (bcd_buf == NULL)
|
||||
{
|
||||
for (i=0;i<len;i++)
|
||||
ascii_buf[i] = '0';
|
||||
ascii_buf[len] = '\0';
|
||||
return;
|
||||
}
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
if (i & 1) ch = *(bcd_buf++) & 0x0f;
|
||||
else ch = *bcd_buf >> 4;
|
||||
ascii_buf[i] = ch + ((ch > 9)? 'A'-10 : '0');
|
||||
}
|
||||
ascii_buf[i] = '\0';
|
||||
}
|
||||
*/
|
||||
|
||||
/*@end@*/
|
||||
#endif
|
||||
648
plat/public/ut/inet/pub_inet_test.c
Normal file
648
plat/public/ut/inet/pub_inet_test.c
Normal file
@@ -0,0 +1,648 @@
|
||||
//////////////////////////////////////////////////
|
||||
//Title : pub_inet_test.c
|
||||
//Auhtor : Liu Wei
|
||||
//Desc : public ipnet function test
|
||||
//Created : 2007-06-22
|
||||
//Revision :
|
||||
//
|
||||
//Revision :
|
||||
//
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <netdb.h>
|
||||
#include <setjmp.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
|
||||
#define MAXINTERFACES 16
|
||||
|
||||
typedef struct EIF
|
||||
{
|
||||
u32 dIfIP;
|
||||
u8 uIfState;
|
||||
}
|
||||
EIF;
|
||||
|
||||
typedef struct IF_ADDR
|
||||
{
|
||||
EIF tIfEntity[MAXINTERFACES];
|
||||
u8 uIfNum;
|
||||
}
|
||||
IfAddr;
|
||||
|
||||
int GetNetIfInfo ( IfAddr * pIfAddr )
|
||||
{
|
||||
int fd;
|
||||
struct ifreq buf[MAXINTERFACES];
|
||||
struct arpreq arp;
|
||||
struct ifconf ifc;
|
||||
|
||||
pIfAddr->uIfNum = 0;
|
||||
|
||||
if( ( fd = socket ( AF_INET, SOCK_DGRAM, 0 ) ) >= 0 )
|
||||
{
|
||||
ifc.ifc_len = sizeof buf;
|
||||
ifc.ifc_buf = ( caddr_t ) buf;
|
||||
if( !ioctl ( fd, SIOCGIFCONF, ( char * ) &ifc ) )
|
||||
{
|
||||
int i;
|
||||
|
||||
pIfAddr->uIfNum = ifc.ifc_len / sizeof ( struct ifreq );
|
||||
pIfAddr->uIfNum = pIfAddr->uIfNum % MAXINTERFACES;
|
||||
for ( i = 0; i < pIfAddr->uIfNum; i++ )
|
||||
{
|
||||
ioctl ( fd, SIOCGIFFLAGS, ( char * ) &buf[i] );
|
||||
pIfAddr->tIfEntity[i].uIfState = buf[i].ifr_flags & IFF_UP;
|
||||
if( !( ioctl ( fd, SIOCGIFADDR, ( char * ) &buf[i] ) ) )
|
||||
{
|
||||
pIfAddr->tIfEntity[i].dIfIP = ( ( struct sockaddr_in * )
|
||||
( &buf[i].ifr_addr ) )->sin_addr.s_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
close ( fd );
|
||||
return pIfAddr->uIfNum;
|
||||
}
|
||||
|
||||
|
||||
#define PACKET_SIZE 4096
|
||||
#define MAX_NO_PACKETS 3
|
||||
|
||||
struct sockaddr_in dest_addr;
|
||||
struct sockaddr_in from;
|
||||
struct timeval tvrecv;
|
||||
|
||||
typedef void PingCallBack( int nPingResult );
|
||||
|
||||
typedef struct ICMP_SERVICE
|
||||
{
|
||||
u8 uSrvState;
|
||||
u8 uPingResult;
|
||||
u8 uIcmpState;
|
||||
u8 uPackNo;
|
||||
u8 uDataLen;
|
||||
u8 nPackNumSend;
|
||||
u8 nPackNumRecv;
|
||||
u8 aSendBuff[PACKET_SIZE];
|
||||
u8 aRecvBuff[PACKET_SIZE];
|
||||
u32 wSockfd;
|
||||
pid_t tPid;
|
||||
struct protoent *pProtoent;
|
||||
PingCallBack *fCallBack;
|
||||
}
|
||||
IcmpSrv;
|
||||
|
||||
IcmpSrv tIcmpSrvEntity;
|
||||
|
||||
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD>㷨
|
||||
u16 IcmpCheckSum ( u16 *addr, int len )
|
||||
{
|
||||
int nleft = len;
|
||||
int sum = 0;
|
||||
u16 *w = addr;
|
||||
u16 answer = 0;
|
||||
|
||||
//<2F><>ICMP<4D><50>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA>λ<EFBFBD>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
while ( nleft > 1 )
|
||||
{
|
||||
sum += *w++;
|
||||
nleft -= 2;
|
||||
}
|
||||
|
||||
//<2F><>ICMP<4D><50>ͷΪ<CDB7><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ֽڡ<D6BD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ϊһ<CEAA><D2BB>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵĸ<DDB5><C4B8>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݵĵ<DDB5><C4B5>ֽ<EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
|
||||
if( nleft == 1 )
|
||||
{
|
||||
*( unsigned char * ) ( &answer ) = *( unsigned char * ) w;
|
||||
sum += answer;
|
||||
}
|
||||
|
||||
sum = ( sum >> 16 ) + ( sum & 0xffff );
|
||||
sum += ( sum >> 16 );
|
||||
answer = ~sum;
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ICMP<4D><50>ͷ
|
||||
int IcmpPacking ( IcmpSrv *pIS )
|
||||
{
|
||||
int i, packsize;
|
||||
struct icmp *icmp;
|
||||
struct timeval *tval;
|
||||
|
||||
icmp = ( struct icmp * ) pIS->aSendBuff;
|
||||
icmp->icmp_type = ICMP_ECHO;
|
||||
icmp->icmp_code = 0;
|
||||
icmp->icmp_cksum = 0;
|
||||
icmp->icmp_seq = pIS->nPackNumSend;
|
||||
icmp->icmp_id = pIS->tPid;
|
||||
packsize = 8 + pIS->uDataLen;
|
||||
|
||||
//<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
tval = ( struct timeval * ) icmp->icmp_data;
|
||||
gettimeofday ( tval, NULL );
|
||||
|
||||
icmp->icmp_cksum = IcmpCheckSum ( (u16 *)icmp, packsize );
|
||||
|
||||
return packsize;
|
||||
}
|
||||
|
||||
//<2F><>ȥICMP<4D><50>ͷ
|
||||
int IcmpUnPack ( u8 *buf, int len , IcmpSrv *pIS )
|
||||
{
|
||||
int i, nIpHdrLen;
|
||||
struct ip *pIP;
|
||||
struct icmp *icmp;
|
||||
struct timeval *tvSend;
|
||||
struct timeval tvRecv;
|
||||
double rtt;
|
||||
|
||||
|
||||
gettimeofday ( &tvRecv, NULL );
|
||||
pIP = ( struct ip * ) buf;
|
||||
//<2F><>ip<69><70>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>,<2C><>ip<69><70>ͷ<EFBFBD>ij<EFBFBD><C4B3>ȱ<EFBFBD>־<EFBFBD><D6BE>4
|
||||
nIpHdrLen = pIP->ip_hl << 2;
|
||||
|
||||
//Խ<><D4BD>ip<69><70>ͷ,ָ<><D6B8>ICMP<4D><50>ͷ
|
||||
icmp = ( struct icmp * ) ( buf + nIpHdrLen );
|
||||
|
||||
//ICMP<4D><50>ͷ<EFBFBD><CDB7>ICMP<4D><50><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
|
||||
len -= nIpHdrLen;
|
||||
|
||||
if( len < 8 )
|
||||
//С<><D0A1>ICMP<4D><50>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B2BBBA><EFBFBD>
|
||||
{
|
||||
printf ( "ICMP packets's length is less than 8 " );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ICMP<4D>Ļ<EFBFBD>Ӧ
|
||||
if( ( icmp->icmp_type == ICMP_ECHOREPLY ) && ( icmp->icmp_id == pIS->tPid ) )
|
||||
{
|
||||
tvSend = ( struct timeval * ) icmp->icmp_data;
|
||||
|
||||
rtt = ( tvRecv.tv_sec * 1000 + tvRecv.tv_usec / 1000 ) -
|
||||
( tvSend->tv_sec * 1000 + tvSend->tv_usec / 1000 );
|
||||
|
||||
printf ( "%d byte from %s: icmp_seq=%u ttl=%d rtt=%.3f ms \n"
|
||||
, len, inet_ntoa ( from.sin_addr )
|
||||
, icmp->icmp_seq, pIP->ip_ttl, rtt
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IcmpStatis ( IcmpSrv *pIS )
|
||||
{
|
||||
int nSend , nRecv ;
|
||||
|
||||
nSend = pIS->nPackNumSend;
|
||||
nRecv = pIS->nPackNumRecv;
|
||||
|
||||
printf ( " --------------------PING statistics------------------- \n" );
|
||||
printf ( "%d packets transmitted, %d received , %%%d lost \n\n"
|
||||
, nSend, nRecv, ( nSend - nRecv ) / nSend * 100 );
|
||||
close ( pIS->wSockfd );
|
||||
pIS->uSrvState = 0;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D><50><EFBFBD><EFBFBD>
|
||||
int IcmpSend ( IcmpSrv *pIS )
|
||||
{
|
||||
int nSize;
|
||||
|
||||
if ( pIS->nPackNumSend < MAX_NO_PACKETS )
|
||||
{
|
||||
pIS->nPackNumSend++;
|
||||
nSize = IcmpPacking ( pIS );
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ICMP<4D><50>ͷ
|
||||
if( sendto ( pIS->wSockfd, pIS->aSendBuff, nSize, 0,
|
||||
( struct sockaddr * ) &dest_addr, sizeof ( dest_addr ) ) < 0 )
|
||||
{
|
||||
perror ( "sendto error" );
|
||||
return 0;
|
||||
}
|
||||
printf("[IcmpSend] : Send icmp Pack %d \n" , pIS->nPackNumSend);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D><50><EFBFBD><EFBFBD>
|
||||
void IcmpRecv ( IcmpSrv *pIS )
|
||||
{
|
||||
int n, fromlen;
|
||||
extern int errno;
|
||||
|
||||
|
||||
fromlen = sizeof ( from );
|
||||
while ( pIS->nPackNumRecv < pIS->nPackNumSend )
|
||||
{
|
||||
if( ( n = recvfrom ( pIS->wSockfd, pIS->aRecvBuff, sizeof ( pIS->aRecvBuff ),
|
||||
0, ( struct sockaddr * ) &from, &fromlen ) ) < 0 )
|
||||
|
||||
{
|
||||
if( errno == EINTR )
|
||||
continue;
|
||||
perror ( "recvfrom error" );
|
||||
continue;
|
||||
}
|
||||
if( IcmpUnPack ( pIS->aRecvBuff, n , pIS ) == -1 )
|
||||
continue;
|
||||
pIS->nPackNumRecv++;
|
||||
}
|
||||
}
|
||||
|
||||
int PingInit ( IcmpSrv *pIS , int nDataLen )
|
||||
{
|
||||
memset( pIS , 0 , sizeof(IcmpSrv) );
|
||||
pIS->uSrvState = 0;
|
||||
|
||||
pIS->uDataLen = 56;
|
||||
|
||||
|
||||
if( ( pIS->pProtoent = getprotobyname ( "icmp" ) ) == NULL )
|
||||
{
|
||||
perror ( "getprotobyname" );
|
||||
exit ( 1 );
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>rootȨ<74><C8A8>,<2C><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD>û<EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
setuid ( getuid ( ) );
|
||||
|
||||
//<2F><>ȡmain<69>Ľ<EFBFBD><C4BD><EFBFBD>id,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ICMP<4D>ı<EFBFBD>־<EFBFBD><D6BE>
|
||||
pIS->tPid = getpid ( );
|
||||
|
||||
}
|
||||
|
||||
|
||||
int PingTimer ( IcmpSrv *pIS )
|
||||
{
|
||||
if( pIS->uSrvState )
|
||||
{
|
||||
IcmpRecv( pIS );
|
||||
switch( pIS->uIcmpState )
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
IcmpSend( pIS );
|
||||
pIS->uIcmpState++;
|
||||
break;
|
||||
default:
|
||||
if( pIS->nPackNumRecv >= 3 )
|
||||
{
|
||||
IcmpStatis( pIS );
|
||||
pIS->fCallBack( 1 );
|
||||
}
|
||||
if( pIS->uIcmpState++ > 200 )
|
||||
{
|
||||
IcmpStatis( pIS );
|
||||
pIS->fCallBack( 0 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int PingStart( IcmpSrv *pIS , char *sIP , PingCallBack fCallBack )
|
||||
{
|
||||
int nSize;
|
||||
struct hostent *pHost;
|
||||
//struct in_addr *pInAddr;
|
||||
u32 nInetAddr;
|
||||
|
||||
|
||||
if( pIS->uSrvState )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pIS->fCallBack = fCallBack;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ICMP<4D><50>ԭʼ<D4AD><EFBFBD><D7BD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>ֻ<EFBFBD><D6BB>root<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( ( pIS->wSockfd = socket ( AF_INET, SOCK_RAW, pIS->pProtoent->p_proto ) ) < 0 )
|
||||
{
|
||||
perror ( "socket error" );
|
||||
exit ( 1 );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD>ֽ<EFBFBD><D6BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>50K<30><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪΪ<D2AA>˼<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ping<6E><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>
|
||||
setsockopt ( pIS->wSockfd, SOL_SOCKET, SO_RCVBUF, &nSize, sizeof ( nSize ) );
|
||||
bzero ( &dest_addr, sizeof ( dest_addr ) );
|
||||
dest_addr.sin_family = AF_INET;
|
||||
|
||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip<69><70>ַ
|
||||
nInetAddr = inet_addr ( sIP ) ;
|
||||
if( nInetAddr == INADDR_NONE )
|
||||
{
|
||||
if( ( pHost = gethostbyname ( sIP ) ) == NULL ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
perror ( "gethostbyname error" );
|
||||
exit ( 1 );
|
||||
}
|
||||
memcpy ( ( char * ) &dest_addr.sin_addr, pHost->h_addr, pHost->h_length );
|
||||
}
|
||||
else //<2F><>ip<69><70>ַ
|
||||
{
|
||||
dest_addr.sin_addr.s_addr = nInetAddr;
|
||||
//memcpy( (char *)&dest_addr,(char *)&nInetAddr,host->h_length);
|
||||
}
|
||||
printf ( "PING %s(%s): %d bytes data in ICMP packets. \n", sIP
|
||||
, inet_ntoa ( dest_addr.sin_addr ) , pIS->uDataLen );
|
||||
|
||||
pIS->uSrvState = 1 ;
|
||||
pIS->uIcmpState = 1;
|
||||
|
||||
}
|
||||
|
||||
//<2F><>ӡip<69><70><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>Ϣ
|
||||
void printIP ( char *packet, int len )
|
||||
{
|
||||
struct sockaddr_in addr_src, addr_dst;
|
||||
struct ip *pip = ( struct ip * ) packet;
|
||||
|
||||
printf ( "ip head len:%d ", pip->ip_hl << 2 );
|
||||
printf ( "ip len:%d ", ntohs ( pip->ip_len ) );
|
||||
printf ( "ip pro id:%d ", pip->ip_p );
|
||||
printf ( "ip ttl:%d ", pip->ip_ttl );
|
||||
printf ( "ip offset:%d ", ntohs ( pip->ip_off ) & IP_OFFMASK );
|
||||
|
||||
memset ( &addr_src, 0, sizeof ( struct sockaddr_in ) );
|
||||
memset ( &addr_dst, 0, sizeof ( struct sockaddr_in ) );
|
||||
memcpy ( &addr_src, &pip->ip_src, sizeof ( struct sockaddr_in ) );
|
||||
memcpy ( &addr_dst, &pip->ip_dst, sizeof ( struct sockaddr_in ) );
|
||||
printf ( "src ip:%x ", addr_src.sin_addr );
|
||||
printf ( "dst ip:%x ", addr_dst.sin_addr );
|
||||
}
|
||||
|
||||
void NetCapPing( int nRet )
|
||||
{
|
||||
if( nRet )
|
||||
{
|
||||
printf("Host is rearchable\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Host is not rearchable\n");
|
||||
}
|
||||
}
|
||||
|
||||
static char *pStrEqTok = NULL;
|
||||
static u8 uStrEqState = 0;
|
||||
|
||||
#define CNULL '\0'
|
||||
#define STR_CHECK_END(str,ch) ( str[strlen(str)-1] == ch )
|
||||
#define STR_CUT_LAST(str) ( str[strlen(str)-1] = CNULL )
|
||||
|
||||
void StrTrimMoreSpace(char *pStr )
|
||||
{
|
||||
char *pSrc , *pDst , *pCh;
|
||||
|
||||
pDst = pStr;
|
||||
pCh = pSrc = strdup( pStr );
|
||||
|
||||
for( ; *pSrc ; pSrc++ )
|
||||
{
|
||||
if( !( isspace(*pSrc) && isspace( *(pSrc+1) ) ) )
|
||||
{
|
||||
*pDst++ = *pSrc;
|
||||
}
|
||||
}
|
||||
*pDst = CNULL;
|
||||
}
|
||||
|
||||
char *StrEqTok( char *pStr )
|
||||
{
|
||||
char *p, *pCh;
|
||||
char *pDel = " ";
|
||||
|
||||
pCh = NULL;
|
||||
|
||||
if( pStr == NULL )
|
||||
{
|
||||
pStr = pStrEqTok;
|
||||
}
|
||||
else
|
||||
{
|
||||
pStr += strspn (pStr, pDel);
|
||||
if (*pStr == '\0')
|
||||
{
|
||||
pStrEqTok = NULL;
|
||||
return NULL;
|
||||
}
|
||||
StrTrimMoreSpace( pStr );
|
||||
}
|
||||
|
||||
if( pStr == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uStrEqState = uStrEqState > 2 ? 0 : uStrEqState;
|
||||
|
||||
pCh = strpbrk (pStr, pDel );
|
||||
if( pCh == NULL )
|
||||
{
|
||||
pStrEqTok = NULL;
|
||||
pCh = pStr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pStrEqTok = pCh + 1;
|
||||
*pCh = CNULL;
|
||||
pCh = pStr;
|
||||
}
|
||||
|
||||
p = strchr( pCh , '=');
|
||||
if( p == NULL )
|
||||
{
|
||||
if( pStrEqTok == NULL )
|
||||
{
|
||||
goto STREQTOK_CLEAN_UP;
|
||||
}
|
||||
|
||||
if( uStrEqState == 0 || uStrEqState == 2 )
|
||||
{ //expres left and right
|
||||
uStrEqState++;
|
||||
return pCh;
|
||||
}
|
||||
else
|
||||
{ //Miss '='
|
||||
goto STREQTOK_CLEAN_UP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( uStrEqState == 0 && STR_CHECK_END( pCh , '=') )
|
||||
{ //expres left and '='
|
||||
uStrEqState+=2;
|
||||
STR_CUT_LAST(pCh);
|
||||
return pCh;
|
||||
}
|
||||
else if( uStrEqState == 1 && pCh[0] == '=')
|
||||
{ //'=' meet
|
||||
if( pCh[1] == CNULL )
|
||||
{
|
||||
if( pStrEqTok == NULL )
|
||||
{
|
||||
goto STREQTOK_CLEAN_UP;
|
||||
}
|
||||
pStr = pStrEqTok;
|
||||
pCh = strpbrk (pStr, pDel);
|
||||
if( pCh == NULL )
|
||||
{
|
||||
pStrEqTok = NULL;
|
||||
pCh = pStr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pStrEqTok = pCh + 1;
|
||||
*pCh = CNULL;
|
||||
pCh = pStr;
|
||||
}
|
||||
uStrEqState = 3;
|
||||
return pCh;
|
||||
|
||||
}
|
||||
else
|
||||
{ //expres '=' and right
|
||||
uStrEqState = 3; //all meet
|
||||
return ++pCh;
|
||||
}
|
||||
}
|
||||
else if( uStrEqState == 0 )
|
||||
{ //expres left and '=' and right
|
||||
if( pStrEqTok != NULL )
|
||||
{
|
||||
*(pStrEqTok -1) = ' ';
|
||||
}
|
||||
pStrEqTok = p + 1;
|
||||
*p = CNULL;
|
||||
uStrEqState = 2;
|
||||
return pCh;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto STREQTOK_CLEAN_UP;
|
||||
}
|
||||
}
|
||||
STREQTOK_CLEAN_UP:
|
||||
pStrEqTok = NULL;
|
||||
uStrEqState = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int main ( )
|
||||
{
|
||||
int i, ret = 0;
|
||||
IfAddr tIfAddr;
|
||||
IcmpSrv tIcmpSrv;
|
||||
char tmpStr[80];
|
||||
|
||||
ret = GetNetIfInfo ( &tIfAddr );
|
||||
|
||||
printf ( "Interface num :%d \n\n", ret );
|
||||
for ( i = 0; i < ret; i++ )
|
||||
{
|
||||
printf ( "If %d : state : %d ip : %s \n\n"
|
||||
, i, tIfAddr.tIfEntity[i].uIfState
|
||||
, inet_ntoa ( *((struct in_addr* )&tIfAddr.tIfEntity[i].dIfIP ))
|
||||
);
|
||||
}
|
||||
|
||||
#define STR(s) #s
|
||||
printf(STR(if(NOTSO(a)) return 0\n));
|
||||
|
||||
#define FPOS( type, field ) /*lint -e545 */ ( (u32) &(( type *) 0)-> field ) /*lint +e545 */
|
||||
|
||||
|
||||
#define FSIZ( type, field ) sizeof( ((type *) 0)->field )
|
||||
|
||||
printf("Pos : %ld \n" , FPOS(IfAddr ,uIfNum ) );
|
||||
printf("Size : %ld \n" , FSIZ(IfAddr ,uIfNum ) );
|
||||
printf("Pos : %ld \n" , FPOS(IfAddr ,tIfEntity ) );
|
||||
printf("Size : %ld \n" , FSIZ(IfAddr ,tIfEntity ) );
|
||||
printf("Pos : %ld \n" , FPOS(EIF ,dIfIP ) );
|
||||
printf("Size : %ld \n" , FSIZ(EIF ,dIfIP ) );
|
||||
printf("Pos : %ld \n" , FPOS(EIF ,uIfState ) );
|
||||
printf("Size : %ld \n" , FSIZ(EIF ,uIfState ) );
|
||||
printf("Pos : %ld \n" , FPOS(IcmpSrv ,nPackNumSend ) );
|
||||
printf("Size : %ld \n" , FSIZ(IcmpSrv ,nPackNumSend ) );
|
||||
printf("Pos : %ld \n" , FPOS(IcmpSrv ,aSendBuff ) );
|
||||
printf("Size : %ld \n" , FSIZ(IcmpSrv ,aSendBuff ) );
|
||||
|
||||
printf("Please input ip and port : ");
|
||||
|
||||
fgets( tmpStr, 80 ,stdin );
|
||||
|
||||
printf("%s\n", tmpStr);
|
||||
if( STR_CHECK_END(tmpStr , '\n' ) )
|
||||
{
|
||||
STR_CUT_LAST(tmpStr );
|
||||
}
|
||||
//StrTrimMoreSpace(tmpStr);
|
||||
//printf("trim space : \n%s\n" ,tmpStr );
|
||||
|
||||
{
|
||||
char *p = NULL;
|
||||
u8 uFlag = 0;
|
||||
|
||||
p = StrEqTok(tmpStr);
|
||||
printf( "Name: %-20s " , p);
|
||||
for( ; p = StrEqTok(NULL); )
|
||||
{
|
||||
uFlag = uFlag ? 0 : 1;
|
||||
if( uFlag )
|
||||
{
|
||||
printf( "Valu: %-20s \n" , p);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Name: %-20s " , p);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
PingInit( &tIcmpSrv , 56 );
|
||||
|
||||
ret = PingStart( &tIcmpSrv , "172.18.99.1" , NetCapPing );
|
||||
if( !ret )
|
||||
{
|
||||
printf("ping is processing\n");
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
PingTimer( &tIcmpSrv );
|
||||
sleep ( 1 );
|
||||
//ÿ<><C3BF>һ<EFBFBD>뷢<EFBFBD><EBB7A2>һ<EFBFBD><D2BB>ICMP<4D><50><EFBFBD><EFBFBD>
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
98
plat/public/ut/main/Makefile
Normal file
98
plat/public/ut/main/Makefile
Normal file
@@ -0,0 +1,98 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile for module Version : V1.4 ##
|
||||
## ##
|
||||
## Created : Wei Liu 07/04/11 ##
|
||||
## Revision: [Last]Wei Liu 07/06/18 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project correlation(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## MODULE= [Module Name]
|
||||
## TYPE = app/plat => Module Type
|
||||
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
|
||||
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
|
||||
|
||||
## BUILD = lib/exef => Output file format
|
||||
## CFG = debug/release => Build Configuration
|
||||
|
||||
## SRC_PATH = [Source file path]
|
||||
## INC_PATH = [Include file path]
|
||||
## APP_PATH = [App Module path]
|
||||
## PLT_PATH = [Plat Module path]
|
||||
|
||||
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
|
||||
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
|
||||
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
|
||||
|
||||
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
|
||||
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
|
||||
## snmp iptrans debug sccp public
|
||||
##
|
||||
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
|
||||
## LIB_ADD e.g. = -liba3a8 -lm
|
||||
|
||||
## OBJ_ADD = [Extend third party object files needed]
|
||||
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
|
||||
MODULE = publictest
|
||||
TYPE = plat
|
||||
|
||||
DBUG_FLAGS_ADD =
|
||||
RELS_FLAGS_ADD =
|
||||
|
||||
##Default commonly as below
|
||||
|
||||
BUILD = exef
|
||||
CFG = debug
|
||||
|
||||
PLT_LIB = public
|
||||
APP_LIB =
|
||||
LIB_ADD =
|
||||
|
||||
SRC_PATH = ./src
|
||||
INC_PATH = ./src/include
|
||||
PLT_PATH = ../../../../plat
|
||||
APP_PATH = ../../../../mss
|
||||
|
||||
OBJ_ADD =
|
||||
TEST_OBJ_PATH = ../../obj
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
## CCFLAG_SWITCH = on/off => gcc flag show on/off
|
||||
## COVER_NEED = yes/no => PTF cover report needed
|
||||
## COVER_REPORT_PATH = [path ] => PTF cover report path
|
||||
|
||||
CCFLAG_SWITCH = on
|
||||
COVER_NEED =
|
||||
COVER_REPORT_PATH = ./ut/ut_doc/output
|
||||
|
||||
##---------------------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.rules
|
||||
|
||||
|
||||
|
||||
5
plat/public/ut/main/bin/.svn/all-wcprops
Normal file
5
plat/public/ut/main/bin/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 54
|
||||
/svn/wxc2/!svn/ver/1/trunk/R4S/plat/public/ut/main/bin
|
||||
END
|
||||
28
plat/public/ut/main/bin/.svn/entries
Normal file
28
plat/public/ut/main/bin/.svn/entries
Normal file
@@ -0,0 +1,28 @@
|
||||
10
|
||||
|
||||
dir
|
||||
114
|
||||
http://172.25.201.20/svn/wxc2/trunk/R4S/plat/public/ut/main/bin
|
||||
http://172.25.201.20/svn/wxc2
|
||||
|
||||
|
||||
|
||||
2011-09-23T09:01:37.023785Z
|
||||
1
|
||||
xueqiang.sheng
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4a7aa47d-8bee-446f-9599-049dc37ff264
|
||||
|
||||
5
plat/public/ut/main/obj/.svn/all-wcprops
Normal file
5
plat/public/ut/main/obj/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 54
|
||||
/svn/wxc2/!svn/ver/1/trunk/R4S/plat/public/ut/main/obj
|
||||
END
|
||||
28
plat/public/ut/main/obj/.svn/entries
Normal file
28
plat/public/ut/main/obj/.svn/entries
Normal file
@@ -0,0 +1,28 @@
|
||||
10
|
||||
|
||||
dir
|
||||
114
|
||||
http://172.25.201.20/svn/wxc2/trunk/R4S/plat/public/ut/main/obj
|
||||
http://172.25.201.20/svn/wxc2
|
||||
|
||||
|
||||
|
||||
2011-09-23T09:01:37.023785Z
|
||||
1
|
||||
xueqiang.sheng
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4a7aa47d-8bee-446f-9599-049dc37ff264
|
||||
|
||||
11
plat/public/ut/main/src/.svn/all-wcprops
Normal file
11
plat/public/ut/main/src/.svn/all-wcprops
Normal file
@@ -0,0 +1,11 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 54
|
||||
/svn/wxc2/!svn/ver/1/trunk/R4S/plat/public/ut/main/src
|
||||
END
|
||||
main.c
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 61
|
||||
/svn/wxc2/!svn/ver/1/trunk/R4S/plat/public/ut/main/src/main.c
|
||||
END
|
||||
62
plat/public/ut/main/src/.svn/entries
Normal file
62
plat/public/ut/main/src/.svn/entries
Normal file
@@ -0,0 +1,62 @@
|
||||
10
|
||||
|
||||
dir
|
||||
114
|
||||
http://172.25.201.20/svn/wxc2/trunk/R4S/plat/public/ut/main/src
|
||||
http://172.25.201.20/svn/wxc2
|
||||
|
||||
|
||||
|
||||
2011-09-23T09:01:37.023785Z
|
||||
1
|
||||
xueqiang.sheng
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4a7aa47d-8bee-446f-9599-049dc37ff264
|
||||
|
||||
main.c
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2012-12-28T03:06:27.578125Z
|
||||
4a3e0b7b095c32b64c152c36991fc15d
|
||||
2011-09-23T09:01:37.023785Z
|
||||
1
|
||||
xueqiang.sheng
|
||||
has-props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
399
|
||||
|
||||
5
plat/public/ut/main/src/.svn/prop-base/main.c.svn-base
Normal file
5
plat/public/ut/main/src/.svn/prop-base/main.c.svn-base
Normal file
@@ -0,0 +1,5 @@
|
||||
K 14
|
||||
svn:executable
|
||||
V 1
|
||||
*
|
||||
END
|
||||
19
plat/public/ut/main/src/.svn/text-base/main.c.svn-base
Normal file
19
plat/public/ut/main/src/.svn/text-base/main.c.svn-base
Normal file
@@ -0,0 +1,19 @@
|
||||
//////////////////////////////////////////////////
|
||||
//Title : main.c
|
||||
//Auhtor : Liu Wei
|
||||
//Desc : public function test
|
||||
//Created : 2007-06-24
|
||||
//Revision :
|
||||
//
|
||||
//Revision :
|
||||
//
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#include "../../src/include/includes.h"
|
||||
#include "../../src/include/public.h"
|
||||
#include "../../src/include/function.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
19
plat/public/ut/main/src/main.c
Normal file
19
plat/public/ut/main/src/main.c
Normal file
@@ -0,0 +1,19 @@
|
||||
//////////////////////////////////////////////////
|
||||
//Title : main.c
|
||||
//Auhtor : Liu Wei
|
||||
//Desc : public function test
|
||||
//Created : 2007-06-24
|
||||
//Revision :
|
||||
//
|
||||
//Revision :
|
||||
//
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#include "../../src/include/includes.h"
|
||||
#include "../../src/include/public.h"
|
||||
#include "../../src/include/function.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
15
plat/public/ut/public_test/public_test.c
Normal file
15
plat/public/ut/public_test/public_test.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* public test c file */
|
||||
/* Written by Liu Zhiguo 2002-03-26 */
|
||||
/* Version 1.0 */
|
||||
/* -------------------------------- */
|
||||
|
||||
#include "./include/includes.h"
|
||||
#include "./include/public.h"
|
||||
#include "./include/function.h"
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
72
plat/public/ut/timer/Makefile
Normal file
72
plat/public/ut/timer/Makefile
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
##----------------------------------------------------------##
|
||||
## ##
|
||||
## Universal Makefile for wxc2 module ##
|
||||
## --By Wei Liu 2007/04/11 ##
|
||||
## ##
|
||||
##----------------------------------------------------------##
|
||||
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Project correlation(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
##Module Name
|
||||
MODULE = tmtest
|
||||
|
||||
#BUILD = lib/exef
|
||||
BUILD = exef
|
||||
|
||||
#CFG = debug / release
|
||||
CFG = debug
|
||||
|
||||
#Source file path
|
||||
SRC_PATH= ./
|
||||
|
||||
#include file path
|
||||
INC_PATH= ./
|
||||
|
||||
#extend wxc2plat module lib need
|
||||
WXC2_PLT_LIB= public
|
||||
|
||||
#extend wxc2plat module lib need
|
||||
WXC2_APP_LIB=
|
||||
|
||||
#extend wxc2plat path default to ./wxc2plat
|
||||
WXC2_PLT_PATH = ../../../../wxc2plat
|
||||
|
||||
#extend wxc2plat path default to ./wxc2app
|
||||
WXC2_APP_PATH =
|
||||
|
||||
#extend obj needed
|
||||
CFG_OBJ =
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## Make configuration(Customer define)
|
||||
##
|
||||
##--------------------------------------
|
||||
|
||||
#gcc flag show on/off
|
||||
CCFLAG_SWITCH = on
|
||||
|
||||
#customer debug version flag add for compile
|
||||
DEBUG_CFLAGS_ADD = -D_MSCR83 -D_DEVELOPER
|
||||
|
||||
#customer release version flag add for compile
|
||||
RELEASE_CFLAGS_ADD = -D_MSCR83
|
||||
|
||||
#need cover fucntion of PTF for test = YES/NO
|
||||
COVER_NEED =
|
||||
|
||||
#cover fucntion output path of PTF for test
|
||||
COVER_REPORT_PATH = ./ut/ut_doc/output
|
||||
|
||||
##--------------------------------------
|
||||
##
|
||||
## include makefile.rules (Do not change)
|
||||
##
|
||||
##--------------------------------------
|
||||
include Makefile.rules
|
||||
5
plat/public/ut/timer/bin/.svn/all-wcprops
Normal file
5
plat/public/ut/timer/bin/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 55
|
||||
/svn/wxc2/!svn/ver/1/trunk/R4S/plat/public/ut/timer/bin
|
||||
END
|
||||
28
plat/public/ut/timer/bin/.svn/entries
Normal file
28
plat/public/ut/timer/bin/.svn/entries
Normal file
@@ -0,0 +1,28 @@
|
||||
10
|
||||
|
||||
dir
|
||||
114
|
||||
http://172.25.201.20/svn/wxc2/trunk/R4S/plat/public/ut/timer/bin
|
||||
http://172.25.201.20/svn/wxc2
|
||||
|
||||
|
||||
|
||||
2011-09-23T09:01:37.023785Z
|
||||
1
|
||||
xueqiang.sheng
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4a7aa47d-8bee-446f-9599-049dc37ff264
|
||||
|
||||
5
plat/public/ut/timer/ut/.svn/all-wcprops
Normal file
5
plat/public/ut/timer/ut/.svn/all-wcprops
Normal file
@@ -0,0 +1,5 @@
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 54
|
||||
/svn/wxc2/!svn/ver/1/trunk/R4S/plat/public/ut/timer/ut
|
||||
END
|
||||
28
plat/public/ut/timer/ut/.svn/entries
Normal file
28
plat/public/ut/timer/ut/.svn/entries
Normal file
@@ -0,0 +1,28 @@
|
||||
10
|
||||
|
||||
dir
|
||||
114
|
||||
http://172.25.201.20/svn/wxc2/trunk/R4S/plat/public/ut/timer/ut
|
||||
http://172.25.201.20/svn/wxc2
|
||||
|
||||
|
||||
|
||||
2011-09-23T09:01:37.023785Z
|
||||
1
|
||||
xueqiang.sheng
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4a7aa47d-8bee-446f-9599-049dc37ff264
|
||||
|
||||
155
plat/public/ut/timer/wxc_tmtest.c
Normal file
155
plat/public/ut/timer/wxc_tmtest.c
Normal file
@@ -0,0 +1,155 @@
|
||||
|
||||
#include "assert.h"
|
||||
#include "../../src/include/includes.h"
|
||||
#include "../../src/include/public.h"
|
||||
#include "../../src/include/wxc_timer.h"
|
||||
|
||||
|
||||
u32 hlr_timer_flag;
|
||||
u32 hlr_20ms_flag;
|
||||
|
||||
void system_init ( void )
|
||||
{
|
||||
sleep ( 3 );
|
||||
hlr_timer_flag = 0;
|
||||
hlr_20ms_flag = 0;
|
||||
}
|
||||
|
||||
void timer_callback ( )
|
||||
{
|
||||
hlr_20ms_flag++;
|
||||
hlr_timer_flag++;
|
||||
printf("10 ms call back : %d\n" , hlr_timer_flag);
|
||||
}
|
||||
|
||||
void set_timer ( )
|
||||
{
|
||||
struct sigaction act;
|
||||
struct itimerval value;
|
||||
struct itimerval old_value;
|
||||
|
||||
value.it_interval.tv_sec = 0;
|
||||
value.it_interval.tv_usec = 10000; // 10 ms
|
||||
value.it_value.tv_sec = 0;
|
||||
value.it_value.tv_usec = 10000; // 10 ms
|
||||
act.sa_handler = timer_callback;
|
||||
sigemptyset ( &act.sa_mask );
|
||||
act.sa_flags = 0;
|
||||
if( sigaction ( SIGALRM, &act, NULL ) == -1 )
|
||||
{
|
||||
printf ( "Timer error\n" );
|
||||
exit ( 0 );
|
||||
}
|
||||
setitimer ( ITIMER_REAL, &value, &old_value );
|
||||
iopl ( 3 );
|
||||
}
|
||||
|
||||
void tm_app_callback_10ms ( u16 dSuitId, u16 dData )
|
||||
{
|
||||
printf("10 ms call back\n");
|
||||
}
|
||||
|
||||
void tm_app_callback_1s ( u16 dSuitId, u16 dData )
|
||||
{
|
||||
printf("10 ms call back\n");
|
||||
}
|
||||
|
||||
void tm_app_callback_50s ( u16 dSuitId, u16 dData )
|
||||
{
|
||||
printf("10 ms call back\n");
|
||||
}
|
||||
|
||||
void tm_app_callback_5000s ( u16 dSuitId, u16 dData )
|
||||
{
|
||||
printf("10 ms call back\n");
|
||||
}
|
||||
|
||||
|
||||
void tm_app_init ( )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int app_state;
|
||||
WxcTimer tTimer10ms;
|
||||
WxcTimer tTimer1s;
|
||||
WxcTimer tTimer50s;
|
||||
WxcTimer tTimer5000s;
|
||||
|
||||
typedef enum TMTEST_STATE
|
||||
{
|
||||
APP_REGSITER,
|
||||
APP_START,
|
||||
APP_TIMEROUT,
|
||||
APP_STOP,
|
||||
}
|
||||
TM_STATE;
|
||||
|
||||
|
||||
void tm_app_test ( )
|
||||
{
|
||||
|
||||
|
||||
switch ( app_state )
|
||||
{
|
||||
case APP_REGSITER:
|
||||
tTimer10ms.dExpires = 1;
|
||||
tTimer10ms.dSuitNumber = 1;
|
||||
tTimer10ms.pFunc = &tm_app_callback_10ms;
|
||||
tTimer10ms.dData = 0;
|
||||
TimerAdd ( &tTimer10ms );
|
||||
|
||||
tTimer1s.dExpires = 100;
|
||||
tTimer1s.dSuitNumber = 10;
|
||||
tTimer1s.pFunc = &tm_app_callback_1s;
|
||||
tTimer1s.dData = 0;
|
||||
TimerAdd ( &tTimer1s );
|
||||
|
||||
tTimer50s.dExpires = 5000;
|
||||
tTimer50s.dSuitNumber = 100;
|
||||
tTimer50s.pFunc = &tm_app_callback_50s;
|
||||
tTimer50s.dData = 0;
|
||||
TimerAdd ( &tTimer50s );
|
||||
|
||||
tTimer5000s.dExpires = 5000000;
|
||||
tTimer5000s.dSuitNumber = 10;
|
||||
tTimer5000s.pFunc = &tm_app_callback_5000s;
|
||||
tTimer5000s.dData = 0;
|
||||
TimerAdd ( &tTimer5000s );
|
||||
app_state++;
|
||||
break;
|
||||
|
||||
case APP_START:
|
||||
app_state++;
|
||||
break;
|
||||
|
||||
case APP_TIMEROUT:
|
||||
|
||||
TimerAdd ( &tTimer50s );
|
||||
app_state++;
|
||||
break;
|
||||
case APP_STOP:
|
||||
|
||||
TimerAdd ( &tTimer50s );
|
||||
app_state++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main ( int argc, char *argv[] )
|
||||
{
|
||||
|
||||
system_init ( );
|
||||
|
||||
set_timer ( );
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
usleep ( 1 );
|
||||
tm_app_test ( );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user