isolated_device_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "fmt"
  17. "testing"
  18. )
  19. func TestSIsolatedDevicePCIInfo_GetThroughputPerLane(t *testing.T) {
  20. type fields struct {
  21. TransferRatePerLane string
  22. LaneWidth int
  23. }
  24. tests := []struct {
  25. fields fields
  26. want float64
  27. }{
  28. {
  29. fields{
  30. "2.5GT/s",
  31. 1,
  32. },
  33. 0.25,
  34. },
  35. {
  36. fields{
  37. "2.6GT/s",
  38. 1,
  39. },
  40. -1,
  41. },
  42. {
  43. fields{
  44. "5.0GT/s",
  45. 2,
  46. },
  47. 0.5,
  48. },
  49. {
  50. fields{
  51. "5GT/s",
  52. 2,
  53. },
  54. 0.5,
  55. },
  56. {
  57. fields{
  58. "8GT/s",
  59. 1,
  60. },
  61. 0.985,
  62. },
  63. {
  64. fields{
  65. "16GT/s",
  66. 1,
  67. },
  68. 1.969,
  69. },
  70. {
  71. fields{
  72. "32GT/s",
  73. 1,
  74. },
  75. 3.938,
  76. },
  77. {
  78. fields{
  79. "64GT/s",
  80. 1,
  81. },
  82. 7.563,
  83. },
  84. {
  85. fields{
  86. "128GT/s",
  87. 1,
  88. },
  89. 15.125,
  90. },
  91. }
  92. for _, tt := range tests {
  93. t.Run(fmt.Sprintf("Speed %s, Width x%d", tt.fields.TransferRatePerLane, tt.fields.LaneWidth), func(t *testing.T) {
  94. info := IsolatedDevicePCIEInfo{
  95. TransferRatePerLane: tt.fields.TransferRatePerLane,
  96. LaneWidth: tt.fields.LaneWidth,
  97. }
  98. if got := info.GetThroughputPerLane(); got.Throughput != tt.want {
  99. t.Errorf("SIsolatedDevicePCIInfo.GetThroughputPerLane() = %v, want %v", got, tt.want)
  100. }
  101. })
  102. }
  103. }