...

Source file src/edge-infra.dev/pkg/sds/display/k8s/apis/v2/defaults_test.go

Documentation: edge-infra.dev/pkg/sds/display/k8s/apis/v2

     1  package v2
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  var (
    11  	ncr1234  = MPID("NCR-1234")
    12  	ncr5678  = MPID("NCR-5678")
    13  	ncr30578 = MPID("NCR-30578")
    14  	ncr22800 = MPID("NCR-22800")
    15  
    16  	disabledDPMS = &DPMS{
    17  		Enabled:     &dpmsDisabled,
    18  		BlankTime:   &zeroSeconds,
    19  		StandbyTime: &zeroSeconds,
    20  		SuspendTime: &zeroSeconds,
    21  		OffTime:     &zeroSeconds,
    22  	}
    23  )
    24  
    25  func TestApplyDefaults(t *testing.T) {
    26  	tcs := []struct {
    27  		displayConfig  *DisplayConfig
    28  		inputDevices   []InputDeviceName
    29  		expectedResult *DisplayConfig
    30  	}{
    31  		{
    32  			// test case 1:
    33  			// default DPMS should be added
    34  			displayConfig: &DisplayConfig{},
    35  			inputDevices:  []InputDeviceName{},
    36  			expectedResult: &DisplayConfig{
    37  				DPMS: disabledDPMS,
    38  			},
    39  		},
    40  		{
    41  			// test case 2:
    42  			// DPMS should be overwritten with defaults
    43  			displayConfig: &DisplayConfig{
    44  				DPMS: &DPMS{
    45  					BlankTime:   &thirtySeconds,
    46  					StandbyTime: &sixtySeconds,
    47  					OffTime:     &oneTwentySeconds,
    48  				},
    49  			},
    50  			inputDevices: []InputDeviceName{},
    51  			expectedResult: &DisplayConfig{
    52  				DPMS: disabledDPMS,
    53  			},
    54  		},
    55  		{
    56  			// test case 3:
    57  			// default display should overwrite orientation
    58  			// first display should be primary
    59  			displayConfig: &DisplayConfig{
    60  				Displays: []Display{
    61  					{
    62  						DisplayPort: "card0-HDMI1",
    63  						MPID:        &ncr1234,
    64  						Orientation: &NormalOrientation,
    65  					},
    66  					{
    67  						DisplayPort: "card0-HDMI2",
    68  						MPID:        &ncr5678,
    69  						Orientation: &InvertedOrientation,
    70  					},
    71  				},
    72  			},
    73  			inputDevices: []InputDeviceName{},
    74  			expectedResult: &DisplayConfig{
    75  				Displays: []Display{
    76  					{
    77  						DisplayPort: "card0-HDMI1",
    78  						MPID:        &ncr1234,
    79  						Primary:     &primary,
    80  						Orientation: &NormalOrientation,
    81  					},
    82  					{
    83  						DisplayPort: "card0-HDMI2",
    84  						MPID:        &ncr5678,
    85  						Primary:     &notPrimary,
    86  						Orientation: &NormalOrientation,
    87  					},
    88  				},
    89  				DPMS: disabledDPMS,
    90  			},
    91  		},
    92  		{
    93  			// test case 4:
    94  			// first display in layout should be primary
    95  			displayConfig: &DisplayConfig{
    96  				Displays: []Display{
    97  					{
    98  						DisplayPort: "card0-HDMI1",
    99  						MPID:        &ncr1234,
   100  						Primary:     &primary,
   101  					},
   102  					{
   103  						DisplayPort: "card0-HDMI2",
   104  						MPID:        &ncr5678,
   105  						Primary:     &notPrimary,
   106  					},
   107  				},
   108  				Layout: Layout{"card0-HDMI2", "card0-HDMI1"},
   109  			},
   110  			inputDevices: []InputDeviceName{},
   111  			expectedResult: &DisplayConfig{
   112  				Displays: []Display{
   113  					{
   114  						DisplayPort: "card0-HDMI1",
   115  						MPID:        &ncr1234,
   116  						Primary:     &notPrimary,
   117  						Orientation: &NormalOrientation,
   118  					},
   119  					{
   120  						DisplayPort: "card0-HDMI2",
   121  						MPID:        &ncr5678,
   122  						Primary:     &primary,
   123  						Orientation: &NormalOrientation,
   124  					},
   125  				},
   126  				Layout: Layout{"card0-HDMI2", "card0-HDMI1"},
   127  				DPMS:   disabledDPMS,
   128  			},
   129  		},
   130  		{
   131  			// test case 5:
   132  			// match for single input device in list
   133  			displayConfig: &DisplayConfig{
   134  				Displays: []Display{
   135  					{
   136  						DisplayPort: "card0-HDMI1",
   137  						MPID:        &wnx32,
   138  						Primary:     &primary,
   139  						Orientation: &InvertedOrientation,
   140  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   141  					},
   142  					{
   143  						DisplayPort: "card0-DP1",
   144  						MPID:        &ncr1234,
   145  						Orientation: &LeftOrientation,
   146  						Resolution:  &Resolution{Width: 800, Height: 600},
   147  					},
   148  				},
   149  				Layout: Layout{"card0-DP1"},
   150  			},
   151  			inputDevices: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse", "eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216", "Advanced Silicon S.A. CoolTouch® System"},
   152  			expectedResult: &DisplayConfig{
   153  				Displays: []Display{
   154  					{
   155  						DisplayPort: "card0-HDMI1",
   156  						MPID:        &wnx32,
   157  						Primary:     &notPrimary,
   158  						Orientation: &NormalOrientation,
   159  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   160  						InputDeviceMappings: []InputDeviceName{
   161  							"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse",
   162  						},
   163  					},
   164  					{
   165  						DisplayPort: "card0-DP1",
   166  						MPID:        &ncr1234,
   167  						Primary:     &primary,
   168  						Orientation: &NormalOrientation,
   169  						Resolution:  &Resolution{Width: 800, Height: 600},
   170  					},
   171  				},
   172  				Layout: Layout{"card0-DP1"},
   173  				DPMS:   disabledDPMS,
   174  			},
   175  		},
   176  		{
   177  			// test case 6:
   178  			// match for multiple input devices in list
   179  			displayConfig: &DisplayConfig{
   180  				Displays: []Display{
   181  					{
   182  						DisplayPort: "card0-HDMI1",
   183  						MPID:        &ncr30578,
   184  						Primary:     &primary,
   185  						Orientation: &InvertedOrientation,
   186  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   187  					},
   188  					{
   189  						DisplayPort: "card0-DP1",
   190  						MPID:        &ncr1234,
   191  						Orientation: &LeftOrientation,
   192  						Resolution:  &Resolution{Width: 800, Height: 600},
   193  					},
   194  				},
   195  				Layout: Layout{"card0-DP1"},
   196  			},
   197  			inputDevices: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse", "Advanced Silicon S.A. CoolTouch® System", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse"},
   198  			expectedResult: &DisplayConfig{
   199  				Displays: []Display{
   200  					{
   201  						DisplayPort: "card0-HDMI1",
   202  						MPID:        &ncr30578,
   203  						Primary:     &notPrimary,
   204  						Orientation: &NormalOrientation,
   205  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   206  						InputDeviceMappings: []InputDeviceName{
   207  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146",
   208  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse",
   209  						},
   210  					},
   211  					{
   212  						DisplayPort: "card0-DP1",
   213  						MPID:        &ncr1234,
   214  						Primary:     &primary,
   215  						Orientation: &NormalOrientation,
   216  						Resolution:  &Resolution{Width: 800, Height: 600},
   217  					},
   218  				},
   219  				Layout: Layout{"card0-DP1"},
   220  				DPMS:   disabledDPMS,
   221  			},
   222  		},
   223  		{
   224  			// test case 7:
   225  			// no matches for devices in list
   226  			displayConfig: &DisplayConfig{
   227  				Displays: []Display{
   228  					{
   229  						DisplayPort: "card0-HDMI1",
   230  						MPID:        &wnx32,
   231  						Primary:     &primary,
   232  						Orientation: &InvertedOrientation,
   233  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   234  					},
   235  					{
   236  						DisplayPort: "card0-DP1",
   237  						MPID:        &ncr1234,
   238  						Orientation: &LeftOrientation,
   239  						Resolution:  &Resolution{Width: 800, Height: 600},
   240  					},
   241  				},
   242  				Layout: Layout{"card0-DP1"},
   243  			},
   244  			inputDevices: []InputDeviceName{"eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216", "Advanced Silicon S.A. CoolTouch® System"},
   245  			expectedResult: &DisplayConfig{
   246  				Displays: []Display{
   247  					{
   248  						DisplayPort:         "card0-HDMI1",
   249  						MPID:                &wnx32,
   250  						Primary:             &notPrimary,
   251  						Orientation:         &NormalOrientation,
   252  						Resolution:          &Resolution{Width: 1920, Height: 1080},
   253  						InputDeviceMappings: []InputDeviceName{},
   254  					},
   255  					{
   256  						DisplayPort: "card0-DP1",
   257  						MPID:        &ncr1234,
   258  						Primary:     &primary,
   259  						Orientation: &NormalOrientation,
   260  						Resolution:  &Resolution{Width: 800, Height: 600},
   261  					},
   262  				},
   263  				Layout: Layout{"card0-DP1"},
   264  				DPMS:   disabledDPMS,
   265  			},
   266  		},
   267  		{
   268  			// test case 8:
   269  			// display config already has input device before defaults are applied - no additional input added
   270  			displayConfig: &DisplayConfig{
   271  				Displays: []Display{
   272  					{
   273  						DisplayPort:         "card0-HDMI1",
   274  						MPID:                &wnx32,
   275  						Primary:             &primary,
   276  						Orientation:         &InvertedOrientation,
   277  						Resolution:          &Resolution{Width: 1920, Height: 1080},
   278  						InputDeviceMappings: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse"},
   279  					},
   280  					{
   281  						DisplayPort: "card0-DP1",
   282  						MPID:        &ncr1234,
   283  						Orientation: &LeftOrientation,
   284  						Resolution:  &Resolution{Width: 800, Height: 600},
   285  					},
   286  				},
   287  				Layout: Layout{"card0-DP1"},
   288  			},
   289  			inputDevices: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse", "eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216", "Advanced Silicon S.A. CoolTouch® System"},
   290  			expectedResult: &DisplayConfig{
   291  				Displays: []Display{
   292  					{
   293  						DisplayPort:         "card0-HDMI1",
   294  						MPID:                &wnx32,
   295  						Primary:             &notPrimary,
   296  						Orientation:         &NormalOrientation,
   297  						Resolution:          &Resolution{Width: 1920, Height: 1080},
   298  						InputDeviceMappings: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse"},
   299  					},
   300  					{
   301  						DisplayPort: "card0-DP1",
   302  						MPID:        &ncr1234,
   303  						Primary:     &primary,
   304  						Orientation: &NormalOrientation,
   305  						Resolution:  &Resolution{Width: 800, Height: 600},
   306  					},
   307  				},
   308  				Layout: Layout{"card0-DP1"},
   309  				DPMS:   disabledDPMS,
   310  			},
   311  		},
   312  		{
   313  			// test case 9:
   314  			// display config already has input device before defaults are applied - additional inputs are added
   315  			displayConfig: &DisplayConfig{
   316  				Displays: []Display{
   317  					{
   318  						DisplayPort: "card0-HDMI1",
   319  						MPID:        &ncr30578,
   320  						Primary:     &primary,
   321  						Orientation: &InvertedOrientation,
   322  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   323  						InputDeviceMappings: []InputDeviceName{
   324  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146",
   325  						},
   326  					},
   327  					{
   328  						DisplayPort: "card0-DP1",
   329  						MPID:        &ncr1234,
   330  						Orientation: &LeftOrientation,
   331  						Resolution:  &Resolution{Width: 800, Height: 600},
   332  					},
   333  				},
   334  				Layout: Layout{"card0-DP1"},
   335  			},
   336  			inputDevices: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse", "Advanced Silicon S.A. CoolTouch® System", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse"},
   337  			expectedResult: &DisplayConfig{
   338  				Displays: []Display{
   339  					{
   340  						DisplayPort: "card0-HDMI1",
   341  						MPID:        &ncr30578,
   342  						Primary:     &notPrimary,
   343  						Orientation: &NormalOrientation,
   344  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   345  						InputDeviceMappings: []InputDeviceName{
   346  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146",
   347  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse",
   348  						},
   349  					},
   350  					{
   351  						DisplayPort: "card0-DP1",
   352  						MPID:        &ncr1234,
   353  						Primary:     &primary,
   354  						Orientation: &NormalOrientation,
   355  						Resolution:  &Resolution{Width: 800, Height: 600},
   356  					},
   357  				},
   358  				Layout: Layout{"card0-DP1"},
   359  				DPMS:   disabledDPMS,
   360  			},
   361  		},
   362  		{
   363  			// test case 10:
   364  			// multiple displays and input devices - single match
   365  			displayConfig: &DisplayConfig{
   366  				Displays: []Display{
   367  					{
   368  						DisplayPort: "card0-HDMI1",
   369  						MPID:        &ncr30578,
   370  						Primary:     &primary,
   371  						Orientation: &InvertedOrientation,
   372  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   373  					},
   374  					{
   375  						DisplayPort: "card0-DP1",
   376  						MPID:        &wnx32,
   377  						Orientation: &InvertedOrientation,
   378  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   379  					},
   380  				},
   381  				Layout: Layout{"card0-DP1"},
   382  			},
   383  			inputDevices: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse", "Advanced Silicon S.A. CoolTouch® System", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146"},
   384  			expectedResult: &DisplayConfig{
   385  				Displays: []Display{
   386  					{
   387  						DisplayPort:         "card0-HDMI1",
   388  						MPID:                &ncr30578,
   389  						Primary:             &notPrimary,
   390  						Orientation:         &NormalOrientation,
   391  						Resolution:          &Resolution{Width: 1920, Height: 1080},
   392  						InputDeviceMappings: []InputDeviceName{"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146"},
   393  					},
   394  					{
   395  						DisplayPort:         "card0-DP1",
   396  						MPID:                &wnx32,
   397  						Primary:             &primary,
   398  						Orientation:         &NormalOrientation,
   399  						Resolution:          &Resolution{Width: 1920, Height: 1080},
   400  						InputDeviceMappings: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse"},
   401  					},
   402  				},
   403  				Layout: Layout{"card0-DP1"},
   404  				DPMS:   disabledDPMS,
   405  			},
   406  		},
   407  		{
   408  			// test case 11:
   409  			// multiple displays and input devices - multiple matches
   410  			displayConfig: &DisplayConfig{
   411  				Displays: []Display{
   412  					{
   413  						DisplayPort: "card0-HDMI1",
   414  						MPID:        &ncr30578,
   415  						Primary:     &primary,
   416  						Orientation: &InvertedOrientation,
   417  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   418  					},
   419  					{
   420  						DisplayPort: "card0-DP1",
   421  						MPID:        &ncr22800,
   422  						Orientation: &InvertedOrientation,
   423  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   424  					},
   425  				},
   426  				Layout: Layout{"card0-DP1"},
   427  			},
   428  			inputDevices: []InputDeviceName{"Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse", "eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00", "eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00 UNKNOWN", "Advanced Silicon S.A. CoolTouch® System", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146", "eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse"},
   429  			expectedResult: &DisplayConfig{
   430  				Displays: []Display{
   431  					{
   432  						DisplayPort: "card0-HDMI1",
   433  						MPID:        &ncr30578,
   434  						Primary:     &notPrimary,
   435  						Orientation: &NormalOrientation,
   436  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   437  						InputDeviceMappings: []InputDeviceName{
   438  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146",
   439  							"eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse",
   440  						},
   441  					},
   442  					{
   443  						DisplayPort: "card0-DP1",
   444  						MPID:        &ncr22800,
   445  						Primary:     &primary,
   446  						Orientation: &NormalOrientation,
   447  						Resolution:  &Resolution{Width: 1920, Height: 1080},
   448  						InputDeviceMappings: []InputDeviceName{
   449  							"eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00",
   450  							"eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00 UNKNOWN",
   451  						},
   452  					},
   453  				},
   454  				Layout: Layout{"card0-DP1"},
   455  				DPMS:   disabledDPMS,
   456  			},
   457  		},
   458  	}
   459  	for idx, tc := range tcs {
   460  		result, err := tc.displayConfig.GenerateDefaultDisplayConfig(Defaults, tc.inputDevices)
   461  		require.NoError(t, err, fmt.Sprintf("test case %d failed", idx+1))
   462  		require.Equal(t, tc.expectedResult, result, fmt.Sprintf("test case %d failed", idx+1))
   463  	}
   464  }
   465  

View as plain text