18 #include "../suricata-common.h" 
   20 #include "../output-json-stats.h" 
   22 #include "../util-unittest.h" 
   24 static int OutputJsonStatsTest01(
void)
 
   28     thread_records[0].
name = 
"capture.kernel_packets";
 
   29     thread_records[0].
short_name = 
"kernel_packets";
 
   30     thread_records[0].
tm_name = 
"W#01-bond0.30";
 
   31     thread_records[0].
value = 42;
 
   32     thread_records[1].
name = 
"capture.kernel_drops";
 
   34     thread_records[1].
tm_name = 
"W#01-bond0.30";
 
   35     thread_records[1].
value = 4711;
 
   39         .stats = &total_records[0],
 
   41         .tstats = &thread_records[0],
 
   49     json_object_del(r, 
"uptime");
 
   51     char *serialized = json_dumps(r, 0);
 
   54     const char *expected = 
"{\"threads\": {\"W#01-bond0.30\": {\"capture\": {\"kernel_packets\": " 
   55                            "42, \"kernel_drops\": 4711}}}}";
 
   57     int cmp_result = strcmp(expected, serialized);
 
   59         printf(
"unexpected result\nexpected=%s\ngot=%s\n", expected, serialized);
 
   64     return cmp_result == 0;
 
   67 static int OutputJsonStatsTest02(
void)
 
   73     total_records[0].
name = 
"tcp.syn";
 
   75     total_records[0].
tm_name = NULL;
 
   76     total_records[0].
value = 1234;
 
   80     thread_records[1].
name = 
"capture.kernel_packets";
 
   81     thread_records[1].
short_name = 
"kernel_packets";
 
   82     thread_records[1].
tm_name = 
"W#01-bond0.30";
 
   83     thread_records[1].
value = 42;
 
   84     thread_records[2].
name = 
"capture.kernel_drops";
 
   86     thread_records[2].
tm_name = 
"W#01-bond0.30";
 
   87     thread_records[2].
value = 4711;
 
   94     thread_records[7].
name = 
"flow.mgr.full_hash_passes";
 
   95     thread_records[7].
short_name = 
"full_hash_passes";
 
   96     thread_records[7].
tm_name = 
"FM#01";
 
   97     thread_records[7].
value = 10;
 
  101         .stats = &total_records[0],
 
  103         .tstats = &thread_records[0],
 
  111     json_object_del(r, 
"uptime");
 
  113     char *serialized = json_dumps(r, 0);
 
  116     const char *expected = 
"{\"tcp\": {\"syn\": 1234}, \"threads\": {\"W#01-bond0.30\": " 
  117                            "{\"capture\": {\"kernel_packets\": " 
  118                            "42, \"kernel_drops\": 4711}}, \"FM#01\": {\"flow\": {\"mgr\": " 
  119                            "{\"full_hash_passes\": 10}}}}}";
 
  121     int cmp_result = strcmp(expected, serialized);
 
  123         printf(
"unexpected result\nexpected=%s\ngot=%s\n", expected, serialized);
 
  128     return cmp_result == 0;