lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 24 Apr 2019 14:58:14 -0400
From:   Masayoshi Mizuma <msys.mizuma@...il.com>
To:     Brendan Higgins <brendanhiggins@...gle.com>
Cc:     corbet@....net, frowand.list@...il.com, keescook@...gle.com,
        kieran.bingham@...asonboard.com, mcgrof@...nel.org,
        robh@...nel.org, shuah@...nel.org, yamada.masahiro@...ionext.com,
        pmladek@...e.com, linux-doc@...r.kernel.org, amir73il@...il.com,
        dri-devel@...ts.freedesktop.org, Alexander.Levin@...rosoft.com,
        linux-kselftest@...r.kernel.org, linux-nvdimm@...ts.01.org,
        khilman@...libre.com, knut.omang@...cle.com,
        Felix Guo <felixguoxiuping@...il.com>, wfg@...ux.intel.com,
        joel@....id.au, jdike@...toit.com, dan.carpenter@...cle.com,
        devicetree@...r.kernel.org, linux-kbuild@...r.kernel.org,
        Tim.Bird@...y.com, linux-um@...ts.infradead.org,
        rostedt@...dmis.org, julia.lawall@...6.fr,
        kunit-dev@...glegroups.com, richard@....at,
        gregkh@...uxfoundation.org, linux-kernel@...r.kernel.org,
        daniel@...ll.ch, mpe@...erman.id.au, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH v1 14/17] Documentation: kunit: add documentation for
 KUnit

Hi Brendan,

KUNIT_ASSERT_NOT_ERR_OR_NULL() should be replaced to
KUNIT_EXPECT_NOT_ERR_OR_NULL(), right?

On Thu, Apr 04, 2019 at 03:06:49PM -0700, Brendan Higgins wrote:
> Add documentation for KUnit, the Linux kernel unit testing framework.
> - Add intro and usage guide for KUnit
> - Add API reference
> 
> Signed-off-by: Felix Guo <felixguoxiuping@...il.com>
> Signed-off-by: Brendan Higgins <brendanhiggins@...gle.com>
> ---

<snip>

> diff --git a/Documentation/kunit/start.rst b/Documentation/kunit/start.rst
> new file mode 100644
> index 0000000000000..5cdba5091905e
> --- /dev/null
> +++ b/Documentation/kunit/start.rst

<snip>

> +Assertions
> +~~~~~~~~~~
> +
> +KUnit also has the concept of an *assertion*. An assertion is just like an
> +expectation except the assertion immediately terminates the test case if it is
> +not satisfied.
> +
> +For example:
> +
> +.. code-block:: c
> +
> +	static void mock_test_do_expect_default_return(struct kunit *test)
> +	{
> +		struct mock_test_context *ctx = test->priv;
> +		struct mock *mock = ctx->mock;
> +		int param0 = 5, param1 = -5;
> +		const char *two_param_types[] = {"int", "int"};
> +		const void *two_params[] = {&param0, &param1};
> +		const void *ret;
> +
> +		ret = mock->do_expect(mock,
> +				      "test_printk", test_printk,
> +				      two_param_types, two_params,
> +				      ARRAY_SIZE(two_params));

> +		KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ret);

		KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ret);

> +		KUNIT_EXPECT_EQ(test, -4, *((int *) ret));
> +	}
> +
> +In this example, the method under test should return a pointer to a value, so
> +if the pointer returned by the method is null or an errno, we don't want to
> +bother continuing the test since the following expectation could crash the test

> +case. `ASSERT_NOT_ERR_OR_NULL(...)` allows us to bail out of the test case if

  +case. `KUNIT_EXPECT_NOT_ERR_OR_NULL(...)` allows us to bail out of the test case if

Thanks!
Masa

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ