|
| 1 | +package slurm_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/CLIP-HPC/SlurmCommander/internal/slurm" |
| 8 | +) |
| 9 | + |
| 10 | +type gresTest []struct { |
| 11 | + testName string |
| 12 | + input string |
| 13 | + expect int |
| 14 | + expectMap slurm.GresMap |
| 15 | +} |
| 16 | + |
| 17 | +var ( |
| 18 | + gresTestTable = gresTest{ |
| 19 | + { |
| 20 | + testName: "GRES-empty", |
| 21 | + input: "", |
| 22 | + expect: 0, |
| 23 | + expectMap: slurm.GresMap{}, |
| 24 | + }, |
| 25 | + { |
| 26 | + testName: "GRES-junk: asdf123:123:123:123", |
| 27 | + input: "asdf123:123:123:123", |
| 28 | + expect: 0, |
| 29 | + expectMap: slurm.GresMap{}, |
| 30 | + }, |
| 31 | + { |
| 32 | + testName: "GRES-simple: gpu:8(S:0-1)", |
| 33 | + input: "gpu:8(S:0-1)", |
| 34 | + expect: 8, |
| 35 | + expectMap: slurm.GresMap{"": 8}, |
| 36 | + }, |
| 37 | + { |
| 38 | + testName: "GRES: gpu:P100:8(S:0-1)", |
| 39 | + input: "gpu:P100:8(S:0-1)", |
| 40 | + expect: 8, |
| 41 | + expectMap: slurm.GresMap{"P100": 8}, |
| 42 | + }, |
| 43 | + { |
| 44 | + testName: "GRES_USED: gpu:P100:2(IDX:3,7)", |
| 45 | + input: "gpu:P100:2(IDX:3,7)", |
| 46 | + expect: 2, |
| 47 | + expectMap: slurm.GresMap{"P100": 2}, |
| 48 | + }, |
| 49 | + { |
| 50 | + testName: "GRES: gpu:p100:6(S:0),gpu:rtx:2(S:0)", |
| 51 | + input: "gpu:p100:6(S:0),gpu:rtx:2(S:0)", |
| 52 | + expect: 8, |
| 53 | + expectMap: slurm.GresMap{"p100": 6, "rtx": 2}, |
| 54 | + }, |
| 55 | + { |
| 56 | + testName: "GRES_USED: gpu:p100:0(IDX:N/A),gpu:rtx:0(IDX:N/A)", |
| 57 | + input: "gpu:p100:0(IDX:N/A),gpu:rtx:0(IDX:N/A)", |
| 58 | + expect: 0, |
| 59 | + expectMap: slurm.GresMap{"p100": 0, "rtx": 0}, |
| 60 | + }, |
| 61 | + { |
| 62 | + testName: "GRES_USED: gpu:p100:2(IDX:0-1),gpu:rtx:1(IDX:7)", |
| 63 | + input: "gpu:p100:2(IDX:0-1),gpu:rtx:1(IDX:7)", |
| 64 | + expect: 3, |
| 65 | + expectMap: slurm.GresMap{"p100": 2, "rtx": 1}, |
| 66 | + }, |
| 67 | + } |
| 68 | +) |
| 69 | + |
| 70 | +func TestParseGRES(t *testing.T) { |
| 71 | + for i, v := range gresTestTable { |
| 72 | + t.Logf("Running test %d : %q\n", i, v.testName) |
| 73 | + rez := *slurm.ParseGRES(v.input) |
| 74 | + t.Logf("Expect: %d Got: %d\n", v.expect, rez) |
| 75 | + if rez != v.expect { |
| 76 | + t.Fatal("FAILED !!!") |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +func TestParseGRESAll(t *testing.T) { |
| 82 | + for i, v := range gresTestTable { |
| 83 | + t.Logf("Running test %d : %q\n", i, v.testName) |
| 84 | + rez := *slurm.ParseGRESAll(v.input) |
| 85 | + t.Logf("Expect: %#v Got: %#v\n", v.expectMap, rez) |
| 86 | + if !reflect.DeepEqual(rez, v.expectMap) { |
| 87 | + t.Fatal("FAILED !!!") |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments