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