@@ -26,6 +26,9 @@ Approach for this tests is basing on filter_kubernetes tests
26
26
#include <fluent-bit/flb_time.h>
27
27
#include <fluent-bit/flb_pthread.h>
28
28
#include <fluent-bit/flb_compat.h>
29
+ #ifdef FLB_HAVE_UNICODE_ENCODER
30
+ #include <fluent-bit/simdutf/flb_simdutf_connector.h>
31
+ #endif
29
32
#include <stdlib.h>
30
33
#include <sys/stat.h>
31
34
#include <sys/types.h>
@@ -436,6 +439,52 @@ static int cb_check_result(void *record, size_t size, void *data)
436
439
return 0 ;
437
440
}
438
441
442
+ #ifdef FLB_HAVE_UNICODE_ENCODER
443
+ static int cb_check_result_unicode (void * record , size_t size , void * data )
444
+ {
445
+ struct tail_test_result * result ;
446
+ struct tail_file_lines * out ;
447
+ int valid = FLB_FALSE ;
448
+
449
+ result = (struct tail_test_result * ) data ;
450
+
451
+ char * check ;
452
+
453
+ out = get_out_file_content (result -> target );
454
+ if (!out -> lines_c ) {
455
+ goto exit ;
456
+ }
457
+
458
+ valid = flb_simdutf_connector_validate_utf8 (record , size );
459
+ if (valid == FLB_FALSE ) {
460
+ goto exit ;
461
+ }
462
+ /*
463
+ * Our validation is: check that the one of the output lines
464
+ * in the output record.
465
+ */
466
+ int i ;
467
+ result -> nLines = out -> lines_c ;
468
+ for (i = 0 ; i < out -> lines_c ; i ++ ) {
469
+ check = strstr (record , out -> lines [i ]);
470
+ if (check != NULL ) {
471
+ result -> nMatched ++ ;
472
+ goto exit ;
473
+ }
474
+ }
475
+ result -> nNotMatched ++ ;
476
+ exit :
477
+ if (size > 0 ) {
478
+ flb_free (record );
479
+ }
480
+ if (out -> lines_c ) {
481
+ flb_free (out -> lines [0 ]);
482
+ flb_free (out );
483
+ }
484
+ return 0 ;
485
+ }
486
+ #endif
487
+
439
488
void do_test (char * system , const char * target , int tExpected , int nExpected , ...)
440
489
{
441
490
int64_t ret ;
@@ -557,6 +606,121 @@ void flb_test_in_tail_dockermode_firstline_detection()
557
606
NULL );
558
607
}
559
608
609
+ #ifdef FLB_HAVE_UNICODE_ENCODER
610
+ void do_test_unicode (char * system , const char * target , int nExpected , ...)
611
+ {
612
+ int64_t ret ;
613
+ flb_ctx_t * ctx = NULL ;
614
+ int in_ffd ;
615
+ int out_ffd ;
616
+ va_list va ;
617
+ char * key ;
618
+ char * value ;
619
+ char path [PATH_MAX ];
620
+ struct tail_test_result result = {0 };
621
+
622
+ result .nMatched = 0 ;
623
+ result .target = target ;
624
+
625
+ struct flb_lib_out_cb cb ;
626
+ cb .cb = cb_check_result_unicode ;
627
+ cb .data = & result ;
628
+
629
+ /* initialize */
630
+ set_result (0 );
631
+
632
+ ctx = flb_create ();
633
+
634
+ ret = flb_service_set (ctx ,
635
+ "Log_Level" , "error" ,
636
+ NULL );
637
+ TEST_CHECK_ (ret == 0 , "setting service options" );
638
+
639
+ in_ffd = flb_input (ctx , (char * ) system , NULL );
640
+ TEST_CHECK (in_ffd >= 0 );
641
+ TEST_CHECK (flb_input_set (ctx , in_ffd , "tag" , "test" , NULL ) == 0 );
642
+
643
+ /* Compose path based on target */
644
+ snprintf (path , sizeof (path ) - 1 , DPATH "/log/%s.log" , target );
645
+ TEST_CHECK_ (access (path , R_OK ) == 0 , "accessing log file: %s" , path );
646
+
647
+ TEST_CHECK (flb_input_set (ctx , in_ffd ,
648
+ "path" , path ,
649
+ "read_from_head" , "true" ,
650
+ NULL ) == 0 );
651
+
652
+ va_start (va , nExpected );
653
+ while ((key = va_arg (va , char * ))) {
654
+ value = va_arg (va , char * );
655
+ TEST_CHECK (value != NULL );
656
+ TEST_CHECK (flb_input_set (ctx , in_ffd , key , value , NULL ) == 0 );
657
+ }
658
+ va_end (va );
659
+
660
+ out_ffd = flb_output (ctx , (char * ) "lib" , & cb );
661
+ TEST_CHECK (out_ffd >= 0 );
662
+ TEST_CHECK (flb_output_set (ctx , out_ffd ,
663
+ "match" , "test" ,
664
+ "format" , "json" ,
665
+ NULL ) == 0 );
666
+
667
+ TEST_CHECK (flb_service_set (ctx , "Flush" , "0.5" ,
668
+ "Grace" , "1" ,
669
+ NULL ) == 0 );
670
+
671
+ /* Start test */
672
+ /* Start the engine */
673
+ ret = flb_start (ctx );
674
+ TEST_CHECK_ (ret == 0 , "starting engine" );
675
+
676
+ /* /\* Poll for up to 5 seconds or until we got a match *\/ */
677
+ /* for (ret = 0; result.nMatched <= nExpected; ret++) { */
678
+ /* usleep(1000); */
679
+ /* } */
680
+
681
+ /* Wait until matching nExpected results */
682
+ wait_with_timeout (5000 , & result , nExpected );
683
+
684
+ TEST_CHECK (result .nMatched == nExpected );
685
+ TEST_MSG ("result.nMatched: %i\nnExpected: %i" , result .nMatched , nExpected );
686
+
687
+ ret = flb_stop (ctx );
688
+ TEST_CHECK_ (ret == 0 , "stopping engine" );
689
+
690
+ if (ctx ) {
691
+ flb_destroy (ctx );
692
+ }
693
+ }
694
+
695
+ void flb_test_in_tail_utf16le_c ()
696
+ {
697
+ do_test_unicode ("tail" , "unicode_c" , 1 ,
698
+ "Unicode.Encoding" , "auto" ,
699
+ NULL );
700
+ }
701
+
702
+ void flb_test_in_tail_utf16be_c ()
703
+ {
704
+ do_test_unicode ("tail" , "unicode_be_c" , 1 ,
705
+ "Unicode.Encoding" , "auto" ,
706
+ NULL );
707
+ }
708
+
709
+ void flb_test_in_tail_utf16le_j ()
710
+ {
711
+ do_test_unicode ("tail" , "unicode_j" , 1 ,
712
+ "Unicode.Encoding" , "auto" ,
713
+ NULL );
714
+ }
715
+
716
+ void flb_test_in_tail_utf16be_j ()
717
+ {
718
+ do_test_unicode ("tail" , "unicode_be_j" , 1 ,
719
+ "Unicode.Encoding" , "auto" ,
720
+ NULL );
721
+ }
722
+ #endif
723
+
560
724
int write_long_lines (int fd ) {
561
725
ssize_t ret ;
562
726
int i ;
@@ -1978,6 +2142,13 @@ TEST_LIST = {
1978
2142
{"db_compare_filename" , flb_test_db_compare_filename },
1979
2143
#endif
1980
2144
2145
+ #ifdef FLB_HAVE_UNICODE_ENCODER
2146
+ {"utf16le_c" , flb_test_in_tail_utf16le_c },
2147
+ {"utf16be_c" , flb_test_in_tail_utf16be_c },
2148
+ {"utf16le_j" , flb_test_in_tail_utf16le_j },
2149
+ {"utf16be_j" , flb_test_in_tail_utf16be_j },
2150
+ #endif
2151
+
1981
2152
#ifdef in_tail
1982
2153
{"in_tail_dockermode" , flb_test_in_tail_dockermode },
1983
2154
{"in_tail_dockermode_splitted_line" , flb_test_in_tail_dockermode_splitted_line },
0 commit comments