core-framework icon indicating copy to clipboard operation
core-framework copied to clipboard

Sandbox loadSADFile does not handle component with simple property with no explicit <kind> tag specified

Open pacman128 opened this issue 4 years ago • 1 comments

The DTD file for a PRF file specifies that the <simple> tag has an optional <kind> child:

<!ELEMENT simple 
        ( description?
        , value?
        , units?
        , range?
        , enumerations?
        , kind*
        , action?
        )>

<!ELEMENT kind EMPTY>
<!ATTLIST kind
        kindtype        (allocation | property | configure | test | execparam | factoryparam | event | message) 
"configure">

However, the loadSADFile function assumes that the <kind> tag is always present

https://github.com/RedhawkSDR/core-framework/blob/7f72db1dfd794a2b57d33ce0330493299a2dccad/redhawk/src/base/framework/python/ossie/utils/sb/domainless.py#L799

                _prf = parsers.prf.parse(prfFilename)
                execprops = []
                configurable[instanceName] = []
                for prop_check in _prf.get_simple():
                    if prop_check.get_kind()[0].get_kindtype() == 'execparam':                                                                                                                                               
                        execprops.append(str(prop_check.get_id()))
                    if prop_check.get_kind()[0].get_kindtype() == 'configure':
                        if prop_check.get_mode() == 'readwrite' or prop_check.get_mode() == 'writeonly':
                            configurable[instanceName].append(str(prop_check.get_id()))
                    if prop_check.get_kind()[0].get_kindtype() == 'property':
                        if prop_check.get_mode() == 'readwrite' or prop_check.get_mode() == 'writeonly':
                            configurable[instanceName].append(str(prop_check.get_id()))

Calling loadSADFile with a waveform with a component that has a simple property without a <kind> tag will result in an error message:

DEBUG:ossie.utils.sb.domainless:COMPONENT PLACEMENT component spd file id 'PSD_a9532f88-cd71-4e79-938e-fb84c67b0722'
DEBUG:ossie.utils.sb.domainless:COMPONENT PLACEMENT component instantiation id 'PSD_1'
DEBUG:ossie.utils.sb.domainless:COMPONENT PLACEMENT component startorder '1'
DEBUG:ossie.utils.sb.domainless:COMPONENT PLACEMENT component name 'PSD_1'
DEBUG:ossie.utils.sb.domainless:launching component 'PSD_1'
DEBUG:ossie.utils.sandbox.launcher:Killing process group 74527 with signal 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/redhawk/core/lib/python/ossie/utils/sb/domainless.py", line 1097, in loadSADFile
    raise RuntimeError(msg)
RuntimeError:  ERROR - Failed to load sad file: /var/redhawk/sdr/dom/waveforms/MockDetectorWaveform/MockDetectorWaveform.sad.xml REASON: list index out of range

The list index out of range exception is coming from the line:

 if prop_check.get_kind()[0].get_kindtype() == 'execparam': 

I believe the code should check for a missing tag and use the default configure value in this case.

pacman128 avatar Jun 22 '21 14:06 pacman128

As a followup, changing the loop above to the following fixed the problem for me:

    for prop_check in _prf.get_simple():
        if len(prop_check.get_kind()) > 0:
            kind = prop_check.get_kind()[0].get_kindtype()
        else:
            kind = 'configure'
        if kind == 'execparam':
            execprops.append(str(prop_check.get_id()))
        if kind == 'configure':
            if prop_check.get_mode() == 'readwrite' or prop_check.get_mode() == 'writeonly':
                configurable[instanceName].append(str(prop_check.get_id()))
        if kind == 'property':
            if prop_check.get_mode() == 'readwrite' or prop_check.get_mode() == 'writeonly':
                configurable[instanceName].append(str(prop_check.get_id()))

pacman128 avatar Jun 22 '21 16:06 pacman128