public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
[parent not found: <1417596291-8540-1-git-send-email-liwang@redhat.com>]
[parent not found: <1417512939-6435-1-git-send-email-liwang@redhat.com>]
* [LTP] [PATCH] /vm/hugepage/thp/thp05: cleanup should not use safe macros
@ 2014-10-23  3:31 Li Wang
  2014-11-06 10:22 ` Cyril Hrubis
  0 siblings, 1 reply; 6+ messages in thread
From: Li Wang @ 2014-10-23  3:31 UTC (permalink / raw)
  To: ltp-list; +Cc: wangli.ahau

NOTE: It's wise NOT to use safe macros in test cleanup(). This is because
      all safe macros call tst_brkm(), which exits the test immediately, making
      the cleanup() exit prematurely. (Actually, this is hacked around in
      the test library at the moment so that the cleanup() will finish, but
      the hack will be removed in the future).

Signed-off-by: Li Wang <liwan@redhat.com>
---
 testcases/kernel/mem/thp/thp05.c | 69 ++++++++++++++++++++++++++++++++--------
 1 file changed, 56 insertions(+), 13 deletions(-)

diff --git a/testcases/kernel/mem/thp/thp05.c b/testcases/kernel/mem/thp/thp05.c
index 8b595ca..92d9610 100644
--- a/testcases/kernel/mem/thp/thp05.c
+++ b/testcases/kernel/mem/thp/thp05.c
@@ -66,6 +66,7 @@ option_t thp_options[] = {
 static int pre_thp_scan_sleep_millisecs;
 static int pre_thp_alloc_sleep_millisecs;
 static char pre_thp_enabled[BUFSIZ];
+static char buf[BUFSIZ], path[BUFSIZ];
 
 int main(int argc, char *argv[])
 {
@@ -129,19 +130,61 @@ void setup(void)
 
 void cleanup(void)
 {
-	SAFE_FILE_PRINTF(NULL, PATH_KHPD "scan_sleep_millisecs",
-			 "%d", pre_thp_scan_sleep_millisecs);
-
-	SAFE_FILE_PRINTF(NULL, PATH_KHPD "alloc_sleep_millisecs",
-			 "%d", pre_thp_alloc_sleep_millisecs);
-
-	if (strcmp(pre_thp_enabled, "[always] madvise never") == 0)
-		SAFE_FILE_PRINTF(NULL, PATH_THP "enabled", "always");
-	else if (strcmp(pre_thp_enabled, "always [madvise] never") == 0)
-		SAFE_FILE_PRINTF(NULL, PATH_THP "enabled", "madvise");
-	else
-		SAFE_FILE_PRINTF(NULL, PATH_THP "enabled", "never");
-
+	int fd;
+
+	/* restore the scan_sleep_millisecs to original value */
+	snprintf(buf, BUFSIZ, "%d", pre_thp_scan_sleep_millisecs);
+	fd = open(PATH_KHPD "scan_sleep_millisecs", O_WRONLY);
+	if (fd == -1)
+		tst_resm(TWARN | TERRNO, "open");
+	tst_resm(TINFO, "restore scan_sleep_millisecs to %d",
+			pre_thp_scan_sleep_millisecs);
+	if (write(fd, buf, strlen(buf)) != strlen(buf))
+		tst_resm(TWARN | TERRNO, "write");
+	close(fd);
+
+	/* restore the alloc_sleep_millisecs to original value */
+	snprintf(buf, BUFSIZ, "%d", pre_thp_alloc_sleep_millisecs);
+	fd = open(PATH_KHPD "alloc_sleep_millisecs", O_WRONLY);
+	if (fd == -1)
+		tst_resm(TWARN | TERRNO, "open");
+	tst_resm(TINFO, "restore alloc_sleep_millisecs to %d",
+			pre_thp_alloc_sleep_millisecs);
+	if (write(fd, buf, strlen(buf)) != strlen(buf))
+		tst_resm(TWARN | TERRNO, "write");
+	close(fd);
+
+	/* restore the transparent_hugepage options to original state */
+	if (strcmp(pre_thp_enabled, "[always] madvise never") == 0){
+		snprintf(path, BUFSIZ, "always");
+		fd = open(PATH_THP "enabled", O_WRONLY);
+		if (fd == -1)
+			tst_resm(TWARN | TERRNO, "open");
+		tst_resm(TINFO, "restore transparent_hugepage to %s", path);
+		if (write(fd, path, strlen(path)) != strlen(path))
+			tst_resm(TWARN | TERRNO, "write");
+		close(fd);
+	}
+	else if (strcmp(pre_thp_enabled, "always [madvise] never") == 0){
+		snprintf(path, BUFSIZ, "madvise");
+		fd = open(PATH_THP "enabled", O_WRONLY);
+		if (fd == -1)
+			tst_resm(TWARN | TERRNO, "open");
+		tst_resm(TINFO, "restore transparent_hugepage to %s", path);
+		if (write(fd, path, strlen(path)) != strlen(path))
+			tst_resm(TWARN | TERRNO, "write");
+		close(fd);
+	}
+	else{
+		snprintf(path, BUFSIZ, "never");
+		fd = open(PATH_THP "enabled", O_WRONLY);
+		if (fd == -1)
+			tst_resm(TWARN | TERRNO, "open");
+		tst_resm(TINFO, "restore transparent_hugepage to %s", path);
+		if (write(fd, path, strlen(path)) != strlen(path))
+			tst_resm(TWARN | TERRNO, "write");
+		close(fd);
+	}
 	TEST_CLEANUP;
 }
 
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-16 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1417612136-10890-1-git-send-email-liwang@redhat.com>
     [not found] ` <152932834.6076324.1417612296820.JavaMail.zimbra@redhat.com>
2014-12-16 14:47   ` [LTP] [PATCH] /vm/hugepage/thp/thp05: cleanup should not use safe macros Cyril Hrubis
     [not found] <1417596291-8540-1-git-send-email-liwang@redhat.com>
     [not found] ` <373996084.5962831.1417596425167.JavaMail.zimbra@redhat.com>
2014-12-03 10:50   ` Cyril Hrubis
     [not found] <1417512939-6435-1-git-send-email-liwang@redhat.com>
     [not found] ` <2046852420.5414979.1417513768451.JavaMail.zimbra@redhat.com>
2014-12-02 12:00   ` Cyril Hrubis
2014-10-23  3:31 Li Wang
2014-11-06 10:22 ` Cyril Hrubis
     [not found]   ` <857789373.5490769.1415284744752.JavaMail.zimbra@redhat.com>
2014-11-26 14:50     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox