test-manual-understand-autobuilder.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <!--SPDX-License-Identifier: CC-BY-2.0-UK-->
  5. <chapter id='test-manual-understand-autobuilder'>
  6. <title>Understanding the Yocto Project Autobuilder</title>
  7. <section>
  8. <title>Execution Flow within the Autobuilder</title>
  9. <para>The "a-full" and "a-quick" targets are the usual entry points into the Autobuilder and
  10. it makes sense to follow the process through the system starting there. This is best
  11. visualised from the Autobuilder Console view (<link linkend=""
  12. >https://autobuilder.yoctoproject.org/typhoon/#/console</link>). </para>
  13. <para>Each item along the top of that view represents some "target build" and these targets
  14. are all run in parallel. The 'full' build will trigger the majority of them, the "quick"
  15. build will trigger some subset of them. The Autobuilder effectively runs whichever
  16. configuration is defined for each of those targets on a seperate buildbot worker. To
  17. understand the configuration, you need to look at the entry on
  18. <filename>config.json</filename> file within the
  19. <filename>yocto-autobuilder-helper</filename> repository. The targets are defined in
  20. the ‘overrides' section, a quick example could be qemux86-64 which looks
  21. like:<literallayout class="monospaced">
  22. "qemux86-64" : {
  23. "MACHINE" : "qemux86-64",
  24. "TEMPLATE" : "arch-qemu",
  25. "step1" : {
  26. "extravars" : [
  27. "IMAGE_FSTYPES_append = ' wic wic.bmap'"
  28. ]
  29. }
  30. },
  31. </literallayout>And
  32. to expand that, you need the "arch-qemu" entry from the "templates" section, which looks
  33. like:<literallayout class="monospaced">
  34. "arch-qemu" : {
  35. "BUILDINFO" : true,
  36. "BUILDHISTORY" : true,
  37. "step1" : {
  38. "BBTARGETS" : "core-image-sato core-image-sato-dev core-image-sato-sdk core-image-minimal core-image-minimal-dev core-image-sato:do_populate_sdk",
  39. "SANITYTARGETS" : "core-image-minimal:do_testimage core-image-sato:do_testimage core-image-sato-sdk:do_testimage core-image-sato:do_testsdk"
  40. },
  41. "step2" : {
  42. "SDKMACHINE" : "x86_64",
  43. "BBTARGETS" : "core-image-sato:do_populate_sdk core-image-minimal:do_populate_sdk_ext core-image-sato:do_populate_sdk_ext",
  44. "SANITYTARGETS" : "core-image-sato:do_testsdk core-image-minimal:do_testsdkext core-image-sato:do_testsdkext"
  45. },
  46. "step3" : {
  47. "BUILDHISTORY" : false,
  48. "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest ${HELPERSTMACHTARGS} -j 15"],
  49. "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"]
  50. }
  51. },
  52. </literallayout>Combining
  53. these two entries you can see that "qemux86-64" is a three step build where the
  54. <filename>bitbake BBTARGETS</filename> would be run, then <filename>bitbake
  55. SANITYTARGETS</filename> for each step; all for
  56. <filename>MACHINE="qemx86-64"</filename> but with differing SDKMACHINE settings. In
  57. step 1 an extra variable is added to the <filename>auto.conf</filename> file to enable
  58. wic image generation.</para>
  59. <para>While not every detail of this is covered here, you can see how the templating
  60. mechanism allows quite complex configurations to be built up yet allows duplication and
  61. repetition to be kept to a minimum.</para>
  62. <para>The different build targets are designed to allow for parallelisation, so different
  63. machines are usually built in parallel, operations using the same machine and metadata
  64. are built sequentially, with the aim of trying to optimise build efficiency as much as
  65. possible.</para>
  66. <para>The <filename>config.json</filename> file is processed by the scripts in the Helper
  67. repository in the <filename>scripts</filename> directory. The following section details
  68. how this works.</para>
  69. </section>
  70. <section id='test-autobuilder-target-exec-overview'>
  71. <title>Autobuilder Target Execution Overview</title>
  72. <para>For each given target in a build, the Autobuilder executes several steps. These are
  73. configured in <filename>yocto-autobuilder2/builders.py</filename> and roughly consist
  74. of: <orderedlist>
  75. <listitem id='test-list-tgt-exec-clobberdir'>
  76. <para><emphasis>Run <filename>clobberdir</filename></emphasis></para>
  77. <para>This cleans out any previous build. Old builds are left around to allow
  78. easier debugging of failed builds. For additional information, see <link
  79. linkend="test-clobberdir"><filename>clobberdir</filename></link>.</para>
  80. </listitem>
  81. <listitem>
  82. <para><emphasis>Obtain yocto-autobuilder-helper</emphasis></para>
  83. <para>This step clones the <filename>yocto-autobuilder-helper</filename> git
  84. repository. This is necessary to prevent the requirement to maintain all the
  85. release or project-specific code within Buildbot. The branch chosen matches
  86. the release being built so we can support older releases and still make
  87. changes in newer ones.</para>
  88. </listitem>
  89. <listitem>
  90. <para><emphasis>Write layerinfo.json</emphasis></para>
  91. <para>This transfers data in the Buildbot UI when the build was configured to
  92. the Helper.</para>
  93. </listitem>
  94. <listitem>
  95. <para><emphasis>Call scripts/shared-repo-unpack</emphasis></para>
  96. <para>This is a call into the Helper scripts to set up a checkout of all the
  97. pieces this build might need. It might clone the BitBake repository and the
  98. OpenEmbedded-Core repository. It may clone the Poky repository, as well as
  99. additional layers. It will use the data from the
  100. <filename>layerinfo.json</filename> file to help understand the
  101. configuration. It will also use a local cache of repositories to speed up
  102. the clone checkouts. For additional information, see <link
  103. linkend="test-autobuilder-clone-cache">Autobuilder Clone
  104. Cache</link>.</para>
  105. <para>This step has two possible modes of operation. If the build is part of a
  106. parent build, its possible that all the repositories needed may already be
  107. available, ready in a pre-prepared directory. An "a-quick" or "a-full" build
  108. would prepare this before starting the other sub-target builds. This is done
  109. for two reasons:<itemizedlist>
  110. <listitem>
  111. <para>the upstream may change during a build, for example, from a
  112. forced push and this ensures we have matching content for the
  113. whole build</para>
  114. </listitem>
  115. <listitem>
  116. <para>if 15 Workers all tried to pull the same data from the same
  117. repos, we can hit resource limits on upstream servers as they
  118. can think they are under some kind of network attack</para>
  119. </listitem>
  120. </itemizedlist>This pre-prepared directory is shared among the Workers over
  121. NFS. If the build is an individual build and there is no "shared" directory
  122. available, it would clone from the cache and the upstreams as necessary.
  123. This is considered the fallback mode.</para>
  124. </listitem>
  125. <listitem>
  126. <para><emphasis>Call scripts/run-config</emphasis></para>
  127. <para>This is another call into the Helper scripts where its expected that the
  128. main functionality of this target will be executed.</para>
  129. </listitem>
  130. </orderedlist></para>
  131. </section>
  132. <section id='test-autobuilder-tech'>
  133. <title>Autobuilder Technology</title>
  134. <para>The Autobuilder has Yocto Project-specific functionality to allow builds to operate
  135. with increased efficiency and speed.</para>
  136. <section id='test-clobberdir'>
  137. <title>clobberdir</title>
  138. <para>When deleting files, the Autobuilder uses <filename>clobberdir</filename>, which
  139. is a special script that moves files to a special location, rather than deleting
  140. them. Files in this location are deleted by an <filename>rm</filename> command,
  141. which is run under <filename>ionice -c 3</filename>. For example, the deletion only
  142. happens when there is idle IO capacity on the Worker. The Autobuilder Worker Janitor
  143. runs this deletion. See <link linkend="test-autobuilder-worker-janitor">Autobuilder
  144. Worker Janitor</link>.</para>
  145. </section>
  146. <section id='test-autobuilder-clone-cache'>
  147. <title>Autobuilder Clone Cache</title>
  148. <para>Cloning repositories from scratch each time they are required was slow on the
  149. Autobuilder. We therefore have a stash of commonly used repositories pre-cloned on
  150. the Workers. Data is fetched from these during clones first, then "topped up" with
  151. later revisions from any upstream when necesary. The cache is maintained by the
  152. Autobuilder Worker Janitor. See <link linkend="test-autobuilder-worker-janitor"
  153. >Autobuilder Worker Janitor</link>.</para>
  154. </section>
  155. <section id='test-autobuilder-worker-janitor'>
  156. <title>Autobuilder Worker Janitor</title>
  157. <para>This is a process running on each Worker that performs two basic operations,
  158. including background file deletion at IO idle (see <link
  159. linkend="test-list-tgt-exec-clobberdir">Target Execution: clobberdir</link>) and
  160. maintainenance of a cache of cloned repositories to improve the speed the system can
  161. checkout repositories.</para>
  162. </section>
  163. <section id='test-shared-dl-dir'>
  164. <title>Shared DL_DIR</title>
  165. <para>The Workers are all connected over NFS which allows DL_DIR to be shared between
  166. them. This reduces network accesses from the system and allows the build to be sped
  167. up. Usage of the directory within the build system is designed to be able to be
  168. shared over NFS.</para>
  169. </section>
  170. <section id='test-shared-sstate-cache'>
  171. <title>Shared SSTATE_DIR</title>
  172. <para>The Workers are all connected over NFS which allows the
  173. <filename>sstate</filename> directory to be shared between them. This means once
  174. a Worker has built an artefact, all the others can benefit from it. Usage of the
  175. directory within the directory is designed for sharing over NFS.</para>
  176. </section>
  177. <section id='test-resulttool'>
  178. <title>Resulttool</title>
  179. <para>All of the different tests run as part of the build generate output into
  180. <filename>testresults.json</filename> files. This allows us to determine which
  181. tests ran in a given build and their status. Additional information, such as failure
  182. logs or the time taken to run the tests, may also be included.</para>
  183. <para>Resulttool is part of OpenEmbedded-Core and is used to manipulate these json
  184. results files. It has the ability to merge files together, display reports of the
  185. test results and compare different result files.</para>
  186. <para>For details, see <link linkend=""
  187. >https://wiki.yoctoproject.org/wiki/Resulttool</link>.</para>
  188. </section>
  189. </section>
  190. <section id='test-run-config-tgt-execution'>
  191. <title>run-config Target Execution</title>
  192. <para>The <filename>scripts/run-config</filename> execution is where most of the work within
  193. the Autobuilder happens. It runs through a number of steps; the first are general setup
  194. steps that are run once and include:<orderedlist>
  195. <listitem>
  196. <para>Set up any <filename>buildtools-tarball</filename> if configured.</para>
  197. </listitem>
  198. <listitem>
  199. <para>Call "buildhistory-init" if buildhistory is configured.</para>
  200. </listitem>
  201. </orderedlist></para>
  202. <para>For each step that is configured in <filename>config.json</filename>, it will perform
  203. the following:</para>
  204. <para>
  205. <remark>## WRITER's question: What does "logging in as stepXa" and others refer to
  206. below? ##</remark>
  207. <orderedlist>
  208. <listitem id="test-run-config-add-layers-step">
  209. <para dir="ltr">Add any layers that are specified using the
  210. <filename>bitbake-layers add-layer</filename> command (logging as
  211. stepXa)</para>
  212. </listitem>
  213. <listitem>
  214. <para dir="ltr">Call the <filename>scripts/setup-config</filename> script to
  215. generate the necessary <filename>auto.conf</filename> configuration file for
  216. the build</para>
  217. </listitem>
  218. <listitem>
  219. <para dir="ltr">Run the <filename>bitbake BBTARGETS</filename> command (logging
  220. as stepXb)</para>
  221. </listitem>
  222. <listitem>
  223. <para dir="ltr">Run the <filename>bitbake SANITYTARGETS</filename> command
  224. (logging as stepXc)</para>
  225. </listitem>
  226. <listitem>
  227. <para dir="ltr">Run the <filename>EXTRACMDS</filename> command, which are run
  228. within the BitBake build environment (logging as stepXd)</para>
  229. </listitem>
  230. <listitem>
  231. <para dir="ltr">Run the <filename>EXTRAPLAINCMDS</filename> command(s), which
  232. are run outside the BitBake build environment (logging as stepXd)</para>
  233. </listitem>
  234. <listitem>
  235. <para dir="ltr">Remove any layers added in <link
  236. linkend="test-run-config-add-layers-step">step 1</link> using the
  237. <filename>bitbake-layers remove-layer</filename> command (logging as
  238. stepXa)</para>
  239. </listitem>
  240. </orderedlist>
  241. </para>
  242. <para>Once the execution steps above complete, <filename>run-config</filename> executes a
  243. set of post-build steps, including:<orderedlist>
  244. <listitem>
  245. <para dir="ltr">Call <filename>scripts/publish-artifacts</filename> to collect
  246. any output which is to be saved from the build.</para>
  247. </listitem>
  248. <listitem>
  249. <para dir="ltr">Call <filename>scripts/collect-results</filename> to collect any
  250. test results to be saved from the build.</para>
  251. </listitem>
  252. <listitem>
  253. <para dir="ltr">Call <filename>scripts/upload-error-reports</filename> to send
  254. any error reports generated to the remote server.</para>
  255. </listitem>
  256. <listitem>
  257. <para dir="ltr">Cleanup the build directory using <link
  258. linkend="test-clobberdir"><filename>clobberdir</filename></link> if the
  259. build was successful, else rename it to "build-renamed" for potential future
  260. debugging.</para>
  261. </listitem>
  262. </orderedlist></para>
  263. </section>
  264. <section id='test-deploying-yp-autobuilder'>
  265. <title>Deploying Yocto Autobuilder</title>
  266. <para>The most up to date information about how to setup and deploy your own Autbuilder can
  267. be found in README.md in the <filename>yocto-autobuilder2</filename> repository.</para>
  268. <para>We hope that people can use the <filename>yocto-autobuilder2</filename> code directly
  269. but it is inevitable that users will end up needing to heavily customise the
  270. <filename>yocto-autobuilder-helper</filename> repository, particularly the
  271. <filename>config.json</filename> file as they will want to define their own test
  272. matrix.</para>
  273. <para>The Autobuilder supports wo customization options: <itemizedlist>
  274. <listitem>
  275. <para>variable substitution</para>
  276. </listitem>
  277. <listitem>
  278. <para>overlaying configuration files</para>
  279. </listitem>
  280. </itemizedlist>The standard <filename>config.json</filename> minimally attempts to allow
  281. substitution of the paths. The Helper script repository includes a
  282. <filename>local-example.json</filename> file to show how you could override these
  283. from a separate configuration file. Pass the following into the environment of the
  284. Autobuilder:<literallayout class="monospaced">
  285. $ ABHELPER_JSON="config.json local-example.json"
  286. </literallayout>As
  287. another example, you could also pass the following into the
  288. environment:<literallayout class="monospaced">
  289. $ ABHELPER_JSON="config.json <replaceable>/some/location/</replaceable>local.json"
  290. </literallayout>One
  291. issue users often run into is validation of the <filename>config.json</filename> files.
  292. A tip for minimizing issues from invalid json files is to use a Git
  293. <filename>pre-commit-hook.sh</filename> script to verify the JSON file before
  294. committing it. Create a symbolic link as
  295. follows:<literallayout class="monospaced">
  296. $ ln -s ../../scripts/pre-commit-hook.sh .git/hooks/pre-commit
  297. </literallayout></para>
  298. </section>
  299. </chapter>
  300. <!--
  301. vim: expandtab tw=80 ts=4
  302. -->