* [LTP] [PATCH v2] getrusage03: add opportunity to reduce memory allocation's size
@ 2012-02-15 13:04 Filippo ARCIDIACONO
2012-02-16 6:39 ` Caspar Zhang
0 siblings, 1 reply; 4+ messages in thread
From: Filippo ARCIDIACONO @ 2012-02-15 13:04 UTC (permalink / raw)
To: ltp-list
To use this test also in embedded systems it needs to reduce the memory
allocation to avoid the test failing when it check the ru_maxrss field
expecting a value close to the allocated one.
The ru_maxrss field contains the total amount of resident set memory
used, so this field doesn't take into account of the swapped memory.
Passing [num] parameter at command line the test is executed using the
input parameter as multiply factor instead of 10, that is the default
value when no argument is passed.
Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono@st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
---
testcases/kernel/syscalls/getrusage/getrusage03.c | 96 ++++++++++++++------
1 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index 3ec5284..1a7f05d 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -50,11 +50,19 @@ int TST_TOTAL = 1;
static struct rusage ru;
static long maxrss_init;
-static int retval, status;
+static int retval, status, opt_factor;
static pid_t pid;
+static char *factor_str;
+int factor_nr = 10;
+option_t child_options[] = {
+ { "m:", &opt_factor, &factor_str },
+ { NULL, NULL, NULL }
+};
+
+static void usage(void);
static void inherit_fork(void);
-static void inherit_fork2(void);
+static void inherit_fork2(const int size);
static void fork_malloc(void);
static void grandchild_maxrss(void);
static void zombie(void);
@@ -68,23 +76,33 @@ static void cleanup(void);
int main(int argc, char *argv[])
{
- int lc;
+ int lc, size;
char *msg;
- msg = parse_opts(argc, argv, NULL, NULL);
+ msg = parse_opts(argc, argv, child_options, usage);
if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
setup();
+ if (opt_factor)
+ factor_nr = atoi(factor_str);
+
+ if (factor_nr == 0)
+ tst_brkm(TBROK, cleanup, "Input factor must be != 0");
+
+ tst_resm(TINFO, "Using %d as factor allocation mamory!", factor_nr);
+
+ size = 10 * factor_nr;
+
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
- tst_resm(TINFO, "allocate 100MB");
- consume(100);
+ tst_resm(TINFO, "allocate %dMB", size);
+ consume(size);
inherit_fork();
- inherit_fork2();
+ inherit_fork2(size);
fork_malloc();
grandchild_maxrss();
zombie();
@@ -95,6 +113,11 @@ int main(int argc, char *argv[])
tst_exit();
}
+static void usage(void)
+{
+ printf(" -m n use n as multiply factor, default value is 10\n");
+}
+
/* Testcase #01: fork inherit
* expect: initial.self ~= child.self */
static void inherit_fork(void)
@@ -123,17 +146,17 @@ static void inherit_fork(void)
}
/* Testcase #02: fork inherit (cont.)
- * expect: initial.children ~= 100MB, child.children = 0 */
-static void inherit_fork2(void)
+ * expect: initial.children ~= (10 * factor_nr)MB, child.children = 0 */
+static void inherit_fork2(const int size)
{
tst_resm(TINFO, "Testcase #02: fork inherit(cont.)");
SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
- if (is_in_delta(ru.ru_maxrss - 102400))
- tst_resm(TPASS, "initial.children ~= 100MB");
+ if (is_in_delta(ru.ru_maxrss - (10240 * factor_nr)))
+ tst_resm(TPASS, "initial.children ~= %dMB", size);
else
- tst_resm(TFAIL, "initial.children !~= 100MB");
+ tst_resm(TFAIL, "initial.children !~= %dMB", size);
switch (pid = fork()) {
case -1:
@@ -153,9 +176,12 @@ static void inherit_fork2(void)
}
/* Testcase #03: fork + malloc
- * expect: initial.self + 50MB ~= child.self */
+ * expect: initial.self + (5 * factor_nr)MB ~= child.self */
static void fork_malloc(void)
{
+ char pass_msg[BUFSIZ], fail_msg[BUFSIZ];
+ const int size = 5 * factor_nr;
+
tst_resm(TINFO, "Testcase #03: fork + malloc");
SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
@@ -166,25 +192,29 @@ static void fork_malloc(void)
tst_brkm(TBROK|TERRNO, cleanup, "fork #3");
case 0:
maxrss_init = ru.ru_maxrss;
- tst_resm(TINFO, "child allocate +50MB");
- consume(50);
+ tst_resm(TINFO, "child allocate + %dMB", size);
+ consume(size);
SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
tst_resm(TINFO, "child.self = %ld", ru.ru_maxrss);
- exit(is_in_delta(maxrss_init + 51200 - ru.ru_maxrss));
+ exit(is_in_delta(maxrss_init + (5120 * factor_nr) - ru.ru_maxrss));
default:
break;
}
if (waitpid(pid, &status, WUNTRACED|WCONTINUED) == -1)
tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
- check_return(WEXITSTATUS(status), "initial.self + 50MB ~= child.self",
- "initial.self + 50MB !~= child.self");
+ sprintf(pass_msg, "initial.self + %dMB ~= child.self", size);
+ sprintf(fail_msg, "initial.self + %dMB !~= child.self", size);
+ check_return(WEXITSTATUS(status), pass_msg, fail_msg);
}
/* Testcase #04: grandchild maxrss
- * expect: post_wait.children ~= 300MB */
+ * expect: post_wait.children ~= (30 * factor_nr)MB */
static void grandchild_maxrss(void)
{
+ char cmd_system[BUFSIZ];
+ const int size = 30 * factor_nr;
+
tst_resm(TINFO, "Testcase #04: grandchild maxrss");
SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
@@ -194,7 +224,8 @@ static void grandchild_maxrss(void)
case -1:
tst_brkm(TBROK|TERRNO, cleanup, "fork #4");
case 0:
- retval = system("getrusage03_child -g 300");
+ sprintf(cmd_system, "getrusage03_child -g %d", size);
+ retval = system(cmd_system);
if ((WIFEXITED(retval) && WEXITSTATUS(retval) != 0))
tst_brkm(TBROK|TERRNO, cleanup, "system");
exit(0);
@@ -209,16 +240,19 @@ static void grandchild_maxrss(void)
SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
tst_resm(TINFO, "post_wait.children = %ld", ru.ru_maxrss);
- if (is_in_delta(ru.ru_maxrss - 307200))
- tst_resm(TPASS, "child.children ~= 300MB");
+ if (is_in_delta(ru.ru_maxrss - (30720 * factor_nr)))
+ tst_resm(TPASS, "child.children ~= %dMB", size);
else
- tst_resm(TFAIL, "child.children !~= 300MB");
+ tst_resm(TFAIL, "child.children !~= %dMB", size);
}
/* Testcase #05: zombie
- * expect: initial ~= pre_wait, post_wait ~= 400MB */
+ * expect: initial ~= pre_wait, post_wait ~= (40 * factor_nr)MB */
static void zombie(void)
{
+ char cmd_system[BUFSIZ];
+ const int size = 40 * factor_nr;
+
tst_resm(TINFO, "Testcase #05: zombie");
SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
@@ -229,7 +263,8 @@ static void zombie(void)
case -1:
tst_brkm(TBROK, cleanup, "fork #5");
case 0:
- retval = system("getrusage03_child -n 400");
+ sprintf(cmd_system, "getrusage03_child -n %d", size);
+ retval = system(cmd_system);
if ((WIFEXITED(retval) && WEXITSTATUS(retval) != 0))
tst_brkm(TBROK|TERRNO, cleanup, "system");
exit(0);
@@ -252,16 +287,18 @@ static void zombie(void)
SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
tst_resm(TINFO, "post_wait.children = %ld", ru.ru_maxrss);
- if (is_in_delta(ru.ru_maxrss - 409600))
- tst_resm(TPASS, "post_wait.children ~= 400MB");
+ if (is_in_delta(ru.ru_maxrss - (40960 * factor_nr)))
+ tst_resm(TPASS, "post_wait.children ~= %dMB", size);
else
- tst_resm(TFAIL, "post_wait.children !~= 400MB");
+ tst_resm(TFAIL, "post_wait.children !~= %dMB", size);
}
/* Testcase #06: SIG_IGN
* expect: initial ~= after_zombie */
static void sig_ign(void)
{
+ char cmd_system[BUFSIZ];
+
tst_resm(TINFO, "Testcase #06: SIG_IGN");
SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
@@ -273,7 +310,8 @@ static void sig_ign(void)
case -1:
tst_brkm(TBROK, cleanup, "fork #6");
case 0:
- retval = system("getrusage03_child -n 500");
+ sprintf(cmd_system, "getrusage03_child -n %d", 50 * factor_nr);
+ retval = system(cmd_system);
if ((WIFEXITED(retval) && WEXITSTATUS(retval) != 0))
tst_brkm(TBROK|TERRNO, cleanup, "system");
exit(0);
--
1.5.5.6
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: add opportunity to reduce memory allocation's size
2012-02-15 13:04 [LTP] [PATCH v2] getrusage03: add opportunity to reduce memory allocation's size Filippo ARCIDIACONO
@ 2012-02-16 6:39 ` Caspar Zhang
2012-02-16 8:57 ` Filippo ARCIDIACONO
[not found] ` <4f3cc506.49350e0a.271e.703dSMTPIN_ADDED@mx.google.com>
0 siblings, 2 replies; 4+ messages in thread
From: Caspar Zhang @ 2012-02-16 6:39 UTC (permalink / raw)
To: Filippo ARCIDIACONO; +Cc: ltp-list
Hi,
On 02/15/2012 09:04 PM, Filippo ARCIDIACONO wrote:
> static struct rusage ru;
> static long maxrss_init;
> -static int retval, status;
> +static int retval, status, opt_factor;
> static pid_t pid;
> +static char *factor_str;
> +int factor_nr = 10;
missing `static`?
>
> +option_t child_options[] = {
> + { "m:", &opt_factor, &factor_str },
> + { NULL, NULL, NULL }
> +};
> +
> +static void usage(void);
> static void inherit_fork(void);
> -static void inherit_fork2(void);
> +static void inherit_fork2(const int size);
> static void fork_malloc(void);
> static void grandchild_maxrss(void);
> static void zombie(void);
> @@ -68,23 +76,33 @@ static void cleanup(void);
>
> int main(int argc, char *argv[])
> {
> - int lc;
> + int lc, size;
> char *msg;
>
> - msg = parse_opts(argc, argv, NULL, NULL);
> + msg = parse_opts(argc, argv, child_options, usage);
> if (msg != NULL)
> tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
>
> setup();
>
> + if (opt_factor)
> + factor_nr = atoi(factor_str);
> +
> + if (factor_nr == 0)
> + tst_brkm(TBROK, cleanup, "Input factor must be != 0");
Hi, I guess factor_nr should not be < 0 too? If so, you might want to use
factor_nr = SAFE_STRTOL(NULL, factor_str, 1, LONG_MAX);
where SAFE_STRTOL is defined in safe_macros.h, of course you should make
factor_nr to be long int.
Rest looks good to me.
Thanks,
Caspar
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: add opportunity to reduce memory allocation's size
2012-02-16 6:39 ` Caspar Zhang
@ 2012-02-16 8:57 ` Filippo ARCIDIACONO
[not found] ` <4f3cc506.49350e0a.271e.703dSMTPIN_ADDED@mx.google.com>
1 sibling, 0 replies; 4+ messages in thread
From: Filippo ARCIDIACONO @ 2012-02-16 8:57 UTC (permalink / raw)
To: 'Caspar Zhang'; +Cc: ltp-list
> -----Original Message-----
> From: Caspar Zhang [mailto:caspar@casparzhang.com]
> Sent: Thursday, February 16, 2012 7:40 AM
> To: Filippo ARCIDIACONO
> Cc: ltp-list@lists.sourceforge.net
> Subject: Re: [LTP] [PATCH v2] getrusage03: add opportunity to reduce
> memory allocation's size
>
> Hi,
>
> On 02/15/2012 09:04 PM, Filippo ARCIDIACONO wrote:
> > static struct rusage ru;
> > static long maxrss_init;
> > -static int retval, status;
> > +static int retval, status, opt_factor;
> > static pid_t pid;
> > +static char *factor_str;
> > +int factor_nr = 10;
>
> missing `static`?
In my opinion doesn't need to be static.
>
> >
> > +option_t child_options[] = {
> > + { "m:", &opt_factor, &factor_str },
> > + { NULL, NULL, NULL }
> > +};
> > +
> > +static void usage(void);
> > static void inherit_fork(void);
> > -static void inherit_fork2(void);
> > +static void inherit_fork2(const int size);
> > static void fork_malloc(void);
> > static void grandchild_maxrss(void);
> > static void zombie(void);
> > @@ -68,23 +76,33 @@ static void cleanup(void);
> >
> > int main(int argc, char *argv[])
> > {
> > - int lc;
> > + int lc, size;
> > char *msg;
> >
> > - msg = parse_opts(argc, argv, NULL, NULL);
> > + msg = parse_opts(argc, argv, child_options, usage);
> > if (msg != NULL)
> > tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> >
> > setup();
> >
> > + if (opt_factor)
> > + factor_nr = atoi(factor_str);
> > +
> > + if (factor_nr == 0)
> > + tst_brkm(TBROK, cleanup, "Input factor must be != 0");
>
> Hi, I guess factor_nr should not be < 0 too? If so, you might want to
> use
>
> factor_nr = SAFE_STRTOL(NULL, factor_str, 1, LONG_MAX);
>
> where SAFE_STRTOL is defined in safe_macros.h, of course you should
> make
> factor_nr to be long int.
Factor_nr being a multiply factor, should be a relatively small number,
int type should be enough. For this reason I didn't use the SAFE_STRTOL macro you have recently introduced.
It could modify the factor_nr check to "if (factor_nr <= 0)".
Alternatively, as you suggest, it could be use SAFE_STRTOL. In this case I suggest something like
factor_nr = SAFE_STRTOL(NULL, factor_str, 1, FACTOR_MAX)
where FACTOR_MAX should be locally defined, for example, to 20 (two times of actual).
>
> Rest looks good to me.
>
> Thanks,
> Caspar
Filippo.
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: add opportunity to reduce memory allocation's size
[not found] ` <4f3cc506.49350e0a.271e.703dSMTPIN_ADDED@mx.google.com>
@ 2012-02-16 9:27 ` Caspar Zhang
0 siblings, 0 replies; 4+ messages in thread
From: Caspar Zhang @ 2012-02-16 9:27 UTC (permalink / raw)
To: Filippo ARCIDIACONO; +Cc: ltp-list
Hi,
On 02/16/2012 04:57 PM, Filippo ARCIDIACONO wrote:
>
>
>> -----Original Message-----
>> From: Caspar Zhang [mailto:caspar@casparzhang.com]
>> Sent: Thursday, February 16, 2012 7:40 AM
>> To: Filippo ARCIDIACONO
>> Cc: ltp-list@lists.sourceforge.net
>> Subject: Re: [LTP] [PATCH v2] getrusage03: add opportunity to reduce
>> memory allocation's size
>>
>> Hi,
>>
>> On 02/15/2012 09:04 PM, Filippo ARCIDIACONO wrote:
>>> static struct rusage ru;
>>> static long maxrss_init;
>>> -static int retval, status;
>>> +static int retval, status, opt_factor;
>>> static pid_t pid;
>>> +static char *factor_str;
>>> +int factor_nr = 10;
>>
>> missing `static`?
>
> In my opinion doesn't need to be static.
It will be better if you make a global var as `static`, since you will
get noticed if you don't use it in your program.
>
>>
>>>
>>> +option_t child_options[] = {
>>> + { "m:", &opt_factor, &factor_str },
>>> + { NULL, NULL, NULL }
>>> +};
>>> +
>>> +static void usage(void);
>>> static void inherit_fork(void);
>>> -static void inherit_fork2(void);
>>> +static void inherit_fork2(const int size);
>>> static void fork_malloc(void);
>>> static void grandchild_maxrss(void);
>>> static void zombie(void);
>>> @@ -68,23 +76,33 @@ static void cleanup(void);
>>>
>>> int main(int argc, char *argv[])
>>> {
>>> - int lc;
>>> + int lc, size;
>>> char *msg;
>>>
>>> - msg = parse_opts(argc, argv, NULL, NULL);
>>> + msg = parse_opts(argc, argv, child_options, usage);
>>> if (msg != NULL)
>>> tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
>>>
>>> setup();
>>>
>>> + if (opt_factor)
>>> + factor_nr = atoi(factor_str);
>>> +
>>> + if (factor_nr == 0)
>>> + tst_brkm(TBROK, cleanup, "Input factor must be != 0");
>>
>> Hi, I guess factor_nr should not be < 0 too? If so, you might want to
>> use
>>
>> factor_nr = SAFE_STRTOL(NULL, factor_str, 1, LONG_MAX);
>>
>> where SAFE_STRTOL is defined in safe_macros.h, of course you should
>> make
>> factor_nr to be long int.
>
>
> Factor_nr being a multiply factor, should be a relatively small number,
> int type should be enough. For this reason I didn't use the SAFE_STRTOL macro you have recently introduced.
> It could modify the factor_nr check to "if (factor_nr <= 0)".
> Alternatively, as you suggest, it could be use SAFE_STRTOL. In this case I suggest something like
> factor_nr = SAFE_STRTOL(NULL, factor_str, 1, FACTOR_MAX)
> where FACTOR_MAX should be locally defined, for example, to 20 (two times of actual).
sounds reasonable. either using 20 directly or a macro is OK for me.
Thanks,
Caspar
>
>>
>> Rest looks good to me.
>>
>> Thanks,
>> Caspar
>
> Filippo.
>
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-02-16 9:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-15 13:04 [LTP] [PATCH v2] getrusage03: add opportunity to reduce memory allocation's size Filippo ARCIDIACONO
2012-02-16 6:39 ` Caspar Zhang
2012-02-16 8:57 ` Filippo ARCIDIACONO
[not found] ` <4f3cc506.49350e0a.271e.703dSMTPIN_ADDED@mx.google.com>
2012-02-16 9:27 ` Caspar Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox