()
| 158 | # ------------------------------------------------------------------------------ |
| 159 | |
| 160 | def main(): |
| 161 | parser = argparse.ArgumentParser() |
| 162 | parser.add_argument("-o", type=str, dest="out_file", help="output file name, e.g. foo.cpp.") |
| 163 | parser.add_argument("--name", type=str, default="", help="name of the generated instance. This is optional.") |
| 164 | parser.add_argument("--param-set", type=str, help="param set name,e.g. foo_1") |
| 165 | parser.add_argument("--param-file", type=str, help="param file, e.g. config_params.json") |
| 166 | parser.add_argument("--spec", type=str, default="", help="file which defines the API metadata, e.g. L2/meta/api.json") |
| 167 | parser.add_argument("--api", type=str, default="", help="quanlified name of the API, e.g. xf::data_mover::mm2s") |
| 168 | parser.add_argument("--file", type=str, default="", help="customzied generator python file name, e.g. my_test.py") |
| 169 | parser.add_argument("--func", type=str, default="", help="python function name in file, e.g. gen_my_test_config") |
| 170 | parser.add_argument("--valid-params", action='store_true', help="param validation, true for validation") |
| 171 | |
| 172 | args = parser.parse_args() |
| 173 | #print("DEBUG: out_file:", args.out_file) |
| 174 | #print("DEBUG: spec:", args.spec) |
| 175 | #print("DEBUG: api:", args.param_file) |
| 176 | #print("DEBUG: param_set:", args.param_set) |
| 177 | #print("DEBUG: param_file:", args.param_file) |
| 178 | #print("DEBUG: valid_params:", args.valid_params) |
| 179 | res = True |
| 180 | if args.valid_params: |
| 181 | if args.api and args.param_file and args.param_set: |
| 182 | gen = inst_generator(args.spec, args.api, args.param_file, args.param_set) |
| 183 | res = gen.valid_all_params() |
| 184 | else: |
| 185 | print("ERROR: cannot validate without an API name and spec file/param set.") |
| 186 | res = False |
| 187 | elif args.out_file: |
| 188 | if args.api: |
| 189 | if args.param_file and args.param_set: |
| 190 | gen = inst_generator(args.spec, args.api, args.param_file, args.param_set) |
| 191 | res = gen.gen_api_instance(args.out_file, args.name) |
| 192 | else: |
| 193 | print("ERROR: cannot generate API without param file/param set.") |
| 194 | res = False |
| 195 | elif args.file and args.func: |
| 196 | if args.param_file and args.param_set: |
| 197 | res = gen_tb_instance(args.out_file, args.file, args.func, args.param_file, args.param_set) |
| 198 | else: |
| 199 | print("ERROR: cannot generate TB without param file/param set.") |
| 200 | res = False |
| 201 | else: |
| 202 | print("ERROR: cannot generate API without api_name or TB generation file/func") |
| 203 | res = False |
| 204 | return res |
| 205 | |
| 206 | if __name__ == '__main__': |
| 207 | sys.exit(0 if main() else 1) |
no test coverage detected