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_ebpf_testcase_config.py --subsystem-name common \ 19 --subsystem-testcase-config-file xx/xxx.json \ 20 --subsystem-testcase-list [xx/xx.py yy/yy.py ... ] \ 21 ----subsystem-testcase-collect-path [xxx] 22 23Generate the ebpf testcase config files. 24 25""" 26import argparse 27import os 28import os.path 29import sys 30 31sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 32from scripts.util.file_utils import write_json_file # noqa: E402, E501 33 34 35def get_testcase_dest_list(src_testcase_list: list, testcase_collect_path: str): 36 dest_list = [] 37 for testcase in src_testcase_list: 38 file_name = os.path.basename(testcase) 39 dest_list.append(os.path.join(testcase_collect_path, file_name)) 40 return dest_list 41 42 43def write_testcase_config_file(subsystem_name: str, 44 config_file: str, 45 testcase_list: list, 46 testcase_collect_path: str): 47 dest_list = get_testcase_dest_list(testcase_list, testcase_collect_path) 48 49 data = { 50 'subsystem_name': subsystem_name, 51 'testcase_src_list': testcase_list, 52 'testcase_dest_list': dest_list 53 } 54 55 # write the subsystem ebpf testcase config file. 56 write_json_file(config_file, data) 57 58 59def main(argv): 60 parser = argparse.ArgumentParser() 61 parser.add_argument('--subsystem-name', help='', required=True) 62 parser.add_argument('--subsystem-ebpf-testcase-config-file', 63 help='', 64 required=True) 65 parser.add_argument('--subsystem-testcase-list', nargs='+', 66 help='', 67 required=True) 68 parser.add_argument('--subsystem-testcase-collect-path', 69 help='', 70 required=True) 71 args = parser.parse_args() 72 73 subsystem_name = args.subsystem_name 74 subsystem_testcase_config_file = args.subsystem_ebpf_testcase_config_file 75 subsystem_testcase_list = args.subsystem_testcase_list 76 subsystem_testcase_collect_path = args.subsystem_testcase_collect_path 77 78 write_testcase_config_file(subsystem_name, 79 subsystem_testcase_config_file, 80 subsystem_testcase_list, 81 subsystem_testcase_collect_path) 82 83 84if __name__ == "__main__": 85 main(sys.argv) 86