[Intel-gfx] [PATCH i-g-t 1/2] Add support for subtest-specific documentation

Petri Latvala petri.latvala at intel.com
Thu Aug 10 08:31:44 UTC 2017


On Wed, Aug 09, 2017 at 01:18:55PM -0700, Belgaumkar, Vinay wrote:
> > @@ -710,6 +721,8 @@ static int common_init(int *argc, char **argv,
> >   	static struct option long_options[] = {
> >   		{"list-subtests", 0, 0, OPT_LIST_SUBTESTS},
> >   		{"run-subtest", 1, 0, OPT_RUN_SUBTEST},
> > +		{"document-all-subtests", 0, 0, OPT_DOC_SUBTESTS},
> > +		{"document-subtest", 1, 0, OPT_DOC_SINGLE_SUBTEST},
> 
> Can we add these options to the README file as well?
>


Sending another series soon with README updated.


> >   		{"help-description", 0, 0, OPT_DESCRIPTION},
> >   		{"debug", optional_argument, 0, OPT_DEBUG},
> >   		{"interactive-debug", optional_argument, 0, OPT_INTERACTIVE_DEBUG},
> > @@ -800,12 +813,24 @@ static int common_init(int *argc, char **argv,
> >   				igt_log_domain_filter = strdup(optarg);
> >   			break;
> >   		case OPT_LIST_SUBTESTS:
> > -			if (!run_single_subtest)
> > -				list_subtests = true;
> > +			if (runmode == EXECUTE_ALL)
> > +				runmode = LIST_SUBTESTS;
> >   			break;
> >   		case OPT_RUN_SUBTEST:
> > -			if (!list_subtests)
> > -				run_single_subtest = strdup(optarg);
> > +			if (runmode == EXECUTE_ALL) {
> > +				runmode = EXECUTE_SINGLE;
> > +				single_subtest = strdup(optarg);
> > +			}
> > +			break;
> > +		case OPT_DOC_SUBTESTS:
> > +			if (runmode == EXECUTE_ALL)
> > +				runmode = DOCUMENT;
> > +			break;
> > +		case OPT_DOC_SINGLE_SUBTEST:
> > +			if (runmode == EXECUTE_ALL) {
> > +				runmode = DOCUMENT_SINGLE;
> > +				single_subtest = strdup(optarg);
> > +			}
> >   			break;
> >   		case OPT_DESCRIPTION:
> >   			print_test_description();
> > @@ -837,11 +862,11 @@ out:
> >   	/* exit immediately if this test has no subtests and a subtest or the
> >   	 * list of subtests has been requested */
> >   	if (!test_with_subtests) {
> > -		if (run_single_subtest) {
> > -			igt_warn("Unknown subtest: %s\n", run_single_subtest);
> > +		if (runmode == EXECUTE_SINGLE || runmode == DOCUMENT_SINGLE) {
> > +			igt_warn("Unknown subtest: %s\n", single_subtest);
> >   			exit(IGT_EXIT_INVALID);
> >   		}
> > -		if (list_subtests)
> > +		if (runmode == LIST_SUBTESTS || runmode == DOCUMENT)
> >   			exit(IGT_EXIT_INVALID);
> >   	}
> > @@ -849,7 +874,7 @@ out:
> >   		/* exit with no error for -h/--help */
> >   		exit(ret == -1 ? 0 : IGT_EXIT_INVALID);
> > -	if (!list_subtests) {
> > +	if (!igt_only_collect_data()) {
> >   		kick_fbcon(false);
> >   		kmsg(KERN_INFO "[IGT] %s: executing\n", command_str);
> >   		print_version();
> > @@ -957,16 +982,37 @@ bool __igt_run_subtest(const char *subtest_name)
> >   			igt_exit();
> >   		}
> > -	if (list_subtests) {
> > +	if (runmode == LIST_SUBTESTS) {
> >   		printf("%s\n", subtest_name);
> >   		return false;
> >   	}
> > -	if (run_single_subtest) {
> > -		if (uwildmat(subtest_name, run_single_subtest) == 0)
> > +	if (runmode == DOCUMENT) {
> > +		if (current_subtest_documentation) {
> > +			printf("%s:\n\n", subtest_name);
> > +			printf("%s", current_subtest_documentation);
> > +			free(current_subtest_documentation);
> > +			current_subtest_documentation = NULL;
> > +		}
> > +		return false;
> > +	}
> > +
> > +	if (runmode == EXECUTE_SINGLE || runmode == DOCUMENT_SINGLE) {
> > +		if (uwildmat(subtest_name, single_subtest) == 0)
> >   			return false;
> > -		else
> > -			run_single_subtest_found = true;
> > +		else {
> > +			single_subtest_found = true;
> > +
> > +			if (runmode == DOCUMENT_SINGLE) {
> > +				if (current_subtest_documentation) {
> > +					printf("%s", current_subtest_documentation);
> > +					free(current_subtest_documentation);
> > +					current_subtest_documentation = NULL;
> > +				}
> > +
> > +				return false;
> > +			}
> > +		}
> >   	}
> >   	if (skip_subtests_henceforth) {
> > @@ -983,10 +1029,51 @@ bool __igt_run_subtest(const char *subtest_name)
> >   	_igt_log_buffer_reset();
> >   	gettime(&subtest_time);
> > +
> >   	return (in_subtest = subtest_name);
> >   }
> >   /**
> > + * igt_document_subtest:
> > + * @documentation: documentation for the next subtest
> > + *
> > + * This function sets the documentation string for the next occurring subtest.
> > + */
> > +void igt_document_subtest(const char *documentation)
> > +{
> > +	if (runmode == DOCUMENT || runmode == DOCUMENT_SINGLE) {
> > +		free(current_subtest_documentation);
> > +		current_subtest_documentation = strdup(documentation);
> > +	}
> > +}
> > +
> > +/**
> > + * igt_document_subtest_f:
> > + * @documentation: Documentation for the next subtest
> > + * @...: format string and optional arguments
> > + *
> > + * This function sets the documentation string for the next occurring subtest.
> > + *
> > + * Like igt_document_subtest(), but also accepts a printf format
> > + * string instead of a static string.
> > + */
> > +__attribute__((format(printf, 1, 2)))
> > +void igt_document_subtest_f(const char *documentation, ...)
> > +{
> > +	int err;
> > +	va_list args;
> > +
> > +	if (runmode == DOCUMENT || runmode == DOCUMENT_SINGLE) {
> > +		free(current_subtest_documentation);
> > +		va_start(args, documentation);
> > +		err = vasprintf(&current_subtest_documentation, documentation, args);
> 
> Missing va_end?
>

Yep, thanks for spotting this.



> > +		if (err < 0)
> > +			current_subtest_documentation = NULL;
> > +	}
> > +}
> > +
> > +
> > +/**
> >    * igt_subtest_name:
> >    *
> >    * Returns: The name of the currently executed subtest or NULL if called from
> > @@ -998,14 +1085,14 @@ const char *igt_subtest_name(void)
> >   }
> >   /**
> > - * igt_only_list_subtests:
> > + * igt_only_collect_data:
> >    *
> > - * Returns: Returns true if only subtest should be listed and any setup code
> > + * Returns: Returns true if the running mode is only collecting data and any setup code
> >    * must be skipped, false otherwise.
> >    */
> > -bool igt_only_list_subtests(void)
> > +bool igt_only_collect_data(void)
> >   {
> > -	return list_subtests;
> > +	return runmode != EXECUTE_ALL && runmode != EXECUTE_SINGLE;
> >   }
> >   void __igt_subtest_group_save(int *save)
> > @@ -1059,7 +1146,7 @@ void igt_skip(const char *f, ...)
> >   	assert(!test_child);
> > -	if (!igt_only_list_subtests()) {
> > +	if (!igt_only_collect_data()) {
> >   		va_start(args, f);
> >   		vprintf(f, args);
> >   		va_end(args);
> > @@ -1443,12 +1530,12 @@ void igt_exit(void)
> >   		g_key_file_free(igt_key_file);
> >   #endif
> > -	if (run_single_subtest && !run_single_subtest_found) {
> > -		igt_warn("Unknown subtest: %s\n", run_single_subtest);
> > +	if (single_subtest && !single_subtest_found) {
> > +		igt_warn("Unknown subtest: %s\n", single_subtest);
> >   		exit(IGT_EXIT_INVALID);
> >   	}
> > -	if (igt_only_list_subtests())
> > +	if (igt_only_collect_data())
> >   		exit(IGT_EXIT_SUCCESS);
> >   	/* Calling this without calling one of the above is a failure */
> > @@ -2012,7 +2099,7 @@ bool igt_run_in_simulation(void)
> >    */
> >   void igt_skip_on_simulation(void)
> >   {
> > -	if (igt_only_list_subtests())
> > +	if (igt_only_collect_data())
> >   		return;
> >   	if (!in_fixture && !in_subtest) {
> > @@ -2087,7 +2174,7 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
> >   	program_name = command_str;
> >   #endif
> > -	if (list_subtests && level <= IGT_LOG_WARN)
> > +	if (igt_only_collect_data() && level <= IGT_LOG_WARN)
> >   		return;
> >   	if (vasprintf(&line, format, args) == -1)
> > diff --git a/lib/igt_core.h b/lib/igt_core.h
> > index 1619a9d..275e467 100644
> > --- a/lib/igt_core.h
> > +++ b/lib/igt_core.h
> > @@ -197,8 +197,12 @@ bool __igt_run_subtest(const char *subtest_name);
> >   #define igt_subtest_f(f...) \
> >   	__igt_subtest_f(igt_tokencat(__tmpchar, __LINE__), f)
> > +void igt_document_subtest(const char *documentation);
> > +__attribute__((format(printf, 1, 2)))
> > +void igt_document_subtest_f(const char *documentation, ...);
> > +
> >   const char *igt_subtest_name(void);
> > -bool igt_only_list_subtests(void);
> > +bool igt_only_collect_data(void);
> >   void __igt_subtest_group_save(int *);
> >   void __igt_subtest_group_restore(int);
> 
> I have also sent you a separate email with the gtkdoc generated after using
> the new method.
>


The documentation string tracking was indeed done wrong, fixed in the
new series.


--
Petri Latvala


More information about the Intel-gfx mailing list