• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2021 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import sys
21import subprocess
22
23from xdevice import platform_logger
24
25LOG = platform_logger("Gen")
26
27class Gen(object):
28    def process_command_gen(self, options):
29        if (len(options.testtype) != 1) or (options.dirpath == "") or \
30                (options.fuzzername == ""):
31            LOG.error(
32                "GEN need para -t(testtype) -fz(fuzzername) -dp(dirpath)")
33            return
34        if "FUZZ" in options.testtype:
35            self.fuzz_dir_generation(options)
36        else:
37            LOG.error("GEN is not support %s." % options.testtype)
38
39    def gen_fuzzer_list_file(self, fuzzer_list):
40        filepath = os.path.join(sys.source_code_root_path, "test",
41            "developertest", "libs", "fuzzlib", "fuzzer_list.txt")
42        LOG.info("The fuzzer list file path: %s" % filepath)
43        with open(filepath, "w") as gn_file:
44            gn_file.truncate(0)
45            if fuzzer_list:
46                for target in fuzzer_list:
47                    if target:
48                        gn_file.write("\"%s\",\n" % target)
49
50    @classmethod
51    def fuzz_dir_generation(cls, options):
52        helper_path = os.path.join("..", "libs", "fuzzlib", "fuzzer_helper.py")
53        fuzz_path = os.path.join(sys.source_code_root_path, options.dirpath)
54        LOG.info("fuzz_path = %s" % fuzz_path)
55        if not os.path.exists(fuzz_path):
56            os.makedirs(fuzz_path)
57            LOG.info("make folder %s" % fuzz_path)
58
59        command = [sys.executable, helper_path, 'generate',
60                   options.fuzzername, fuzz_path]
61        LOG.info("command %s" % command)
62        subprocess.call(command, shell=False)