• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017  Red Hat, Inc.
3  *
4  * This program is free software;  you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  * the GNU General Public License for more details.
13  */
14 
15  /*
16   * Parse the ksm0* test options in funcion parse_ksm_options().
17   */
18 
19 #include "tst_test.h"
20 
21 int merge_across_nodes;
22 
23 int size = 128, num = 3, unit = 1;
24 char *opt_sizestr, *opt_numstr, *opt_unitstr;
25 
26 struct tst_option ksm_options[] = {
27 	{"n:", &opt_numstr,  "-n       Number of processes"},
28 	{"s:", &opt_sizestr, "-s       Memory allocation size in MB"},
29 	{"u:", &opt_unitstr, "-u       Memory allocation unit in MB"},
30 	{NULL, NULL, NULL}
31 };
32 
parse_ksm_options(char * str_size,int * size,char * str_num,int * num,char * str_unit,int * unit)33 static inline void parse_ksm_options(char *str_size, int *size,
34 		char *str_num, int *num, char *str_unit, int *unit)
35 {
36 	if(tst_parse_int(str_size, size, 1, INT_MAX))
37 		tst_brk(TBROK, "Invalid size '%s'", str_size);
38 
39 	if(tst_parse_int(str_num, num, 3, INT_MAX))
40 		tst_brk(TBROK, "Invalid num '%s'", str_num);
41 
42 	if(tst_parse_int(str_unit, unit, 1, *size))
43 		tst_brk(TBROK, "Invalid unit '%s'", str_unit);
44 	if (*size % *unit != 0)
45 		tst_brk(TBROK,
46 				"the remainder of division of size by unit is "
47 				"not zero.");
48 }
49 
50 static const char * const save_restore[] = {
51 	"?/sys/kernel/mm/ksm/max_page_sharing",
52 	NULL,
53 };
54