backend_test.go 3.11 KB
Newer Older
1
2
3
4
package backend

import (
	"encoding/json"
5
6
	"os"
	"strings"
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	"testing"
)

func TestGetOnlineUser(t *testing.T) {
	lui, err := GetOnlineUser()
	if err != nil {
		t.Error(err)
	}
	for _, v := range lui {
		t.Logf("%+v", v)
	}
	bj, err := json.Marshal(lui)
	if err != nil {
		t.Error(err)
	}
	t.Logf("%s", string(bj))
}

func TestUpdateInfo(t *testing.T) {
	Init()
	defer Shutdown()

	err := DCUSInfoMap.UpdateInfo()
	if err != nil {
		t.Error(err)
	}
	info, lock := DCUSInfoMap.GetInfo()
	defer lock.Unlock()
	for k, v := range info {
		t.Logf("%d: %+v", k, v)
	}

}

func TestGetDCULoad(t *testing.T) {
	Init()
	defer Shutdown()
	load, err := GetDCULoad()
	if err != nil {
		t.Error(err)
	}
	for _, v := range load {
		t.Logf("%+v", v)

		b := []byte(v.Name)
		result := make([]byte, 0, len(b))
		for _, v := range b {
			if v != 0 {
				result = append(result, v)
			} else {
				break
			}
		}
		t.Logf("%s", string(result))
		t.Logf("%d", len(result))
	}
}
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

func TestReMetricsLine(t *testing.T) {
	content, err := os.ReadFile("./rccl-test-output.log")
	if err != nil {
		t.Error(err)
	}
	output := string(content)
	output = strings.Trim(output, "\n")
	for _, v := range strings.Split(output, "\n") {
		if ReMetricsLine.MatchString(v) {
			t.Log("match")
			s := ReMetricsLine.FindAllStringSubmatch(output, -1)
			for _, v := range s {
				for i, u := range v {
					t.Logf(" %d: %s", i, u)
				}
			}
		}
	}
}

func TestReRcclVersion(t *testing.T) {
	content, err := os.ReadFile("./rccl-test-output.log")
	if err != nil {
		t.Error(err)
	}
	output := string(content)
	output = strings.Trim(output, "\n")
	if ReRcclVersion.MatchString(output) {
		t.Log("match")
		s := ReRcclVersion.FindAllStringSubmatch(output, -1)
		for _, v := range s {
			for i, u := range v {
				t.Logf(" %d: %s", i, u)
			}
		}
	}
}

func TestReDeviceLine(t *testing.T) {
	content, err := os.ReadFile("./rccl-test-output.log")
	if err != nil {
		t.Error(err)
	}
	output := string(content)
	output = strings.Trim(output, "\n")
	lines := strings.Split(output, "\n")
	for _, v := range lines {
		if ReDeviceLine.MatchString(v) {
			s := ReDeviceLine.FindAllStringSubmatch(v, -1)
			for _, v := range s {
				for i, u := range v {
					t.Logf(" %d: %s", i, u)
				}
			}
		}
	}

}

func TestParseRcclOutput(t *testing.T) {
	content, err := os.ReadFile("./rccl-test-output.log")
	if err != nil {
		t.Error(err)
	}
	output := string(content)
	result := ParseRcclOutput(output)
	if result == nil {
		t.Error("error parse output")
	}
	t.Logf("result: %+v", result)
	if len(result.Results) > 0 {
		for _, v := range result.Results {
			if v == nil {
				continue
			}
			t.Logf(" item: %+v", v)
		}
	}
}

func TestFile(t *testing.T) {
	st, err := os.Stat("/usr/bin/bash")
	if err != nil {
		t.Error(err)
	}
150
	t.Logf("%v", st.Mode().Perm()&0111 > 0)
151
152
153
}

func TestRcclTestCheck(t *testing.T) {
154
	b, err := AllReducePerf("/home/panyq/wangx/rccl-tests/build-dan", "")
155
156
157
158
	if err != nil {
		t.Error(err)
	}
	t.Logf("result: %+v", b)
159
160
161
162
163
164
165
166
167
}

func TestGetRcclDtk(t *testing.T) {
	path, err := GetRcclDtkPath("/home/panyq/wangx/rccl-tests/build-dan", RCCL_ALL_REDUCE)
	if err != nil {
		t.Error(err)
	}
	t.Logf("dtk path: %s", path)
}