public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Date: Fri, 24 May 2019 15:21:09 +0200	[thread overview]
Message-ID: <20190524132109.GA30293@rei> (raw)
In-Reply-To: <1558684246-2658-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>

Hi!
> +#include <sys/prctl.h>
> +#include <string.h>
> +#include <stdio.h>
> +#include "lapi/syscalls.h"
> +#include "lapi/prctl.h"
> +#include "tst_test.h"
> +
> +static struct tcase {
> +	char setname[20];
> +	char expname[20];
> +} tcases[] = {
> +	{"prctl05_test", "prctl05_test"},
> +	{"prctl05_test_xxxxx", "prctl05_test_xx"}
> +};
> +
> +static void verify_prctl(unsigned int n)
> +{
> +	char buf[20];
> +	char comm_buf[20];
> +	char PROC_NAME_PATH[40];

Uppercase identifiers are by convention used for macros, this should be
proc_path, or just path.

> +	pid_t tid;
> +	struct tcase *tc = &tcases[n];
> +
> +	TEST(prctl(PR_SET_NAME, tc->setname));
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed");
> +		return;
> +	}
> +	tst_res(TPASS,
> +		"prctl(PR_SET_NAME) succeeded, set thread name as %s", tc->setname);

This could be shorter, why not just:

	tst_res(TPASS, "prctl(PR_SET_NAME, '%s')", tc->setname);

> +	TEST(prctl(PR_GET_NAME, buf));
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed");
> +		return;
> +	}


Looks like the null-termination got lost between v2 and v3.

And it would be better not to hardcode the size with:

buf[sizeof(buf)-1] = 0;

> +	if (strcmp(tc->expname, buf))
> +		tst_res(TFAIL,
> +			"prctl(PR_GET_NAME) failed ,expected %s, got %s", tc->expname, buf);
                                                  ^
						  The comma should be
						  before the space.
> +	else
> +		tst_res(TPASS,
> +			"prctl(PR_GET_NAME) succeeded, thread name is %s", buf);
> +
> +	tid = tst_syscall(__NR_gettid);
> +
> +	sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid);
> +	SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf);
> +	if (strcmp(tc->expname, comm_buf))
> +		tst_res(TFAIL,
> +			"%s sets thread name failed, expected %s, got %s",

This message could be shorter and to the point, something as:

tst_res(TFAIL, "%s has %s, expected %s", path, buf, tc->expname);


> +			PROC_NAME_PATH, tc->expname, comm_buf);
> +	else
> +		tst_res(TPASS, "%s sets thread name succeed as %s",

Here as well, something as:

tst_res(TPASS, "%s set to %s", path, buf);

> +			PROC_NAME_PATH, comm_buf);
> +
> +}
> +
> +static struct tst_test test = {
> +	.test = verify_prctl,
> +	.tcnt = ARRAY_SIZE(tcases),
> +};
> -- 
> 2.18.1
> 
> 
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-05-24 13:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-09 12:20 [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME Yang Xu
2019-05-22 10:16 ` xuyang
2019-05-23  9:40 ` Cyril Hrubis
2019-05-23 11:35   ` [LTP] [PATCH v2] " Yang Xu
2019-05-23 11:51     ` Xiao Yang
2019-05-24  7:36       ` xuyang
2019-05-24  7:50       ` [LTP] [PATCH v3] " Yang Xu
2019-05-24 13:21         ` Cyril Hrubis [this message]
2019-05-24 13:45         ` Xiao Yang
2019-05-24 13:48           ` Cyril Hrubis
2019-05-24 13:58             ` Xiao Yang
2019-05-27  8:19               ` [LTP] [PATCH v4] " Yang Xu
2019-05-27 13:41                 ` Cyril Hrubis

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=20190524132109.GA30293@rei \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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