On Sat, Oct 19, 2019 at 5:56 AM Alan Maguire <alan.maguire@xxxxxxxxxx> 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 <mike.salvatore@xxxxxxxxxxxxx> > > > > > > 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 [0], and we'd be careful where a driver imports this > > namespace. > > > > [0] 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. Also, I think we still expect a symbol that is not static to have an appropriate prefix, right? As in, it is *not* okay to have a non-static symbol in apparmor called "inbounds", correct? > 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. 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. 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?