1page.title=Kernel Networking Unit Tests 2@jd:body 3 4<!-- 5 Copyright 2015 The Android Open Source Project 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18--> 19<div id="qv-wrapper"> 20 <div id="qv"> 21 <h2>In this document</h2> 22 <ol id="auto-toc"> 23 </ol> 24 </div> 25</div> 26<p>Since Android 5.0, proper operation of the Android networking stack on Linux 27kernels requires a number of commits that were upstreamed relatively recently 28or have not yet made it upstream. It is not easy to manually verify the 29required kernel functionality or track the missing commits, so the Android team 30is sharing the tests it uses to ensure the kernel behaves as expected.</p> 31 32<h2 id=purpose>Why run the tests?</h2> <p>These tests exist for three main 33reasons:</p> <ol> <li>The exact version of the Linux kernel used on a device is 34typically device-specific, and it is difficult to know whether any kernel will 35work properly without running the tests.</li> <li>Forward-porting and 36back-porting the kernel patches to different kernel versions or different 37device trees may introduce subtle issues that can be impossible to spot without 38running the tests. For example, during development the initial versions of 39certain devices had UID routing patches forward-ported from android-3.4 instead 40of cherry-picked from android-3.10, and did not behave correctly.</li> <li>New 41networking features may require new kernel functionality or kernel bug 42fixes.</li> </ol> <p>If the tests do not pass, the device's network stack will 43behave incorrectly, causing user-visible connectivity bugs such as falling off 44Wi-Fi networks. The device will likely also fail Android Compatibility Test 45Suite (CTS) tests.</p> 46 47<h2 id=using>Using the tests</h2> <p>The tests use <a 48href="http://user-mode-linux.sourceforge.net/">User-Mode Linux</a> to boot the 49kernel as a process on a Linux host machine. See <a 50href="https://source.android.com/source/initializing.html">Establishing a Build 51Environment</a> for suitable operating system versions. The unit test framework 52boots the kernel with an appropriate disk image and runs the tests from the 53host file system. The tests are written in Python 2.x and use TAP interfaces to 54exercise kernel behaviour and the socket API.</p> 55 56<h3 id=compiling>Compiling the kernel for ARCH=um</h3> <p>For the tests to run, 57the kernel must compile for <code>ARCH=um SUBARCH=x86_64</code>. This is a 58supported architecture upstream and in the common Android kernel trees (e.g., 59<code>android-3.10</code>, <code>android-3.18</code>). But sometimes device 60kernels do not compile in this mode because device trees contain 61device-specific or hardware-specific code in common files (e.g., 62<code>sys/exit.c</code>).</p> <p>In many cases, it's sufficient to ensure that 63hardware-specific code is behind an <code>#ifdef</code>. Typically this should 64be an <code>#ifdef</code> on a configuration option that controls the specific 65feature relevant to the code. If there is no such configuration option, put 66hardware-specific code inside <code>#ifndef CONFIG_UML</code> blocks.</p> <p>In 67general, fixing this should be the responsibility of the kernel tree provider 68(e.g., chipset or SoC vendor). We're working with OEMs and vendors to ensure 69that current and future kernels will compile for <code>ARCH=um 70SUBARCH=x86_64</code> without requiring any changes.</p> 71 72<h3 id=running>Running the tests</h3> <p>The tests are at <a 73href="https://android.googlesource.com/kernel/tests/+/master/net/test"><code>kernel/tests/net/test</code></a>. 74It is recommended that the tests <b>be run from AOSP master</b> because they 75are the most up-to-date; in some cases, kernel features that are necessary for 76proper operation in a given Android release do not yet have full test coverage 77in the given release. For information on how to run the tests, see the <a 78href="https://android.googlesource.com/kernel/tests/+/master/net/test/README">kernel 79network test README file</a>. Basically, from the top of your kernel tree, run:</p> 80 81<pre> <android tree>/kernel/tests/net/test/run_net_test.sh all_tests.sh</pre> 82 83<h3 id=passing>Passing the tests</h3> <p>The kernel network test Python 84source files contain comments that specify kernel commits that are known to be 85required to pass the tests. The tests should pass in the common kernel trees - 86at least the <code>android-3.10</code> and <code>android-3.18</code> branches 87in the <a 88href="https://android-review.googlesource.com/#/q/project:kernel/common"><code>kernel/common</code></a> 89project in AOSP. Therefore, passing the tests on a kernel tree that's derived 90from 3.10 or 3.18 should mostly be a matter of cherry-picking the patches from 91these trees.</p> 92 93<h2 id=contributing>Contributing</h2> 94 95<h3 id=reporting>Reporting issues</h3> <p>Please report any issues with 96the kernel network tests in the <a 97href="https://code.google.com/p/android/issues/entry?template=Developer%20bug%20report">Android 98issue tracker</a> with the <a 99href="https://code.google.com/p/android/issues/list?q=label%3AComponent-Networking">Component-Networking</a> 100label.</p> 101 102<h3 id=documenting>Documenting commits and adding tests</h3> <p>Please report 103issues as described above, and if possible upload a change to fix the issue, 104if:</p> <ul> <li>The tests do not pass on the common kernel trees</li> <li>You 105find a necessary commit that is not mentioned in the source comments,</li> 106<li>Getting the tests to pass on upstream kernels requires major changes</li> 107<li>You believe that the tests are overspecified, or the test fail on future 108kernels</li> <li>You'd like to add more tests or more coverage to existing 109tests.</li> 110</ul> 111