diff options
Diffstat (limited to 'test/test.c')
| -rw-r--r-- | test/test.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/test/test.c b/test/test.c index c988439..944e1e5 100644 --- a/test/test.c +++ b/test/test.c @@ -3,6 +3,7 @@ #include <string.h> #include <unistd.h> #include <time.h> +#include <assert.h> #include "cJSON.h" @@ -126,6 +127,40 @@ static void print_confusion_matrix(unsigned int *result, unsigned int os_class_m printf("miss rate: %u%%\n", 100 * missed / (matched + missed)); } +struct osfp_result *test_osfp_json_identify(struct osfp_db *db, const char *json_str) +{ + int ret = OSFP_EINVAL; + struct osfp_fingerprint fp; + struct osfp_os_class_score os_class_score; + struct osfp_result *result; + const char *matched; + + if (db == NULL || json_str == NULL) { + goto exit; + } + + ret = osfp_fingerprint_from_json(&fp, (char *)json_str); + if (ret != 0) { + goto exit; + } + + matched = osfp_score_db_prefilter(db->score_db, &fp, &os_class_score); + if (matched == NULL) { + ret = osfp_score_db_score(db->score_db, 0, &fp, &os_class_score); + if (ret != 0) { + goto exit; + } + } + + result = osfp_result_build(&os_class_score, matched); + if (result == NULL) { + goto exit; + } + + return result; +exit: + return NULL; +} void test_data_prepare() { @@ -229,7 +264,7 @@ void test_miss_rate() osfp_fingerprint_to_json_buf(&fp, str_buf, 2048, 0); fprintf(log_file_ptr, "%s\n", str_buf); - struct osfp_result *result = osfp_json_identify(osfp_db, fp_str); + struct osfp_result *result = test_osfp_json_identify(osfp_db, fp_str); if (result == NULL) { identify_failed_count++; continue; |
