From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH 3/3] libtracefs: Unit test for tracefs_instance_reset()
Date: Mon, 24 Apr 2023 15:45:57 -0400	[thread overview]
Message-ID: <20230424154557.28f371f7@rorschach.local.home> (raw)
In-Reply-To: <20230328150308.34783-4-tz.stoyanov@gmail.com>
On Tue, 28 Mar 2023 18:03:08 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> 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@gmail.com>
> ---
>  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)
next prev parent reply	other threads:[~2023-04-24 19:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 15:03 [PATCH 0/3] Introduce new API to reset ftrace instance Tzvetomir Stoyanov (VMware)
2023-03-28 15:03 ` [PATCH 1/3] libtracefs: New " Tzvetomir Stoyanov (VMware)
2023-04-24 19:42   ` Steven Rostedt
2023-03-28 15:03 ` [PATCH 2/3] libtracefs: Documentation for tracefs_instance_reset() Tzvetomir Stoyanov (VMware)
2023-03-28 15:03 ` [PATCH 3/3] libtracefs: Unit test " Tzvetomir Stoyanov (VMware)
2023-04-24 19:45   ` Steven Rostedt [this message]
2023-03-28 15:13 ` [PATCH 0/3] Introduce new API to reset ftrace instance Steven Rostedt
2023-04-13 12:17   ` Tzvetomir Stoyanov
2023-04-13 12:20     ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20230424154557.28f371f7@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).