<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Hi</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">On Friday, July 8, 2022 4:32:28 PM IST Luo xiaoyu via ltp wrote:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> ---</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>  testcases/kernel/syscalls/open/open03.c | 103 +++++++-----------------</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>  1 file changed, 27 insertions(+), 76 deletions(-)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> diff --git a/testcases/kernel/syscalls/open/open03.c</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> b/testcases/kernel/syscalls/open/open03.c index aa15ee9e9..7926e50f4 100644</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> --- a/testcases/kernel/syscalls/open/open03.c</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +++ b/testcases/kernel/syscalls/open/open03.c</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> @@ -1,90 +1,41 @@</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +// SPDX-License-Identifier: GPL-2.0-or-later</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>  /*</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>   * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * This program is free software; you can redistribute it and/or modify it</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * under the terms of version 2 of the GNU General Public License as</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * published by the Free Software Foundation.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * This program is distributed in the hope that it would be useful, but</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * WITHOUT ANY WARRANTY; without even the implied warranty of</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * Further, this software is distributed without any warranty that it is</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * free of the rightful claim of any third person regarding infringement</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * or the like.  Any license provided herein, whether implied or</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * otherwise, applies only to this software file.  Patent licenses, if</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * any, provided herein do not apply to combinations of this program with</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * other software, or any other product whatsoever.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * You should have received a copy of the GNU General Public License along</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * with this program; if not, write the Free Software Foundation, Inc.,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - * Mountain View, CA  94043, or:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> - *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>   */</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include <sys/types.h></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include <fcntl.h></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include <errno.h></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include <string.h></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include <signal.h></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include "test.h"</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -#include "safe_macros.h"</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -static void setup(void);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -static void cleanup(void);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +/*\</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> + * [DESCRIPTION]</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">^</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Description</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> + *</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> + * Testcase to check that open a new file with O_RDWR | O_CREAT</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> successfully. + */</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -char *TCID = "open03";</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -int TST_TOTAL = 1;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +#include "tst_test.h"</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -static char fname[255];</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -static int fd;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +#define TEST_FILE "testfile"</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -int main(int ac, char **av)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +static void verify_open(void)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>  {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    int lc;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    tst_parse_opts(ac, av, NULL, NULL);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    setup();</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    for (lc = 0; TEST_LOOPING(lc); lc++) {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -        tst_count = 0;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -        TEST(open(fname, O_RDWR | O_CREAT, 0700));</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -        fd = TEST_RETURN;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -        if (TEST_RETURN == -1) {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -            tst_resm(TFAIL | TTERRNO,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -                 "open(%s,O_RDWR|O_CREAT,0700) failed", fname);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -        } else {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -            tst_resm(TPASS,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -                 "open(%s, O_RDWR|O_CREAT,0700) returned %ld",</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -                 fname, TEST_RETURN);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -            SAFE_CLOSE(cleanup, fd);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -            SAFE_UNLINK(cleanup, fname);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -        }</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    int fd;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    TEST(open(TEST_FILE, O_RDWR | O_CREAT, 0700));</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    fd = TST_RET;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    if (TST_RET == -1) {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +        tst_res(TFAIL | TTERRNO,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +            "open(%s, O_RDWR | O_CREAT, 0700) failed", TEST_FILE);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    } else {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +        tst_res(TPASS,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +            "open(%s, O_RDWR | O_CREAT, 0700) returned %ld",</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +            TEST_FILE, TST_RET);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>      }</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">I think we should use TST_EXP_FD() macro here -</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="font-family:Droid Sans Mono;"><span style="font-size:-0.083em;"><span style="color:#bbbbbb;">    </span><span style="color:#268bd2;">TST_EXP_FD</span><span style="color:#bbbbbb;">(</span><span style="color:#268bd2;">open</span><span style="color:#bbbbbb;">(</span><span style="color:#268bd2;">TEST_FILE</span><span style="color:#bbbbbb;">, </span><span style="color:#268bd2;">O_RDWR</span><span style="color:#bbbbbb;"> </span><span style="color:#859900;">|</span><span style="color:#bbbbbb;"> </span><span style="color:#268bd2;">O_CREAT</span><span style="color:#bbbbbb;">, </span><span style="color:#859900;">0</span><span style="color:#d33682;">700</span><span style="color:#bbbbbb;">));</span></span></span></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#bbbbbb;">    </span><span style="color:#268bd2;">SAFE_CLOSE</span><span style="color:#bbbbbb;">(</span><span style="color:#268bd2;">TST_RET</span><span style="color:#bbbbbb;">);</span></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    cleanup();</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    tst_exit();</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    SAFE_CLOSE(fd);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    SAFE_UNLINK(TEST_FILE);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>  }</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -static void setup(void)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -{</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    tst_sig(NOFORK, DEF_HANDLER, cleanup);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    TEST_PAUSE;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    tst_tmpdir();</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    sprintf(fname, "tfile_%d", getpid());</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -}</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -static void cleanup(void)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -{</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -    tst_rmdir();</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> -}</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +static struct tst_test test = {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    .needs_tmpdir = 1,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +    .test_all = verify_open,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> +};</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> --</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> 2.17.1</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">--</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Avinesh</p>
</body>
</html>