isolated_device_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. )
  19. func Test_parseLspci(t *testing.T) {
  20. type args struct {
  21. line string
  22. }
  23. tests := []struct {
  24. name string
  25. args args
  26. want *PCIDevice
  27. }{
  28. {
  29. name: "3D controller",
  30. args: args{`02:00.0 "3D controller [0302]" "NVIDIA Corporation [10de]" "GM108M [GeForce 940MX] [134d]" -ra2 "Lenovo [17aa]" "GM108M [GeForce 940MX] [505e]`},
  31. want: &PCIDevice{
  32. Addr: "02:00.0",
  33. ClassName: "3D controller",
  34. ClassCode: "0302",
  35. VendorName: "NVIDIA Corporation",
  36. VendorId: "10de",
  37. DeviceName: "GM108M [GeForce 940MX]",
  38. DeviceId: "134d",
  39. SubvendorName: "Lenovo",
  40. SubvendorId: "17aa",
  41. SubdeviceName: "GM108M [GeForce 940MX]",
  42. SubdeviceId: "505e",
  43. ModelName: "GeForce 940MX",
  44. },
  45. },
  46. {
  47. name: "VGA",
  48. args: args{`05:00.0 "VGA compatible controller [0300]" "Advanced Micro Devices, Inc. [AMD/ATI] [1002]" "Oland [Radeon HD 8570 / R7 240/340 OEM] [6611]" "Dell [1028]" "Radeon R5 240 OEM [210b]"`},
  49. want: &PCIDevice{
  50. Addr: "05:00.0",
  51. ClassName: "VGA compatible controller",
  52. ClassCode: "0300",
  53. VendorName: "Advanced Micro Devices, Inc. [AMD/ATI]",
  54. VendorId: "1002",
  55. DeviceName: "Oland [Radeon HD 8570 / R7 240/340 OEM]",
  56. DeviceId: "6611",
  57. SubvendorName: "Dell",
  58. SubvendorId: "1028",
  59. SubdeviceName: "Radeon R5 240 OEM",
  60. SubdeviceId: "210b",
  61. ModelName: "Radeon HD 8570 / R7 240/340 OEM",
  62. },
  63. },
  64. }
  65. for _, tt := range tests {
  66. t.Run(tt.name, func(t *testing.T) {
  67. if got := parseLspci(tt.args.line); !reflect.DeepEqual(got, tt.want) {
  68. t.Errorf("parseLspci() = %#v, want %#v", got, tt.want)
  69. }
  70. })
  71. }
  72. }