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 #ifndef KSM_COMMON_H__
11 #define KSM_COMMON_H__
12
13 #include "tst_test.h"
14
15 #define DEFAULT_MEMSIZE 128
16
17 static int size = DEFAULT_MEMSIZE, num = 3, unit = 1;
18 static char *opt_sizestr, *opt_numstr, *opt_unitstr;
19
parse_ksm_options(char * str_size,int * size,char * str_num,int * num,char * str_unit,int * unit)20 static inline void parse_ksm_options(char *str_size, int *size,
21 char *str_num, int *num, char *str_unit, int *unit)
22 {
23 if (tst_parse_int(str_size, size, 1, INT_MAX))
24 tst_brk(TBROK, "Invalid size '%s'", str_size);
25
26 if (tst_parse_int(str_num, num, 3, INT_MAX))
27 tst_brk(TBROK, "Invalid num '%s'", str_num);
28
29 if (tst_parse_int(str_unit, unit, 1, *size))
30 tst_brk(TBROK, "Invalid unit '%s'", str_unit);
31
32 if (*size % *unit != 0)
33 tst_brk(TBROK, "the remainder of division of size by unit is not zero.");
34 }
35
36 #endif /* KSM_COMMON_H__ */
37