From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] syscalls/time{01, 02}: Convert to new API and merge them
Date: Thu, 28 Jan 2021 14:41:34 +0800 [thread overview]
Message-ID: <60125C9E.9020101@cn.fujitsu.com> (raw)
In-Reply-To: <05e9d284-407a-9c42-afcc-6200363d419a@cn.fujitsu.com>
On 2021/1/28 13:30, Ruan Shiyang wrote:
>
>
> On 2021/1/28 ??10:56, Xiao Yang wrote:
>> On 2021/1/27 18:22, Shiyang Ruan wrote:
>>> Merge the two cases because each of them is very simple.
>>>
>>> Signed-off-by: Shiyang Ruan<ruansy.fnst@cn.fujitsu.com>
>>> ---
>>> testcases/kernel/syscalls/time/time01.c | 204
>>> ++++++------------------
>>> testcases/kernel/syscalls/time/time02.c | 147 -----------------
>>> 2 files changed, 47 insertions(+), 304 deletions(-)
>>> delete mode 100644 testcases/kernel/syscalls/time/time02.c
>> Hi Ruan,
>>
>> You also need to remove all entries releated to time02, for example:
>> runtest/syscalls:time02 time02
>> testcases/kernel/syscalls/time/.gitignore:/time02 >
>
> Yes, I forgot that.
>
> ...
>
>>> +/*\
>>> + * [DESCRIPTION]
>>> + * 1) Basic test for the time(2) system call. It is intended to
>>> provide a
>>> + * limited exposure of the system call.
>>> + * 2) Verify that time(2) returns the value of time in seconds
>>> since the Epoch
>>> + * and stores this value in the memory pointed to by the parameter.
>>> +\*/
>>
>> It is better to replace the number with '-' so that it follows the
>> markdown list.
>>
>
> OK.
>
>>>
>>> -void setup();
>>> -void cleanup();
>>> +#include<time.h>
>>> +#include<errno.h>
>>>
>>> -char *TCID = "time01";
>>> -int TST_TOTAL = 1;
>>> +#include "tst_test.h"
>>>
>>> -int main(int ac, char **av)
>>> +static void verify_time(void)
>>> {
>>> - int lc;
>>> -
>>> - tst_parse_opts(ac, av, NULL, NULL);
>>> -
>>> - setup();
>>> -
>>> - for (lc = 0; TEST_LOOPING(lc); lc++) {
>>> + TEST(time(0));
>>>
>>> - tst_count = 0;
>>> -
>>> - /*
>>> - * Call time(2)
>>> - */
>>> - TEST(time(0));
>>> -
>>> - /* check return code */
>>> - if (TEST_RETURN == -1) {
>>> - tst_resm(TFAIL, "time(0) Failed, errno=%d : %s",
>>> - TEST_ERRNO, strerror(TEST_ERRNO));
>>> - } else {
>>> - tst_resm(TPASS, "time(0) returned %ld",
>>> - TEST_RETURN);
>>> - }
>>> - }
>>> -
>>> - cleanup();
>>> - tst_exit();
>>> + if (TST_RET == -1)
>>> + tst_res(TFAIL | TTERRNO, "time(0)");
>>> + else
>>> + tst_res(TPASS, "time(0) returned %ld", TST_RET);
>>> }
>>>
>>> -/***************************************************************
>>> - * setup() - performs all ONE TIME setup for this test.
>>> - ***************************************************************/
>>> -void setup(void)
>>> +static void verify_time_store(void)
>>> {
>>> - void trapper();
>>> -
>>> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
>>> -
>>> - TEST_PAUSE;
>>> + time_t tloc;
>>> +
>>> + TEST(time(&tloc));
>>> +
>>> + if (TST_RET == -1)
>>> + tst_res(TFAIL | TTERRNO, "time(&tloc)");
>>> + else
>>> + if (tloc == TST_RET)
>>> + tst_res(TPASS, "time(&tloc) returned value %ld, "
>>> + "stored value %jd are same",
>>> + TST_RET, (intmax_t) tloc);
>>> + else
>>> + tst_res(TFAIL, "time(&tloc) returned value %ld, "
>>> + "stored value %jd are different",
>>> + TST_RET, (intmax_t) tloc);
>>> }
>>>
>>> -/***************************************************************
>>> - * cleanup() - performs all ONE TIME cleanup for this test at
>>> - * completion or premature exit.
>>> - ***************************************************************/
>>> -void cleanup(void)
>>> +struct tcase {
>>> + void (*verify)(void);
>>> +} tcases[] = {
>>> + {&verify_time },
>>> + {&verify_time_store },
>>> +};
>>> +
>>> +static void run(unsigned int i)
>>> {
>>> + tcases[i].verify();
>>> }
>> I think we don't need to define two different functions.
>> How about defining different arguments and then pass them to time()?
>> for example:
>> struct time_t *args[2]= {NULL, &tloc};
>>
>> static void verify_time_store(unsigned int i)
>> {
>> TEST(time(args[i]));
>> ......
>> }
>
> I think these two are different.
>
> In `verify_time_store()`, we check the return value of `time(&tloc)`
> and judge whether it is equal to the argument `tloc`. But in
> `verify_time()`, the judgment of whether they are equal or not is not
> necessary. So, I think the two functions are needed because of the
> different logic.
Hi Ruan,
How about the following logic?
---------------------------------------------
static void verify_time(unsigned int i)
{
TEST(time(args[i]));
if (TST_RET == -1) {
tst_res(TFAIL | TTERRNO, "time(&tloc)");
return;
}
if (arg[i] && *args[i] != TST_RET) {
tst_res(TFAIL, "...");
return;
}
tst_res(TPASS, "...");
}
---------------------------------------------
Some same steps can be removed in original verify_time_store() and
verify_time(). Is it simpler?
By the way, I have no objection to use different functions.
Best Regards,
Xiao Yang
>
>
> --
> Thanks,
> Ruan Shiyang.
>
>>
>> Best Regards,
>> Xiao Yang
>>> +
>>> +static struct tst_test test = {
>>> + .test = run,
>>> + .tcnt = ARRAY_SIZE(tcases),
>>> +};
> .
>
prev parent reply other threads:[~2021-01-28 6:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-27 10:22 [LTP] [PATCH v2] syscalls/time{01, 02}: Convert to new API and merge them Shiyang Ruan
2021-01-28 2:56 ` Xiao Yang
2021-01-28 5:30 ` Ruan Shiyang
2021-01-28 6:41 ` Xiao Yang [this message]
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=60125C9E.9020101@cn.fujitsu.com \
--to=yangx.jy@cn.fujitsu.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.