[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFd5g446cyijzgap9r8nm_202zkUsfdZXrn5E1_Mfe-R+eFb_g@mail.gmail.com>
Date: Thu, 31 Oct 2019 02:33:32 -0700
From: Brendan Higgins <brendanhiggins@...gle.com>
To: Iurii Zaikin <yzaikin@...gle.com>
Cc: Kees Cook <keescook@...omium.org>,
Luis Chamberlain <mcgrof@...nel.org>,
Alan Maguire <alan.maguire@...cle.com>,
Matthias Maennich <maennich@...gle.com>,
shuah <shuah@...nel.org>,
John Johansen <john.johansen@...onical.com>, jmorris@...ei.org,
serge@...lyn.com, David Gow <davidgow@...gle.com>,
"Theodore Ts'o" <tytso@....edu>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-security-module@...r.kernel.org,
KUnit Development <kunit-dev@...glegroups.com>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@...r.kernel.org>,
Mike Salvatore <mike.salvatore@...onical.com>
Subject: Re: [PATCH linux-kselftest/test v1] apparmor: add AppArmor KUnit
tests for policy unpack
On Wed, Oct 30, 2019 at 1:12 PM Iurii Zaikin <yzaikin@...gle.com> wrote:
>
> > Why can't unit tests live with the code they're testing? They're already
> > logically tied together; what's the harm there? This needn't be the case
> > for ALL tests, etc. The test driver could still live externally. The
> > test in the other .c would just have exported functions... ?
> >
> Curiously enough, this approach has been adopted by D 2.0 where unittests are
> members of the class under test: https://digitalmars.com/d/2.0/unittest.html
Thanks for pointing this out, Iurii, that actually looks pretty cool.
I still personally prefer keeping tests and code separate, but if we
decide to go the route of mixing tests and code, maybe we might want
to use this as a model.
> but such approach is not mainstream.
> I personally like the idea of testing the lowest level bits in isolation even if
> they are not a part of any interface. I think that specifying the
> interface using
> unit tests and ensuring implementation correctness are complementary but
> I haven't had much luck arguing this with our esteemed colleagues.
So I think this is a very subtle point which is very widely
misunderstood. Most people write code and then write their tests,
following this practice along with only testing public interfaces
often causes people to just not test all of their code, which is
wrong.
The idea of only testing public interfaces is supposed to make people
think more carefully about what the composite layers of the program
is. If you are having difficulty getting decent coverage by only
testing your public interfaces, then it likely tells you that you have
one of two problems:
1) You have code that you don't need, and you should remove it.
2) One of the layers in your program is too think, and you should
introduce a new layer with a new public interface that you can test
through.
I think the second point here is problematic with how C is written in
the kernel. We don't really have any concept of public vs. private
inside the kernel outside of static vs. not static, which is much more
restricted.
Powered by blists - more mailing lists