summaryrefslogtreecommitdiff
path: root/test/test.c
diff options
context:
space:
mode:
authorzhuzhenjun <[email protected]>2023-10-26 13:48:41 +0800
committerzhuzhenjun <[email protected]>2023-10-26 13:48:41 +0800
commit13721781f73b4efc2a8a5115c297581c1310d1bb (patch)
tree478660b968f11f699d9d43c24d718405e08d5591 /test/test.c
parentc9247d713da668ed1bd2d332849dd9409330c0e3 (diff)
code: clean upv1.3.4rel-1.3
Diffstat (limited to 'test/test.c')
-rw-r--r--test/test.c37
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;