xref: /openbmc/openbmc/poky/scripts/patchtest.README (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1ac13d5f3SPatrick Williams# Patchtest
2ac13d5f3SPatrick Williams
3ac13d5f3SPatrick Williams## Introduction
4ac13d5f3SPatrick Williams
5ac13d5f3SPatrick WilliamsPatchtest is a test framework for community patches based on the standard
6*8460358cSPatrick Williamsunittest python module. As input, it needs three elements to work properly:
7*8460358cSPatrick Williams
8*8460358cSPatrick Williams- a patch in mbox format (either created with `git format-patch` or fetched
9*8460358cSPatrick Williamsfrom 'patchwork')
10*8460358cSPatrick Williams- a test suite
11*8460358cSPatrick Williams- a target repository
12ac13d5f3SPatrick Williams
13ac13d5f3SPatrick WilliamsThe first test suite intended to be used with patchtest is found in the
14*8460358cSPatrick Williamsopenembedded-core repository [1], targeted for patches that get into the
15ac13d5f3SPatrick Williamsopenembedded-core mailing list [2]. This suite is also intended as a
16ac13d5f3SPatrick Williamsbaseline for development of similar suites for other layers as needed.
17ac13d5f3SPatrick Williams
18*8460358cSPatrick WilliamsPatchtest can either run on a host or a guest machine, depending on
19*8460358cSPatrick Williamswhich environment you prefer. If you plan to test your own patches (a
20*8460358cSPatrick Williamsgood practice before these are sent to the mailing list), the easiest
21*8460358cSPatrick Williamsway is to install and execute on your local host; in the other hand, if
22*8460358cSPatrick Williamsautomatic testing is intended, the guest method is strongly recommended.
23*8460358cSPatrick WilliamsThe guest method requires the use of the patchtest layer, in addition to
24*8460358cSPatrick Williamsthe tools available in oe-core: https://git.yoctoproject.org/patchtest/
25ac13d5f3SPatrick Williams
26ac13d5f3SPatrick Williams## Installation
27ac13d5f3SPatrick Williams
28*8460358cSPatrick WilliamsAs a tool for use with the Yocto Project, the [quick start
29*8460358cSPatrick Williamsguide](https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html)
30*8460358cSPatrick Williamscontains the necessary prerequisites. In addition, patchtest relies on
31*8460358cSPatrick Williamsseveral Python modules for parsing and analysis, which can be installed
32*8460358cSPatrick Williamsby running `pip install -r meta/lib/patchtest/requirements.txt`. Note
33*8460358cSPatrick Williamsthat git-pw is not automatically added to the user's PATH; by default,
34*8460358cSPatrick Williamsit is installed at ~/.local/bin/git-pw.
35ac13d5f3SPatrick Williams
36ac13d5f3SPatrick WilliamsFor git-pw (and therefore scripts such as patchtest-get--series) to work, you need
37ac13d5f3SPatrick Williamsto provide a Patchwork instance in your user's .gitconfig, like so (the project
38ac13d5f3SPatrick Williamscan be specified using the --project argument):
39ac13d5f3SPatrick Williams
40ac13d5f3SPatrick Williams    git config --global pw.server "https://patchwork.yoctoproject.org/api/1.2/"
41ac13d5f3SPatrick Williams
42ac13d5f3SPatrick WilliamsTo work with patchtest, you should have the following repositories cloned:
43ac13d5f3SPatrick Williams
44ac13d5f3SPatrick Williams1. https://git.openembedded.org/openembedded-core/ (or https://git.yoctoproject.org/poky/)
45ac13d5f3SPatrick Williams2. https://git.openembedded.org/bitbake/ (if not using poky)
46ac13d5f3SPatrick Williams3. https://git.yoctoproject.org/patchtest (if using guest mode)
47ac13d5f3SPatrick Williams
48ac13d5f3SPatrick Williams## Usage
49ac13d5f3SPatrick Williams
50ac13d5f3SPatrick Williams### Obtaining Patches
51ac13d5f3SPatrick Williams
52ac13d5f3SPatrick WilliamsPatch files can be obtained directly from cloned repositories using `git
53ac13d5f3SPatrick Williamsformat-patch -N` (where N is the number of patches starting from HEAD to
54ac13d5f3SPatrick Williamsgenerate). git-pw can also be used with filters for users, patch/series IDs,
55ac13d5f3SPatrick Williamsand timeboxes if specific patches are desired. For more information, see the
56ac13d5f3SPatrick Williamsgit-pw [documentation](https://patchwork.readthedocs.io/projects/git-pw/en/latest/).
57ac13d5f3SPatrick Williams
58ac13d5f3SPatrick WilliamsAlternatively, `scripts/patchtest-get-series` can be used to pull mbox files from
59ac13d5f3SPatrick Williamsthe Patchwork instance configured previously in .gitconfig. It uses a log file
60ac13d5f3SPatrick Williamscalled ".series_test.log" to store and compare series IDs so that the same
61ac13d5f3SPatrick Williamsversions of a patch are not tested multiple times unintentionally. By default,
62ac13d5f3SPatrick Williamsit will pull up to five patch series from the last 30 minutes using oe-core as
63ac13d5f3SPatrick Williamsthe target project, but these parameters can be configured using the `--limit`,
64ac13d5f3SPatrick Williams`--interval`, and `--project` arguments respectively. For more information, run
65ac13d5f3SPatrick Williams`patchtest-get-series -h`.
66ac13d5f3SPatrick Williams
67ac13d5f3SPatrick Williams### Host Mode
68ac13d5f3SPatrick Williams
69ac13d5f3SPatrick WilliamsTo run patchtest on the host, do the following:
70ac13d5f3SPatrick Williams
71ac13d5f3SPatrick Williams1. In openembedded-core/poky, do `source oe-init-build-env`
72ac13d5f3SPatrick Williams2. Generate patch files from the target repository by doing `git-format patch -N`,
73ac13d5f3SPatrick Williams   where N is the number of patches starting at HEAD, or by using git-pw
74ac13d5f3SPatrick Williams   or patchtest-get-series
75ac13d5f3SPatrick Williams3. Run patchtest on a patch file by doing the following:
76ac13d5f3SPatrick Williams
77ac13d5f3SPatrick Williams        patchtest --patch /path/to/patch/file
78ac13d5f3SPatrick Williams
79ac13d5f3SPatrick Williams    or, if you have stored the patch files in a directory, do:
80ac13d5f3SPatrick Williams
81ac13d5f3SPatrick Williams        patchtest --directory /path/to/patch/directory
82ac13d5f3SPatrick Williams
83ac13d5f3SPatrick Williams    For example, to test `master-gcc-Fix--fstack-protector-issue-on-aarch64.patch` against the oe-core test suite:
84ac13d5f3SPatrick Williams
85ac13d5f3SPatrick Williams        patchtest --patch master-gcc-Fix--fstack-protector-issue-on-aarch64.patch
86ac13d5f3SPatrick Williams
87ac13d5f3SPatrick Williams    If you want to use a different test suite or target repository, you can use the --testdir and --repodir flags:
88ac13d5f3SPatrick Williams
89ac13d5f3SPatrick Williams        patchtest --patch /path/to/patch/file --repodir /path/to/repo --testdir /path/to/test/dir
90ac13d5f3SPatrick Williams
91ac13d5f3SPatrick Williams### Guest Mode
92ac13d5f3SPatrick Williams
93ac13d5f3SPatrick WilliamsPatchtest's guest mode has been refactored to more closely mirror the
94ac13d5f3SPatrick Williamstypical Yocto Project image build workflow, but there are still some key
95ac13d5f3SPatrick Williamsdifferences to keep in mind. The primary objective is to provide a level
96ac13d5f3SPatrick Williamsof isolation from the host when testing patches pulled automatically
97ac13d5f3SPatrick Williamsfrom the mailing lists. When executed this way, the test process is
98ac13d5f3SPatrick Williamsessentially running random code from the internet and could be
99ac13d5f3SPatrick Williamscatastrophic if malicious bits or even poorly-handled edge cases aren't
100ac13d5f3SPatrick Williamsprotected against. In order to use this mode, the
101ac13d5f3SPatrick Williamshttps://git.yoctoproject.org/patchtest/ repository must be cloned and
102ac13d5f3SPatrick Williamsthe meta-patchtest layer added to bblayers.conf.
103ac13d5f3SPatrick Williams
104ac13d5f3SPatrick WilliamsThe general flow of guest mode is:
105ac13d5f3SPatrick Williams
106ac13d5f3SPatrick Williams1. Run patchtest-setup-sharedir --directory <dirname> to create a
107ac13d5f3SPatrick Williams   directory for mounting
108ac13d5f3SPatrick Williams2. Collect patches via patchtest-get-series (or other manual step) into the
109ac13d5f3SPatrick Williams   <dirname>/mboxes path
110ac13d5f3SPatrick Williams3. Ensure that a user with ID 1200 has appropriate read/write
111ac13d5f3SPatrick Williams   permissions to <dirname> and <dirname>/mboxes, so that the
112ac13d5f3SPatrick Williams   "patchtest" user in the core-image-patchtest image can function
113ac13d5f3SPatrick Williams4. Build the core-image-patchtest image
114ac13d5f3SPatrick Williams5. Run the core-image-patchtest image with the mounted sharedir, like
115ac13d5f3SPatrick Williams   so:
116ac13d5f3SPatrick Williams   `runqemu kvm nographic qemuparams="-snapshot -fsdev
117ac13d5f3SPatrick Williams   local,id=test_mount,path=/workspace/yocto/poky/build/patchtestdir,security_model=mapped
118ac13d5f3SPatrick Williams   -device virtio-9p-pci,fsdev=test_mount,mount_tag=test_mount -smp 4 -m
119ac13d5f3SPatrick Williams   2048"`
120ac13d5f3SPatrick Williams
121*8460358cSPatrick WilliamsPatchtest is run by an initscript for the core-image-patchtest image and
122ac13d5f3SPatrick Williamsshuts down after completion, so there is no input required from a user
123ac13d5f3SPatrick Williamsduring operation. Unlike in host mode, the guest is designed to
124ac13d5f3SPatrick Williamsautomatically generate test result files, in the same directory as the
125ac13d5f3SPatrick Williamstargeted patch files but with .testresult as an extension. These contain
126ac13d5f3SPatrick Williamsthe entire output of the patchtest run for each respective pass,
127ac13d5f3SPatrick Williamsincluding the PASS, FAIL, and SKIP indicators for each test run.
128ac13d5f3SPatrick Williams
129*8460358cSPatrick Williams### Running Patchtest Selftests
130*8460358cSPatrick Williams
131*8460358cSPatrick WilliamsPatchtest also includes selftests, which are currently in the form of
132*8460358cSPatrick Williamsseveral contrived patch files and a runner script found in
133*8460358cSPatrick Williams`meta/lib/patchtest/selftest/`. In order to run these, the
134*8460358cSPatrick Williams`meta-selftest` layer must be added to bblayers.conf. It is also
135*8460358cSPatrick Williamsrecommended to set BB_SERVER_TIMEOUT (and thus enable memory-resident
136*8460358cSPatrick Williamsbitbake) in local.conf to reduce runtime, as the bitbake startup process
137*8460358cSPatrick Williamswill otherwise add to it significantly when restarted for each test
138*8460358cSPatrick Williamspatch.
139*8460358cSPatrick Williams
140ac13d5f3SPatrick Williams## Contributing
141ac13d5f3SPatrick Williams
14273bd93f1SPatrick WilliamsThe yocto mailing list (openembedded-core@lists.openembedded.org) is used for questions,
143ac13d5f3SPatrick Williamscomments and patch review.  It is subscriber only, so please register before
144ac13d5f3SPatrick Williamsposting.
145ac13d5f3SPatrick Williams
146ac13d5f3SPatrick WilliamsWhen sending single patches, please use something like:
147ac13d5f3SPatrick Williams
14873bd93f1SPatrick Williams    git send-email -M -1 --to=openembedded-core@lists.openembedded.org --subject-prefix=OE-core][PATCH
149ac13d5f3SPatrick Williams
150ac13d5f3SPatrick Williams## Maintenance
151ac13d5f3SPatrick Williams-----------
152ac13d5f3SPatrick Williams
153ac13d5f3SPatrick WilliamsMaintainers:
154ac13d5f3SPatrick Williams    Trevor Gamblin <tgamblin@baylibre.com>
155ac13d5f3SPatrick Williams
156ac13d5f3SPatrick Williams## Links
157ac13d5f3SPatrick Williams-----
158ac13d5f3SPatrick Williams[1] https://git.openembedded.org/openembedded-core/
159ac13d5f3SPatrick Williams[2] https://www.yoctoproject.org/community/mailing-lists/
160