[igt-dev] [PATCH i-g-t 2/4] runner: const-correct the unit tests

Arkadiusz Hiler arkadiusz.hiler at intel.com
Mon Nov 5 11:35:45 UTC 2018


On Mon, Oct 29, 2018 at 04:30:52PM +0200, Petri Latvala wrote:
> const where possible, and cast away const when passing argv to
> parse_options, which expects non-const strings, because it passes them
> to getopt_long, which expects non-const strings...
> 
> Signed-off-by: Petri Latvala <petri.latvala at intel.com>
> ---
>  runner/runner_tests.c | 318 +++++++++++++++++++++---------------------
>  1 file changed, 159 insertions(+), 159 deletions(-)
> 
> diff --git a/runner/runner_tests.c b/runner/runner_tests.c
> index 9c0f9eb0..d07e6f37 100644
> --- a/runner/runner_tests.c
> +++ b/runner/runner_tests.c
> @@ -12,7 +12,7 @@
>  
>  static char testdatadir[] = TESTDATA_DIRECTORY;
>  
> -static void igt_assert_eqstr(char *one, char *two)
> +static void igt_assert_eqstr(const char *one, const char *two)
>  {
>  	if (one == NULL && two == NULL)
>  		return;
> @@ -38,7 +38,7 @@ static void debug_print_executions(struct job_list *list)
>  
>  }
>  
> -static char *dump_file(int dirfd, char *name)
> +static char *dump_file(int dirfd, const char *name)
>  {
>  	int fd = openat(dirfd, name, O_RDONLY);
>  	ssize_t s;
> @@ -61,7 +61,7 @@ static char *dump_file(int dirfd, char *name)
>  	return buf;
>  }
>  
> -static void job_list_filter_test(char *name, char *filterarg1, char *filterarg2,
> +static void job_list_filter_test(const char *name, const char *filterarg1, const char *filterarg2,
>  				 size_t expected_normal, size_t expected_multiple)
>  {
>  	int multiple;
> @@ -73,18 +73,18 @@ static void job_list_filter_test(char *name, char *filterarg1, char *filterarg2,
>  	for (multiple = 0; multiple < 2; multiple++) {
>  		igt_subtest_f("job-list-filters-%s-%s", name, multiple ? "multiple" : "normal") {
>  			struct job_list list;
> -			char *argv[] = { "runner",
> -					 /* Ugly but does the trick */
> -					 multiple ? "--multiple-mode" : "--sync",
> -					 filterarg1, filterarg2,
> -					 testdatadir,
> -					 "path-to-results",
> +			const char *argv[] = { "runner",
> +					       /* Ugly but does the trick */
> +					       multiple ? "--multiple-mode" : "--sync",
> +					       filterarg1, filterarg2,
> +					       testdatadir,
> +					       "path-to-results",
>  			};
>  			bool success = false;
>  			size_t size;
>  
>  			init_job_list(&list);
> -			igt_assert(parse_options(ARRAY_SIZE(argv), argv, &settings));
> +			igt_assert(parse_options(ARRAY_SIZE(argv), (char**)argv, &settings));

Please include explanation, In the commit message, why you are making
`char *argv[]` const and then you still resort to (char**) cast here.

With that,
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
for the whole series.


More information about the igt-dev mailing list