Linux Test Project
 help / color / mirror / Atom feed
From: Julio Cruz <jcsistemas2001@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] Check available memory to support embedded devices
Date: Wed, 16 Mar 2016 11:01:15 +0800	[thread overview]
Message-ID: <1458097275-2769-1-git-send-email-jcsistemas2001@gmail.com> (raw)

This patch check the available memory before to perform the 
different test cases. If the memory is not enough (according with
each test case), the test finish as TCONF.
This could be usefull when you are testing on embedded devices
with RAM memory limitation (i.e. 512MB)
This patch no changed the test case procedure and is still valid 
for non-embedded devices. It just verify the available memory.

Signed-off-by: Julio Cruz <jcsistemas2001@gmail.com>
---
 testcases/kernel/syscalls/getrusage/getrusage03.c | 80 +++++++++++++++++------
 1 file changed, 61 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index 54cdc83..8967c8e 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -45,7 +45,10 @@
 char *TCID = "getrusage03";
 int TST_TOTAL = 1;
 
-#define DELTA_MAX	10240
+#define DELTA_MAX	        10240
+#define DEFAULT_ALLOCATION_MB	100
+
+unsigned long avail_memory_mb;
 
 static struct rusage ru;
 static long maxrss_init;
@@ -65,6 +68,14 @@ static void consume(int mega);
 static void setup(void);
 static void cleanup(void);
 
+unsigned long get_available_memory_mb(void)
+{
+	unsigned long long ps, pn;
+	ps = sysconf(_SC_PAGESIZE);
+	pn = sysconf(_SC_AVPHYS_PAGES);
+	return ps * pn / (1024*1024);
+}
+
 int main(int argc, char *argv[])
 {
 	int lc;
@@ -73,19 +84,26 @@ int main(int argc, char *argv[])
 
 	setup();
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		tst_resm(TINFO, "allocate 100MB");
-		consume(100);
-
-		inherit_fork();
-		inherit_fork2();
-		fork_malloc();
-		grandchild_maxrss();
-		zombie();
-		sig_ign();
-		exec_without_fork();
+	avail_memory_mb = get_available_memory_mb();
+
+	tst_resm(TINFO, "Available memory: %ldMB\n", avail_memory_mb);
+	if (avail_memory_mb < DEFAULT_ALLOCATION_MB) {
+		tst_resm(TCONF, "Not enough memory to run this case\n");
+	} else {
+		for (lc = 0; TEST_LOOPING(lc); lc++) {
+			tst_count = 0;
+
+			tst_resm(TINFO, "allocate %dMB", DEFAULT_ALLOCATION_MB);
+			consume(DEFAULT_ALLOCATION_MB);
+
+			inherit_fork();
+			inherit_fork2();
+			fork_malloc();
+			grandchild_maxrss();
+			zombie();
+			sig_ign();
+			exec_without_fork();
+		}
 	}
 	cleanup();
 	tst_exit();
@@ -95,11 +113,15 @@ int main(int argc, char *argv[])
  * expect: initial.self ~= child.self */
 static void inherit_fork(void)
 {
-	tst_resm(TINFO, "Testcase #01: fork inherit");
-
 	SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
 	tst_resm(TINFO, "initial.self = %ld", ru.ru_maxrss);
 
+	tst_resm(TINFO, "Testcase #01: fork inherit");
+	if (avail_memory_mb < DEFAULT_ALLOCATION_MB*2) {
+		tst_resm(TCONF, "Not enough memory to run this case\n");
+		return;
+	}
+
 	switch (pid = fork()) {
 	case -1:
 		tst_brkm(TBROK | TERRNO, cleanup, "fork #1");
@@ -119,17 +141,21 @@ static void inherit_fork(void)
 }
 
 /* Testcase #02: fork inherit (cont.)
- * expect: initial.children ~= 100MB, child.children = 0 */
+ * expect: initial.children ~= DEFAULT_ALLOCATION_MB, child.children = 0 */
 static void inherit_fork2(void)
 {
 	tst_resm(TINFO, "Testcase #02: fork inherit(cont.)");
+	if (avail_memory_mb < DEFAULT_ALLOCATION_MB*2) {
+		tst_resm(TCONF, "Not enough memory to run this case\n");
+		return;
+	}
 
 	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");
+		tst_resm(TPASS, "initial.children ~= %dMB", DEFAULT_ALLOCATION_MB);
 	else
-		tst_resm(TFAIL, "initial.children !~= 100MB");
+		tst_resm(TFAIL, "initial.children !~= %dMB", DEFAULT_ALLOCATION_MB);
 
 	switch (pid = fork()) {
 	case -1:
@@ -153,6 +179,10 @@ static void inherit_fork2(void)
 static void fork_malloc(void)
 {
 	tst_resm(TINFO, "Testcase #03: fork + malloc");
+	if (avail_memory_mb < (DEFAULT_ALLOCATION_MB*2+50)) {
+		tst_resm(TCONF, "Not enough memory to run this case\n");
+		return;
+	}
 
 	SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
 	tst_resm(TINFO, "initial.self = %ld", ru.ru_maxrss);
@@ -182,6 +212,10 @@ static void fork_malloc(void)
 static void grandchild_maxrss(void)
 {
 	tst_resm(TINFO, "Testcase #04: grandchild maxrss");
+	if (avail_memory_mb <= (DEFAULT_ALLOCATION_MB+300)) {
+		tst_resm(TCONF, "Not enough memory to run this case\n");
+		return;
+	}
 
 	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
 	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
@@ -216,6 +250,10 @@ static void grandchild_maxrss(void)
 static void zombie(void)
 {
 	tst_resm(TINFO, "Testcase #05: zombie");
+	if (avail_memory_mb <= (DEFAULT_ALLOCATION_MB+400)) {
+		tst_resm(TCONF, "Not enough memory to run this case\n");
+		return;
+	}
 
 	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
 	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
@@ -259,6 +297,10 @@ static void zombie(void)
 static void sig_ign(void)
 {
 	tst_resm(TINFO, "Testcase #06: SIG_IGN");
+	if (avail_memory_mb <= (DEFAULT_ALLOCATION_MB+500)) {
+		tst_resm(TCONF, "Not enough memory to run test case");
+		return;
+	}
 
 	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
 	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
-- 
1.9.1


             reply	other threads:[~2016-03-16  3:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16  3:01 Julio Cruz [this message]
2016-03-17  9:20 ` [LTP] [PATCH] Check available memory to support embedded devices Jan Stancek
2016-03-20 13:58   ` Julio Cruz
2016-03-23  4:28   ` Julio Cruz Barroso
     [not found]     ` <FF335120-237D-434A-AC4D-D88A0B2DD0E2@smartmatic.com>
     [not found]       ` <1714664694.15587378.1459340331690.JavaMail.zimbra@redhat.com>
     [not found]         ` <AF04265A3FC2B144B9892F621A394E13EA409B66@tethys>
     [not found]           ` <1024370333.16915329.1459580215038.JavaMail.zimbra@redhat.com>
2016-04-07 10:07             ` Julio Cruz Barroso

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=1458097275-2769-1-git-send-email-jcsistemas2001@gmail.com \
    --to=jcsistemas2001@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox