<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 31, 2019 at 2:45 PM Eric Lin <<a href="mailto:tesheng@andestech.com">tesheng@andestech.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">When doing save_nr_hugepages() in setup() and there<br>
is no Huge page support in system, it will call<br>
cleanup() and write wrong orig_shmmax and orig_shmmni<br>
value back to file.<br>
<br>
To fix it, we initialize the orig_shmmax and<br>
orig_shmmni to -1 and check it in cleanup().<br>
<br>
Signed-off-by: Eric Lin <<a href="mailto:tesheng@andestech.com" target="_blank">tesheng@andestech.com</a>><br></blockquote><div><span class="gmail_default" style="font-size:small">Reviewed-by: Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>></span></div><div><span class="gmail_default" style="font-size:small"></span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c | 5 +++--<br>
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 5 +++--<br>
2 files changed, 6 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c<br>
index d375810cb..c76e4167f 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c<br>
@@ -38,7 +38,7 @@<br>
static long huge_free;<br>
static long huge_free2;<br>
static long hugepages;<br>
-static long orig_shmmax, new_shmmax;<br>
+static long orig_shmmax = -1, new_shmmax;<br>
<br>
static void shared_hugepage(void);<br>
<br>
@@ -106,7 +106,8 @@ static void setup(void)<br>
static void cleanup(void)<br>
{<br>
restore_nr_hugepages();<br>
- SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);<br>
+ if (orig_shmmax != -1)<br>
+ SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);<br>
}<br>
<br>
static struct tst_test test = {<br>
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c<br>
index d5255228b..f2ecc465d 100644<br>
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c<br>
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c<br>
@@ -39,7 +39,7 @@ static int num_shms;<br>
static int shm_id_arr[MAXIDS];<br>
<br>
static long hugepages = 128;<br>
-static long orig_shmmni;<br>
+static long orig_shmmni = -1;<br>
static struct tst_option options[] = {<br>
{"s:", &nr_opt, "-s num Set the number of the been allocated hugepages"},<br>
{NULL, NULL, NULL}<br>
@@ -105,7 +105,8 @@ static void cleanup(void)<br>
for (i = 0; i < num_shms; i++)<br>
rm_shm(shm_id_arr[i]);<br>
<br>
- FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);<br>
+ if (orig_shmmni != -1)<br>
+ FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);<br>
restore_nr_hugepages();<br>
}<br>
<br>
-- <br>
2.17.0<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>