From: Arnout Vandecappelle Date: Wed, 13 Sep 2017 23:04:02 +0200 Subject: [Buildroot] testing/infra: generating tests for python packages In-Reply-To: <20170913164151.GA2946@scaer> References: <59b8a611e5261_146deae7dc527e9@ultri3.mail> <20170913164151.GA2946@scaer> Message-ID: <1616cbc3-4ebc-7dfd-9144-3eeddae80bc9@mind.be> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: buildroot@busybox.net On 13-09-17 18:41, Yann E. MORIN wrote: > Ricardo, Thomas, All, > > On 2017-09-13 00:29 -0300, Ricardo Martincoski spake thusly: >> Thomas mentioned [1] you guys talked about tests for python packages being >> generated by the test infra. >> >> I performed an experiment [2] ignoring where the data is coming from (whether >> it comes from the package recipe or from inside the infra) and I start this >> thread to follow up the discussion. I didn't look at your solution yet, Ricardo, but here are my high-level observations. > I also performed an experiment, which failed because I am no python > expert, but basically it was something like (in pseudo code because I > lost it and it anyway did not work): > > support/testing/tests/package/test_python-modules.py > > for dir, files, _ = os.walk(os.path.join(buildroot_top_dir,'package'): > pkg = os.path.last_component(dir) > for f in files: > if re.match('{}-test.py'.format(pkg),f): > import_module(os.path.join(dir,f)) > > which basically scans the Buildroot package/ subdir to search for files > matching the glob 'PKG_NAME-test.py' (with PKG_NAME replaced by the > package name, obviously), and imports them one by one. Looks like the right thing to do to me. However, to be consistent with the existing tests, the pattern should be test_pkg.py, and the package name should go through - to _ conversion. > In turn, each of those files would define standard test classes, for > example: > > package/python-cryptography/python-cryptography-test.py > > import os > import tests.package.testpythonbase > > class TestPythonCryptography(tests.package.testpythonbase.BaseClass): > config = "blabla" > > def test_run(self): > emulator.exec("python -c 'import cryptography'") Yes, we want to be explicit, so this looks good. Only in the config part we could perhaps do some automagic, i.e. automagically selecting python and the package itself. > Of course, one may be more inventive with the tests. > > And in the end, it would have been all integrated in the current infra. > > But alas, that import stuff I could not make to work... :-( Maybe there > is a node function to tell it where to load extra tests from? We can just add support/testing to sys.path. > > An alternative would be to go with per-package test files, like > explained above, but have the support/testing/run-test script do the can > before calling nose, and for each file if finds, do a symlink ( or a > copy) in the testing infra, in a special directory that is git-ignored ? Bwerk, hack... > > *That* would be pretty trivial (even I could do it, that's saying > something!). > > To be honest, I would highly prefer that we go this kind of route rather > than generate the tests from higher-level metadata. Especially, I'm not > fond of adding FOO_TEST_CMDS in the .mk files. Absolutely. We certainly want to be able to do more things than a simple import so we want a full .py file. And also we want to be explicit about things. > Now, completely unrelated to the above, when we want to test each module > to ensure they are correct and have the required dependencies, we need > to have a configuration for each of the modules, which means doing one > build per module we want to test, each build including building the > python interpreter. This will make for a very long test campaign, > indeed... :-/ We don't care that it takes a long time. It's not intended to be run sequentially anyway. And in gitlab, all tests run in parallel (but only on 4 builders IIRC). As long as the tests on gitlab finish within a day or so, we're golden. Regards, Arnout -- Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF