• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2017  Red Hat, Inc.
4  */
5 
6  /*
7   * Parse the ksm0* test options in funcion parse_ksm_options().
8   */
9 
10 #include "tst_test.h"
11 
12 int merge_across_nodes;
13 
14 int size = 128, num = 3, unit = 1;
15 char *opt_sizestr, *opt_numstr, *opt_unitstr;
16 
17 struct tst_option ksm_options[] = {
18 	{"n:", &opt_numstr,  "-n       Number of processes"},
19 	{"s:", &opt_sizestr, "-s       Memory allocation size in MB"},
20 	{"u:", &opt_unitstr, "-u       Memory allocation unit in MB"},
21 	{NULL, NULL, NULL}
22 };
23 
parse_ksm_options(char * str_size,int * size,char * str_num,int * num,char * str_unit,int * unit)24 static inline void parse_ksm_options(char *str_size, int *size,
25 		char *str_num, int *num, char *str_unit, int *unit)
26 {
27 	if(tst_parse_int(str_size, size, 1, INT_MAX))
28 		tst_brk(TBROK, "Invalid size '%s'", str_size);
29 
30 	if(tst_parse_int(str_num, num, 3, INT_MAX))
31 		tst_brk(TBROK, "Invalid num '%s'", str_num);
32 
33 	if(tst_parse_int(str_unit, unit, 1, *size))
34 		tst_brk(TBROK, "Invalid unit '%s'", str_unit);
35 	if (*size % *unit != 0)
36 		tst_brk(TBROK,
37 				"the remainder of division of size by unit is "
38 				"not zero.");
39 }
40 
41 static const char * const save_restore[] = {
42 	"?/sys/kernel/mm/ksm/max_page_sharing",
43 	NULL,
44 };
45