Skip to content

Commit

Permalink
fix(generate): handle invalid signal name for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
christka1 committed Nov 4, 2024
1 parent 7798b54 commit 5a220ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/generate/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (c *compiler) addMetadata() {
sig, ok := c.db.Signal(def.MessageID.ToCAN(), string(def.SignalName))
if !ok {
c.addWarning(&compileError{def: def, reason: "no declared signal"})
continue
}
if def.AttributeName == "GenSigStartValue" {
sig.DefaultValue = int(def.IntValue)
Expand Down
14 changes: 14 additions & 0 deletions internal/generate/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,17 @@ func Test_CopyFrom_PreservesOutOfRangeValues(t *testing.T) {
t.Errorf("Expected frames of messages to be identical (%v != %v)", m2.Frame(), original.Frame())
}
}

func TestCompile_MetadataInvalidSignalReference(t *testing.T) {
finish := runTestInDir(t, "../..")
defer finish()
const exampleDBCFile = "testdata/dbc-invalid/example/example_metadata_invalid_signal_reference.dbc"
input, err := os.ReadFile(exampleDBCFile)
assert.NilError(t, err)
result, err := Compile(exampleDBCFile, input)
if err != nil {
t.Fatal(err)
}
// We expect one warning for incorrect signal length in declaration of float32 signal
assert.Equal(t, len(result.Warnings), 1)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VERSION ""

NS_ :

BS_:

BU_: DBG IO

BO_ 42 AMessage: 8 Vector__XXX
SG_ ASignal : 7|16@0- (1,0) [-32768|32767] "%" Vector__XXX

BA_DEF_ SG_ "GenSigStartValue" FLOAT -3.4E+038 3.4E+038;
BA_DEF_DEF_ "GenSigStartValue" 0;
BA_ "GenSigStartValue" SG_ 42 AnotherSignalName 0;

0 comments on commit 5a220ab

Please sign in to comment.