mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
bench: added test tools, updated results; added inline option for parse & render
This commit is contained in:
parent
1edd326f1f
commit
1cc5499777
15 changed files with 438 additions and 131 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -10,7 +10,10 @@ test/testMatch
|
|||
test/testParser
|
||||
test/testRender
|
||||
test/testPsyc
|
||||
test/testPsycFast
|
||||
test/testPsycSpeed
|
||||
test/testJson
|
||||
test/testJsonGlib
|
||||
test/testStrlen
|
||||
test/testText
|
||||
test/isRoutingVar
|
||||
test/getVarType
|
||||
|
|
3
bench/.gitignore
vendored
Normal file
3
bench/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.html
|
||||
*.pdf
|
||||
packets/
|
|
@ -5,23 +5,21 @@
|
|||
|
||||
Parsing time of 1 000 000 packets in milliseconds:
|
||||
|
||||
| | libpsyc | libpsyc fast | json-c | json-glib | libxml sax | libxml | rapidxml fast | rapidxml |
|
||||
|-----------+---------+--------------+--------+-----------+------------+--------+---------------+----------|
|
||||
| presence | 597 | 246 | 3247 | 10197 | 4997 | 7557 | 1643 | 1719 |
|
||||
| chat msg | 714 | 320 | | | 5997 | 9777 | 1799 | 1893 |
|
||||
| activity | 903 | 366 | 5768 | 16846 | 13357 | 28858 | 4001 | 4419 |
|
||||
| user prof | 1806 | 608 | 5847 | 17468 | 7350 | 12377 | 2218 | 2477 |
|
||||
|-----------+---------+--------------+--------+-----------+------------+--------+---------------+----------|
|
||||
| / | < | > | < | > | < | > | < | > |
|
||||
| | strlen | libpsyc | json-c | json-glib | libxml sax | libxml | rapidxml |
|
||||
|-----------+--------+---------+--------+-----------+------------+--------+----------|
|
||||
| presence | 30 | 246 | 2463 | 10197 | 4997 | 7557 | 1719 |
|
||||
| chat msg | 41 | 320 | | | 5997 | 9777 | 1893 |
|
||||
| activity | 42 | 366 | 4666 | 16846 | 13357 | 28858 | 4419 |
|
||||
| user prof | 55 | 608 | 4715 | 17468 | 7350 | 12377 | 2477 |
|
||||
|-----------+--------+---------+--------+-----------+------------+--------+----------|
|
||||
| / | < | < | < | > | < | > | > |
|
||||
|
||||
* Commands used
|
||||
|
||||
: ./testPsyc -snc 1000000 -f $file
|
||||
: ./testPsycFast -sc 1000000 -f $file
|
||||
: ./testPsycSpeed -sc 1000000 -f $file
|
||||
: ./testJson -snc 1000000 -f $file
|
||||
: ./testJsonGlib -snc 1000000 -f $file
|
||||
: ./testStrlen -sc 1000000 -f $file
|
||||
: ./rapidxml 1000000 $file
|
||||
: fast_mode=1 ./rapidxml 1000000 $file
|
||||
: ./libxml 1000000 $file
|
||||
: ./libxml-sax 1000000 $file
|
||||
|
|
|
@ -428,6 +428,9 @@ const char * psyc_getParseRemainingBuffer (psycParseState *state)
|
|||
* @param value In case of a modifier it will point to the value,
|
||||
* in case of the body it will point to the data.
|
||||
*/
|
||||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||
psycString *name, psycString *value);
|
||||
|
||||
|
@ -443,6 +446,9 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
|||
* @param value Contains the list to be parsed.
|
||||
* @param elem It will point to the next element in the list.
|
||||
*/
|
||||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseListRC psyc_parseList (psycParseListState *state, psycString *elem);
|
||||
|
||||
/** @} */ // end of parse group
|
||||
|
|
|
@ -58,11 +58,17 @@ typedef enum
|
|||
* @see psyc_newRawPacket2
|
||||
* @see psyc_setPacketLength
|
||||
*/
|
||||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Render a PSYC list into a buffer.
|
||||
*/
|
||||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderListRC psyc_renderList (psycList *list, char *buffer, size_t buflen);
|
||||
|
||||
/** @} */ // end of render group
|
||||
|
|
|
@ -202,6 +202,9 @@ parseRC psyc_parseModifier (psycParseState *state, char *oper,
|
|||
}
|
||||
|
||||
/** Parse PSYC packets. */
|
||||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||
psycString *name, psycString *value)
|
||||
{
|
||||
|
@ -483,6 +486,9 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
|||
}
|
||||
|
||||
/** List parser. */
|
||||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseListRC psyc_parseList (psycParseListState *state, psycString *elem)
|
||||
{
|
||||
if (state->cursor >= state->buffer.length)
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#include <psyc/render.h>
|
||||
#include <psyc/syntax.h>
|
||||
|
||||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderListRC psyc_renderList (psycList *list, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i, cur = 0;
|
||||
|
@ -64,6 +67,9 @@ size_t psyc_renderModifier (psycModifier *mod, char *buffer)
|
|||
return cur;
|
||||
}
|
||||
|
||||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i, cur = 0, len;
|
||||
|
|
|
@ -4,7 +4,7 @@ CFLAGS_COMMON = -Wall -std=c99 ${OPT}
|
|||
CFLAGS = -I../include -I../src ${CFLAGS_COMMON}
|
||||
LDFLAGS = -L../lib
|
||||
LOADLIBES = -lpsyc -lm
|
||||
TARGETS = testPsyc testPsycFast testParser testMatch testRender testText isRoutingVar getVarType
|
||||
TARGETS = testPsyc testPsycSpeed testParser testMatch testRender testText isRoutingVar getVarType
|
||||
O = test.o
|
||||
WRAPPER =
|
||||
DIET = diet
|
||||
|
@ -21,8 +21,15 @@ all: ${TARGETS}
|
|||
it: all
|
||||
|
||||
testPsyc: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET}
|
||||
testPsycFast: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET}
|
||||
#testPsycFast: LOADLIBES := ${LOADLIBES_NET}
|
||||
testPsycSpeed: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET}
|
||||
#testPsycSpeed: LOADLIBES := ${LOADLIBES_NET}
|
||||
|
||||
testJson: LOADLIBES := ${LOADLIBES_NET} -ljson
|
||||
|
||||
testJsonGlib: CFLAGS = ${CFLAGS_COMMON} -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
|
||||
testJsonGlib: LOADLIBES := ${LOADLIBES_NET} -ljson-glib-1.0
|
||||
|
||||
testStrlen: LOADLIBES := ${LOADLIBES_NET}
|
||||
|
||||
diet: WRAPPER = ${DIET}
|
||||
diet: all
|
||||
|
|
28
test/test.h
28
test/test.h
|
@ -14,6 +14,34 @@
|
|||
# define NUM_PARSERS 100
|
||||
#endif
|
||||
|
||||
#define CASE_f case 'f': filename = optarg; break;
|
||||
#define CASE_p case 'p': port = optarg; check_range(c, optarg, 1, 0); break;
|
||||
#define CASE_b case 'b': recv_buf_size = atoi(optarg); check_range(c, optarg, 1, RECV_BUF_SIZE); break;
|
||||
#define CASE_c case 'c': count = atoi(optarg); check_range(c, optarg, 1, 0); break;
|
||||
#define CASE_n case 'n': no_render = 1; break;
|
||||
#define CASE_m case 'm': multiple = 1; break;
|
||||
#define CASE_q case 'q': quiet = 1; break;
|
||||
#define CASE_r case 'r': routing_only = 1; break;
|
||||
#define CASE_s case 's': stats = 1; break;
|
||||
#define CASE_v case 'v': verbose++; break;
|
||||
#define CASE_P case 'P': progress = 1; break;
|
||||
#define CASE_S case 'S': single = 1; break;
|
||||
#define HELP_FILE(name, opts) name " -f <filename> [-b <read_buf_size>] [-c <count>] [-" opts "]\n"
|
||||
#define HELP_PORT(name, opts) name " [-p <port>] [-b <recv_buf_size>] [-" opts "]\n"
|
||||
#define HELP_f " -f <filename>\tInput file name\n"
|
||||
#define HELP_p " -p <port>\t\tListen on TCP port, default is %s\n"
|
||||
#define HELP_b " -b <buf_size>\tRead/receive buffer size, default is %d\n"
|
||||
#define HELP_c " -c <count>\t\tParse data from file <count> times\n"
|
||||
#define HELP_m " -m\t\t\tParse multiple packets from file\n"
|
||||
#define HELP_n " -n\t\t\tNo rendering, only parsing\n"
|
||||
#define HELP_q " -q\t\t\tQuiet mode, don't output rendered string\n"
|
||||
#define HELP_r " -r\t\t\tParse routing header only\n"
|
||||
#define HELP_S " -S\t\t\tSingle packet mode, close connection after parsing one packet\n"
|
||||
#define HELP_s " -s\t\t\tShow statistics at the end\n"
|
||||
#define HELP_v " -v\t\t\tVerbose, can be specified multiple times for more verbosity\n"
|
||||
#define HELP_P " -P\t\t\tShow progress\n"
|
||||
#define HELP_h " -h\t\t\tShow this help\n"
|
||||
|
||||
void test_init(int i);
|
||||
int test_input(int i, char *recvbuf, size_t nbytes);
|
||||
|
||||
|
|
113
test/testJson.c
Normal file
113
test/testJson.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <json/json.h>
|
||||
#include <json/json_object.h>
|
||||
#include <json/json_tokener.h>
|
||||
|
||||
#include "test.c"
|
||||
|
||||
// cmd line args
|
||||
char *filename, *port = "4441";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t multiple, single, no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
|
||||
int exit_code;
|
||||
|
||||
json_object *obj;
|
||||
json_tokener *tok;
|
||||
enum json_tokener_error error;
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:mnqsvPSh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b CASE_c
|
||||
CASE_m CASE_n CASE_q CASE_s
|
||||
CASE_v CASE_S CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testJson", "mnqSsvP")
|
||||
HELP_PORT("testJson", "nqsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_q HELP_S
|
||||
HELP_s HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
void test_init (int i) {
|
||||
tok = json_tokener_new();
|
||||
}
|
||||
|
||||
int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||
size_t cursor = 0;
|
||||
int r, ret = 0;
|
||||
|
||||
json_tokener_reset(tok);
|
||||
|
||||
do {
|
||||
obj = json_tokener_parse_ex(tok, recvbuf + cursor, nbytes - cursor);
|
||||
cursor += tok->char_offset;
|
||||
|
||||
if (verbose)
|
||||
printf("#%d\n", tok->err);
|
||||
|
||||
switch (tok->err) {
|
||||
case json_tokener_continue:
|
||||
return 0;
|
||||
|
||||
case json_tokener_success:
|
||||
if (!no_render) {
|
||||
const char *str = json_object_to_json_string(obj);
|
||||
if (!quiet) {
|
||||
size_t len = strlen(str);
|
||||
if (filename) {
|
||||
r = write(1, str, len);
|
||||
r = write(1, "\n", 1);
|
||||
} else {
|
||||
send(i, str, len, 0);
|
||||
send(i, "\n", 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json_object_put(obj);
|
||||
|
||||
if (verbose)
|
||||
printf("# Done parsing.\n");
|
||||
else if (progress)
|
||||
r = write(1, ".", 1);
|
||||
if ((filename && !multiple) || (!filename && single))
|
||||
return -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("parse error\n");
|
||||
exit_code = tok->err;
|
||||
return -1;
|
||||
}
|
||||
} while (cursor < nbytes);
|
||||
|
||||
return ret;
|
||||
}
|
100
test/testJsonGlib.c
Normal file
100
test/testJsonGlib.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "test.c"
|
||||
|
||||
// cmd line args
|
||||
char *filename, *port = "4442";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
|
||||
int exit_code;
|
||||
|
||||
JsonParser *parser;
|
||||
JsonGenerator *generator;
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:nqsvPh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b
|
||||
CASE_c CASE_n CASE_q
|
||||
CASE_s CASE_v CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testJsonGlib", "mnqSsvP")
|
||||
HELP_PORT("testJsonGlib", "nqsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_q HELP_S
|
||||
HELP_s HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
void test_init (int i) {
|
||||
g_type_init();
|
||||
parser = json_parser_new();
|
||||
generator = json_generator_new();
|
||||
}
|
||||
|
||||
int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||
JsonNode *root;
|
||||
GError *error;
|
||||
char *str;
|
||||
size_t len;
|
||||
int r, ret;
|
||||
|
||||
ret = json_parser_load_from_data(parser, recvbuf, nbytes, &error);
|
||||
|
||||
if (!ret) {
|
||||
printf("Parse error\n");
|
||||
exit_code = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
root = json_parser_get_root(parser);
|
||||
|
||||
if (!no_render) {
|
||||
json_generator_set_root(generator, root);
|
||||
str = json_generator_to_data(generator, &len);;
|
||||
if (!quiet) {
|
||||
if (filename) {
|
||||
r = write(1, str, len);
|
||||
r = write(1, "\n", 1);
|
||||
} else {
|
||||
send(i, str, len, 0);
|
||||
send(i, "\n", 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
printf("# Done parsing.\n");
|
||||
else if (progress)
|
||||
r = write(1, ".", 1);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -313,37 +313,19 @@ inline void resetString (psycString *s, uint8_t freeptr)
|
|||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:nmqrsvPSh")) != -1) {
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:mnqrsvPSh")) != -1) {
|
||||
switch (c) {
|
||||
case 'f': filename = optarg; break;
|
||||
case 'p': port = optarg; check_range(c, optarg, 1, 0); break;
|
||||
case 'b': recv_buf_size = atoi(optarg); check_range(c, optarg, 1, RECV_BUF_SIZE); break;
|
||||
case 'c': count = atoi(optarg); check_range(c, optarg, 1, 0); break;
|
||||
case 'n': no_render = 1; break;
|
||||
case 'm': multiple = 1; break;
|
||||
case 'q': quiet = 1; break;
|
||||
case 'r': routing_only = 1; break;
|
||||
case 's': stats = 1; break;
|
||||
case 'v': verbose++; break;
|
||||
case 'P': progress = 1; break;
|
||||
case 'S': single = 1; break;
|
||||
CASE_f CASE_p CASE_b CASE_c
|
||||
CASE_m CASE_n CASE_q CASE_r
|
||||
CASE_s CASE_v CASE_S CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
"testPsyc -f <filename> [-b <read_buf_size>] [-c <count>] [-mnqrSsvP]\n"
|
||||
"testPsyc [-p <port>] [-b <recv_buf_size>] [-nqrsvP]\n"
|
||||
" -f <filename>\tInput file name\n"
|
||||
" -p <port>\t\tListen on TCP port, default is %s\n"
|
||||
" -b <buf_size>\tRead/receive buffer size, default is %d\n"
|
||||
" -c <count>\t\tParse data from file <count> times\n"
|
||||
" -m\t\t\tParse multiple packets from file\n"
|
||||
" -n\t\t\tNo rendering, only parsing\n"
|
||||
" -r\t\t\tParse routing header only\n"
|
||||
" -q\t\t\tQuiet mode, don't output rendered string\n"
|
||||
" -S\t\t\tSingle packet mode, close connection after parsing one packet\n"
|
||||
" -s\t\t\tShow statistics at the end\n"
|
||||
" -v\t\t\tVerbose, can be specified multiple times for more verbosity\n"
|
||||
" -P\t\t\tShow progress\n"
|
||||
" -h\t\t\tShow this help\n",
|
||||
HELP_FILE("testPsyc", "mnqrSsvP")
|
||||
HELP_PORT("testPsyc", "nqrsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_r
|
||||
HELP_q HELP_S HELP_s
|
||||
HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
//#define PSYC_PARSE_INLINE
|
||||
//#include "../src/parse.c"
|
||||
#include <psyc/parse.h>
|
||||
|
||||
#include "test.c"
|
||||
|
||||
// max size for routing & entity header
|
||||
#define ROUTING_LINES 16
|
||||
#define ENTITY_LINES 32
|
||||
|
||||
// cmd line args
|
||||
char *filename, *port = "4440";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t routing_only;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
|
||||
psycParseState parser;
|
||||
|
||||
void test_init (int i) {
|
||||
// reset parser state
|
||||
if (routing_only)
|
||||
psyc_initParseState2(&parser, PSYC_PARSE_ROUTING_ONLY);
|
||||
else
|
||||
psyc_initParseState(&parser);
|
||||
}
|
||||
|
||||
int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||
char oper;
|
||||
psycString name, value;
|
||||
int ret;
|
||||
|
||||
parser.buffer = (psycString){nbytes, recvbuf};
|
||||
parser.cursor = 0;
|
||||
|
||||
for (;;) {
|
||||
ret = psyc_parse(&parser, &oper, &name, &value);
|
||||
|
||||
if (ret == PSYC_PARSE_COMPLETE || ret < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:qrsvh")) != -1) {
|
||||
switch (c) {
|
||||
case 'f': filename = optarg; break;
|
||||
case 'p': port = optarg; check_range(c, optarg, 1, 0); break;
|
||||
case 'b': recv_buf_size = atoi(optarg); check_range(c, optarg, 1, RECV_BUF_SIZE); break;
|
||||
case 'c': count = atoi(optarg); check_range(c, optarg, 1, 0); break;
|
||||
case 'r': routing_only = 1; break;
|
||||
case 's': stats = 1; break;
|
||||
case 'v': verbose++; break;
|
||||
case 'h':
|
||||
printf(
|
||||
"testPsyc -f <filename> [-b <read_buf_size>] [-c <count>] [-mnqrSsvP]\n"
|
||||
"testPsyc [-p <port>] [-b <recv_buf_size>] [-nqrsvP]\n"
|
||||
" -f <filename>\tInput file name\n"
|
||||
" -p <port>\t\tListen on TCP port, default is %s\n"
|
||||
" -b <buf_size>\tRead/receive buffer size, default is %d\n"
|
||||
" -c <count>\t\tParse data from file <count> times\n"
|
||||
" -r\t\t\tParse routing header only\n"
|
||||
" -s\t\t\tShow statistics at the end\n"
|
||||
" -h\t\t\tShow this help\n"
|
||||
" -v\t\t\tVerbose\n",
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return 0;
|
||||
}
|
74
test/testPsycSpeed.c
Normal file
74
test/testPsycSpeed.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define __INLINE_PSYC_PARSE
|
||||
#include "../src/parse.c"
|
||||
//#include <psyc/parse.h>
|
||||
|
||||
#include "test.c"
|
||||
|
||||
// max size for routing & entity header
|
||||
#define ROUTING_LINES 16
|
||||
#define ENTITY_LINES 32
|
||||
|
||||
// cmd line args
|
||||
char *filename, *port = "4440";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t routing_only;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
|
||||
psycParseState parser;
|
||||
|
||||
void test_init (int i) {
|
||||
if (routing_only)
|
||||
psyc_initParseState2(&parser, PSYC_PARSE_ROUTING_ONLY);
|
||||
else
|
||||
psyc_initParseState(&parser);
|
||||
}
|
||||
|
||||
int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||
char oper;
|
||||
psycString name, value;
|
||||
int ret;
|
||||
|
||||
psyc_setParseBuffer2(&parser, recvbuf, nbytes);
|
||||
|
||||
for (;;) {
|
||||
ret = psyc_parse(&parser, &oper, &name, &value);
|
||||
if (ret == PSYC_PARSE_COMPLETE || ret < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:rsh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b CASE_c
|
||||
CASE_r CASE_s
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testPsycSpeed", "rs")
|
||||
HELP_PORT("testPsycSpeed", "rs")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_r HELP_s HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return 0;
|
||||
}
|
63
test/testStrlen.c
Normal file
63
test/testStrlen.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
#define _GNU_SOURCE
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "test.c"
|
||||
|
||||
// cmd line args
|
||||
char *filename, *port = "4443";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
|
||||
int exit_code;
|
||||
|
||||
void test_init (int i) {
|
||||
}
|
||||
|
||||
int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||
size_t len = strnlen(recvbuf, nbytes);
|
||||
|
||||
if (!len) {
|
||||
printf("Empty string\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:sh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b CASE_c
|
||||
CASE_s
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testStrlen", "s")
|
||||
HELP_PORT("testStrlen", "s")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_s HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
Loading…
Reference in a new issue