github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/dbc/analysis/passes/multiplexedsignals/analyzer_test.go (about)

     1  package multiplexedsignals
     2  
     3  import (
     4  	"testing"
     5  	"text/scanner"
     6  
     7  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis"
     8  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis/analysistest"
     9  )
    10  
    11  func TestAnalyzer(t *testing.T) {
    12  	analysistest.Run(t, Analyzer(), []*analysistest.Case{
    13  		{
    14  			Name: "valid",
    15  			Data: `
    16  BO_ 200 SENSOR_SONARS: 8 SENSOR
    17   SG_ SENSOR_SONARS_mux M : 0|4@1+ (1,0) [0|0] "" DRIVER,IO
    18   SG_ SENSOR_SONARS_err_count : 4|12@1+ (1,0) [0|0] "" DRIVER,IO
    19   SG_ SENSOR_SONARS_left m0 : 16|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    20   SG_ SENSOR_SONARS_middle m0 : 28|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    21   SG_ SENSOR_SONARS_right m0 : 40|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    22   SG_ SENSOR_SONARS_rear m0 : 52|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    23   SG_ SENSOR_SONARS_no_filt_left m1 : 16|12@1+ (0.1,0) [0|0] "" DBG
    24   SG_ SENSOR_SONARS_no_filt_middle m1 : 28|12@1+ (0.1,0) [0|0] "" DBG
    25   SG_ SENSOR_SONARS_no_filt_right m1 : 40|12@1+ (0.1,0) [0|0] "" DBG
    26   SG_ SENSOR_SONARS_no_filt_rear m1 : 52|12@1+ (0.1,0) [0|0] "" DBG
    27  			`,
    28  		},
    29  
    30  		{
    31  			Name: "multiple multiplexer switches",
    32  			Data: `
    33  BO_ 200 SENSOR_SONARS: 8 SENSOR
    34   SG_ SENSOR_SONARS_mux M : 0|4@1+ (1,0) [0|0] "" DRIVER,IO
    35   SG_ SENSOR_SONARS_err_count M : 4|12@1+ (1,0) [0|0] "" DRIVER,IO
    36   SG_ SENSOR_SONARS_left m0 : 16|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    37   SG_ SENSOR_SONARS_middle m0 : 28|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    38   SG_ SENSOR_SONARS_right m0 : 40|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    39   SG_ SENSOR_SONARS_rear m0 : 52|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    40   SG_ SENSOR_SONARS_no_filt_left m1 : 16|12@1+ (0.1,0) [0|0] "" DBG
    41   SG_ SENSOR_SONARS_no_filt_middle m1 : 28|12@1+ (0.1,0) [0|0] "" DBG
    42   SG_ SENSOR_SONARS_no_filt_right m1 : 40|12@1+ (0.1,0) [0|0] "" DBG
    43   SG_ SENSOR_SONARS_no_filt_rear m1 : 52|12@1+ (0.1,0) [0|0] "" DBG
    44  			`,
    45  			Diagnostics: []*analysis.Diagnostic{
    46  				{
    47  					Pos:     scanner.Position{Line: 3, Column: 2},
    48  					Message: "more than one multiplexer switch",
    49  				},
    50  			},
    51  		},
    52  
    53  		{
    54  			Name: "signed multiplexer switch",
    55  			Data: `
    56  BO_ 200 SENSOR_SONARS: 8 SENSOR
    57   SG_ SENSOR_SONARS_mux M : 0|4@1- (1,0) [0|0] "" DRIVER,IO
    58   SG_ SENSOR_SONARS_err_count : 4|12@1+ (1,0) [0|0] "" DRIVER,IO
    59   SG_ SENSOR_SONARS_left m0 : 16|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    60   SG_ SENSOR_SONARS_middle m0 : 28|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    61   SG_ SENSOR_SONARS_right m0 : 40|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    62   SG_ SENSOR_SONARS_rear m0 : 52|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    63   SG_ SENSOR_SONARS_no_filt_left m1 : 16|12@1+ (0.1,0) [0|0] "" DBG
    64   SG_ SENSOR_SONARS_no_filt_middle m1 : 28|12@1+ (0.1,0) [0|0] "" DBG
    65   SG_ SENSOR_SONARS_no_filt_right m1 : 40|12@1+ (0.1,0) [0|0] "" DBG
    66   SG_ SENSOR_SONARS_no_filt_rear m1 : 52|12@1+ (0.1,0) [0|0] "" DBG
    67  			`,
    68  			Diagnostics: []*analysis.Diagnostic{
    69  				{
    70  					Pos:     scanner.Position{Line: 2, Column: 2},
    71  					Message: "signed multiplexer switch",
    72  				},
    73  			},
    74  		},
    75  
    76  		{
    77  			Name: "no multiplexer switch",
    78  			Data: `
    79  BO_ 200 SENSOR_SONARS: 8 SENSOR
    80   SG_ SENSOR_SONARS_err_count : 4|12@1+ (1,0) [0|0] "" DRIVER,IO
    81   SG_ SENSOR_SONARS_left m0 : 16|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    82  			`,
    83  			Diagnostics: []*analysis.Diagnostic{
    84  				{
    85  					Pos:     scanner.Position{Line: 3, Column: 2},
    86  					Message: "no multiplexer switch for multiplexed signal",
    87  				},
    88  			},
    89  		},
    90  
    91  		{
    92  			Name: "too big multiplexer switch",
    93  			Data: `
    94  BO_ 200 SENSOR_SONARS: 8 SENSOR
    95   SG_ SENSOR_SONARS_mux M : 0|4@1+ (1,0) [0|0] "" DRIVER,IO
    96   SG_ SENSOR_SONARS_err_count : 4|12@1+ (1,0) [0|0] "" DRIVER,IO
    97   SG_ SENSOR_SONARS_left m16 : 16|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    98   SG_ SENSOR_SONARS_middle m0 : 28|12@1+ (0.1,0) [0|0] "" DRIVER,IO
    99   SG_ SENSOR_SONARS_right m0 : 40|12@1+ (0.1,0) [0|0] "" DRIVER,IO
   100   SG_ SENSOR_SONARS_rear m0 : 52|12@1+ (0.1,0) [0|0] "" DRIVER,IO
   101   SG_ SENSOR_SONARS_no_filt_left m1 : 16|12@1+ (0.1,0) [0|0] "" DBG
   102   SG_ SENSOR_SONARS_no_filt_middle m1 : 28|12@1+ (0.1,0) [0|0] "" DBG
   103   SG_ SENSOR_SONARS_no_filt_right m1 : 40|12@1+ (0.1,0) [0|0] "" DBG
   104   SG_ SENSOR_SONARS_no_filt_rear m1 : 52|12@1+ (0.1,0) [0|0] "" DBG
   105  			`,
   106  			Diagnostics: []*analysis.Diagnostic{
   107  				{
   108  					Pos:     scanner.Position{Line: 4, Column: 2},
   109  					Message: "multiplexer switch exceeds max value: 15",
   110  				},
   111  			},
   112  		},
   113  	})
   114  }