mirror of
				git://git.psyc.eu/libpsyc
				synced 2024-08-15 03:19:02 +00:00 
			
		
		
		
	test: stats option for files too
This commit is contained in:
		
							parent
							
								
									6529f30380
								
							
						
					
					
						commit
						1ba9567100
					
				
					 2 changed files with 22 additions and 8 deletions
				
			
		
							
								
								
									
										10
									
								
								test/test.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								test/test.c
									
										
									
									
									
								
							|  | @ -38,6 +38,7 @@ void test_file(const char* filename, size_t recv_buf_size) { | ||||||
| 	char buf[CONT_BUF_SIZE + RECV_BUF_SIZE];  // cont buf + recv buf: [  ccrrrr]
 | 	char buf[CONT_BUF_SIZE + RECV_BUF_SIZE];  // cont buf + recv buf: [  ccrrrr]
 | ||||||
| 	char *recvbuf = buf + CONT_BUF_SIZE;      // recv buf:                 ^^^^
 | 	char *recvbuf = buf + CONT_BUF_SIZE;      // recv buf:                 ^^^^
 | ||||||
| 	size_t nbytes; | 	size_t nbytes; | ||||||
|  | 	struct timeval start, end; | ||||||
| 
 | 
 | ||||||
| 	int fd = open(filename, O_RDONLY); | 	int fd = open(filename, O_RDONLY); | ||||||
| 	if (fd < 0) { | 	if (fd < 0) { | ||||||
|  | @ -45,10 +46,19 @@ void test_file(const char* filename, size_t recv_buf_size) { | ||||||
| 		exit(1); | 		exit(1); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	test_init(0); | 	test_init(0); | ||||||
| 
 | 
 | ||||||
|  | 	if (stats) | ||||||
|  | 		gettimeofday(&start, NULL); | ||||||
|  | 
 | ||||||
| 	while ((nbytes = read(fd, (void*)recvbuf, recv_buf_size))) | 	while ((nbytes = read(fd, (void*)recvbuf, recv_buf_size))) | ||||||
| 		test_input(0, recvbuf, nbytes); | 		test_input(0, recvbuf, nbytes); | ||||||
|  | 
 | ||||||
|  | 	if (stats) { | ||||||
|  | 		gettimeofday(&end, NULL); | ||||||
|  | 		printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec) / 1000); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void test_server(const char* port, size_t recv_buf_size) { | void test_server(const char* port, size_t recv_buf_size) { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <stdint.h> | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| #include <getopt.h> | #include <getopt.h> | ||||||
|  | @ -19,7 +20,7 @@ | ||||||
| 
 | 
 | ||||||
| // cmd line args
 | // cmd line args
 | ||||||
| uint8_t verbose, stats; | uint8_t verbose, stats; | ||||||
| uint8_t routing_only, parse_multiple, no_render, progress; | uint8_t routing_only, parse_multiple, no_render, quiet, progress; | ||||||
| char *filename, *port = "4440"; | char *filename, *port = "4440"; | ||||||
| size_t recv_buf_size = RECV_BUF_SIZE; | size_t recv_buf_size = RECV_BUF_SIZE; | ||||||
| 
 | 
 | ||||||
|  | @ -32,7 +33,7 @@ int contbytes, last_ret; | ||||||
| 
 | 
 | ||||||
| int main (int argc, char **argv) { | int main (int argc, char **argv) { | ||||||
| 	int c; | 	int c; | ||||||
| 	while ((c = getopt (argc, argv, "f:p:b:mnrsvP")) != -1) { | 	while ((c = getopt (argc, argv, "f:p:b:mnqrsvP")) != -1) { | ||||||
| 		switch (c) { | 		switch (c) { | ||||||
| 			case 'f': filename = optarg; break; | 			case 'f': filename = optarg; break; | ||||||
| 			case 'p': port = optarg; | 			case 'p': port = optarg; | ||||||
|  | @ -43,6 +44,7 @@ int main (int argc, char **argv) { | ||||||
| 				break; | 				break; | ||||||
| 			case 'm': parse_multiple = 1; break; | 			case 'm': parse_multiple = 1; break; | ||||||
| 			case 'n': no_render = 1; break; | 			case 'n': no_render = 1; break; | ||||||
|  | 			case 'q': quiet = 1; break; | ||||||
| 			case 'r': routing_only = 1; break; | 			case 'r': routing_only = 1; break; | ||||||
| 			case 's': stats = 1; break; | 			case 's': stats = 1; break; | ||||||
| 			case 'v': verbose++; break; | 			case 'v': verbose++; break; | ||||||
|  | @ -160,6 +162,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) { | ||||||
| 					psyc_setPacketLength(&packets[i]); | 					psyc_setPacketLength(&packets[i]); | ||||||
| 
 | 
 | ||||||
| 					if (psyc_render(&packets[i], sendbuf, SEND_BUF_SIZE) == PSYC_RENDER_SUCCESS) { | 					if (psyc_render(&packets[i], sendbuf, SEND_BUF_SIZE) == PSYC_RENDER_SUCCESS) { | ||||||
|  | 						if (!quiet) { | ||||||
| 							if (filename && write(1, sendbuf, packets[i].length) == -1) { | 							if (filename && write(1, sendbuf, packets[i].length) == -1) { | ||||||
| 								perror("write"); | 								perror("write"); | ||||||
| 								ret = -1; | 								ret = -1; | ||||||
|  | @ -167,6 +170,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) { | ||||||
| 								perror("send"); | 								perror("send"); | ||||||
| 								ret = -1; | 								ret = -1; | ||||||
| 							} | 							} | ||||||
|  | 						} | ||||||
| 					} else { | 					} else { | ||||||
| 						printf("# Render error"); | 						printf("# Render error"); | ||||||
| 						ret = -1; | 						ret = -1; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue