@@ -60,6 +60,7 @@ static void srunner_run_init(SRunner * sr, enum print_output print_mode);
6060static void srunner_run_end (SRunner * sr , enum print_output print_mode );
6161static void srunner_iterate_suites (SRunner * sr ,
6262 const char * sname , const char * tcname ,
63+ const char * inc_tags , const char * exc_tags ,
6364 enum print_output print_mode );
6465static void srunner_iterate_tcase_tfuns (SRunner * sr , TCase * tc );
6566static void srunner_add_failure (SRunner * sr , TestResult * tf );
@@ -158,8 +159,50 @@ static void srunner_run_end(SRunner * sr,
158159 set_fork_status (CK_FORK );
159160}
160161
162+ /*
163+ * Helper func to compare two lists of tags and return true if there is a
164+ * common tag.
165+ */
166+ static unsigned int matching_tag (const char * tags1_orig , const char * tags2_orig )
167+ {
168+
169+ char * saveptr1 ;
170+ char * saveptr2 ;
171+ char * tags1 ;
172+ char * tag1 ;
173+
174+
175+ if ((tags1_orig == NULL ) || (tags2_orig == NULL ))
176+ return 0 ;
177+
178+ tags1 = strdup (tags1_orig );
179+ tag1 = strtok_r (tags1 , " " , & saveptr1 );
180+ while (tag1 ) {
181+
182+ char * tags2 , * tag2 ;
183+
184+ tags2 = strdup (tags2_orig );
185+ tag2 = strtok_r (tags2 , " " , & saveptr2 );
186+ while (tag2 ) {
187+ if (strcmp (tag1 , tag2 ) == 0 ) {
188+
189+ free (tags2 );
190+ free (tags1 );
191+ return 1 ;
192+ }
193+
194+ tag2 = strtok_r (NULL , " " , & saveptr2 );
195+ }
196+ free (tags2 );
197+ tag1 = strtok_r (NULL , " " , & saveptr1 );
198+ }
199+ free (tags1 );
200+ return 0 ;
201+ }
202+
161203static void srunner_iterate_suites (SRunner * sr ,
162204 const char * sname , const char * tcname ,
205+ const char * inc_tags , const char * exc_tags ,
163206 enum print_output CK_ATTRIBUTE_UNUSED
164207 print_mode )
165208{
@@ -191,6 +234,14 @@ static void srunner_iterate_suites(SRunner * sr,
191234 {
192235 continue ;
193236 }
237+ if (inc_tags != NULL ) {
238+ if (!matching_tag (inc_tags , tc -> tags ))
239+ continue ;
240+ }
241+ if (exc_tags != NULL ) {
242+ if (matching_tag (inc_tags , tc -> tags ))
243+ continue ;
244+ }
194245
195246 srunner_run_tcase (sr , tc );
196247 }
@@ -738,10 +789,13 @@ void srunner_run_all(SRunner * sr, enum print_output print_mode)
738789{
739790 srunner_run (sr , NULL , /* All test suites. */
740791 NULL , /* All test cases. */
792+ NULL , /* Include all tags */
793+ NULL , /* Exclude no tags */
741794 print_mode );
742795}
743796
744797void srunner_run (SRunner * sr , const char * sname , const char * tcname ,
798+ const char * inc_tags , const char * exc_tags ,
745799 enum print_output print_mode )
746800{
747801#if defined(HAVE_SIGACTION ) && defined(HAVE_FORK )
@@ -756,7 +810,11 @@ void srunner_run(SRunner * sr, const char *sname, const char *tcname,
756810 if (!tcname )
757811 tcname = getenv ("CK_RUN_CASE" );
758812 if (!sname )
759- sname = getenv ("CK_RUN_SUITE" );
813+ sname = getenv ("CK_RUN_SUITE" );
814+ if (!inc_tags )
815+ inc_tags = getenv ("CK_INC_TAGS" );
816+ if (!exc_tags )
817+ exc_tags = getenv ("CK_EXC_TAGS" );
760818
761819 if (sr == NULL )
762820 return ;
@@ -779,7 +837,7 @@ void srunner_run(SRunner * sr, const char *sname, const char *tcname,
779837 sigaction (SIGTERM , & sigterm_new_action , & sigterm_old_action );
780838#endif /* HAVE_SIGACTION && HAVE_FORK */
781839 srunner_run_init (sr , print_mode );
782- srunner_iterate_suites (sr , sname , tcname , print_mode );
840+ srunner_iterate_suites (sr , sname , tcname , inc_tags , exc_tags , print_mode );
783841 srunner_run_end (sr , print_mode );
784842#if defined(HAVE_SIGACTION ) && defined(HAVE_FORK )
785843 sigaction (SIGALRM , & sigalarm_old_action , NULL );
0 commit comments