diff --git a/llvm_test_script/plugin/Clang Plugin test manual.md b/llvm_test_script/plugin/ClangPluginTestManual.md similarity index 90% rename from llvm_test_script/plugin/Clang Plugin test manual.md rename to llvm_test_script/plugin/ClangPluginTestManual.md index ca27ae5cdf72bd11f9a3b367c8e54a0f74abfccd..4bba1685cd84f2db47d068b8027a8e242651a673 100644 --- a/llvm_test_script/plugin/Clang Plugin test manual.md +++ b/llvm_test_script/plugin/ClangPluginTestManual.md @@ -1,6 +1,6 @@ # Clang Plugin 测试框架指南 -Clang Plugin测试框架基于Python Unittest2开发,提供 [Clang Plugins](https://clang.llvm.org/docs/ClangPlugins.html) 端测编译和生成物检查等功能。 +Clang Plugin测试框架基于Python Unittest开发,提供 [Clang Plugins](https://clang.llvm.org/docs/ClangPlugins.html) 端测编译和生成物检查等功能。 ## 1. 测试框架功能介绍 @@ -8,6 +8,7 @@ Clang Plugin测试框架基于Python Unittest2开发,提供 [Clang Plugins](ht ``` --| TestCase # 测试用例模块的目录 + --| __init__.py # 将本文件夹变成一个可识别的测试模块 --| test.py # 测试用例模块,其中包含了相关的测试用例 --| test.cpp # 测试用例使用的c/c++测试程序 --| runtest.py # 测试框架入口 @@ -16,7 +17,7 @@ Clang Plugin测试框架基于Python Unittest2开发,提供 [Clang Plugins](ht ### 1.2 TestBase 功能介绍 -该类继承于unittest2.TestCase,以便于能够自动的发现用例和收集统计用例执行结果。 +该类继承于unittest.TestCase,以便于能够自动的发现用例和收集统计用例执行结果。 该类提供如下方法,便于开发者实现Plugin测试用例: @@ -134,7 +135,9 @@ Clang Plugin测试框架基于Python Unittest2开发,提供 [Clang Plugins](ht 上述用例模块是针对Plugin:print-fns的测试,该plugin的功能是输出所有的top-level函数名称。 -其中测试用例test_01:测试plugin print-fns的功能是否符合预期 +每个测试用例模块文件夹下需要添加空文件\_\_init\_\_.py。如无此文件,测试框架将无法识别到次测试用例模块。 + +测试用例test_01:测试plugin print-fns的功能是否符合预期 ``` def test_01(self): @@ -160,7 +163,7 @@ def test_01(self): 'Terminal output does not meet expectations') ``` -其中测试用例test_02:测试plugin print-fns是否影响最终生成物可执行程序 +测试用例test_02:测试plugin print-fns是否影响最终生成物可执行程序 ``` def test_02(self): diff --git a/llvm_test_script/plugin/PrintFunctionNames/__init__.py b/llvm_test_script/plugin/PrintFunctionNames/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/llvm_test_script/plugin/Testbase.py b/llvm_test_script/plugin/Testbase.py index f5aa3f01b26a192b7003520cb715fe4e5285702c..dd2166cbaab92dabd8a0d166b83f567066eb80a2 100644 --- a/llvm_test_script/plugin/Testbase.py +++ b/llvm_test_script/plugin/Testbase.py @@ -1,5 +1,5 @@ import subprocess -import unittest2 +import unittest import os class CompileResult(): @@ -7,13 +7,13 @@ class CompileResult(): self.returncode = returncode self.out = 'stdout: ' + stdout + ';\n' + 'stderr: ' + stderr -class TestBase(unittest2.TestCase): +class TestBase(unittest.TestCase): def pluginAssert(self, expr, msg=None): """Check that the expression is true.""" if not expr: raise self.failureException('PluginTest: ' + msg) - + def compile(self, compiler_path, source_file_path, compile_mode, output_file_name, output_dir=None, plugin_name=None, plugin_so_path=None, args=""): @@ -29,7 +29,7 @@ class TestBase(unittest2.TestCase): os.makedirs(output_dir) elif not os.path.isdir(output_dir): return CompileResult(1, "", "Invalid output path.") - + output = os.path.join(output_dir, output_file_name) if compile_mode == '-cc1': @@ -72,27 +72,27 @@ class TestBase(unittest2.TestCase): process_result = subprocess.run(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=True, + stderr=subprocess.PIPE, + shell=True, encoding="utf-8") - ret = CompileResult(process_result.returncode, - process_result.stdout, + ret = CompileResult(process_result.returncode, + process_result.stdout, process_result.stderr) return ret - + def match_num(self, pattern, file): """ count match number. """ cmd = 'grep -c ' + pattern + ' ' + file - ret = subprocess.run(cmd, + ret = subprocess.run(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=True, + stderr=subprocess.PIPE, + shell=True, encoding="utf-8") return int(ret.stdout) - + def match_lines(self, pattern, file): """ show the match lines. @@ -100,7 +100,7 @@ class TestBase(unittest2.TestCase): cmd = 'grep -n ' + pattern + ' ' + file ret = subprocess.run(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True, encoding="utf-8") return ret.stdout diff --git a/llvm_test_script/plugin/runtest.py b/llvm_test_script/plugin/runtest.py index 9e2ab576fe9f7635aa480472cf72ae845ce8ac8a..f6a0b3a80cce915adba8281f12c86fc74c940e49 100644 --- a/llvm_test_script/plugin/runtest.py +++ b/llvm_test_script/plugin/runtest.py @@ -1,6 +1,6 @@ import argparse import platform -import unittest2 +import unittest import sys import os @@ -8,8 +8,8 @@ class RunTest: args = None test_dir = None test_name = None - suite = unittest2.TestSuite() - loader = unittest2.TestLoader() + suite = unittest.TestSuite() + loader = unittest.TestLoader() failureException = Exception def __init__(self): @@ -80,7 +80,7 @@ class RunTest: def run_test(self): if self.check_args(): self.discover_cases() - runner = unittest2.TextTestRunner(verbosity=2) + runner = unittest.TextTestRunner(verbosity=2) runner.run(self.suite) else: print('Please input cerrent test case save path.')