Steven Moreland | e58566b | 2020-05-16 02:08:05 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2020 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 | |
| 18 | import subprocess |
| 19 | import unittest |
| 20 | |
| 21 | def run_cmd(cmd, ignore_error=False): |
| 22 | print("Running command:", cmd) |
| 23 | p = subprocess.Popen(cmd, shell=True) |
| 24 | p.communicate() |
| 25 | if not ignore_error and p.returncode: |
| 26 | raise subprocess.CalledProcessError(p.returncode, cmd) |
| 27 | return p.returncode |
| 28 | |
| 29 | class TestFmq(unittest.TestCase): |
| 30 | pass |
| 31 | |
| 32 | def make_test(client, server): |
| 33 | def test(self): |
| 34 | try: |
| 35 | run_cmd("adb shell killall %s >/dev/null 2>&1" % client, ignore_error=True) |
| 36 | run_cmd("adb shell killall %s >/dev/null 2>&1" % server, ignore_error=True) |
| 37 | run_cmd("adb shell \"( %s ) </dev/null >/dev/null 2>&1 &\"" % server) |
| 38 | run_cmd("adb shell %s" % client) |
| 39 | finally: |
| 40 | run_cmd("adb shell killall %s >/dev/null 2>&1" % client, ignore_error=True) |
| 41 | run_cmd("adb shell killall %s >/dev/null 2>&1" % server, ignore_error=True) |
| 42 | return test |
| 43 | |
Steven Moreland | d498c04 | 2020-09-10 22:16:56 +0000 | [diff] [blame^] | 44 | def has_bitness(bitness): |
| 45 | return 0 == run_cmd("echo '[[ \"$(getprop ro.product.cpu.abilist%s)\" != \"\" ]]' | adb shell sh" % bitness, ignore_error=True) |
Steven Moreland | e58566b | 2020-05-16 02:08:05 +0000 | [diff] [blame] | 46 | |
| 47 | if __name__ == '__main__': |
| 48 | clients = [] |
| 49 | servers = [] |
| 50 | |
Steven Moreland | d498c04 | 2020-09-10 22:16:56 +0000 | [diff] [blame^] | 51 | if has_bitness(32): |
Steven Moreland | e58566b | 2020-05-16 02:08:05 +0000 | [diff] [blame] | 52 | clients += ["/data/nativetest/fmq_test_client/fmq_test_client"] |
| 53 | servers += ["/data/nativetest/android.hardware.tests.msgq@1.0-service-test/android.hardware.tests.msgq@1.0-service-test"] |
| 54 | |
Steven Moreland | d498c04 | 2020-09-10 22:16:56 +0000 | [diff] [blame^] | 55 | if has_bitness(64): |
Steven Moreland | e58566b | 2020-05-16 02:08:05 +0000 | [diff] [blame] | 56 | clients += ["/data/nativetest64/fmq_test_client/fmq_test_client"] |
| 57 | servers += ["/data/nativetest64/android.hardware.tests.msgq@1.0-service-test/android.hardware.tests.msgq@1.0-service-test"] |
| 58 | |
| 59 | assert len(clients) > 0 |
| 60 | assert len(servers) > 0 |
| 61 | |
| 62 | def short_name(binary): |
| 63 | if "64" in binary: |
| 64 | return "64" |
| 65 | return "32" |
| 66 | |
| 67 | for client in clients: |
| 68 | for server in servers: |
| 69 | test_name = 'test_%s_to_%s' % (short_name(client), short_name(server)) |
| 70 | test = make_test(client, server) |
| 71 | setattr(TestFmq, test_name, test) |
| 72 | |
| 73 | suite = unittest.TestLoader().loadTestsFromTestCase(TestFmq) |
| 74 | unittest.TextTestRunner(verbosity=2).run(suite) |