ONE - On-device Neural Engine
Loading...
Searching...
No Matches
conftest Namespace Reference

Functions

 extract_test_args (s)
 
 pytest_addoption (parser)
 
 pytest_generate_tests (metafunc)
 
 copy_if_changed (src_filepath, dst_filepath)
 
 copy_ref_files (ref_file_src, ref_file_dst)
 
 copy_circle_model (model_src, model_dst)
 
 prepare_materials (test_name, tflrecipe_path, circlerecipe_path, binary_path, artifacts_path)
 

Function Documentation

◆ copy_circle_model()

conftest.copy_circle_model (   model_src,
  model_dst 
)

Definition at line 54 of file conftest.py.

54def copy_circle_model(model_src, model_dst):
55 copy_if_changed(model_src, model_dst)
56
57

References copy_if_changed().

Referenced by prepare_materials().

◆ copy_if_changed()

conftest.copy_if_changed (   src_filepath,
  dst_filepath 
)

Definition at line 23 of file conftest.py.

23def copy_if_changed(src_filepath, dst_filepath):
24 do_copy = False
25 if (os.path.isfile(dst_filepath)):
26 file_diff = os.stat(src_filepath).st_mtime - os.stat(dst_filepath).st_mtime
27 if file_diff > 1:
28 print("file:" + src_filepath + " changed, update")
29 do_copy = True
30 else:
31 do_copy = True
32
33 if do_copy:
34 print("file:" + src_filepath + " copy to: " + dst_filepath)
35 shutil.copyfile(src_filepath, dst_filepath)
36
37
38# prepare reference input/output files to build folder for luci-eval-driver
39# from ref data in res/TensorFlowLiteRecipes/*/ref.input* and ref.output*
40# as model_name.ref.input* and model_name.ref.output*

Referenced by copy_circle_model(), and copy_ref_files().

◆ copy_ref_files()

conftest.copy_ref_files (   ref_file_src,
  ref_file_dst 
)

Definition at line 41 of file conftest.py.

41def copy_ref_files(ref_file_src, ref_file_dst):
42 num_data = 0
43 while True:
44 input_file_src = ref_file_src + str(num_data)
45 if (not os.path.isfile(input_file_src)):
46 break
47 input_file_dst = ref_file_dst + str(num_data)
48 copy_if_changed(input_file_src, input_file_dst)
49 # try next file
50 num_data = num_data + 1
51
52
53# copy circle mode from common-artifacts to build binary

References copy_if_changed().

Referenced by prepare_materials().

◆ extract_test_args()

conftest.extract_test_args (   s)

Definition at line 4 of file conftest.py.

4def extract_test_args(s):
5 p = re.compile('add\\((.*)\\)')
6 result = p.search(s)
7 return result.group(1)
8
9

Referenced by prepare_materials(), and pytest_generate_tests().

◆ prepare_materials()

conftest.prepare_materials (   test_name,
  tflrecipe_path,
  circlerecipe_path,
  binary_path,
  artifacts_path 
)

Definition at line 58 of file conftest.py.

59 artifacts_path):
60 # tfl? or circle?
61 recipe_path = tflrecipe_path
62 # check with 'test.recipe' file as 'ref.input?' can be absent for no input model
63 test_recipe = os.path.join(recipe_path, test_name, 'test.recipe')
64 if (not os.path.isfile(test_recipe)):
65 recipe_path = circlerecipe_path
66
67 ref_input_src = os.path.join(recipe_path, test_name, 'ref.input')
68 ref_input_dst = os.path.join(binary_path, test_name + '.ref.input')
69 copy_ref_files(ref_input_src, ref_input_dst)
70
71 ref_input_src = os.path.join(recipe_path, test_name, 'ref.output')
72 ref_input_dst = os.path.join(binary_path, test_name + '.ref.output')
73 copy_ref_files(ref_input_src, ref_input_dst)
74
75 cirle_model_src = os.path.join(artifacts_path, test_name + '.circle')
76 cicle_model_dst = os.path.join(binary_path, test_name + '.circle')
77 copy_circle_model(cirle_model_src, cicle_model_dst)
78
79

References copy_circle_model(), copy_ref_files(), extract_test_args(), and prepare_materials().

Referenced by prepare_materials().

◆ pytest_addoption()

conftest.pytest_addoption (   parser)

Definition at line 10 of file conftest.py.

10def pytest_addoption(parser):
11 parser.addoption("--test_list", action="store", help="Path to test list")
12 parser.addoption("--bin_dir", action="store", help="Directory including artifacts")
13 parser.addoption("--circle_part_driver",
14 action="store",
15 help="Path to circle part driver")
16
17

◆ pytest_generate_tests()

conftest.pytest_generate_tests (   metafunc)

Definition at line 18 of file conftest.py.

18def pytest_generate_tests(metafunc):
19 list_path = metafunc.config.getoption('test_list')
20 bin_dir = metafunc.config.getoption('bin_dir')
21 circle_part_driver = metafunc.config.getoption('circle_part_driver')
22
23 with open(list_path) as f:
24 contents = [line.rstrip() for line in f]
25
26 comment_removed = [line for line in contents if not line.startswith('#')]
27 newline_removed = [line for line in comment_removed if line.startswith('add(')]
28 test_args = [extract_test_args(line) for line in newline_removed]
29 # add(RECIPE_NAME PARTITION_NAME EXPECTED_OUTPUT_COUNT)
30 partition_list = [(arg.split()[1], bin_dir, circle_part_driver) for arg in test_args]
31
32 if 'test_name' in metafunc.fixturenames:
33 metafunc.parametrize('test_name,bin_dir,part_driver_path', partition_list)

References extract_test_args().