loci: convert locitest away from inheritance union
diff --git a/c_gen/c_test_gen.py b/c_gen/c_test_gen.py
index db7ca28..5ddd4e9 100644
--- a/c_gen/c_test_gen.py
+++ b/c_gen/c_test_gen.py
@@ -701,6 +701,8 @@
"""
for version in of_g.of_version_range:
for cls in of_g.standard_class_order:
+ if type_maps.class_is_inheritance_root(cls):
+ continue
(members, member_types) = scalar_member_types_get(cls, version)
scalar_funs_instance(out, cls, version, members, member_types)
@@ -710,8 +712,7 @@
base_type = loxi_utils.list_to_entry_type(cls)
setup_template = """
%(subcls)s_init(%(inst)s, %(v_name)s, -1, 1);
- %(cls)s_append_bind(list,
- (%(base_type)s_t *)%(inst)s);
+ %(cls)s_append_bind(list, %(inst)s);
value = %(subcls)s_%(v_name)s_populate(
%(inst)s, value);
cur_len += %(inst)s->length;
@@ -772,7 +773,7 @@
""" % dict(cls=cls, v_name=loxi_utils.version_to_name(version)))
base_type = loxi_utils.list_to_entry_type(cls)
out.write("""
- %(base_type)s_t elt;
+ of_object_t elt;
int cur_len = 0;
(void) elt;
(void) cur_len;
@@ -792,7 +793,7 @@
out.write(" %s_t *%s;\n" % (subcls, instance))
out.write("\n /* Instantiate pointers for each subclass */\n")
for instance, subcls in sub_classes:
- out.write(" %s = &elt.%s;\n" % (instance, instance))
+ out.write(" %s = &elt;\n" % (instance))
if not type_maps.class_is_virtual(base_type): # No inheritance case
setup_instance(out, cls, base_type, "elt_p", v_name, version)
@@ -821,7 +822,7 @@
""" % dict(cls=cls, v_name=loxi_utils.version_to_name(version)))
base_type = loxi_utils.list_to_entry_type(cls)
out.write("""
- %(base_type)s_t elt;
+ of_object_t elt;
(void) elt;
""" % dict(cls=cls, base_type=base_type))
@@ -839,7 +840,7 @@
out.write(" %s_t *%s;\n" % (subcls, instance))
out.write("\n /* Instantiate pointers for each subclass */\n")
for instance, subcls in sub_classes:
- out.write(" %s = &elt.%s;\n" % (instance, instance))
+ out.write(" %s = &elt;\n" % (instance))
if not type_maps.class_is_virtual(base_type) or sub_classes:
out.write(" TEST_OK(%(cls)s_first(list, &elt));\n" % dict(cls=cls))
@@ -1181,7 +1182,7 @@
""" % dict(cls=cls, v_name=loxi_utils.version_to_name(version)))
base_type = loxi_utils.list_to_entry_type(cls)
out.write("""
- %(base_type)s_t elt;
+ of_object_t elt;
int cur_len = 0;
(void) elt;
(void) cur_len;
@@ -1201,7 +1202,7 @@
out.write(" %s_t *%s;\n" % (subcls, instance))
out.write("\n /* Instantiate pointers for each subclass */\n")
for instance, subcls in sub_classes:
- out.write(" %s = &elt.%s;\n" % (instance, instance))
+ out.write(" %s = &elt;\n" % (instance))
if not type_maps.class_is_virtual(base_type): # No inheritance case
setup_instance(out, cls, base_type, "elt_p", v_name, version)
@@ -1227,7 +1228,7 @@
""" % dict(cls=cls, v_name=loxi_utils.version_to_name(version)))
base_type = loxi_utils.list_to_entry_type(cls)
out.write("""
- %(base_type)s_t elt;
+ of_object_t elt;
int count = 0;
int rv;
""" % dict(cls=cls, base_type=base_type))
@@ -1249,7 +1250,7 @@
out.write(" %s_t *%s;\n" % (subcls, instance))
out.write("\n /* Instantiate pointers for each subclass */\n")
for instance, subcls in sub_classes:
- out.write(" %s = &elt.%s;\n" % (instance, instance))
+ out.write(" %s = &elt;\n" % (instance))
if not type_maps.class_is_virtual(base_type) or sub_classes:
out.write(" TEST_OK(%(cls)s_first(list, &elt));\n" % dict(cls=cls))
@@ -1661,8 +1662,8 @@
%(cls)s_%(ver_name)s_dup(
%(cls)s_t *src)
{
- %(elt_type)s_t src_elt;
- %(elt_type)s_t *dst_elt;
+ of_object_t src_elt;
+ of_object_t *dst_elt;
int rv;
%(cls)s_t *dst;
@@ -1697,9 +1698,9 @@
*
* The caller is responsible for deleting the returned value
*/
-%(cls)s_t *
+of_object_t *
%(cls)s_%(ver_name)s_dup(
- %(cls)s_t *src)
+ of_object_t *src)
{
""" % dict(cls=cls, ver_name=ver_name))
@@ -1708,9 +1709,8 @@
for (_, sub_cls) in sub_classes:
sub_enum = sub_cls.upper()
out.write("""
- if (src->header.object_id == %(sub_enum)s) {
- return (%(cls)s_t *)%(sub_cls)s_%(ver_name)s_dup(
- (of_object_t *)src);
+ if (src->object_id == %(sub_enum)s) {
+ return %(sub_cls)s_%(ver_name)s_dup(src);
}
""" % dict(sub_cls=sub_cls, ver_name=ver_name, sub_enum=sub_enum, cls=cls))
@@ -1851,22 +1851,21 @@
for cls in of_g.standard_class_order:
out.write("""
-%(cls)s_t *
+of_object_t *
%(cls)s_dup(
- %(cls)s_t *src)
+ of_object_t *src)
{
""" % dict(cls=cls))
for version in of_g.of_version_range:
if not loxi_utils.class_in_version(cls, version):
continue
- hdr = "header." if type_maps.class_is_inheritance_root(cls) else ""
ver_name = loxi_utils.version_to_name(version)
out.write("""
- if (src->%(hdr)sversion == %(ver_name)s) {
+ if (src->version == %(ver_name)s) {
return %(cls)s_%(ver_name)s_dup(src);
}
-""" % dict(cls=cls, ver_name=ver_name, hdr=hdr))
+""" % dict(cls=cls, ver_name=ver_name))
out.write("""
/* Class not supported in given version */
@@ -1920,9 +1919,9 @@
for cls in of_g.standard_class_order:
out.write("""
-extern %(cls)s_t *
+extern of_object_t *
%(cls)s_dup(
- %(cls)s_t *src);
+ of_object_t *src);
""" % dict(cls=cls))
for version in of_g.of_version_range:
@@ -1931,9 +1930,9 @@
continue
ver_name = loxi_utils.version_to_name(version)
out.write("""
-extern %(cls)s_t *
+extern of_object_t *
%(cls)s_%(ver_name)s_dup(
- %(cls)s_t *src);
+ of_object_t *src);
""" % dict(cls=cls, ver_name=ver_name))
out.write("\n#endif /* _OF_DUP_H_ */\n")
diff --git a/c_gen/templates/locitest/test_utils.c b/c_gen/templates/locitest/test_utils.c
index 10a6b3d..d078a59 100644
--- a/c_gen/templates/locitest/test_utils.c
+++ b/c_gen/templates/locitest/test_utils.c
@@ -43,12 +43,8 @@
test_has_outport(void)
{
of_list_action_t *list;
- of_action_t elt;
- of_action_set_dl_src_t *set_dl_src;
- of_action_output_t *output;
-
- set_dl_src = &elt.set_dl_src;
- output = &elt.output;
+ of_object_t set_dl_src;
+ of_object_t output;
list = of_list_action_new(OF_VERSION_1_0);
TEST_ASSERT(list != NULL);
@@ -57,25 +53,25 @@
TEST_ASSERT(!of_action_list_has_out_port(list, 1));
/* Add some other action */
- of_action_set_dl_src_init(set_dl_src, OF_VERSION_1_0, -1, 1);
- TEST_OK(of_list_action_append_bind(list, (of_action_t *)set_dl_src));
+ of_action_set_dl_src_init(&set_dl_src, OF_VERSION_1_0, -1, 1);
+ TEST_OK(of_list_action_append_bind(list, &set_dl_src));
TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
TEST_ASSERT(!of_action_list_has_out_port(list, 1));
/* Add port 2 */
- of_action_output_init(output, OF_VERSION_1_0, -1, 1);
- TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
- of_action_output_port_set(output, 2);
+ of_action_output_init(&output, OF_VERSION_1_0, -1, 1);
+ TEST_OK(of_list_action_append_bind(list, &output));
+ of_action_output_port_set(&output, 2);
TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
TEST_ASSERT(!of_action_list_has_out_port(list, 1));
TEST_ASSERT(of_action_list_has_out_port(list, 2));
/* Add port 1 */
- of_action_output_init(output, OF_VERSION_1_0, -1, 1);
- TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
- of_action_output_port_set(output, 1);
+ of_action_output_init(&output, OF_VERSION_1_0, -1, 1);
+ TEST_OK(of_list_action_append_bind(list, &output));
+ of_action_output_port_set(&output, 1);
TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
TEST_ASSERT(of_action_list_has_out_port(list, 1));
@@ -88,26 +84,26 @@
TEST_ASSERT(list != NULL);
/* Add port 2 */
- of_action_output_init(output, OF_VERSION_1_0, -1, 1);
- TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
- of_action_output_port_set(output, 2);
+ of_action_output_init(&output, OF_VERSION_1_0, -1, 1);
+ TEST_OK(of_list_action_append_bind(list, &output));
+ of_action_output_port_set(&output, 2);
TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
TEST_ASSERT(!of_action_list_has_out_port(list, 1));
TEST_ASSERT(of_action_list_has_out_port(list, 2));
/* Add some other action */
- of_action_set_dl_src_init(set_dl_src, OF_VERSION_1_0, -1, 1);
- TEST_OK(of_list_action_append_bind(list, (of_action_t *)set_dl_src));
+ of_action_set_dl_src_init(&set_dl_src, OF_VERSION_1_0, -1, 1);
+ TEST_OK(of_list_action_append_bind(list, &set_dl_src));
TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
TEST_ASSERT(!of_action_list_has_out_port(list, 1));
TEST_ASSERT(of_action_list_has_out_port(list, 2));
/* Add port 1 */
- of_action_output_init(output, OF_VERSION_1_0, -1, 1);
- TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
- of_action_output_port_set(output, 1);
+ of_action_output_init(&output, OF_VERSION_1_0, -1, 1);
+ TEST_OK(of_list_action_append_bind(list, &output));
+ of_action_output_port_set(&output, 1);
TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
TEST_ASSERT(of_action_list_has_out_port(list, 1));
diff --git a/c_gen/templates/locitest/test_validator.c b/c_gen/templates/locitest/test_validator.c
index a4b55eb..fde5cba 100644
--- a/c_gen/templates/locitest/test_validator.c
+++ b/c_gen/templates/locitest/test_validator.c
@@ -88,9 +88,9 @@
of_message_t msg;
of_flow_modify_actions_bind(obj, &list);
of_action_set_tp_dst_init(&element1, OF_VERSION_1_0, -1, 1);
- of_list_action_append_bind(&list, (of_action_t *)&element1);
+ of_list_action_append_bind(&list, &element1);
of_action_output_init(&element2, OF_VERSION_1_0, -1, 1);
- of_list_action_append_bind(&list, (of_action_t *)&element2);
+ of_list_action_append_bind(&list, &element2);
msg = OF_OBJECT_TO_MESSAGE(obj);
TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0);
diff --git a/test_data/of10/flow_add.data b/test_data/of10/flow_add.data
index 60fd780..275a40e 100644
--- a/test_data/of10/flow_add.data
+++ b/test_data/of10/flow_add.data
@@ -117,19 +117,19 @@
of_list_action_t actions;
of_flow_add_actions_bind(obj, &actions);
{
- of_action_t action;
- of_action_output_init(&action.output, OF_VERSION_1_0, -1, 1);
+ of_object_t action;
+ of_action_output_init(&action, OF_VERSION_1_0, -1, 1);
of_list_action_append_bind(&actions, &action);
- of_action_output_port_set(&action.output, OF_PORT_DEST_FLOOD);
+ of_action_output_port_set(&action, OF_PORT_DEST_FLOOD);
}
{
- of_action_t action;
- of_action_nicira_dec_ttl_init(&action.nicira_dec_ttl, OF_VERSION_1_0, -1, 1);
+ of_object_t action;
+ of_action_nicira_dec_ttl_init(&action, OF_VERSION_1_0, -1, 1);
of_list_action_append_bind(&actions, &action);
}
{
- of_action_t action;
- of_action_bsn_set_tunnel_dst_init(&action.bsn_set_tunnel_dst, OF_VERSION_1_0, -1, 1);
+ of_object_t action;
+ of_action_bsn_set_tunnel_dst_init(&action, OF_VERSION_1_0, -1, 1);
of_list_action_append_bind(&actions, &action);
}
}