Browse Source

wow, less confuzzled now

master
heck 5 years ago
parent
commit
8055b4db9f
  1. 2
      pEpACIDgen/c_2_ast.py
  2. 380
      tests/test_pEpACIDgen.py

2
pEpACIDgen/c_2_ast.py

@ -18,7 +18,7 @@ class C2AST:
def parse(self, filename, content=None, follow_includes=False): def parse(self, filename, content=None, follow_includes=False):
index = clang.cindex.Index.create() index = clang.cindex.Index.create()
arguments = ["-x", "c"] arguments = ["-x", "c", "-I/Users/heck/local-default/include/"]
options = clang.cindex.TranslationUnit.PARSE_SKIP_FUNCTION_BODIES options = clang.cindex.TranslationUnit.PARSE_SKIP_FUNCTION_BODIES
if content: if content:
content = [(filename, content)] content = [(filename, content)]

380
tests/test_pEpACIDgen.py

@ -2,164 +2,179 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is under GNU Affero General Public License 3.0 # This file is under GNU Affero General Public License 3.0
# see LICENSE.txt # see LICENSE.txt
import re
import pytest import pytest
import pEpACIDgen import pEpACIDgen
types_with_alias = [] # "type" - is the name of the type for which vars of all variations of this type exists
types_no_alias = [] # (Variations being combinations of this type with qualifier alias and typedef,
types_no_alias.append({"var": ["_P"], # Which means that all variations resolve to the same underlying type)
"type_names": [ #
]}) # "requires" - is the list of types that this underlying type depends on
# (a type is not self sufficient, a struct for instance can have members of plenty of types, etc...)
types_no_alias.append({"var": ["_E"], #
"type_names": [ # Subject of this test is to make sure:
"enum _E" # All variations for all the "type"s given extract the ACID of all the types,
]}) # and only the types specified on "requires".
types_with_alias.append({"var": ["E"], all_types = []
"type_names": [
"enum E" all_types.append({"type": ["_P"],
]}) "requires": [
]})
types_no_alias.append({"var": ["_PS"],
"type_names": [ all_types.append({"type": ["_E"],
"struct _PS" "requires": [
]}) "enum _E"
]})
types_with_alias.append({"var": ["PS"],
"type_names": [ all_types.append({"type": ["E"],
"struct PS" "requires": [
]}) "enum E"
]})
types_no_alias.append({"var": ["_CS"],
"type_names": [ # all_types.append({"type": ["XE"],
"struct _CS", # "requires": [
"struct PS", # "AXE"
"struct _PS" # ]})
]})
all_types.append({"type": ["_PS"],
types_with_alias.append({"var": ["CS"], "requires": [
"type_names": [ "struct _PS"
"struct CS", ]})
"struct _PS",
"struct PS" all_types.append({"type": ["PS"],
]}) "requires": [
"struct PS"
types_no_alias.append({"var": ["_CCS"], ]})
"type_names": [
"struct _CCS", all_types.append({"type": ["_CS"],
"struct CS", "requires": [
"struct _PS", "struct _CS",
"struct PS" "struct PS",
]}) "struct _PS"
]})
types_with_alias.append({"var": ["CCS"],
"type_names": [ all_types.append({"type": ["CS"],
"struct CCS", "requires": [
"struct CS", "struct CS",
"struct _PS", "struct _PS",
"struct PS" "struct PS"
]}) ]})
types_no_alias.append({"var": ["_HS"], all_types.append({"type": ["_CCS"],
"type_names": [ "requires": [
"struct _HS", "struct _CCS",
"struct _NCS", "struct CS",
"struct CS", "struct _PS",
"struct _PS", "struct PS"
"struct PS" ]})
]})
all_types.append({"type": ["CCS"],
types_with_alias.append({"var": ["HS"], "requires": [
"type_names": [ "struct CCS",
"struct HS", "struct CS",
"struct _NPS" "struct _PS",
]}) "struct PS"
]})
types_no_alias.append({"var": ["_NCS"],
"type_names": [ all_types.append({"type": ["_HS"],
"struct _NCS", "requires": [
"struct CS", "struct _HS",
"struct _PS", "struct _NCS",
"struct PS" "struct CS",
]}) "struct _PS",
"struct PS"
types_no_alias.append({"var": ["_NPS"], ]})
"type_names": [
"struct _NPS" all_types.append({"type": ["HS"],
]}) "requires": [
"struct HS",
types_no_alias.append({"var": ["_HHS"], "struct _NPS"
"type_names": [ ]})
"struct _HHS",
"struct _NHS", all_types.append({"type": ["_NCS"],
"struct _NNPS" "requires": [
]}) "struct _NCS",
"struct CS",
types_with_alias.append({"var": ["HHS"], "struct _PS",
"type_names": [ "struct PS"
"struct HHS", ]})
"struct _NHS1",
"struct _NNCS", all_types.append({"type": ["_NPS"],
"struct _CS", "requires": [
"struct PS", "struct _NPS"
"struct _PS", ]})
"enum _NENHS"
]}) all_types.append({"type": ["_HHS"],
"requires": [
types_no_alias.append({"var": ["_NHS"], "struct _HHS",
"type_names": [ "struct _NHS",
"struct _NHS", "struct _NNPS"
"struct _NNPS" ]})
]})
all_types.append({"type": ["HHS"],
types_no_alias.append({"var": ["_NNPS"], "requires": [
"type_names": [ "struct HHS",
"struct _NNPS" "struct _NHS1",
]}) "struct _NNCS",
"struct _CS",
types_no_alias.append({"var": ["_NHS1"], "struct PS",
"type_names": [ "struct _PS",
"struct _NHS1", "enum _NENHS"
"struct _NNCS", ]})
"struct _CS",
"struct PS", all_types.append({"type": ["_NHS"],
"struct _PS", "requires": [
"enum _NENHS" "struct _NHS",
]}) "struct _NNPS"
]})
types_no_alias.append({"var": ["_NNCS"],
"type_names": [ all_types.append({"type": ["_NNPS"],
"struct _NNCS", "requires": [
"struct _CS", "struct _NNPS"
"struct PS", ]})
"struct _PS"
]}) all_types.append({"type": ["_NHS1"],
"requires": [
types_no_alias.append({"var": ["_NENHS"], "struct _NHS1",
"type_names": [ "struct _NNCS",
"enum _NENHS" "struct _CS",
]}) "struct PS",
"struct _PS",
types_no_alias.append({"var": ["_HS1"], "enum _NENHS"
"type_names": [ ]})
"struct _HS1",
"enum _NEHS" all_types.append({"type": ["_NNCS"],
]}) "requires": [
"struct _NNCS",
types_no_alias.append({"var": ["_NEHS"], "struct _CS",
"type_names": [ "struct PS",
"enum _NEHS" "struct _PS"
]}) ]})
all_types.append({"type": ["_NENHS"],
"requires": [
"enum _NENHS"
]})
all_types.append({"type": ["_HS1"],
"requires": [
"struct _HS1",
"enum _NEHS"
]})
all_types.append({"type": ["_NEHS"],
"requires": [
"enum _NEHS"
]})
def resolve_vars_and_funcs_to_acid(vars, funcs): def resolve_vars_and_funcs_to_acid(vars, funcs):
header_filename = "examples/lib/lib_test/lib_test.h" header_filename = "examples/lib/lib_test/lib_test.h"
libclang_path = "/opt/local/libexec/llvm-9.0/lib/libclang.dylib" libclang_path = "/opt/local/libexec/llvm-9.0/lib/libclang.dylib"
acidgen = pEpACIDgen.pEpACIDGen(libclang_path, header_filename, "test_pEpACIDgen") acidgen = pEpACIDgen.pEpACIDGen(libclang_path, header_filename, "test_pEpACIDgen")
header = acidgen.extract(vars,funcs) header = acidgen.extract(vars, funcs)
return header["acid"] return header["acid"]
@ -191,31 +206,46 @@ def check_expected_types_resolved(vars, funcs, type_names_expected):
assert type_names == type_names_expected assert type_names == type_names_expected
@pytest.mark.skip # Variations
@pytest.mark.parametrize('vars', [["var_TP"]]) # a var var_X of a type X can generally exist in the variations:
@pytest.mark.parametrize('funcs', [""]) # * X var_X
def test_manual(vars, funcs): # * AX var_AX
resolve_vars_and_funcs_to_acid(vars, funcs) # * TX var_TX
# * TAX var_TAX
# * TTX var_TTX
# @pytest.mark.skip # * TTAX var_TTAX
# AND the type of ALL these vars resolves to the same underlying type X
#
# types with no alias
# type with no alias can only exists in variations NOT ending with A
#
# Anonymous types (enum only)
# an anonymous type only exists because of its alias typedef enum { a;b;c } XE;
# Therefore, only variations ending with A are valid
@pytest.mark.parametrize('variation', ["var_", "var_A", "var_T", "var_TA", "var_TT", "var_TTA"]) @pytest.mark.parametrize('variation', ["var_", "var_A", "var_T", "var_TA", "var_TT", "var_TTA"])
@pytest.mark.parametrize('data', types_with_alias) @pytest.mark.parametrize('data', all_types)
def test_single_var_with_alias(data, variation):
var_list = []
for var in data["var"]:
var_name = variation + var
var_list.append(var_name)
check_expected_types_resolved(var_list, [], data["type_names"])
@pytest.mark.parametrize('variation', ["var_", "var_T", "var_TT"])
@pytest.mark.parametrize('data', types_no_alias)
def test_single_var_no_alias(data, variation): def test_single_var_no_alias(data, variation):
var_list = [] type = data["type"][0]
for var in data["var"]: var_name = variation + type
var_name = variation + var
var_list.append(var_name) # it the type begins with _ it has no alias
re_type_no_alias = re.compile("^_")
check_expected_types_resolved(var_list, [], data["type_names"]) # if the variation ends with a is an alias of something
re_vari_alias = re.compile("A$")
# if the type contains an X is is an anonymous type
re_type_anonynmous = re.compile("X")
skipmsg = "variation not valid:" + variation + " for type:" + type
re_vari_invalid_for_anon = re.compile("")
if re_type_no_alias.search(type):
if re_vari_alias.search(variation):
print(skipmsg)
pytest.skip(skipmsg)
# the anonymous type only exists because of its alias
if re_type_anonynmous.search(type):
if not re_vari_alias.search(variation):
print(skipmsg)
pytest.skip(skipmsg)
check_expected_types_resolved([var_name], [], data["requires"])

Loading…
Cancel
Save