blob: 4e3aa40ded647f0c7653dbac04612c1356cc67a3 [file] [log] [blame]
TatWai Chong6a46b252024-01-12 13:13:22 -08001# Copyright (c) 2020-2024, ARM Limited.
Jeremy Johnson015c3552022-02-23 12:15:03 +00002# SPDX-License-Identifier: Apache-2.0
3import json
4
5# Used by basic_test_generator to create test description
6
7
8def write_test_json(
9 filename,
10 tf_model_filename=None,
11 tf_result_npy_filename=None,
12 tf_result_name=None,
13 tflite_model_filename=None,
14 tflite_result_npy_filename=None,
15 tflite_result_name=None,
16 ifm_name=None,
17 ifm_file=None,
18 ifm_shape=None,
TatWai Chong6a46b252024-01-12 13:13:22 -080019 ifm_dynamic=False,
Jeremy Johnson015c3552022-02-23 12:15:03 +000020 framework_exclusions=None,
21 quantized=False,
Eric Kunze97b00272023-07-20 10:52:56 -070022 test_name=None,
Jeremy Johnson015c3552022-02-23 12:15:03 +000023):
24
25 test_desc = dict()
26
Eric Kunze97b00272023-07-20 10:52:56 -070027 if test_name:
28 test_desc["name"] = test_name
29
Jeremy Johnson015c3552022-02-23 12:15:03 +000030 if tf_model_filename:
31 test_desc["tf_model_filename"] = tf_model_filename
32
33 if tf_result_npy_filename:
34 test_desc["tf_result_npy_filename"] = tf_result_npy_filename
35
36 if tf_result_name:
37 test_desc["tf_result_name"] = tf_result_name
38
39 if tflite_model_filename:
40 test_desc["tflite_model_filename"] = tflite_model_filename
41
42 if tflite_result_npy_filename:
43 test_desc["tflite_result_npy_filename"] = tflite_result_npy_filename
44
45 if tflite_result_name:
46 test_desc["tflite_result_name"] = tflite_result_name
47
48 if ifm_file:
49 if not isinstance(ifm_file, list):
50 ifm_file = [ifm_file]
51 test_desc["ifm_file"] = ifm_file
52
53 # Make sure these arguments are wrapped as lists
54 if ifm_name:
55 if not isinstance(ifm_name, list):
56 ifm_name = [ifm_name]
57 test_desc["ifm_name"] = ifm_name
58
59 if ifm_shape:
60 if not isinstance(ifm_shape, list):
61 ifm_shape = [ifm_shape]
62 test_desc["ifm_shape"] = ifm_shape
63
TatWai Chong6a46b252024-01-12 13:13:22 -080064 if ifm_dynamic:
65 test_desc["ifm_dynamic"] = True
66
Jeremy Johnson015c3552022-02-23 12:15:03 +000067 # Some tests cannot be used with specific frameworks.
68 # This list indicates which tests should be excluded from a given framework.
69 if framework_exclusions:
70 if not isinstance(framework_exclusions, list):
71 framework_exclusions = [framework_exclusions]
72 test_desc["framework_exclusions"] = framework_exclusions
73
74 if quantized:
75 test_desc["quantized"] = 1
76
77 with open(filename, "w") as f:
78 json.dump(test_desc, f, indent=" ")