1 # Copyright 2010 Google Inc. Released under the GPL v2
3 # Eric Li <ericli@google.com>
5 import logging
, os
, pickle
, re
, sys
7 from autotest_lib
.client
.bin
import setup_job
as client_setup_job
10 def touch_init(parent_dir
, child_dir
):
12 Touch __init__.py file all alone through from dir_patent to child_dir.
14 So client tests could be loaded as Python modules. Assume child_dir is a
15 subdirectory of parent_dir.
18 if not child_dir
.startswith(parent_dir
):
19 logging
.error('%s is not a subdirectory of %s' % (child_dir
,
22 sub_parent_dirs
= parent_dir
.split(os
.path
.sep
)
23 sub_child_dirs
= child_dir
.split(os
.path
.sep
)
24 for sub_dir
in sub_child_dirs
[len(sub_parent_dirs
):]:
25 sub_parent_dirs
.append(sub_dir
)
26 path
= os
.path
.sep
.join(sub_parent_dirs
)
27 init_py
= os
.path
.join(path
, '__init__.py')
28 open(init_py
, 'a').close()
31 def init_test(testdir
):
33 Instantiate a client test object from a given test directory.
35 @param testdir The test directory.
36 @returns A test object or None if failed to instantiate.
47 return client_setup_job
.init_test(options
, testdir
)
50 def setup(autotest_client_dir
, client_test_dir
):
52 Setup prebuild of a client test.
54 @param autotest_client_dir: The autotest/client base directory.
55 @param client_test_dir: The actual test directory under client.
58 os
.environ
['AUTODIR'] = autotest_client_dir
59 touch_init(autotest_client_dir
, client_test_dir
)
61 # instantiate a client_test instance.
62 client_test
= init_test(client_test_dir
)
63 client_setup_job
.setup_test(client_test
)