1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16""" 17 18Usage: gen_summary_ebpf_testcase_config.py \ 19 --ebpf-testcase-path out/xxx/ebpf_testcase \ 20 --ebpf-summary-config-file xx/xxx.json \ 21 22Generate the summary ebpf testcase config files. 23 24""" 25import argparse 26import os 27import os.path 28import sys 29import json 30 31 32def summary_subsystem_config_file(testcase_dir: str, summary_file: str): 33 if testcase_dir == ' ': 34 return 35 36 subsystem_list = [] 37 for root, dirs, files in os.walk(testcase_dir): 38 for name in files: 39 if name.endswith('.json'): 40 subsystem_list.append(os.path.join(root, name)) 41 42 # load the subsystem testcase info 43 context = [] 44 for file_path in subsystem_list: 45 try: 46 with open(file_path, 'r') as infile: 47 file_data = json.load(infile) 48 context.append(file_data) 49 except OSError as err: 50 raise err 51 52 # write the summary file.json 53 try: 54 with open(summary_file, 'w') as out_file: 55 json.dump(context, out_file, sort_keys=True, indent=2) 56 except OSError as err: 57 raise err 58 59 60def main(argv): 61 parser = argparse.ArgumentParser() 62 parser.add_argument('--ebpf-testcase-path', help='', required=True) 63 parser.add_argument('--ebpf-summary-config-file', help='', required=True) 64 args = parser.parse_args() 65 66 testcase_dir = args.ebpf_testcase_path 67 summary_file = args.ebpf_summary_config_file 68 69 if os.path.exists(summary_file): 70 os.remove(summary_file) 71 72 summary_subsystem_config_file(testcase_dir, summary_file) 73 74 75if __name__ == "__main__": 76 main(sys.argv) 77