blob: 9901573af9126c3dba80224f44333908799ef5f4 [file] [log] [blame]
Tri Vo568c7442018-01-29 11:21:29 -08001#!/usr/bin/env python
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import logging
19import os
20
21from vts.runners.host import asserts
22from vts.runners.host import base_test
23from vts.runners.host import const
24from vts.runners.host import keys
25from vts.runners.host import test_runner
26from vts.utils.python.os import path_utils
27
28
29class VtsKernelNetTest(base_test.BaseTestClass):
30 """Host test class to run android kernel unit test.
31
32 Attributes:
33 dut: AndroidDevice, the device under test.
34 shell: AdbProxy, instance of adb shell.
35 host_bin_path: string, path to test binary on the host.
36 target_bin_path: string, path to test binary on the target.
37 """
38
39 def setUpClass(self):
40 required_params = [
41 keys.ConfigKeys.IKEY_DATA_FILE_PATH,
42 ]
43 self.getUserParams(required_params)
44 logging.info('%s: %s', keys.ConfigKeys.IKEY_DATA_FILE_PATH,
45 self.data_file_path)
46
47 self.dut = self.android_devices[0]
48 self.shell = self.dut.adb.shell
49
50 # 32-bit version of the test should only run against 32-bit kernel;
51 # same for 64 bit.
52 bin_path = os.path.join(
53 'nativetest64' if self.dut.is64Bit else 'nativetest',
54 'kernel_net_tests',
55 'kernel_net_tests')
56
57 self.host_bin_path = os.path.join(self.data_file_path, 'DATA', bin_path)
58 self.target_bin_path = path_utils.JoinTargetPath('data', bin_path)
59
60 def tearDownClass(self):
61 self.shell('rm -rf %s' % path_utils.TargetDirName(self.target_bin_path))
62
63 def testKernelNetworking(self):
64 """Android kernel unit test."""
65 # Push the test binary to target device.
66 self.shell('mkdir -p %s' % path_utils.TargetDirName(self.target_bin_path))
67 self.dut.adb.push('%s %s' % (self.host_bin_path, self.target_bin_path))
68 self.shell('chmod 777 %s' % self.target_bin_path)
69
70 # Execute the test binary.
71 result = self.shell(self.target_bin_path, no_except=True)
72
73 logging.info('stdout: %s', result[const.STDOUT])
74 logging.error('stderr: %s', result[const.STDERR])
75 logging.info('exit code: %s', result[const.EXIT_CODE])
76 asserts.assertFalse(
77 result[const.EXIT_CODE],
78 'kernel_net_tests binary returned non-zero exit code.')
79
80if __name__ == '__main__':
81 test_runner.main()