From: Luis Chamberlain <firstname.lastname@example.org> To: Brendan Higgins <email@example.com> Cc: Alan Maguire <firstname.lastname@example.org>, Matthias Maennich <email@example.com>, shuah <firstname.lastname@example.org>, John Johansen <email@example.com>, firstname.lastname@example.org, email@example.com, Kees Cook <firstname.lastname@example.org>, Iurii Zaikin <email@example.com>, David Gow <firstname.lastname@example.org>, Theodore Ts'o <email@example.com>, Linux Kernel Mailing List <firstname.lastname@example.org>, email@example.com, KUnit Development <firstname.lastname@example.org>, "open list:KERNEL SELFTEST FRAMEWORK" <email@example.com>, Mike Salvatore <firstname.lastname@example.org> Subject: Re: [PATCH linux-kselftest/test v1] apparmor: add AppArmor KUnit tests for policy unpack Date: Thu, 24 Oct 2019 10:15:29 +0000 [thread overview] Message-ID: <20191024101529.GK11244@42.do-not-panic.com> (raw) In-Reply-To: <CAFd5g46aO4jwyo32DSz4L8GdhP6t38+Qb9NB+3fev3u4G6sg4w@mail.gmail.com> On Wed, Oct 23, 2019 at 05:42:18PM -0700, Brendan Higgins wrote: > On Sat, Oct 19, 2019 at 5:56 AM Alan Maguire <email@example.com> wrote: > > > > On Fri, 18 Oct 2019, Luis Chamberlain wrote: > > > > > On Thu, Oct 17, 2019 at 05:18:16PM -0700, Brendan Higgins wrote: > > > > From: Mike Salvatore <firstname.lastname@example.org> > > > > > > > > In order to write the tests against the policy unpacking code, some > > > > static functions needed to be exposed for testing purposes. One of the > > > > goals of this patch is to establish a pattern for which testing these > > > > kinds of functions should be done in the future. > > > > > > And you'd run into the same situation expressed elsewhere with kunit of > > > an issue of the kunit test as built-in working but if built as a module > > > then it would not work, given the lack of exports. Symbols namespaces > > > should resolve this , and we'd be careful where a driver imports this > > > namespace. > > > > > >  https://lwn.net/Articles/798254/ > > Maybe I am not understanding how the symbol namespaces work, but it > seems that it doesn't actually solve our problem, at least not all of > it. > > First off this doesn't solve the problem for when a piece of code is > included as a module; it also does not address the problem for symbols > that would not normally be exported. The suggestion is that since exporting certain symbols may not be wise, exporting them for say a test namespace may make more sense. Then the hacks don't need to be used for the lookup, therefore decreasing test / complexity time. This would only make sense if there really is no performance penalty known for having the symbol be exported. > > WRT adding tests, I think what we're aiming at is a set of best practices > > to advise test developers using KUnit, while attempting to minimize > > side-effects of any changes we need to make to support testability. > > > > One aspect of this we probably have to consider is inlining of code. For > > cases like this where the functions are small and are called in a small > > number of cases, any testability changes we make may push a > > previously-inlined function to not be inlined, with potential performance > > side-effects for the subsystem. In such cases, I wonder if the right > > answer would be to suggest actually defining the functions as > > inline in the header file? That way the compiler still gets to decide (as > > opposed to __always_inline), and we don't perturb performance too much. > > That's a really good point. Okay, so it seems that making the symbols > public when not testing is probably not okay on its own. If we are > going to do that, we probably need to do something like what you are > suggesting. If namespaces were to be used, and a consideration is that certain symbols should not be public as otherwise there would be a real perfomance hit, having a macro which only exports the namespace if a build option is enabled would suffice as well. That is, a no-op if the test feature is disabled, exported into a namespace otherwise. But if a new build option were to be considered to help build a different test kernel it begs the question if we just want or not a full sweaping -fno-inline could be considered on the top level Makefile when testing. The cost is a bloat the kernel, and it may also produce slightly different runtimes. With a test specific symbol namespace thing, we'd only export to a namespace those symbols being tested. FWIW we currently only enable -fno-inline-functions-called-once when we have CONFIG_DEBUG_SECTION_MISMATCH enabled. Your suggestion below with __visible_for_testing aligns with the gcc flags I mentioned. > With that, I think the best solution in this case will be the > "__visible_for_testing" route. It has no overhead when testing is > turned off (in fact it is no different in anyway when testing is > turned off). The downsides I see are: > > 1) You may not be able to test non-module code not compiled for > testing later with the test modules that Alan is working on (But the > only way I think that will work is by preventing the symbol from being > inlined, right?). > > 2) I think "__visible_for_testing" will be prone to abuse. Here, I > think there are reasons why we might want to expose these symbols for > testing, but not otherwise. Nevertheless, I think most symbols that > should be tested should probably be made visible by default. Since you > usually only want to test your public interfaces. I could very well > see this getting used as a kludge that gets used far too frequently. There are two parts to your statement on 2): a) possible abuse of say __visible_for_testing b) you typically only want to test your public interfaces For a) I think a proper module testing namespace thing would less likely be prone to abuse over somethingmore generic. It has the penalty of always being enabled (unless you kconfig it to allow you to disable it). While I don't fully agree with b) I think for the most part it remains true. But I'd agree more with this: Most functions you want to test likely don't have a performance criteria to be kept inline And for those situations I think a wrapper kconfig to convert a subsystem specific namespace call to be a nop would make sense. Luis > Nevertheless, based on Alan's point, I suspect it, for this case at > least, will likely be the least painful. > > How do people feel about that?
next prev parent reply other threads:[~2019-10-24 10:15 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-18 0:18 Brendan Higgins 2019-10-18 0:33 ` Iurii Zaikin 2019-10-30 18:59 ` Kees Cook 2019-11-06 0:35 ` Brendan Higgins 2019-11-06 0:37 ` Brendan Higgins 2019-10-18 0:43 ` Brendan Higgins 2019-10-18 16:25 ` Theodore Y. Ts'o 2019-10-18 21:41 ` Brendan Higgins 2019-10-30 19:02 ` Kees Cook 2019-10-31 9:01 ` Brendan Higgins 2019-10-18 12:29 ` Luis Chamberlain 2019-10-19 12:56 ` Alan Maguire 2019-10-19 18:36 ` Luis Chamberlain 2019-10-24 0:42 ` Brendan Higgins 2019-10-24 10:15 ` Luis Chamberlain [this message] 2019-10-30 19:09 ` Kees Cook 2019-10-30 20:11 ` Iurii Zaikin 2019-10-31 1:40 ` John Johansen 2019-10-31 9:33 ` Brendan Higgins 2019-10-31 18:40 ` Kees Cook 2019-11-05 16:43 ` Mike Salvatore 2019-11-05 23:59 ` Brendan Higgins 2019-10-31 1:37 ` John Johansen 2019-10-31 9:17 ` Brendan Higgins 2019-11-01 12:30 ` Alan Maguire 2019-11-05 23:44 ` Brendan Higgins
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=20191024101529.GK11244@42.do-not-panic.com \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH linux-kselftest/test v1] apparmor: add AppArmor KUnit tests for policy unpack' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).