[LTP] [PATCH] sysctl/sysctl03: Test whether return EINVAL when passing negative value

Cyril Hrubis chrubis@suse.cz
Fri Jan 28 11:31:42 CET 2022


Hi!
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> +# Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> +#
> +# When we pass a negative value to the proc_doulongvec_minmax() function,
> +# the function should return EINVAL and the corresponding interface value
> +# does not change.
> +#
> +# It is also a regression test for
> +# commit 1622ed7d0743 ("sysctl: returns -EINVAL when a negative value is passed
> +# to proc_doulongvec_minmax").
> +#
> +# Use fs.epoll.max_user_watches interface to test this.
> +
> +TST_TESTFUNC=do_test
> +TST_SETUP=setup
> +TST_NEEDS_ROOT=1
> +TST_NEEDS_CMDS="sysctl"
> +TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y, CONFIG_INOTIFY_USER=y"
> +sys_name="fs.epoll.max_user_watches"
> +sys_file="/proc/sys/fs/epoll/max_user_watches"
> +
> +. tst_test.sh
> +
> +setup()
> +{
> +	orig_value=$(cat "$sys_file")
> +}
> +
> +do_test()
> +{
> +	tst_res TINFO "trying to set $sys_name=-1"
> +
> +	sysctl -w -q $sys_name=-1 2>&1 | grep -q "Invalid argument"
> +
> +	if [ $? -eq 0 ]; then
> +		tst_res TPASS "sysctl returns EINVAL when passing a negative value"
> +	else
> +		tst_res TFAIL "sysctl doesn't return EINVAL when passing a negative value"
> +	fi
> +
> +	new_value=$(cat "$sys_file")
> +	if [ $orig_value -eq $new_value ]; then
> +		tst_res TPASS "the interface value doesn't change when passing a negative value"
> +	else
> +		tst_res TFAIL "the interface value changes when passing a negative value"
> +		sysctl -w -q $sys_name=$orig_value
> +	fi
> +}
> +
> +tst_run

I'm just wondering if this wouldn't be actually easier as a C test. I
bet that simple write() to the sys_file would work exactly the same and
we wouldn't depend on sysctl being present on the system.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list