Re: [PATCH 3/3] libtracefs: Unit test for tracefs_instance_reset()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 28 Mar 2023 18:03:08 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:

> The logic of the tracefs_instance_reset() is complex and should be
> covered by the unit tests of the tracefs library.
> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx>
> ---
>  utest/tracefs-utest.c | 183 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 183 insertions(+)
> 
> diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
> index e0e3c07..5866339 100644
> --- a/utest/tracefs-utest.c
> +++ b/utest/tracefs-utest.c
> @@ -1618,6 +1618,187 @@ static void test_instance_file(void)
>  	free(inst_dir);
>  }
>  
> +static bool test_check_file_contetnt(struct tracefs_instance *instance, char *file,

Misspelling of "content"

> +				     char *content, bool full_match, bool ignore_comments)
> +{
> +	char *save = NULL;
> +	char *buf, *line;
> +	bool ret = false;
> +	int len;
> +
> +	if (!tracefs_file_exists(instance, file))
> +		return false;
> +
> +	buf = tracefs_instance_file_read(instance, file, NULL);
> +	if (strlen(content) == 0) {
> +		/* check for empty file */
> +		if (!buf)
> +			return true;
> +		if (!ignore_comments) {
> +			if (strlen(buf) > 0)
> +				goto out;
> +		} else {
> +			line = strtok_r(buf, "\n", &save);
> +			while (line) {
> +				if (line[0] != '#')
> +					goto out;
> +				line = strtok_r(NULL, "\n", &save);
> +			}
> +		}
> +	} else {
> +		if (!buf || strlen(buf) < 1)
> +			return false;
> +		if (full_match) {
> +			/* strip the newline */
> +			len = strlen(buf)-1;

Let's keep with the linux style of spaces between operands:

  strlen(buf) - 1;

> +			while (buf[len] == '\n' || buf[len] == '\r') {
> +				buf[len] = '\0';
> +				len = strlen(buf)-1;

Here too.

> +				if (len < 0)
> +					goto out;
> +			}
> +			if (strcmp(buf, content))
> +				goto out;
> +		} else {
> +			if (!strstr(buf, content))
> +				goto out;
> +		}
> +	}
> +
> +	ret = true;
> +out:
> +	free(buf);
> +	return ret;
> +}
> +
> +static bool test_check_event_file_contetnt(struct tracefs_instance *instance,

Misspelled "content".


-- Steve

> +					   char *system, char *event, char *file,
> +					   char *content, bool full_match, bool ignore_comments)
> +{
> +	char *efile;
> +	int ret;
> +
> +	ret = asprintf(&efile, "events/%s/%s/%s", system, event, file);
> +	if (ret <= 0)
> +		return false;
> +	ret = test_check_file_contetnt(instance, efile, content, full_match, ignore_comments);
> +	free(efile);
> +	return ret;
> +}
> +
> +static bool check_cpu_mask(struct tracefs_instance *instance)



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux