From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH V2 05/14] mem/thp: convert to new API
Date: Mon, 10 Apr 2017 18:05:47 +0800 [thread overview]
Message-ID: <20170410100556.4465-6-liwang@redhat.com> (raw)
In-Reply-To: <20170410100556.4465-1-liwang@redhat.com>
Signed-off-by: Li Wang <liwang@redhat.com>
---
runtest/mm | 2 +-
testcases/kernel/mem/thp/thp01.c | 85 +++++++++++++++----------------------
testcases/kernel/mem/thp/thp02.c | 89 ++++++++++++--------------------------
testcases/kernel/mem/thp/thp03.c | 92 +++++++++++++---------------------------
4 files changed, 92 insertions(+), 176 deletions(-)
diff --git a/runtest/mm b/runtest/mm
index d108d18..fd37f1c 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -81,7 +81,7 @@ oom05 oom05
swapping01 swapping01 -i 5
-thp01 thp01 -I 120
+thp01 thp01 -I 10
thp02 thp02
thp03 thp03
diff --git a/testcases/kernel/mem/thp/thp01.c b/testcases/kernel/mem/thp/thp01.c
index e1eaa50..37124f6 100644
--- a/testcases/kernel/mem/thp/thp01.c
+++ b/testcases/kernel/mem/thp/thp01.c
@@ -1,4 +1,18 @@
/*
+ * Copyright (C) 2011-2017 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Description:
+ *
* This is a reproducer of CVE-2011-0999, which fixed by mainline commit
* a7d6e4ecdb7648478ddec76d30d87d03d6e22b31:
*
@@ -13,27 +27,6 @@
* invalid opcode: 0000 [#1] SMP
* last sysfs file: /sys/devices/system/cpu/cpu23/cache/index2/shared_cpu_map
* ....
- *
- * Copyright (C) 2011 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
*/
#include <sys/types.h>
@@ -41,11 +34,9 @@
#include <sys/wait.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <unistd.h>
-#include "test.h"
-
-char *TCID = "thp01";
-int TST_TOTAL = 1;
+#include "mem.h"
#define ARRAY_SZ 256
@@ -58,22 +49,12 @@ static struct rlimit rl = {
.rlim_max = RLIM_INFINITY,
};
-static void setup(void);
-static void cleanup(void);
-
-int main(int argc, char **argv)
+static void thp_test(void)
{
- int i, lc, st;
+ int i, st;
pid_t pid;
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- switch (pid = fork()) {
- case -1:
- tst_brkm(TBROK | TERRNO, cleanup, "fork");
+ switch (pid = SAFE_FORK()) {
case 0:
memset(arg, 'c', length - 1);
arg[length - 1] = '\0';
@@ -91,29 +72,31 @@ int main(int argc, char **argv)
}
default:
if (waitpid(pid, &st, 0) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+ tst_brk(TBROK | TERRNO, "waitpid");
if (!WIFEXITED(st) || WEXITSTATUS(st) != 0)
- tst_brkm(TBROK, cleanup,
- "child exited abnormally");
- }
+ tst_brk(TBROK, "child exited abnormally");
}
- tst_resm(TPASS, "system didn't crash, pass.");
- cleanup();
- tst_exit();
+
+ tst_res(TPASS, "system didn't crash, pass.");
}
static void setup(void)
{
ps = sysconf(_SC_PAGESIZE);
length = 32 * ps;
- arg = malloc(length);
- if (arg == NULL)
- tst_brkm(TBROK | TERRNO, NULL, "malloc");
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
+ arg = SAFE_MALLOC(length);
}
static void cleanup(void)
{
+ free(arg);
}
+
+static struct tst_test test = {
+ .tid = "thp01",
+ .needs_root = 1,
+ .forks_child = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = thp_test,
+};
diff --git a/testcases/kernel/mem/thp/thp02.c b/testcases/kernel/mem/thp/thp02.c
index eb919aa..45cfbe5 100644
--- a/testcases/kernel/mem/thp/thp02.c
+++ b/testcases/kernel/mem/thp/thp02.c
@@ -1,24 +1,15 @@
/*
- * Copyright (C) 2011 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2011-2017 Red Hat, Inc.
*
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
*
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * 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.
*
* thp02 - detect mremap bug when THP is enabled.
*
@@ -52,36 +43,11 @@
#include <unistd.h>
#include "mem.h"
-char *TCID = "thp02";
-int TST_TOTAL = 1;
-
#ifdef HAVE_MREMAP_FIXED
static int ps;
static long hps, size;
static void *p, *p2, *p3, *p4;
-static void do_mremap(void);
-
-int main(int argc, char **argv)
-{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- do_mremap();
- }
- tst_resm(TPASS, "Still alive.");
-
- cleanup();
- tst_exit();
-
-}
-
static void do_mremap(void)
{
int i;
@@ -89,11 +55,11 @@ static void do_mremap(void)
for (i = 0; i < 4; i++) {
if (posix_memalign(&p, hps, size))
- tst_brkm(TBROK | TERRNO, cleanup, "memalign p");
+ tst_brk(TBROK | TERRNO, "memalign p");
if (posix_memalign(&p2, hps, size))
- tst_brkm(TBROK | TERRNO, cleanup, "memalign p2");
+ tst_brk(TBROK | TERRNO, "memalign p2");
if (posix_memalign(&p3, hps, size))
- tst_brkm(TBROK | TERRNO, cleanup, "memalign p3");
+ tst_brk(TBROK | TERRNO, "memalign p3");
memset(p, 0xff, size);
memset(p2, 0xff, size);
@@ -108,37 +74,36 @@ static void do_mremap(void)
*/
old_addr = p + ps * (i >> 1);
new_addr = p3 + ps * (i & 1);
- tst_resm(TINFO, "mremap %p to %p", old_addr, new_addr);
+ tst_res(TINFO, "mremap %p to %p", old_addr, new_addr);
p4 = mremap(old_addr, size - ps, size - ps,
MREMAP_FIXED | MREMAP_MAYMOVE, new_addr);
if (p4 == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mremap");
+ tst_brk(TBROK | TERRNO, "mremap");
if (memcmp(p4, p2, size - ps))
- tst_brkm(TBROK, cleanup, "mremap bug");
+ tst_brk(TBROK, "mremap bug");
}
+
+ tst_res(TPASS, "Still alive.");
}
-void setup(void)
+static void setup(void)
{
if (access(PATH_THP, F_OK) == -1)
- tst_brkm(TCONF, NULL, "THP not enabled in kernel?");
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
+ tst_brk(TCONF, "THP not enabled in kernel?");
ps = sysconf(_SC_PAGESIZE);
- hps = read_meminfo("Hugepagesize:") * 1024;
+ hps = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
size = hps * 4;
}
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .tid = "thp02",
+ .needs_root = 1,
+ .setup = setup,
+ .test_all = do_mremap,
+};
#else
-int main(void)
-{
- tst_brkm(TCONF, NULL, "MREMAP_FIXED not present in <sys/mman.h>");
-}
+ TST_TEST_TCONF("MREMAP_FIXED not present in <sys/mman.h>");
#endif /* HAVE_MREMAP_FIXED */
diff --git a/testcases/kernel/mem/thp/thp03.c b/testcases/kernel/mem/thp/thp03.c
index 6b0f829..44541d9 100644
--- a/testcases/kernel/mem/thp/thp03.c
+++ b/testcases/kernel/mem/thp/thp03.c
@@ -1,24 +1,15 @@
/*
- * Copyright (C) 2012 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2012-2017 Red Hat, Inc.
*
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
*
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * 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.
*
* thp03 - Case for spliting unaligned memory.
* - System will panic if failed.
@@ -46,11 +37,6 @@
#include <string.h>
#include <errno.h>
#include "mem.h"
-#include "safe_macros.h"
-#include "test.h"
-
-char *TCID = "thp03";
-int TST_TOTAL = 1;
#ifdef MADV_MERGEABLE
@@ -60,24 +46,6 @@ static long hugepage_size;
static long unaligned_size;
static long page_size;
-int main(int argc, char **argv)
-{
- int lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- thp_test();
- }
- tst_resm(TPASS, "system didn't crash, pass.");
- cleanup();
- tst_exit();
-}
-
static void thp_test(void)
{
void *p;
@@ -85,53 +53,53 @@ static void thp_test(void)
p = mmap(NULL, unaligned_size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
+ tst_brk(TBROK | TERRNO, "mmap");
memset(p, 0x00, unaligned_size);
if (mprotect(p, unaligned_size, PROT_NONE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "mprotect");
+ tst_brk(TBROK | TERRNO, "mprotect");
if (madvise(p + hugepage_size, page_size, MADV_MERGEABLE) == -1) {
if (errno == EINVAL) {
- tst_brkm(TCONF, cleanup,
+ tst_brk(TCONF,
"MADV_MERGEABLE is not enabled/supported");
} else {
- tst_brkm(TBROK | TERRNO, cleanup, "madvise");
+ tst_brk(TBROK | TERRNO, "madvise");
}
}
- switch (fork()) {
- case -1:
- tst_brkm(TBROK | TERRNO, cleanup, "fork");
+ switch (SAFE_FORK()) {
case 0:
exit(0);
default:
if (waitpid(-1, NULL, 0) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+ tst_brk(TBROK | TERRNO, "waitpid");
}
+
+ tst_res(TPASS, "system didn't crash, pass.");
+ munmap(p, unaligned_size);
}
-void setup(void)
+static void setup(void)
{
if (access(PATH_THP, F_OK) == -1)
- tst_brkm(TCONF, NULL, "THP not enabled in kernel?");
+ tst_brk(TCONF, "THP not enabled in kernel?");
- hugepage_size = read_meminfo("Hugepagesize:") * KB;
+ hugepage_size = SAFE_READ_MEMINFO("Hugepagesize:") * KB;
unaligned_size = hugepage_size * 4 - 1;
- page_size = SAFE_SYSCONF(NULL, _SC_PAGESIZE);
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
+ page_size = SAFE_SYSCONF(_SC_PAGESIZE);
}
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .tid = "thp03",
+ .needs_root = 1,
+ .forks_child = 1,
+ .setup = setup,
+ .test_all = thp_test,
+};
#else
-int main(void)
-{
- tst_brkm(TCONF, NULL, "Kernel doesn't support MADV_MERGEABLE"
+ TST_TEST_TCONF("Kernel doesn't support MADV_MERGEABLE"
" or you need to update your glibc-headers");
}
#endif
--
2.9.3
next prev parent reply other threads:[~2017-04-10 10:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-10 10:05 [LTP] [PATCH V2 00/14] Convert LTP kernel/mem/testcase to New API Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 01/14] mem/lib: convert to new API Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 02/14] mem/oom: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 03/14] mem/oom: fix the timeout issue Li Wang
2017-07-07 15:11 ` Cyril Hrubis
2017-07-10 7:01 ` Li Wang
2017-07-13 9:06 ` Richard Palethorpe
2017-07-14 3:16 ` Li Wang
2017-07-10 7:38 ` Jan Stancek
2017-04-10 10:05 ` [LTP] [PATCH V2 04/14] mem/ksm: convert to new API Li Wang
2017-07-07 14:49 ` Cyril Hrubis
2017-07-07 15:29 ` Cyril Hrubis
2017-07-10 7:33 ` Li Wang
2017-04-10 10:05 ` Li Wang [this message]
2017-07-07 15:27 ` [LTP] [PATCH V2 05/14] mem/thp: " Cyril Hrubis
2017-07-11 4:32 ` Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 06/14] mem/hugetlb: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 07/14] mem/hugemmap: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 08/14] mem/hugeshmat: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 09/14] mem/hugeshmctl: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 10/14] mm/hugeshmdt: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 11/14] mem/hugeshmget: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 12/14] mem/cpuset: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 13/14] mem/swapping: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 14/14] mem/tunable: " Li Wang
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=20170410100556.4465-6-liwang@redhat.com \
--to=liwang@redhat.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