• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os
2
3import lit.util  # pylint: disable=import-error
4
5from libcxx.android.executors import AdbExecutor
6from libcxx.test.executor import LocalExecutor, TimeoutExecutor
7import libcxx.test.format
8import libcxx.android.adb as adb
9
10
11class HostTestFormat(libcxx.test.format.LibcxxTestFormat):
12    # pylint: disable=super-init-not-called
13    def __init__(self, cxx, libcxx_src_root, libcxx_obj_root, timeout,
14                 exec_env=None):
15        self.cxx = cxx
16        self.libcxx_src_root = libcxx_src_root
17        self.libcxx_obj_root = libcxx_obj_root
18        self.use_verify_for_fail = False
19        self.executor = TimeoutExecutor(timeout, LocalExecutor())
20
21        # We need to use LD_LIBRARY_PATH because the build system's rpath is
22        # relative, which won't work since we're running from /tmp. We can
23        # either scan `cxx_under_test`/`link_template` to determine whether
24        # we're 32-bit or 64-bit, scan testconfig.mk, or just add both
25        # directories and let the linker sort it out. I'm choosing the lazy
26        # option.
27        outdir = os.getenv('ANDROID_HOST_OUT')
28        libpath = os.pathsep.join([
29            os.path.join(outdir, 'lib'),
30            os.path.join(outdir, 'lib64'),
31        ])
32        env = {'LD_LIBRARY_PATH': libpath}
33        if exec_env is not None:
34            env.update(exec_env)
35        self.exec_env = env
36
37
38class TestFormat(HostTestFormat):
39    def __init__(self, cxx, libcxx_src_root, libcxx_obj_root, device_dir,
40                 timeout, exec_env=None):
41        HostTestFormat.__init__(
42            self,
43            cxx,
44            libcxx_src_root,
45            libcxx_obj_root,
46            timeout,
47            exec_env)
48        self.device_dir = device_dir
49        self.executor = TimeoutExecutor(timeout, AdbExecutor())
50
51    def _working_directory(self, file_name):
52        return os.path.join(self.device_dir, file_name)
53
54    def _wd_path(self, test_name, file_name):
55        return os.path.join(self._working_directory(test_name), file_name)
56
57    def _clean(self, exec_path):
58        exec_file = os.path.basename(exec_path)
59        cmd = ['adb', 'shell', 'rm', '-rf', self._working_directory(exec_file)]
60        lit.util.executeCommand(cmd)
61        try:
62            os.remove(exec_path)
63        except OSError:
64            pass
65
66    def _run(self, exec_path, _, in_dir=None):
67        raise NotImplementedError()
68