1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (C) 2017  Red Hat, Inc.
4f08c3bdfSopenharmony_ci */
5f08c3bdfSopenharmony_ci
6f08c3bdfSopenharmony_ci /*
7f08c3bdfSopenharmony_ci  * Parse the ksm0* test options in funcion parse_ksm_options().
8f08c3bdfSopenharmony_ci  */
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_ci#include "tst_test.h"
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_ci#define DEFAULT_MEMSIZE 128
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ciint size = DEFAULT_MEMSIZE, num = 3, unit = 1;
15f08c3bdfSopenharmony_cichar *opt_sizestr, *opt_numstr, *opt_unitstr;
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_cistatic inline void parse_ksm_options(char *str_size, int *size,
18f08c3bdfSopenharmony_ci		char *str_num, int *num, char *str_unit, int *unit)
19f08c3bdfSopenharmony_ci{
20f08c3bdfSopenharmony_ci	if(tst_parse_int(str_size, size, 1, INT_MAX))
21f08c3bdfSopenharmony_ci		tst_brk(TBROK, "Invalid size '%s'", str_size);
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_ci	if(tst_parse_int(str_num, num, 3, INT_MAX))
24f08c3bdfSopenharmony_ci		tst_brk(TBROK, "Invalid num '%s'", str_num);
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_ci	if(tst_parse_int(str_unit, unit, 1, *size))
27f08c3bdfSopenharmony_ci		tst_brk(TBROK, "Invalid unit '%s'", str_unit);
28f08c3bdfSopenharmony_ci	if (*size % *unit != 0)
29f08c3bdfSopenharmony_ci		tst_brk(TBROK,
30f08c3bdfSopenharmony_ci				"the remainder of division of size by unit is "
31f08c3bdfSopenharmony_ci				"not zero.");
32f08c3bdfSopenharmony_ci}
33