diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/test.c | 38 | ||||
-rw-r--r-- | src/test.h | 4 |
2 files changed, 36 insertions, 6 deletions
@@ -14,13 +14,14 @@ void run_test () //tree_balanced_insert(NULL, NULL, NULL, 15 ); //Normal tests test_tree(); - test_dns_parsing(); - test_dns_parsing_fuzz(); + //test_dns_parsing(); + test_dns_message_fuzz(); + test_dns_qname_fuzz(); } int test_tree () { - printf("\ntest_tree()\n"); + printf("\n-> test_tree()\n======\n\n"); struct tree_node* root = NULL; @@ -42,7 +43,7 @@ int test_tree () int test_dns_parsing () { - printf("test_dns_parsing()\n"); + printf("\n-> test_dns_parsing()\n======\n\n"); char in[128]; char out[128]; @@ -78,7 +79,7 @@ int test_dns_parsing () return 0; } -int test_dns_parsing_fuzz() +int test_dns_qname_fuzz() { printf("\n-> test_parsing_fuzz()\n======\n\n"); FILE* urand = fopen ("/dev/urandom", "r"); @@ -106,4 +107,31 @@ int test_dns_parsing_fuzz() return 0; } + +int test_dns_message_fuzz() +{ + printf("\n-> test_dns_message_fuzz()\n======\n\n"); + FILE* urand = fopen ("/dev/urandom", "r"); + char rand[128]; + + if (!urand) + return 1; + + unsigned long int limit = 10000000; + unsigned long int valid_cnt = 0; + struct dns_message msg; + + for (unsigned long int i = 0; i < limit; i++) { + if (fread (rand, 128, 1, urand) > 0) { + if ( ! dns_parse_packet(rand, 128, &msg) ) { + valid_cnt++; + } + } + } + + float valid_percent = (float)valid_cnt / (float)limit * 100; + printf("# of valid messages in random data: %i / %i = %f%%\n", valid_cnt, limit, valid_percent); + + return 0; +} #endif @@ -24,6 +24,8 @@ int test_tree (); int test_dns_parsing (); -int test_dns_parsing_fuzz(); +int test_dns_qname_fuzz(); + +int test_dns_message_fuzz(); #endif |