* [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup
@ 2013-05-16 3:01 DAN LI
2013-05-16 3:09 ` [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr DAN LI
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: DAN LI @ 2013-05-16 3:01 UTC (permalink / raw)
To: LTP list
1. Remove useless comments
2. Revise code to follow ltp-code-style
Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/shmat/shmat01.c | 114 +++++++-------------------
1 file changed, 31 insertions(+), 83 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
index 51e25c5..3461782 100644
--- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
+++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
@@ -1,20 +1,19 @@
/*
+ * Copyright (c) International Business Machines Corp., 2001
*
- * Copyright (c) International Business Machines Corp., 2001
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
@@ -38,79 +37,54 @@
* otherwise
* issue a FAIL message
* call cleanup
- *
- * USAGE: <for command-line>
- * shmat01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * none
*/
#include "ipcshm.h"
#include "shmat_common.h"
-char *TCID = "shmat01";
-
-static void check_functionality(int);
+#define CASE0 10
+#define CASE1 20
-#define CASE0 10 /* values to write into the shared */
-#define CASE1 20 /* memory location. */
+char *TCID = "shmat01";
+int TST_TOTAL = 3;
int shm_id_1 = -1;
-void *base_addr; /* By probing this address first, we can make
- * non-aligned addresses from it for different
- * architectures without explicitly code it.
- */
-
-void *addr; /* for result of shmat-call */
+/*
+ * By probing this address first, we can make
+ * non-aligned addresses from it for different
+ * architectures without explicitly code it.
+ */
+void *base_addr;
+void *addr;
-struct test_case_t {
+static struct test_case_t {
int *shmid;
int offset;
int flags;
-};
+} *TC;
-int TST_TOTAL = 3;
-
-struct test_case_t *TC;
+static void check_functionality(int);
-int main(int ac, char **av)
+int main(int argc, char *argv[])
{
- int lc;
+ int lc, i;
char *msg;
- int i;
- msg = parse_opts(ac, av, NULL, NULL);
+ msg = parse_opts(argc, argv, NULL, NULL);
if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
+ setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
tst_count = 0;
- /* loop through the test cases */
for (i = 0; i < TST_TOTAL; i++) {
- /*
- * Use TEST macro to make the call
- */
base_addr = probe_free_addr();
- errno = 0;
+
addr = shmat(*(TC[i].shmid), base_addr + TC[i].offset,
TC[i].flags);
TEST_ERRNO = errno;
@@ -125,10 +99,6 @@ int main(int ac, char **av)
tst_resm(TPASS, "call succeeded");
}
- /*
- * clean up things in case we are looping - in
- * this case, detach the shared memory
- */
if (shmdt(addr) == -1)
tst_brkm(TBROK, cleanup,
"Couldn't detach shared memory");
@@ -215,12 +185,8 @@ static void check_functionality(int i)
tst_resm(TPASS, "conditions and functionality are correct");
}
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
void setup(void)
{
-
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
@@ -244,31 +210,18 @@ void setup(void)
TC[2].offset = 0;
TC[2].flags = SHM_RDONLY;
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See ../lib/libipc.c for more information.
- */
tst_tmpdir();
- /* Get an IPC resouce key */
shmkey = getipckey();
- /* create a shared memory resource with read and write permissions */
shm_id_1 = shmget(shmkey++, INT_SIZE, SHM_RW | IPC_CREAT | IPC_EXCL);
if (shm_id_1 == -1)
tst_brkm(TBROK, cleanup, "Failed to create shared memory "
"resource 1 in setup()");
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
void cleanup(void)
{
-
- /* if it exists, remove the shared memory resource */
rm_shm(shm_id_1);
if (TC != NULL)
@@ -276,10 +229,5 @@ void cleanup(void)
tst_rmdir();
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
-
}
--
1.8.1
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread* [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
2013-05-16 3:01 [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup DAN LI
@ 2013-05-16 3:09 ` DAN LI
2013-05-16 7:23 ` Jan Stancek
2013-05-17 5:39 ` [LTP] [PATCH V2 " DAN LI
2013-05-17 7:24 ` [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup Wanlong Gao
2 siblings, 1 reply; 7+ messages in thread
From: DAN LI @ 2013-05-16 3:09 UTC (permalink / raw)
To: LTP list
Test for statement:
"If shmaddr is NULL, the system chooses a suitable (unused) address
at which to attach the segment."
Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/shmat/shmat01.c | 41 ++++++++++++++++++---------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
index 3461782..13c9b1b 100644
--- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
+++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
@@ -46,7 +46,7 @@
#define CASE1 20
char *TCID = "shmat01";
-int TST_TOTAL = 3;
+int TST_TOTAL = 4;
int shm_id_1 = -1;
@@ -70,6 +70,7 @@ int main(int argc, char *argv[])
{
int lc, i;
char *msg;
+ void *attchaddr;
msg = parse_opts(argc, argv, NULL, NULL);
if (msg != NULL)
@@ -85,10 +86,10 @@ int main(int argc, char *argv[])
base_addr = probe_free_addr();
- addr = shmat(*(TC[i].shmid), base_addr + TC[i].offset,
- TC[i].flags);
- TEST_ERRNO = errno;
+ attchaddr = (i ? base_addr + TC[i].offset : NULL);
+ addr = shmat(*(TC[i].shmid), attchaddr, TC[i].flags);
+ TEST_ERRNO = errno;
if (addr == (void *)-1) {
tst_brkm(TFAIL | TTERRNO, cleanup,
"shmat call failed");
@@ -148,11 +149,20 @@ static void check_functionality(int i)
* If this fails the program will get a SIGSEGV, dump
* core and exit.
*/
-
*shared = CASE0;
break;
case 1:
/*
+ * Check the functionality of the first call by simply
+ * "writing" a value to the shared memory space.
+ * If this fails the program will get a SIGSEGV, dump
+ * core and exit.
+ */
+
+ *shared = CASE0;
+ break;
+ case 2:
+ /*
* Check the functionality of the second call by writing
* a value to the shared memory space and then checking
* that the original address given was rounded down as
@@ -167,7 +177,7 @@ static void check_functionality(int i)
fail = 1;
}
break;
- case 2:
+ case 3:
/*
* This time the shared memory is read only. Read the value
* and check that it is equal to the value set in case #2,
@@ -195,20 +205,25 @@ void setup(void)
if (TC == NULL)
tst_brkm(TFAIL | TERRNO, cleanup, "failed to allocate memory");
- /* a straight forward read/write attach */
+ /* set NULL as attaching address*/
TC[0].shmid = &shm_id_1;
TC[0].offset = 0;
TC[0].flags = 0;
- /* an attach using unaligned memory */
+ /* a straight forward read/write attach */
TC[1].shmid = &shm_id_1;
- TC[1].offset = SHMLBA - 1;
- TC[1].flags = SHM_RND;
+ TC[1].offset = 0;
+ TC[1].flags = 0;
- /* a read only attach */
+ /* an attach using unaligned memory */
TC[2].shmid = &shm_id_1;
- TC[2].offset = 0;
- TC[2].flags = SHM_RDONLY;
+ TC[2].offset = SHMLBA - 1;
+ TC[2].flags = SHM_RND;
+
+ /* a read only attach */
+ TC[3].shmid = &shm_id_1;
+ TC[3].offset = 0;
+ TC[3].flags = SHM_RDONLY;
tst_tmpdir();
--
1.8.1
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
2013-05-16 3:09 ` [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr DAN LI
@ 2013-05-16 7:23 ` Jan Stancek
0 siblings, 0 replies; 7+ messages in thread
From: Jan Stancek @ 2013-05-16 7:23 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
----- Original Message -----
> From: "DAN LI" <li.dan@cn.fujitsu.com>
> To: "LTP list" <ltp-list@lists.sourceforge.net>
> Sent: Thursday, 16 May, 2013 5:09:36 AM
> Subject: [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
>
>
> Test for statement:
> "If shmaddr is NULL, the system chooses a suitable (unused) address
> at which to attach the segment."
>
> Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
> ---
> testcases/kernel/syscalls/ipc/shmat/shmat01.c | 41
> ++++++++++++++++++---------
> 1 file changed, 28 insertions(+), 13 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> index 3461782..13c9b1b 100644
> --- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> +++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> @@ -46,7 +46,7 @@
> #define CASE1 20
>
> char *TCID = "shmat01";
> -int TST_TOTAL = 3;
> +int TST_TOTAL = 4;
>
> int shm_id_1 = -1;
>
> @@ -70,6 +70,7 @@ int main(int argc, char *argv[])
> {
> int lc, i;
> char *msg;
> + void *attchaddr;
>
> msg = parse_opts(argc, argv, NULL, NULL);
> if (msg != NULL)
> @@ -85,10 +86,10 @@ int main(int argc, char *argv[])
>
> base_addr = probe_free_addr();
>
> - addr = shmat(*(TC[i].shmid), base_addr + TC[i].offset,
> - TC[i].flags);
> - TEST_ERRNO = errno;
> + attchaddr = (i ? base_addr + TC[i].offset : NULL);
> + addr = shmat(*(TC[i].shmid), attchaddr, TC[i].flags);
Hi,
I'd suggest adding a field to test_case_t, which would tell if you need probe_free_addr()
or NULL, so you don't need to check for specific testcase number.
>
> + TEST_ERRNO = errno;
> if (addr == (void *)-1) {
> tst_brkm(TFAIL | TTERRNO, cleanup,
> "shmat call failed");
> @@ -148,11 +149,20 @@ static void check_functionality(int i)
> * If this fails the program will get a SIGSEGV, dump
> * core and exit.
> */
> -
> *shared = CASE0;
> break;
> case 1:
> /*
> + * Check the functionality of the first call by simply
> + * "writing" a value to the shared memory space.
> + * If this fails the program will get a SIGSEGV, dump
> + * core and exit.
> + */
> +
> + *shared = CASE0;
> + break;
Since case 0 and case 1 are the same, I'd suggest making it as fallthrough.
> + case 2:
> + /*
> * Check the functionality of the second call by writing
> * a value to the shared memory space and then checking
> * that the original address given was rounded down as
It's not directly visible in patch, but case 2 is now using TC[1].
Comments don't match case numbers, both case 0 and case 1 say now "first call",
I would drop that numbering in comments.
Regards,
Jan
> @@ -167,7 +177,7 @@ static void check_functionality(int i)
> fail = 1;
> }
> break;
> - case 2:
> + case 3:
> /*
> * This time the shared memory is read only. Read the value
> * and check that it is equal to the value set in case #2,
> @@ -195,20 +205,25 @@ void setup(void)
> if (TC == NULL)
> tst_brkm(TFAIL | TERRNO, cleanup, "failed to allocate memory");
>
> - /* a straight forward read/write attach */
> + /* set NULL as attaching address*/
> TC[0].shmid = &shm_id_1;
> TC[0].offset = 0;
> TC[0].flags = 0;
>
> - /* an attach using unaligned memory */
> + /* a straight forward read/write attach */
> TC[1].shmid = &shm_id_1;
> - TC[1].offset = SHMLBA - 1;
> - TC[1].flags = SHM_RND;
> + TC[1].offset = 0;
> + TC[1].flags = 0;
>
> - /* a read only attach */
> + /* an attach using unaligned memory */
> TC[2].shmid = &shm_id_1;
> - TC[2].offset = 0;
> - TC[2].flags = SHM_RDONLY;
> + TC[2].offset = SHMLBA - 1;
> + TC[2].flags = SHM_RND;
> +
> + /* a read only attach */
> + TC[3].shmid = &shm_id_1;
> + TC[3].offset = 0;
> + TC[3].flags = SHM_RDONLY;
>
> tst_tmpdir();
>
> --
> 1.8.1
>
>
>
>
> ------------------------------------------------------------------------------
> AlienVault Unified Security Management (USM) platform delivers complete
> security visibility with the essential security capabilities. Easily and
> efficiently configure, manage, and operate all of your security controls
> from a single console and one unified framework. Download a free trial.
> http://p.sf.net/sfu/alienvault_d2d
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
>
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH V2 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
2013-05-16 3:01 [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup DAN LI
2013-05-16 3:09 ` [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr DAN LI
@ 2013-05-17 5:39 ` DAN LI
2013-05-17 7:06 ` Jan Stancek
2013-05-17 7:24 ` Wanlong Gao
2013-05-17 7:24 ` [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup Wanlong Gao
2 siblings, 2 replies; 7+ messages in thread
From: DAN LI @ 2013-05-17 5:39 UTC (permalink / raw)
To: LTP list
Test for statement:
"If shmaddr is NULL, the system chooses a suitable (unused) address
at which to attach the segment."
Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/shmat/shmat01.c | 60 +++++++++++++++++----------
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
index 3461782..3c09817 100644
--- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
+++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
@@ -46,7 +46,7 @@
#define CASE1 20
char *TCID = "shmat01";
-int TST_TOTAL = 3;
+int TST_TOTAL = 4;
int shm_id_1 = -1;
@@ -62,6 +62,7 @@ static struct test_case_t {
int *shmid;
int offset;
int flags;
+ int getbase;
} *TC;
static void check_functionality(int);
@@ -70,6 +71,7 @@ int main(int argc, char *argv[])
{
int lc, i;
char *msg;
+ void *attchaddr;
msg = parse_opts(argc, argv, NULL, NULL);
if (msg != NULL)
@@ -83,12 +85,16 @@ int main(int argc, char *argv[])
for (i = 0; i < TST_TOTAL; i++) {
- base_addr = probe_free_addr();
+ if (TC[i].getbase) {
+ base_addr = probe_free_addr();
+ attchaddr = base_addr + TC[i].offset;
+ } else {
+ attchaddr = NULL;
+ }
- addr = shmat(*(TC[i].shmid), base_addr + TC[i].offset,
- TC[i].flags);
- TEST_ERRNO = errno;
+ addr = shmat(*(TC[i].shmid), attchaddr, TC[i].flags);
+ TEST_ERRNO = errno;
if (addr == (void *)-1) {
tst_brkm(TFAIL | TTERRNO, cleanup,
"shmat call failed");
@@ -142,35 +148,36 @@ static void check_functionality(int i)
/* check for specific conditions depending on the type of attach */
switch (i) {
case 0:
+ case 1:
/*
- * Check the functionality of the first call by simply
- * "writing" a value to the shared memory space.
+ * Check the functionality of shmat by simply "writing"
+ * a value to the shared memory space.
* If this fails the program will get a SIGSEGV, dump
* core and exit.
*/
*shared = CASE0;
break;
- case 1:
+ case 2:
/*
- * Check the functionality of the second call by writing
- * a value to the shared memory space and then checking
- * that the original address given was rounded down as
+ * Check the functionality of shmat by writing a value
+ * to the shared memory space and then checking that
+ * the original address given was rounded down as
* specified in the man page.
*/
*shared = CASE1;
- orig_add = addr + ((unsigned long)TC[1].offset % SHMLBA);
- if (orig_add != base_addr + TC[1].offset) {
+ orig_add = addr + ((unsigned long)TC[2].offset % SHMLBA);
+ if (orig_add != base_addr + TC[2].offset) {
tst_resm(TFAIL, "shared memory address is not "
"correct");
fail = 1;
}
break;
- case 2:
+ case 3:
/*
* This time the shared memory is read only. Read the value
- * and check that it is equal to the value set in case #2,
+ * and check that it is equal to the value set in last case,
* because shared memory is persistent.
*/
@@ -195,20 +202,29 @@ void setup(void)
if (TC == NULL)
tst_brkm(TFAIL | TERRNO, cleanup, "failed to allocate memory");
- /* a straight forward read/write attach */
+ /* set NULL as attaching address*/
TC[0].shmid = &shm_id_1;
TC[0].offset = 0;
TC[0].flags = 0;
+ TC[0].getbase = 0;
- /* an attach using unaligned memory */
+ /* a straight forward read/write attach */
TC[1].shmid = &shm_id_1;
- TC[1].offset = SHMLBA - 1;
- TC[1].flags = SHM_RND;
+ TC[1].offset = 0;
+ TC[1].flags = 0;
+ TC[1].getbase = 1;
- /* a read only attach */
+ /* an attach using unaligned memory */
TC[2].shmid = &shm_id_1;
- TC[2].offset = 0;
- TC[2].flags = SHM_RDONLY;
+ TC[2].offset = SHMLBA - 1;
+ TC[2].flags = SHM_RND;
+ TC[2].getbase = 1;
+
+ /* a read only attach */
+ TC[3].shmid = &shm_id_1;
+ TC[3].offset = 0;
+ TC[3].flags = SHM_RDONLY;
+ TC[3].getbase = 1;
tst_tmpdir();
--
1.8.1
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [LTP] [PATCH V2 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
2013-05-17 5:39 ` [LTP] [PATCH V2 " DAN LI
@ 2013-05-17 7:06 ` Jan Stancek
2013-05-17 7:24 ` Wanlong Gao
1 sibling, 0 replies; 7+ messages in thread
From: Jan Stancek @ 2013-05-17 7:06 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
----- Original Message -----
> From: "DAN LI" <li.dan@cn.fujitsu.com>
> To: "LTP list" <ltp-list@lists.sourceforge.net>
> Cc: "Jan Stancek" <jstancek@redhat.com>
> Sent: Friday, 17 May, 2013 7:39:32 AM
> Subject: [LTP] [PATCH V2 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
>
>
> Test for statement:
> "If shmaddr is NULL, the system chooses a suitable (unused) address
> at which to attach the segment."
>
> Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
V2 looks good to me, applies cleanly, tested on x86_64.
Reviewed-by: Jan Stancek <jstancek@redhat.com>
> ---
> testcases/kernel/syscalls/ipc/shmat/shmat01.c | 60
> +++++++++++++++++----------
> 1 file changed, 38 insertions(+), 22 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> index 3461782..3c09817 100644
> --- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> +++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
> @@ -46,7 +46,7 @@
> #define CASE1 20
>
> char *TCID = "shmat01";
> -int TST_TOTAL = 3;
> +int TST_TOTAL = 4;
>
> int shm_id_1 = -1;
>
> @@ -62,6 +62,7 @@ static struct test_case_t {
> int *shmid;
> int offset;
> int flags;
> + int getbase;
> } *TC;
>
> static void check_functionality(int);
> @@ -70,6 +71,7 @@ int main(int argc, char *argv[])
> {
> int lc, i;
> char *msg;
> + void *attchaddr;
>
> msg = parse_opts(argc, argv, NULL, NULL);
> if (msg != NULL)
> @@ -83,12 +85,16 @@ int main(int argc, char *argv[])
>
> for (i = 0; i < TST_TOTAL; i++) {
>
> - base_addr = probe_free_addr();
> + if (TC[i].getbase) {
> + base_addr = probe_free_addr();
> + attchaddr = base_addr + TC[i].offset;
> + } else {
> + attchaddr = NULL;
> + }
>
> - addr = shmat(*(TC[i].shmid), base_addr + TC[i].offset,
> - TC[i].flags);
> - TEST_ERRNO = errno;
> + addr = shmat(*(TC[i].shmid), attchaddr, TC[i].flags);
>
> + TEST_ERRNO = errno;
> if (addr == (void *)-1) {
> tst_brkm(TFAIL | TTERRNO, cleanup,
> "shmat call failed");
> @@ -142,35 +148,36 @@ static void check_functionality(int i)
> /* check for specific conditions depending on the type of attach */
> switch (i) {
> case 0:
> + case 1:
> /*
> - * Check the functionality of the first call by simply
> - * "writing" a value to the shared memory space.
> + * Check the functionality of shmat by simply "writing"
> + * a value to the shared memory space.
> * If this fails the program will get a SIGSEGV, dump
> * core and exit.
> */
>
> *shared = CASE0;
> break;
> - case 1:
> + case 2:
> /*
> - * Check the functionality of the second call by writing
> - * a value to the shared memory space and then checking
> - * that the original address given was rounded down as
> + * Check the functionality of shmat by writing a value
> + * to the shared memory space and then checking that
> + * the original address given was rounded down as
> * specified in the man page.
> */
>
> *shared = CASE1;
> - orig_add = addr + ((unsigned long)TC[1].offset % SHMLBA);
> - if (orig_add != base_addr + TC[1].offset) {
> + orig_add = addr + ((unsigned long)TC[2].offset % SHMLBA);
> + if (orig_add != base_addr + TC[2].offset) {
> tst_resm(TFAIL, "shared memory address is not "
> "correct");
> fail = 1;
> }
> break;
> - case 2:
> + case 3:
> /*
> * This time the shared memory is read only. Read the value
> - * and check that it is equal to the value set in case #2,
> + * and check that it is equal to the value set in last case,
> * because shared memory is persistent.
> */
>
> @@ -195,20 +202,29 @@ void setup(void)
> if (TC == NULL)
> tst_brkm(TFAIL | TERRNO, cleanup, "failed to allocate memory");
>
> - /* a straight forward read/write attach */
> + /* set NULL as attaching address*/
> TC[0].shmid = &shm_id_1;
> TC[0].offset = 0;
> TC[0].flags = 0;
> + TC[0].getbase = 0;
>
> - /* an attach using unaligned memory */
> + /* a straight forward read/write attach */
> TC[1].shmid = &shm_id_1;
> - TC[1].offset = SHMLBA - 1;
> - TC[1].flags = SHM_RND;
> + TC[1].offset = 0;
> + TC[1].flags = 0;
> + TC[1].getbase = 1;
>
> - /* a read only attach */
> + /* an attach using unaligned memory */
> TC[2].shmid = &shm_id_1;
> - TC[2].offset = 0;
> - TC[2].flags = SHM_RDONLY;
> + TC[2].offset = SHMLBA - 1;
> + TC[2].flags = SHM_RND;
> + TC[2].getbase = 1;
> +
> + /* a read only attach */
> + TC[3].shmid = &shm_id_1;
> + TC[3].offset = 0;
> + TC[3].flags = SHM_RDONLY;
> + TC[3].getbase = 1;
>
> tst_tmpdir();
>
> --
> 1.8.1
>
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [LTP] [PATCH V2 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr
2013-05-17 5:39 ` [LTP] [PATCH V2 " DAN LI
2013-05-17 7:06 ` Jan Stancek
@ 2013-05-17 7:24 ` Wanlong Gao
1 sibling, 0 replies; 7+ messages in thread
From: Wanlong Gao @ 2013-05-17 7:24 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
On 05/17/2013 01:39 PM, DAN LI wrote:
> Test for statement:
> "If shmaddr is NULL, the system chooses a suitable (unused) address
> at which to attach the segment."
>
> Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
Applied, thank you.
Wanlong Gao
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup
2013-05-16 3:01 [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup DAN LI
2013-05-16 3:09 ` [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr DAN LI
2013-05-17 5:39 ` [LTP] [PATCH V2 " DAN LI
@ 2013-05-17 7:24 ` Wanlong Gao
2 siblings, 0 replies; 7+ messages in thread
From: Wanlong Gao @ 2013-05-17 7:24 UTC (permalink / raw)
To: DAN LI; +Cc: LTP list
On 05/16/2013 11:01 AM, DAN LI wrote:
> 1. Remove useless comments
>
> 2. Revise code to follow ltp-code-style
>
> Signed-off-by: DAN LI <li.dan@cn.fujitsu.com>
Applied, thank you.
Wanlong Gao
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-05-17 7:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-16 3:01 [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup DAN LI
2013-05-16 3:09 ` [LTP] [PATCH 2/2] shmat/shmat01.c: Test for specifying NULL to shmaddr DAN LI
2013-05-16 7:23 ` Jan Stancek
2013-05-17 5:39 ` [LTP] [PATCH V2 " DAN LI
2013-05-17 7:06 ` Jan Stancek
2013-05-17 7:24 ` Wanlong Gao
2013-05-17 7:24 ` [LTP] [PATCH 1/2] shmat/shmat01.c: cleanup Wanlong Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox