From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH] sysctl/sysctl03: Test whether return EINVAL when passing negative value
Date: Sun, 30 Jan 2022 02:24:54 +0000 [thread overview]
Message-ID: <61F5F724.9020700@fujitsu.com> (raw)
In-Reply-To: <YfPGDmF0UFFjeABu@yuki>
Hi Cyril
> 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.
If using C program, it seems not have a suitable place to put this test
case. Do you have some advise?
Best Regards
Yang Xu
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-01-30 2:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 5:51 [LTP] [PATCH] sysctl/sysctl03: Test whether return EINVAL when passing negative value Yang Xu
2022-01-28 10:31 ` Cyril Hrubis
2022-01-30 2:24 ` xuyang2018.jy [this message]
2022-02-16 12:59 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=61F5F724.9020700@fujitsu.com \
--to=xuyang2018.jy@fujitsu.com \
--cc=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox