gpu_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 isolated_device
  15. import (
  16. "reflect"
  17. "testing"
  18. api "yunion.io/x/onecloud/pkg/apis/compute"
  19. )
  20. func Test_parsePCIELinkCap(t *testing.T) {
  21. tests := []struct {
  22. line string
  23. want *api.IsolatedDevicePCIEInfo
  24. wantErr bool
  25. }{
  26. {
  27. line: `LnkCap: Port #0, Speed 2.5GT/s, Width x16, ASPM L0s L1, Exit Latency L0s <1us, L1 <4us`,
  28. want: &api.IsolatedDevicePCIEInfo{
  29. TransferRatePerLane: "2.5GT/s",
  30. LaneWidth: 16,
  31. Version: api.PCIEVersion1,
  32. Throughput: "4.00 GB/s",
  33. },
  34. wantErr: false,
  35. },
  36. {
  37. line: ` LnkCap: Port #0, Speed 8GT/s, Width x16, ASPM L0s L1, Exit Latency L0s <1us, L1 <4us`,
  38. want: &api.IsolatedDevicePCIEInfo{
  39. TransferRatePerLane: "8GT/s",
  40. LaneWidth: 16,
  41. Version: api.PCIEVersion3,
  42. Throughput: "15.76 GB/s",
  43. },
  44. wantErr: false,
  45. },
  46. {
  47. line: ` LnkCap: Port #0, Speed 16GT/s, Width x4, ASPM L0s L1, Exit Latency L0s <1us, L1 <4us`,
  48. want: &api.IsolatedDevicePCIEInfo{
  49. TransferRatePerLane: "16GT/s",
  50. LaneWidth: 4,
  51. Version: api.PCIEVersion4,
  52. Throughput: "7.88 GB/s",
  53. },
  54. wantErr: false,
  55. },
  56. {
  57. line: ``,
  58. want: nil,
  59. wantErr: true,
  60. },
  61. }
  62. for _, tt := range tests {
  63. t.Run(tt.line, func(t *testing.T) {
  64. got, err := parsePCIELinkCap(tt.line)
  65. if (err != nil) != tt.wantErr {
  66. t.Errorf("parsePCIELinkCap() error = %v, wantErr %v", err, tt.wantErr)
  67. return
  68. }
  69. if !reflect.DeepEqual(got, tt.want) {
  70. t.Errorf("parsePCIELinkCap() = %v, want %v", got, tt.want)
  71. }
  72. })
  73. }
  74. }