def test_evaluate_kinds_struct_records(): nodes = [ model.Struct("Fix", [ model.StructMember("a", "u8"), ]), model.Struct("Dyn", [ model.StructMember("a_len", "u8"), model.StructMember("a", "u8", bound="a_len"), ]), model.Struct("X", [ model.StructMember("a", "Dyn"), model.StructMember("b_len", "u8"), model.StructMember("b", "Fix", bound="b_len"), model.StructMember("c", "Fix", greedy=True), ]), ] model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) assert [x.kind for x in nodes] == [ model.Kind.FIXED, model.Kind.DYNAMIC, model.Kind.UNLIMITED, ] assert [x.kind for x in nodes[2].members] == [ model.Kind.DYNAMIC, model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, ]
def test_evaluate_kinds_arrays(): nodes = [ model.Struct("A", [ model.StructMember("a", "u8"), model.StructMember("b", "u8", optional=True), model.StructMember("c", "u8", size="5"), model.StructMember("d_len", "u8"), model.StructMember("d", "u8", bound="d_len", size="5"), model.StructMember("e_len", "u8"), model.StructMember("e", "u8", bound="e_len"), model.StructMember("f", "u8", greedy=True), ]), ] model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) assert [x.kind for x in nodes[0].members] == [ model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, model.Kind.FIXED, ]
def test_partition_fixed(): nodes = [ model.Struct("Fixed", [ model.StructMember("a", "u8"), model.StructMember("b", "u8"), model.StructMember("c", "u8"), ]) ] model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) main, parts = model.partition(nodes[0].members) assert [x.name for x in main] == ["a", "b", "c"] assert [[x.name for x in part] for part in parts] == []
def test_partition_many_arrays_mixed(): nodes = [ model.Struct("ManyArraysMixed", [ model.StructMember("num_of_a", "u8"), model.StructMember("num_of_b", "u8"), model.StructMember("a", "u8", bound="num_of_a"), model.StructMember("b", "u8", bound="num_of_b"), ]), ] model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) main, parts = model.partition(nodes[0].members) assert [x.name for x in main] == ["num_of_a", "num_of_b", "a"] assert [[x.name for x in part] for part in parts] == [["b"]]
def test_partition_many_dynamic_structs(): nodes = [ model.Struct("Dynamic", [ model.StructMember("num_of_a", "u8"), model.StructMember("a", "u8", bound="num_of_a"), ]), model.Struct("X", [ model.StructMember("a", "Dynamic"), model.StructMember("b", "Dynamic"), model.StructMember("c", "Dynamic"), ]), ] model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) main, parts = model.partition(nodes[1].members) assert [x.name for x in main] == ["a"] assert [[x.name for x in part] for part in parts] == [["b"], ["c"]]
def process(nodes, warn=None): model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) model.evaluate_sizes(nodes, **(warn and {'warn': warn} or {})) return nodes
def test_evaluate_kinds_with_typedefs(): nodes = [ model.Struct("Empty", []), model.Struct("Dynamic", [ model.StructMember("a_len", "u8"), model.StructMember("a", "u8", bound="a_len"), ]), model.Struct("Fixed", [ model.StructMember("a", "u8", size="10"), ]), model.Struct("Limited", [ model.StructMember("a_len", "u8"), model.StructMember("a", "u8", bound="a_len", size="10"), ]), model.Struct("Greedy", [ model.StructMember("a", "byte", greedy=True), ]), model.Struct("DynamicWrapper", [ model.StructMember("a", "Dynamic"), ]), model.Struct("GreedyWrapper", [ model.StructMember("a", "Greedy"), ]), model.Struct("GreedyDynamic", [ model.StructMember("a", "Dynamic", greedy=True), ]), model.Typedef("TU8", "u8"), model.Typedef("TDynamic", "Dynamic"), model.Typedef("TGreedy", "Greedy"), model.Struct("TypedefedU8", [ model.StructMember("a", "TU8"), ]), model.Struct("TypedefedDynamic", [ model.StructMember("a", "TDynamic"), ]), model.Struct("TypedefedGreedy", [ model.StructMember("a", "TGreedy"), ]), model.Typedef("TTDynamic", "TDynamic"), model.Typedef("TTTDynamic", "TTDynamic"), model.Struct("DeeplyTypedefed", [ model.StructMember("a", "TTTDynamic"), ]), ] model.cross_reference(nodes) model.evaluate_stiffness_kinds(nodes) assert [x.kind for x in nodes if isinstance(x, model.Struct)] == [ model.Kind.FIXED, model.Kind.DYNAMIC, model.Kind.FIXED, model.Kind.FIXED, model.Kind.UNLIMITED, model.Kind.DYNAMIC, model.Kind.UNLIMITED, model.Kind.UNLIMITED, model.Kind.FIXED, model.Kind.DYNAMIC, model.Kind.UNLIMITED, model.Kind.DYNAMIC, ]