Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also generate normalized XML #168

Merged
merged 2 commits into from
Jul 6, 2020
Merged

Also generate normalized XML #168

merged 2 commits into from
Jul 6, 2020

Conversation

lategoodbye
Copy link
Collaborator

In order to increase the test coverage also generate the normalized version
of XML output.

generate_xml() {
directory="$1"
hexfile="$2"
mode="$3"

filename=`basename $hexfile .hex`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filename=`basename $hexfile .hex`
filename=$(basename "$hexfile" .hex)

Shellcheck, a linter for shell scripts using $( ) instead of , and wants you to add quotes where filenames possibly could contain spaces.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

# Parse hex file and write XML in file
$mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new"
$mbus_parse_hex $options "$hexfile" > "$directory/$filename$suffix.new"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal opinion: I would have a dot after filename, and probably keep "xml.new" down here.
Since that is invariant (does not differ over the two cases.

 if [ $mode = "normalized" ]; then
        options="-n"
        suffix="norm"
    else
        options=""
        suffix=""
    fi
  ...
    $mbus_parse_hex $options "$hexfile" > "$directory/$filename.${suffix}xml.new"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand the keep xml.new thing. In case the output differ we keep the new file. So we need the suffix, otherwise we will overwrite the new default output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was trying to say, is that both modes "default" and "normalized" will name the files withe the ending ".xml.new",

I would write it like this:

options = ""
if [ "$mode" = "default" ]; then
    mode=""
elif [ "$mode" = "normalized" ];
    mode=".norm"
    options="-n"
else
    echo "ERROR: Unknown mode $mode."
    return 1
fi
...
$mbus_parse_hex $options "$hexfile" > "$directory/$filename$mode.xml.new"

diff -u "$directory/$filename$mode.xml" "$directory/$filename$mode.xm.new" 2> /dev/null > "$directory/$filename$mode.dif"

fi

# Compare old XML with new XML and write in file
diff -u "$directory/$filename.xml" "$directory/$filename.xml.new" 2> /dev/null > "$directory/$filename.dif"
diff -u "$directory/$filename$suffix" "$directory/$filename$suffix.new" 2> /dev/null > "$directory/$filename.dif"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
diff -u "$directory/$filename$suffix" "$directory/$filename$suffix.new" 2> /dev/null > "$directory/$filename.dif"
diff -u "$directory/$filename$suffix" "$directory/$filename$suffix.new" 2> /dev/null > "$directory/$filename$suffix.dif"

I would like to run all tests at once, and see every failed test at once. Both not nromailized and normalized could fail. So it is better to add the suffix here. So there is no question about which test that failed.

Copy link
Contributor

@fredrik-sk fredrik-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some more things...

Comment on lines +103 to +105
generate_xml "$directory" "$hexfile" "default"

generate_xml "$directory" "$hexfile" "normalized"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we don't seem to look at the return value of the function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or did you intend me to update the commit "make build stop on broken tests"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was your idea, so you should get the credits for it.

rm "$directory/$filename.dif"
;;
esac

return 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 0
return $result

@lategoodbye
Copy link
Collaborator Author

I pushed a new version

@fredrik-sk
Copy link
Contributor

Hello

We can definetly handle this as a new issue.
I want to point out what I have seen, and what my opinions are.

I didn't notice this until I rebased my work onto your PR and ran the tests.
There is some file that gives some output

When looking at the tests of this PR, https://github.com/rscada/libmbus/pull/168/checks?check_run_id=816071416

Lines 12-14 of the step "generate test frames" is new.
There is no indication what file is causing this. (The level above probably just ignores it.)

mbus_vif_unit_normalize: Unknown VIF 0x07B
mbus_vib_unit_normalize: Error mbus_vif_unit_normalize
mbus_parse_variable_record: problem with mbus_vib_unit_normalize

Locally, I added this command echo "*** "$hexfile at the loop at the end of generate-xml.sh.

It indicated:

*** test/test-frames/sen_pollutherm.hex

Looking at the diff, indicates that datarecord with id=2 is completly empty in the normalized file.
The contents in the record with id=9, is how the normalized xml should look?

diff -u sen_pollutherm.xml sen_pollutherm.norm.xml | less

     <DataRecord id="1">
         <Function>Instantaneous value</Function>
         <StorageNumber>0</StorageNumber>
-        <Unit>Volume (1e-2  m^3)</Unit>
-        <Value>799892</Value>
+        <Unit>m^3</Unit>
+        <Quantity>Volume</Quantity>
+        <Value>7998.920000</Value>
     </DataRecord>

     <DataRecord id="2">
-        <Function>Instantaneous value</Function>
-        <StorageNumber>0</StorageNumber>
-        <Unit>Unknown (VIF=0x7B)</Unit>
-        <Value>302</Value>
     </DataRecord>
...
     <DataRecord id="9">
         <Function>More records follow</Function>
+        <StorageNumber>0</StorageNumber>
+        <Unit></Unit>
+        <Quantity></Quantity>
         <Value></Value>
     </DataRecord>

I would suggest two actions from this.

  • Perhaps avoid checking in sen_pollutherm.norm.xml until this has been solved.
  • Implement some way that the error messages could say what file caused the problem. Either by setting the name of the
    file as a global variable, or that this problem results in an exitcode of -1 in mbus_parse_hex.
  • Fix this particular VIF if it exists in the standard.

Comment on lines +31 to +32
<DataRecord id="2">
</DataRecord>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment #168 (comment) .

This is probably where this is printed.

mbus_vif_unit_normalize: Unknown VIF 0x07B
mbus_vib_unit_normalize: Error mbus_vif_unit_normalize
mbus_parse_variable_record: problem with mbus_vib_unit_normalize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps skip checking in this file while this issue remains?

In order to increase the test coverage also generate the normalized version
of XML output.
@lategoodbye lategoodbye merged commit e27a95c into master Jul 6, 2020
@lategoodbye lategoodbye deleted the generate-norm-xml branch July 19, 2020 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants