Bug 8647

Summary: Script to analyse what areas a patch changes and what tests need running
Product: [QA/Testing] Build Testing Reporter: Paul Eggleton <bluelightning>
Component: generalAssignee: Unassigned <unassigned>
Status: RESOLVED WONTFIX QA Contact: Apoorv <apoorv.sangal>
Severity: enhancement    
Priority: Low CC: akuster, alexandru.c.georgescu, benjamin.esquivel, bogdanx.a.voiculescu, daniel.alexandrux.istrate, jose.perez.carranza, joshuagloe, leonardo.sandoval.gonzalez, randy.macleod, richard.purdie, ross.burton, sgw, tim.orling
Version: 5.99   
Target Milestone: Future   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know
Bug Depends on: 8750    
Bug Blocks:    
Attachments:
Description Flags
poky modules import dependencies graph
none
A dictionary of test cases mapped to list of files they touch (from coverage)
none
by how many tests those files are touched none

Description Paul Eggleton 2015-11-05 10:09:54 UTC
Relating to bug 4078 and bug 6370, we would benefit from having a script which would simply look at the files being changed by a patch, and then make suggestions on a reasonable set of tests that should be run to detect any regressions that the patch might possibly cause. Those tests could be simply a parse, oe-selftest tests, building of particular recipe(s), etc.
Comment 1 Daniel Istrate 2015-11-10 12:10:35 UTC
Notes after discussion with Paul:

This script is intended to be automatically run when someone sends a patch to the mailing list - see https://bugzilla.yoctoproject.org/show_bug.cgi?id=8648

It should be outputting some sort of directives that the calling script can interpret - it shouldn't be outputting a list of shell commands. It's intended for consumption by another script, not a human, so brief and easy to parse.

It needs to be able to handle change to any file in the tree... now, it can be that it doesn't know how to test everything and that's fine - this is meant to be for a quick "smoke test" of the patch, not exhaustive testing, but at the base level for example if it changes something in scripts/lib/devtool/ it needs to be telling me to run the devtool tests (or a subset of them)

It'll end up being a big map of files to tests; it may be possible to have decorators on the tests to define some of it.


This script would take as input a commit and suggest what tests to run.

$ analyze_patch 94decbce394f74f11f79f6779598426e423e1745
--> selftest bblayers.BitbakeLayers.test_bitbakelayers_showrecipes
Comment 3 Daniel Istrate 2015-11-20 14:32:46 UTC
To give it a try:

1. Get first 100 commits from poky
[daniel@fedora-ws poky]$ git log --oneline -n 100 | cut -d ' ' -f 1 > /tmp/first_100_commits.txt
2. Run the script against all of them
[daniel@fedora-ws poky-build]$ for i in `cat /tmp/first_100_commits.txt` ; do analyze_patch -r $i; done

This script works from the sourced env also.
Comment 4 Daniel Istrate 2015-11-23 13:00:21 UTC
Attached mail sent to Paul the previous week. I am still open to suggestions.

Hi Paul,

I managed to determine how the files (.py) influence one another, by following the import chain.  I attached a graph illustrating this for whoever is curious.
This is useful if you want to see what influence a commit change has.

Now I need a method to determine for the given affected files what tests to suggest.
How should I map the runtine/oe-selftest/bitbake (or other) tests?

We did a brainstorming here at QA + Cristian, in short this is what we came up with:
-	This is a good candidate for a neural net implementation :)
-	We need a mechanism that computes  some sort of dictionary based on the existing test cases that we have. So for each test case/ category of test cases to have some keywords associated. If this process is not fast enough we should consider caching it, can we use sstate for that? Also this process should be automated. Now, when a file is changed, what criteria should we consider for testing? Its name, its location, its content, its type?
-	What are all the tests that could be suggested? Based on what?
-	If there is a .bb, .bbappend file it means it’s a recipe and suggest to rebuild the recipe.

Richard suggested to do a mapping for bitbake tests (bitbake/lib/bb/tests) to bitbake/lib/bb/, as they have the same filename. So if a file from bitbake/lib/bb/ changed to look for a corresponding test in bitbake/lib/bb/tests/.


This is how the graph was generated:
daniel@ubuntu-ws:~/poky$ sfood . | grep -v /usr/lib/python | grep -v /usr/share/pyshared/ | grep -v None | grep ".py')," | grep ".py'))" | sfood-graph | dot -Tsvg -o deps.svg


Thanks,
--Daniel
Comment 5 Daniel Istrate 2015-11-23 13:01:08 UTC
Created attachment 2865 [details]
poky modules import dependencies graph
Comment 6 Leonardo Sandoval Gonzalez 2015-11-24 18:07:25 UTC
Some questions for Paul

(In reply to comment #1)
> Notes after discussion with Paul:
> 
> This script is intended to be automatically run when someone sends a patch
> to the mailing list - see
> https://bugzilla.yoctoproject.org/show_bug.cgi?id=8648
> 
> It should be outputting some sort of directives that the calling script can
> interpret - it shouldn't be outputting a list of shell commands. It's
> intended for consumption by another script, not a human, so brief and easy
> to parse.

> 
> It needs to be able to handle change to any file in the tree... now, it can
> be that it doesn't know how to test everything and that's fine - this is
> meant to be for a quick "smoke test" of the patch, not exhaustive testing,
> but at the base level for example if it changes something in
> scripts/lib/devtool/ it needs to be telling me to run the devtool tests (or
> a subset of them)
> 

I was thinking of using oe-selftest to figure out the mapping between unit tests and the files being exercise. This way, there is no need to have some extra mapping (on a separate file, which at the end it will need maintenance).

> It'll end up being a big map of files to tests; it may be possible to have
> decorators on the tests to define some of it.
> 

Can you elaborate more on the decorators?

> 
> This script would take as input a commit and suggest what tests to run.
> 
> $ analyze_patch 94decbce394f74f11f79f6779598426e423e1745
> --> selftest bblayers.BitbakeLayers.test_bitbakelayers_showrecipes

Perhaps for M1, we should just throw the full command, and latter abstract a bit more as you mentioned before (<script to run the test> <parameters>)
Comment 7 Alexandru Georgescu 2015-12-07 08:13:12 UTC
Bug 8750 is sent for review.
Comment 8 Daniel Istrate 2015-12-10 14:31:07 UTC
Hi,

    To get a mapping of test case to files they 'touch' I was thinking to build upon bug 8679 (https://bugzilla.yoctoproject.org/show_bug.cgi?id=8679#c4). With a little parsing I was able to get a dictionary tests -> list of files they touch (will attach to bug).

    Doing analysis on this dictionary I noticed that there are lot of files 'touched' by tests that doesn't necessarily has something to do with the test (will attach to bug). Most of them are 'touched' because of the bitbake process that most tests spawn, which loads all it's modules even though some of the bitbake features are not specifically tested in that test.
    Take for instance 'bitbake/lib/bb/fetch2/clearcase.py'  which is 'touched' by all test cases (according to coverage), but as RP confirmed that there is no test atm that tests that.

    So this approach doesn't gives us an accurate mapping of 'random file' to test cases. Even though this will make it dependent of the output of the coverage that has to be cached, so it will always be a little out of sync.

    The other idea that I explored was to have feature tag decorators for test cases (bug 8750) that will describe what features a test case tests. This will allow to run tests based on that tag.

    So the problem is split into two parts: 'random file' -> feature tag -> test cases. Bug 8750 addresses the second part which maps feature tag to test cases.

    This still leaves the question open: How do you map a random file (from a commit message) to a feature tag/suite of tests to run?

Thanks,
--Daniel
Comment 9 Daniel Istrate 2015-12-10 14:33:39 UTC
Created attachment 2890 [details]
A dictionary of test cases mapped to list of files they touch (from coverage)
Comment 10 Daniel Istrate 2015-12-10 14:35:58 UTC
Created attachment 2891 [details]
by how many tests those files are touched
Comment 11 Daniel Istrate 2016-01-07 09:37:30 UTC
Assigning to Paul for more info.
Any suggestions on how to implement this, would be much appreciated.

Thanks,
--Daniel
Comment 12 Leonardo Sandoval Gonzalez 2016-01-28 17:09:01 UTC
M2 missed.

patchtest [1], the new tool to test patches from patchwork is almost done. A patch analysis should be included on the repository [2] and derived tests based on this.

[1] https://github.com/lsandoval/patchtest
[2] https://github.com/aphran/pt-suites
Comment 13 Stephen K Jolley 2016-02-01 22:54:04 UTC
It appears the NEEDINFO has been answered.
Comment 14 Benjamin Esquivel 2016-02-19 22:47:51 UTC
Per our talks with Paul, this will move to 2.2 based on load.
Comment 15 Paul Eggleton 2016-07-11 21:17:08 UTC
Reviewing this, I think we don't have enough of an idea of how to practically implement it without signing ourselves up for a huge maintenance burden. It's also not something that should block the release. Therefore let's move it to Medium/Future until such time as we have a better idea of how to do it.
Comment 16 Armin Kuster 2019-12-22 20:42:08 UTC
I don't think this is going to fly in the current state of the YP.
Comment 17 Randy MacLeod 2020-01-30 16:28:47 UTC
This is a good idea but it's not possible with current YP community participation levels.