"""
Usage: gen_summary_ebpf_testcase_config.py \
--ebpf-testcase-path out/xxx/ebpf_testcase \
--ebpf-summary-config-file xx/xxx.json \
Generate the summary ebpf testcase config files.
"""
import argparse
import os
import os.path
import sys
import json
def summary_subsystem_config_file(testcase_dir: str, summary_file: str):
if testcase_dir == ' ':
return
subsystem_list = []
for root, dirs, files in os.walk(testcase_dir):
for name in files:
if name.endswith('.json'):
subsystem_list.append(os.path.join(root, name))
context = []
for file_path in subsystem_list:
try:
with open(file_path, 'r') as infile:
file_data = json.load(infile)
context.append(file_data)
except OSError as err:
raise err
try:
with open(summary_file, 'w') as out_file:
json.dump(context, out_file, sort_keys=True, indent=2)
except OSError as err:
raise err
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--ebpf-testcase-path', help='', required=True)
parser.add_argument('--ebpf-summary-config-file', help='', required=True)
args = parser.parse_args()
testcase_dir = args.ebpf_testcase_path
summary_file = args.ebpf_summary_config_file
if os.path.exists(summary_file):
os.remove(summary_file)
summary_subsystem_config_file(testcase_dir, summary_file)
if __name__ == "__main__":
main(sys.argv)