Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add mmvdump and more client tests #18

Merged
merged 17 commits into from Jul 28, 2016
View
@@ -436,3 +436,58 @@ func TestWritingInstanceMetric(t *testing.T) {
t.Errorf("expected a string at offset %v", off)
}
}
+
+func TestStringValueWriting(t *testing.T) {
+ c, err := NewPCPClient("test", ProcessFlag)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ metric := c.MustRegisterString("test.str", "kirk", CounterSemantics, StringType, OneUnit)
+ c.MustStart()
+ defer c.MustStop()
+
+ h, _, _, v, _, _, s, err := mmvdump.Dump(c.buffer.Bytes())
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ if h.Toc != 3 {
+ t.Errorf("expected toc to be 3, not %v", h.Toc)
+ }
+
+ sm := metric.(*PCPSingletonMetric)
+
+ if val, ok := v[uint64(sm.valueoffset)]; !ok {
+ t.Errorf("expected value at %v", sm.valueoffset)
+ } else {
+ add := uint64(val.Extra)
+ if str, ok := s[add]; !ok {
+ t.Errorf("expected a string at address %v", add)
+ } else {
+ if v := string(str.Payload[:4]); v != "kirk" {
+ t.Errorf("expected metric value to be kirk, not %v", v)
+ }
+ }
+ }
+
+ sm.Set("spock")
+
+ _, _, _, v, _, _, s, err = mmvdump.Dump(c.buffer.Bytes())
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ val := v[uint64(sm.valueoffset)]
+ add := uint64(val.Extra)
+ if str, ok := s[add]; !ok {
+ t.Errorf("expected a string at address %v", add)
+ } else {
+ if v := string(str.Payload[:5]); v != "spock" {
+ t.Errorf("expected metric value to be spock, not %v", v)
+ }
+ }
+}
@@ -81,7 +81,11 @@ func printValue(offset uint64) {
if m.Typ != mmvdump.StringType {
a, err = mmvdump.FixedVal(v.Val, m.Typ)
} else {
- a, err = mmvdump.StringVal(v.Val, strings)
+ v, ok := strings[uint64(v.Extra)]
+ if !ok {
+ panic("invalid string address")
+ }
+ a = string(v.Payload[:])
}
if m.Indom != mmvdump.NoIndom {
View
@@ -226,13 +226,3 @@ func FixedVal(data uint64, t Type) (interface{}, error) {
return nil, errors.New("invalid type")
}
-
-// StringVal will infer the string corresponding to an address
-func StringVal(data uint64, strings map[uint64]*String) (string, error) {
- str, ok := strings[data]
- if !ok {
- return "", errors.New("invalid string address")
- }
-
- return string(str.Payload[:]), nil
-}
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.