add a testcase to test /proc/sys/vm/nr_hugepages vm tunable
PATCH 1/1 add a testcase to test /proc/sys/vm/nr_hugepages vm tunable
In reply to a message not in the archivehi,I'd like to add several testcases to test vm tunable(/proc/sys/vm/*). the patch is designed to test nr_hugepages vm tunable, and I will add more to test other vm tunables.
--- testcases/kernel/mem/vmtunabe/Makefile | 31 +++++ testcases/kernel/mem/vmtunabe/nr_hugepages.c | 166 ++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/mem/vmtunabe/Makefile create mode 100644 testcases/kernel/mem/vmtunabe/nr_hugepages.c
testcases/kernel/mem/vmtunabe/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +# +# Copyright (C) 2010 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. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +include $(top_srcdir)/include/mk/generic_trunk_target.mk + +include $(top_srcdir)/include/mk/testcases.mk
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
1.7.2.3
From 98708590d4822aa442cc3261fcb84dcd79967fa2 Mon Sep 17 00:00:00 2001
From: Zhouping Liu <[email protected]>
Date: Mon, 13 Dec 2010 13:38:52 +0800
Subject: [PATCH 1/2] add a testcase nr_hugepages for vm tunable
--- testcases/kernel/mem/vmtunabe/Makefile | 31 +++++ testcases/kernel/mem/vmtunabe/nr_hugepages.c | 166 ++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/mem/vmtunabe/Makefile create mode 100644 testcases/kernel/mem/vmtunabe/nr_hugepages.c
testcases/kernel/mem/vmtunabe/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +# +# Copyright (C) 2010 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. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +include $(top_srcdir)/include/mk/generic_trunk_target.mk + +include $(top_srcdir)/include/mk/testcases.mk
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
1.7.2.3
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL, new data types, scalar functions, improved concurrency, built-in packages, OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
General comments:
1. No runtest entry.
2. If your test requires root, use tst_require_root() from libltp.
3. Use TERRNO liberally if you want to provide a sensible error back to the user in the event of a libcall or syscall failure with a predefined error.
More comments inline.
Quoted 36 lines · Zhouping Liu
hi,I'd like to add several testcases to test vm
tunable(/proc/sys/vm/*). the patch is designed to testnr_hugepagesvm tunable, and I will add more to test other vm tunables.Signed-off-by Zhouping Liu <[email protected]>---
testcases/kernel/mem/vmtunabe/Makefile | 31 +++++testcases/kernel/mem/vmtunabe/nr_hugepages.c| 166 ++++++++++++++++++++++++++2 files changed, 197 insertions(+), 0 deletions(-)create mode 100644 testcases/kernel/mem/vmtunabe/Makefile create mode 100644
testcases/kernel/mem/vmtunabe/nr_hugepages.ctestcases/kernel/mem/vmtunabe/Makefile new file +18
-0@@ -0,0 +1,31 @@ +# +# Copyright (C) 2010 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. +#
testcases/kernel/mem/vmtunabe/Makefile line 28
Quoted 10 lines
testcases/kernel/mem/vmtunabe/Makefile new file +10
-0+# 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. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/env_pre.mk +
gcooper> Delete blank line.
testcases/kernel/mem/vmtunabe/Makefile line 29
Quoted 1 line
testcases/kernel/mem/vmtunabe/Makefile new file +1
-0+include $(top_srcdir)/include/mk/generic_trunk_target.mk
gcooper> Delete above line.
Quoted 56 lines
testcases/kernel/mem/vmtunabe/Makefile new file +1
-0+include $(top_srcdir)/include/mk/testcases.mktestcases/kernel/mem/vmtunabe/nr_hugepages.c new file +49
-0@@ -0,0 +1,166 @@ +/* +* vm tunable test +* +* ******************************************************************** +* Copyright (C) 2010 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. +* +* ******************************************************************** +* +* File Name: nr_hugepage.c +* Author: Zhouping Liu <[email protected]> +* Description: +* The program is designed to test /proc/sys/vm/nr_hugepages. +* set the different values to nr_hugepages and watch this operations +* work normally. if you set nr_hugepages, you can see this change in +* /proc/meminfo: HugePages_Total +* +*/ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdint.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/types.h> + +#include "test.h" +#include "usctest.h"
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 59
Quoted 10 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +10
-0+char *TCID ="nr_hugepages" ; +#define BUFFER_SIZE 256 +/* why I set HUGEPAGES 30, I think this value is appropriate, +* In general, all the systems can provide about 30 hugepages if they +* support hugepage, if you make a much larger value, it will cause +* shortage memory. +*/ +#define HUGEPAGES 30 + +int TST_TOTAL =1 ;
gcooper> Need spaces between `='.
Quoted 20 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +20
-0+/* set hugepages */ +int set_hugepages (int nr_hugepages); +/* get the total of hugepages and surplus hugepages */ +int get_hugepages (int *nr_hugepages); + +/* check whether the /proc/sys/vm/nr_hugepages file exist +* if not, then the test can't run continue. +* */ +int check_system (); + +/* make some clean work. */ +void cleanup (); + +int old_hugepages =0 ;/* save the old nr_hugepages value */ + +int main (int argc,char *argv[]) +{ + int lc = 0; /* loop counter */ + char *msg; /* message returned from parse_opts */ + int counter = 0;
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 90
Quoted 10 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +10
-0+ int nr = 10; + int hugepages = 0; + + /* if check_system() return zero, + * the system can't support this test. + */ + if (!check_system()) { + tst_resm(TFAIL, "Can't test nr_hugepages and \ +nr_overcommit_hugepages,no such file" ); + tst_exit();
gcooper> Use tst_brkm with TCONF|TERRNO.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 91
Quoted 2 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +2
-0+ } + if ( (msg = parse_opts(argc, argv, NULL, NULL)) != NULL ) {
gcooper> Remove spurious spaces in enclosure.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 100
Quoted 8 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +8
-0+ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR -%s ", msg); + } + + + get_hugepages(&old_hugepages); + tst_resm(TINFO, "the old nr_hugepages is %d\n",old_hugepages); + + for ( lc = 0; TEST_LOOPING(lc); lc++ ) {
gcooper> This TEST_LOOPING stuff in all of the tests is garbage. I don't see why it needs to exist. Delete outer loop and dedent please.
Quoted 13 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +13
-0+ for ( counter = 0; counter < nr; counter++ ) { + set_hugepages(HUGEPAGES + counter); + tst_resm(TINFO, "set nr_hugepages %d", + HUGEPAGES + counter); + get_hugepages(&hugepages); + if ( hugepages != HUGEPAGES + counter ) { + set_hugepages(old_hugepages); /* recover the original value */ + tst_brkm(TFAIL, cleanup, "nr_hugepages error"); + } + } + } + + set_hugepages(old_hugepages); /* recover the primary value */
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 123
Quoted 10 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +10
-0+ tst_resm(TPASS, "nr_hugepages"); + cleanup(); + return 0; +} + +int get_hugepages (int *nr_hugepages) +{ + FILE *f; + int retcode = 0; + char buff[BUFFER_SIZE];
gcooper> Fix alignment.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 124
Quoted 2 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +2
-0+ f = fopen("/proc/meminfo", "r"); + if (!f) {
gcooper> Do `f == NULL'
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 125
Quoted 1 line
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +1
-0+ tst_brkm(TFAIL, cleanup, "Please run the test using root user.");
gcooper> Message is FUD. Fix.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 129
Quoted 3 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +3
-0+ } + while (fgets(buff,BUFFER_SIZE, f) != NULL) { + if((retcode = sscanf(buff, "HugePages_Total: %d ", nr_hugepages)) == 1)
gcooper> What if this value wasn't scanned?
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 140
Quoted 11 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +11
-0+ break; + } + fclose(f); + return 0; +} + +int set_hugepages (int nr_hugepages) +{ + FILE *f ; + f = fopen("/proc/sys/vm/nr_hugepages","w"); + if (!f) {
gcooper> Do `f == NULL'.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 143
Quoted 3 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +3
-0+ tst_brkm(TFAIL, NULL, "No permission, using root user."); + tst_exit(); + }
gcooper> Message is FUD. Fix.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 144
Quoted 2 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +2
-0+ /* write nr_hugepages to /proc/sys/vm/nr_hugepages */ + fprintf(f, "%d", nr_hugepages);
Don't you care if this was written out?
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 154
Quoted 8 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +8
-0+ fclose(f); + return 0; +} + +int check_system () +{ + int flag = -1; + flag = access("/proc/sys/vm/nr_hugepages",F_OK);
gcooper> Missing space between comma and constant.
testcases/kernel/mem/vmtunabe/nr_hugepages.c line 166
Quoted 12 lines
testcases/kernel/mem/vmtunabe/nr_hugepages.c new file +12
-0+ if (flag == 0) { + return 1; + } else { + return 0; + } +} + +void cleanup (void ) +{ + set_hugepages(old_hugepages); + tst_exit(); +}
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL, new data types, scalar functions, improved concurrency, built-in packages, OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list