# Path: pif_ir/bir/objects/bir_struct.py
# class BIRStruct(object):
#     required_attributes = ['fields']
# 
#     def __init__(self, name, struct_attrs):
#         check_attributes(name, struct_attrs, BIRStruct.required_attributes)
#         logging.debug("Adding bir_struct {0}".format(name))
# 
#         self.name = name
#         self.length = 0
#         self.fields = OrderedDict()
#         self.field_offsets = OrderedDict()
# 
#         for tmp_field in struct_attrs['fields']:
#             for name, size in tmp_field.items():
#                 self.fields[name] = size
# 
#             self.field_offsets[name] = self.length
#             self.length += size
# 
#     def __len__(self):
#         return self.length
# 
#     def field_offset(self, fld_name):
#         return self.field_offsets.get(fld_name, 0)
# 
#     def field_size(self, fld_name):
#         return self.fields.get(fld_name, 0)


import logging
from pif_ir.bir.objects.bir_struct import BIRStruct
from test_common import yaml_eth_struct_dict
#!/usr/bin/env python

logging.basicConfig(level=logging.INFO)
logging.info("RUNNING TEST: %s" % __file__)

bir_struct = BIRStruct('eth_t', yaml_eth_struct_dict)

# Test field_offset() function
offset_tests = [('dst', 0), ('src', 48), ('type_', 96), ('bad', 0)]
for tc, test in enumerate(offset_tests):
    offset = bir_struct.field_offset(test[0])
    if offset != test[1]:
        logging.error("failed offset test case {}: {} != {}".format(
            tc, offset, test[1]))

# Path: pif_ir/bir/objects/bir_struct.py
# class BIRStruct(object):
#     required_attributes = ['fields']
# 
#     def __init__(self, name, struct_attrs):
#         check_attributes(name, struct_attrs, BIRStruct.required_attributes)
#         logging.debug("Adding bir_struct {0}".format(name))
# 
#         self.name = name
#         self.length = 0
#         self.fields = OrderedDict()
#         self.field_offsets = OrderedDict()
# 
#         for tmp_field in struct_attrs['fields']:
#             for name, size in tmp_field.items():
#                 self.fields[name] = size
# 
#             self.field_offsets[name] = self.length
#             self.length += size
# 
#     def __len__(self):
#         return self.length
# 
#     def field_offset(self, fld_name):
#         return self.field_offsets.get(fld_name, 0)
# 
#     def field_size(self, fld_name):
#         return self.fields.get(fld_name, 0)


# Path: pif_ir/bir/tests/test_bir_struct.py
import logging
from pif_ir.bir.objects.bir_struct import BIRStruct
from test_common import yaml_eth_struct_dict

#!/usr/bin/env python

logging.basicConfig(level=logging.INFO)
logging.info("RUNNING TEST: %s" % __file__)

bir_struct = BIRStruct('eth_t', yaml_eth_struct_dict)

# Test field_offset() function
offset_tests = [('dst', 0), ('src', 48), ('type_', 96), ('bad', 0)]
for tc, test in enumerate(offset_tests):
    offset = bir_struct.field_offset(test[0])
    if offset != test[1]:
        logging.error("failed offset test case {}: {} != {}".format(
            tc, offset, test[1]))

        exit(1)