diff --git a/CuteDNS.files b/CuteDNS.files index 45b9931b1851f4c17f643f984e16b517c4e1a078..6ad2a9f9ecee8a901d553bbb9d6678c8b6fb8445 100644 --- a/CuteDNS.files +++ b/CuteDNS.files @@ -32,12 +32,13 @@ src/zone/zone-parser.h src/tests/libtap/tap.c src/tests/libtap/tap.h src/tests/main.c -src/tests/cuckoo-test.c -src/tests/cuckoo-test.h src/tests/server_tests.c src/tests/skiplist_tests.c src/tests/da_tests.c src/tests/tap_unit.h +src/tests/zonedb_tests.c +src/tests/dnslib_tests.c +src/tests/cuckoo_tests.c src/tests/template_tests.c src/other/log.h src/other/log.c diff --git a/src/tests/cuckoo-test.h b/src/tests/cuckoo-test.h deleted file mode 100644 index 26cd8b4f3cc2586b38facddb05966d0e49ddb32a..0000000000000000000000000000000000000000 --- a/src/tests/cuckoo-test.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CUCKOO_TEST -#define CUCKOO_TEST - -#define CT_TEST_REHASH -#define CT_TEST_STASH - -/*----------------------------------------------------------------------------*/ - -int ct_test_hash_table( char *filename ); - -int ct_start_server( char *filename ); - -/*----------------------------------------------------------------------------*/ - -#endif // CUCKOO_TEST diff --git a/src/tests/cuckoo-test.c b/src/tests/cuckoo_tests.c similarity index 95% rename from src/tests/cuckoo-test.c rename to src/tests/cuckoo_tests.c index cdd0897299bd62ca06b64805fdacd8c6a99211c4..6bf59e8812e0f1e8698bd98df1a8ce7f64c6a032 100644 --- a/src/tests/cuckoo-test.c +++ b/src/tests/cuckoo_tests.c @@ -1,21 +1,45 @@ -#include "cuckoo-test.h" +#include "tap_unit.h" + +static int cuckoo_tests_count(int argc, char *argv[]); +static int cuckoo_tests_run(int argc, char *argv[]); + +/*! Exported unit API. + */ +unit_api cuckoo_tests_api = { + "Cuckoo hashing", //! Unit name + &cuckoo_tests_count, //! Count scheduled tests + &cuckoo_tests_run //! Run scheduled tests +}; + +/*! \todo Implement theese tests into API. + */ + +/*! This helper routine should report number of + * scheduled tests for given parameters. + */ +static int cuckoo_tests_count(int argc, char *argv[]) +{ + return 0; +} + +/*! Run all scheduled tests for given parameters. + */ +static int cuckoo_tests_run(int argc, char *argv[]) +{ + return 0; +} + #include <stdio.h> #include <string.h> #include <assert.h> #include <urcu.h> -#include "common.h" -#include "cuckoo-hash-table.h" -#include "dns-simple.h" -#include "socket-manager.h" -#include "dispatcher.h" -#include "dynamic-array.h" - //#define CK_TEST_DEBUG //#define CK_TEST_LOOKUP //#define CK_TEST_OUTPUT //#define CK_TEST_REMOVE //#define CK_TEST_COMPARE +#define CT_TEST_REHASH #ifdef CK_TEST_DEBUG #define CK_TEST_LOOKUP @@ -35,6 +59,13 @@ #define ERR_FILL 9 #define ERR_REMOVE 10 +#include "common.h" +#include "cuckoo-hash-table.h" +#include "dns-simple.h" +#include "socket-manager.h" +#include "dispatcher.h" +#include "dynamic-array.h" + static const uint BUF_SIZE = 20; static const uint ARRAY_SIZE = 500; @@ -250,7 +281,7 @@ int ct_hash_names( ck_hash_table *table, char **domains, uint count ) //if ((i & (((uint32_t)1<<(10)) - 1)) == 0) printf("%u\n", i); if ((res = ck_insert_item(table, domains[i], strlen(domains[i]), - domains[i])) + domains[i])) != 0) { fprintf(stderr, "\nInsert item returned %d.\n", res); return ERR_INSERT; @@ -448,7 +479,7 @@ void ct_answer_request( const char *query_wire, uint size, #ifdef CK_TEST_OUTPUT printf("Query parsed, ID: %u, QNAME: %s\n", query->header.id, - query->questions[0].qname); + query->questions[0].qname); hex_print(query->questions[0].qname, strlen(query->questions[0].qname)); #endif @@ -624,7 +655,7 @@ int ct_compare_items_array( da_array *items1, da_array *items2 ) int found = 0; for (uint j = 0; j < count2; ++j) { if (strcmp(((char **)(da_get_items(items1)))[i], - ((char **)(da_get_items(items2)))[j]) == 0) { + ((char **)(da_get_items(items2)))[j]) == 0) { ++found; } } @@ -650,7 +681,7 @@ int ct_compare_items_array( da_array *items1, da_array *items2 ) int found = 0; for (uint j = 0; j < count1; ++j) { if (strcmp(((char **)(da_get_items(items1)))[j], - ((char **)(da_get_items(items2)))[i]) == 0) { + ((char **)(da_get_items(items2)))[i]) == 0) { ++found; } } @@ -707,7 +738,7 @@ void *ct_read_item( ck_hash_table *table, const dnss_dname test_name ) // get a reference to the item, protect by RCU printf("[Read] Acquiring reference to the item...\n"); printf("[Read] Key: %*s, key size: %u\n", dname_size, test_dname, - dname_size); + dname_size); rcu_read_lock(); const ck_hash_table_item *item = ck_find_item(table, test_dname, dname_size - 1); @@ -717,16 +748,16 @@ void *ct_read_item( ck_hash_table *table, const dnss_dname test_name ) rcu_unregister_thread(); return NULL; } - printf("[Read] Found item with key: %*s, value: %p\n", item->key_length, - item->key, item->value); + //printf("[Read] Found item with key: %*s, value: %p\n", item->key_length, + // item->key, item->value); // wait some time, so that the item is deleted printf("[Read] Waiting...\n"); ct_waste_time(5000000); printf("[Read] Done.\n"); - printf("[Read] Still holding item with key: %*s, value: %p\n", - item->key_length, item->key, item->value); + //printf("[Read] Still holding item with key: %*s, value: %p\n", + // item->key_length, item->key, item->value); // release the pointer printf("[Read] Releasing the item...\n"); @@ -902,7 +933,7 @@ int ct_test_hash_table( char *filename ) printf("Testing lookup...\n\n"); res = ct_test_fnc_from_file(table, file, ct_test_lookup); printf("\nDone. Items not found: %d\n\n", - da_get_count(&items_not_found)); + da_get_count(&items_not_found)); ct_clear_items_array(&items_not_found); printf("Testing rehash...\n"); @@ -916,7 +947,7 @@ int ct_test_hash_table( char *filename ) printf("Testing lookup...\n\n"); res = ct_test_fnc_from_file(table, file, ct_test_lookup); printf("\nDone. Items not found: %d\n\n", - da_get_count(&items_not_found)); + da_get_count(&items_not_found)); ct_clear_items_array(&items_not_found); printf("Testing removal...\n\n"); @@ -928,7 +959,7 @@ int ct_test_hash_table( char *filename ) printf("\nDone. Result: %d\n\n", res); printf("Comparing array of not found items with array of removed " - "items...\n\n"); + "items...\n\n"); res = ct_compare_items_array(&items_not_found, &items_removed); printf("\nDone. Result: %d\n\n", res); diff --git a/src/tests/dnslib_tests.c b/src/tests/dnslib_tests.c new file mode 100644 index 0000000000000000000000000000000000000000..cc9e5a7b5b2183f383e00b4d3e74a58135f6ccaf --- /dev/null +++ b/src/tests/dnslib_tests.c @@ -0,0 +1,30 @@ +#include "tap_unit.h" + +static int dnslib_tests_count(int argc, char *argv[]); +static int dnslib_tests_run(int argc, char *argv[]); + +/*! Exported unit API. + */ +unit_api dnslib_tests_api = { + "DNS library", //! Unit name + &dnslib_tests_count, //! Count scheduled tests + &dnslib_tests_run //! Run scheduled tests +}; + +/*! \todo Implement theese tests into API. + */ + +/*! This helper routine should report number of + * scheduled tests for given parameters. + */ +static int dnslib_tests_count(int argc, char *argv[]) +{ + return 0; +} + +/*! Run all scheduled tests for given parameters. + */ +static int dnslib_tests_run(int argc, char *argv[]) +{ + return 0; +} diff --git a/src/tests/main.c b/src/tests/main.c index 5950d71bdd88c8b8bd5957f293b784cbc2a2330a..a7173a73815fb75692f98ebbf8b64e28c9e577a9 100644 --- a/src/tests/main.c +++ b/src/tests/main.c @@ -2,9 +2,12 @@ #include "common.h" // Units to test -#include "server_tests.c" #include "skiplist_tests.c" #include "da_tests.c" +#include "cuckoo_tests.c" +#include "zonedb_tests.c" +#include "dnslib_tests.c" +#include "server_tests.c" // Run all loaded units int main(int argc, char * argv[]) @@ -13,6 +16,9 @@ int main(int argc, char * argv[]) unit_api* tests[] = { &skiplist_tests_api, //! Skip list unit &da_tests_api, //! Dynamic array unit + &cuckoo_tests_api, //! Cuckoo hashing unit + &zonedb_tests_api, //! Zone database unit + &dnslib_tests_api, //! DNS library unit &server_tests_api, //! Server unit NULL }; diff --git a/src/tests/skiplist_tests.c b/src/tests/skiplist_tests.c index f2f7785bb8dda3c81accdb757d2c95edfbdd42ea..6d1aa90533a8b5799b58fba61faba4b3631acce5 100644 --- a/src/tests/skiplist_tests.c +++ b/src/tests/skiplist_tests.c @@ -1,5 +1,6 @@ #include "tap_unit.h" #include "skip-list.h" +#include <time.h> static int skiplist_tests_count(int argc, char * argv[]); static int skiplist_tests_run(int argc, char * argv[]); diff --git a/src/tests/zonedb_tests.c b/src/tests/zonedb_tests.c new file mode 100644 index 0000000000000000000000000000000000000000..ab4480655a79ab45324ac2479ab7a8454adf345b --- /dev/null +++ b/src/tests/zonedb_tests.c @@ -0,0 +1,30 @@ +#include "tap_unit.h" + +static int zonedb_tests_count(int argc, char *argv[]); +static int zonedb_tests_run(int argc, char *argv[]); + +/*! Exported unit API. + */ +unit_api zonedb_tests_api = { + "Zone database", //! Unit name + &zonedb_tests_count, //! Count scheduled tests + &zonedb_tests_run //! Run scheduled tests +}; + +/*! \todo Implement theese tests into API. + */ + +/*! This helper routine should report number of + * scheduled tests for given parameters. + */ +static int zonedb_tests_count(int argc, char *argv[]) +{ + return 0; +} + +/*! Run all scheduled tests for given parameters. + */ +static int zonedb_tests_run(int argc, char *argv[]) +{ + return 0; +}