60
60
#include <stdio.h>
61
61
#include <stdlib.h>
62
62
#include <string.h>
63
+ #include <sys/mman.h>
63
64
#include <sys/types.h>
64
65
#include <sys/wait.h>
65
66
#include <unistd.h>
122
123
* and runs "statement", which is usually "return" or "goto skip".
123
124
*/
124
125
#define SKIP (statement , fmt , ...) do { \
126
+ snprintf(_metadata->results->reason, \
127
+ sizeof(_metadata->results->reason), fmt, ##__VA_ARGS__); \
125
128
if (TH_LOG_ENABLED) { \
126
- fprintf(TH_LOG_STREAM, "# SKIP " fmt " \n", \
127
- ##__VA_ARGS__ ); \
129
+ fprintf(TH_LOG_STREAM, "# SKIP %s \n", \
130
+ _metadata->results->reason ); \
128
131
} \
129
132
_metadata->passed = 1; \
130
133
_metadata->skip = 1; \
762
765
} \
763
766
}
764
767
768
+ struct __test_results {
769
+ char reason [1024 ]; /* Reason for test result */
770
+ };
771
+
765
772
struct __test_metadata ;
766
773
struct __fixture_variant_metadata ;
767
774
@@ -815,6 +822,7 @@ struct __test_metadata {
815
822
bool timed_out ; /* did this test timeout instead of exiting? */
816
823
__u8 step ;
817
824
bool no_print ; /* manual trigger when TH_LOG_STREAM is not available */
825
+ struct __test_results * results ;
818
826
struct __test_metadata * prev , * next ;
819
827
};
820
828
@@ -957,6 +965,7 @@ void __run_test(struct __fixture_metadata *f,
957
965
t -> trigger = 0 ;
958
966
t -> step = 0 ;
959
967
t -> no_print = 0 ;
968
+ memset (t -> results -> reason , 0 , sizeof (t -> results -> reason ));
960
969
961
970
ksft_print_msg (" RUN %s%s%s.%s ...\n" ,
962
971
f -> name , variant -> name [0 ] ? "." : "" , variant -> name , t -> name );
@@ -986,8 +995,8 @@ void __run_test(struct __fixture_metadata *f,
986
995
f -> name , variant -> name [0 ] ? "." : "" , variant -> name , t -> name );
987
996
988
997
if (t -> skip )
989
- ksft_test_result_skip ("%s%s%s.%s \n" ,
990
- f -> name , variant -> name [ 0 ] ? "." : "" , variant -> name , t -> name );
998
+ ksft_test_result_skip ("%s\n" , t -> results -> reason [ 0 ] ?
999
+ t -> results -> reason : "unknown" );
991
1000
else
992
1001
ksft_test_result (t -> passed , "%s%s%s.%s\n" ,
993
1002
f -> name , variant -> name [0 ] ? "." : "" , variant -> name , t -> name );
@@ -999,6 +1008,7 @@ static int test_harness_run(int __attribute__((unused)) argc,
999
1008
struct __fixture_variant_metadata no_variant = { .name = "" , };
1000
1009
struct __fixture_variant_metadata * v ;
1001
1010
struct __fixture_metadata * f ;
1011
+ struct __test_results * results ;
1002
1012
struct __test_metadata * t ;
1003
1013
int ret = 0 ;
1004
1014
unsigned int case_count = 0 , test_count = 0 ;
@@ -1013,6 +1023,9 @@ static int test_harness_run(int __attribute__((unused)) argc,
1013
1023
}
1014
1024
}
1015
1025
1026
+ results = mmap (NULL , sizeof (* results ), PROT_READ | PROT_WRITE ,
1027
+ MAP_SHARED | MAP_ANONYMOUS , -1 , 0 );
1028
+
1016
1029
ksft_print_header ();
1017
1030
ksft_set_plan (test_count );
1018
1031
ksft_print_msg ("Starting %u tests from %u test cases.\n" ,
@@ -1021,14 +1034,18 @@ static int test_harness_run(int __attribute__((unused)) argc,
1021
1034
for (v = f -> variant ?: & no_variant ; v ; v = v -> next ) {
1022
1035
for (t = f -> tests ; t ; t = t -> next ) {
1023
1036
count ++ ;
1037
+ t -> results = results ;
1024
1038
__run_test (f , v , t );
1039
+ t -> results = NULL ;
1025
1040
if (t -> passed )
1026
1041
pass_count ++ ;
1027
1042
else
1028
1043
ret = 1 ;
1029
1044
}
1030
1045
}
1031
1046
}
1047
+ munmap (results , sizeof (* results ));
1048
+
1032
1049
ksft_print_msg ("%s: %u / %u tests passed.\n" , ret ? "FAILED" : "PASSED" ,
1033
1050
pass_count , count );
1034
1051
ksft_exit (ret == 0 );
0 commit comments