From 90d4441e0f8bdba6d08a97d8d53f7e9be71fe214 Mon Sep 17 00:00:00 2001 From: caojiale1 Date: Thu, 7 Sep 2023 20:25:11 +0800 Subject: [PATCH] Signed-off-by caojiale1 caojiale1@huawei.com Signed-off-by: caojiale1 --- src/core/driver/drivers.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index b748bc3..f0c7f40 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -686,16 +686,26 @@ class CppTestDriver(IDriver): @staticmethod def _alter_init(name): - lines = list() - with open(name, "r") as f: - for line in f: - line_strip = line.strip() - if not line_strip: - continue - if line_strip[0] != "#" and line_strip[0] != "/" and line_strip[0] != "*": - lines.append(line_strip) - with open(name, "w") as f: - f.writelines(lines) + with open(name, "rb") as f: + lines = f.read() + str_content = lines.decode("utf-8") + + pattern_sharp = '^\s*#.*$(\n|\r\n)' + pattern_star = '/\*.*?\*/(\n|\r\n)+' + pattern_xml = '(\n|\r\n)+' + + if re.match(pattern_sharp, str_content, flags=re.M): + striped_content = re.sub(pattern_sharp, '', str_content, flags=re.M) + elif re.findall(pattern_star, str_content, flags=re.S): + striped_content = re.sub(pattern_star, '', str_content, flags=re.S) + elif re.findall(pattern_xml, str_content, flags=re.S): + striped_content = re.sub(pattern_xml, '', str_content, flags=re.S) + else: + striped_content = str_content + + striped_bt = striped_content.encode("utf-8") + with open(name, "wb") as f: + f.write(striped_bt) def _push_corpus_cov_if_exist(self, suite_file): corpus_path = suite_file.split("fuzztest")[-1].strip(os.sep) -- Gitee