@@ -19,6 +19,7 @@ import (
19
19
"os"
20
20
"path/filepath"
21
21
"reflect"
22
+ "runtime"
22
23
"sort"
23
24
"testing"
24
25
@@ -426,11 +427,113 @@ func TestTopologyWithNodesWithoutCPU(t *testing.T) {
426
427
}
427
428
428
429
func TestTopologyOnSystemZ (t * testing.T ) {
429
- machineArch = "s390" // overwrite package variable
430
- nodes , cores , err := GetTopology (& fakesysfs.FakeSysFs {})
431
- assert .Nil (t , err )
432
- assert .Nil (t , nodes )
433
- assert .NotNil (t , cores )
430
+ if runtime .GOARCH != "s390x" {
431
+ t .Skip ("skipping TestTopologyOnSystemZ due to wrong architecture" )
432
+ } else {
433
+ machineArch = "s390" // overwrite package variable
434
+ sysFs := & fakesysfs.FakeSysFs {}
435
+
436
+ c := sysfs.CacheInfo {
437
+ Id : 0 ,
438
+ Size : 128 * 1024 ,
439
+ Type : "Data" ,
440
+ Level : 0 ,
441
+ Cpus : 2 ,
442
+ }
443
+ sysFs .SetCacheInfo (c )
444
+
445
+ nodesPaths := []string {}
446
+ sysFs .SetNodesPaths (nodesPaths , nil )
447
+
448
+ cpusPaths := map [string ][]string {
449
+ "/sys/devices/system/cpu" : {
450
+ "/sys/devices/system/cpu/cpu0" ,
451
+ "/sys/devices/system/cpu/cpu1" ,
452
+ "/sys/devices/system/cpu/cpu2" ,
453
+ "/sys/devices/system/cpu/cpu3" ,
454
+ },
455
+ }
456
+ sysFs .SetCPUsPaths (cpusPaths , nil )
457
+
458
+ coreThread := map [string ]string {
459
+ "/sys/devices/system/cpu/cpu0" : "0" ,
460
+ "/sys/devices/system/cpu/cpu1" : "1" ,
461
+ "/sys/devices/system/cpu/cpu2" : "0" ,
462
+ "/sys/devices/system/cpu/cpu3" : "1" ,
463
+ }
464
+ sysFs .SetCoreThreads (coreThread , nil )
465
+
466
+ physicalPackageIDs := map [string ]string {
467
+ "/sys/devices/system/cpu/cpu0" : "0" ,
468
+ "/sys/devices/system/cpu/cpu1" : "1" ,
469
+ "/sys/devices/system/cpu/cpu2" : "0" ,
470
+ "/sys/devices/system/cpu/cpu3" : "1" ,
471
+ }
472
+ sysFs .SetPhysicalPackageIDs (physicalPackageIDs , nil )
473
+
474
+ bookIDs := map [string ]string {
475
+ "/sys/devices/system/cpu/cpu0" : "1" ,
476
+ "/sys/devices/system/cpu/cpu1" : "1" ,
477
+ "/sys/devices/system/cpu/cpu2" : "1" ,
478
+ "/sys/devices/system/cpu/cpu3" : "1" ,
479
+ }
480
+ sysFs .SetBookIDs (bookIDs , nil )
481
+
482
+ drawerIDs := map [string ]string {
483
+ "/sys/devices/system/cpu/cpu0" : "0" ,
484
+ "/sys/devices/system/cpu/cpu1" : "0" ,
485
+ "/sys/devices/system/cpu/cpu2" : "0" ,
486
+ "/sys/devices/system/cpu/cpu3" : "0" ,
487
+ }
488
+ sysFs .SetDrawerIDs (drawerIDs , nil )
489
+
490
+ topology , numCores , err := GetTopology (sysFs )
491
+ assert .Nil (t , err )
492
+ assert .Equal (t , 2 , len (topology ))
493
+ assert .Equal (t , 4 , numCores )
494
+
495
+ topologyJSON1 , err := json .Marshal (topology [0 ])
496
+ assert .Nil (t , err )
497
+ topologyJSON2 , err := json .Marshal (topology [1 ])
498
+ assert .Nil (t , err )
499
+
500
+ expectedTopology1 := `{"node_id":0,"memory":0,"hugepages":null,"distances":null,"cores":[{"core_id":0,"thread_ids":[0,2],"caches":[{"id":0, "size":131072,"type":"Data","level":0}], "socket_id": 0, "book_id":"1", "drawer_id":"0", "uncore_caches":null}],"caches":null}`
501
+ expectedTopology2 := `
502
+ {
503
+ "node_id":1,
504
+ "memory":0,
505
+ "hugepages":null,
506
+ "distances": null,
507
+ "cores":[
508
+ {
509
+ "core_id":1,
510
+ "thread_ids":[
511
+ 1,
512
+ 3
513
+ ],
514
+ "caches":[
515
+ {
516
+ "id": 0,
517
+ "size":131072,
518
+ "type":"Data",
519
+ "level":0
520
+ }
521
+ ],
522
+ "socket_id": 1,
523
+ "book_id": "1",
524
+ "drawer_id": "0",
525
+ "uncore_caches": null
526
+ }
527
+ ],
528
+ "caches":null
529
+ }`
530
+
531
+ json1 := string (topologyJSON1 )
532
+ json2 := string (topologyJSON2 )
533
+
534
+ assert .JSONEq (t , expectedTopology1 , json1 )
535
+ assert .JSONEq (t , expectedTopology2 , json2 )
536
+ }
434
537
}
435
538
436
539
func TestMemoryInfo (t * testing.T ) {
0 commit comments