File: proc_unexported_test.go

package info (click to toggle)
delve 1.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,136 kB
  • sloc: ansic: 111,947; sh: 194; asm: 147; makefile: 43; python: 23
file content (98 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
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
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
package proc

import (
	"testing"
)

func TestAlignAddr(t *testing.T) {
	c := func(align, in, tgt int64) {
		out := alignAddr(in, align)
		if out != tgt {
			t.Errorf("alignAddr(%x, %x) = %x, expected %x", in, align, out, tgt)
		}
	}

	for i := int64(0); i <= 0xf; i++ {
		c(1, i, i)
		c(1, i+0x10000, i+0x10000)
	}

	for _, example := range []struct{ align, in, tgt int64 }{
		{2, 0, 0},
		{2, 1, 2},
		{2, 2, 2},
		{2, 3, 4},
		{2, 4, 4},
		{2, 5, 6},
		{2, 6, 6},
		{2, 7, 8},
		{2, 8, 8},
		{2, 9, 0xa},
		{2, 0xa, 0xa},
		{2, 0xb, 0xc},
		{2, 0xc, 0xc},
		{2, 0xd, 0xe},
		{2, 0xe, 0xe},
		{2, 0xf, 0x10},

		{4, 0, 0},
		{4, 1, 4},
		{4, 2, 4},
		{4, 3, 4},
		{4, 4, 4},
		{4, 5, 8},
		{4, 6, 8},
		{4, 7, 8},
		{4, 8, 8},
		{4, 9, 0xc},
		{4, 0xa, 0xc},
		{4, 0xb, 0xc},
		{4, 0xc, 0xc},
		{4, 0xd, 0x10},
		{4, 0xe, 0x10},
		{4, 0xf, 0x10},

		{8, 0, 0},
		{8, 1, 8},
		{8, 2, 8},
		{8, 3, 8},
		{8, 4, 8},
		{8, 5, 8},
		{8, 6, 8},
		{8, 7, 8},
		{8, 8, 8},
		{8, 9, 0x10},
		{8, 0xa, 0x10},
		{8, 0xb, 0x10},
		{8, 0xc, 0x10},
		{8, 0xd, 0x10},
		{8, 0xe, 0x10},
		{8, 0xf, 0x10},
	} {
		c(example.align, example.in, example.tgt)
		c(example.align, example.in+0x10000, example.tgt+0x10000)
	}
}

func TestConvertInt(t *testing.T) {
	var testCases = []struct {
		in     uint64
		signed bool
		size   int64
		tgt    uint64
	}{
		{1, false, 1, 1},
		{uint64(0xf0), true, 1, 0xfffffffffffffff0},
		{uint64(0xf0), false, 1, 0xf0},
		{uint64(0x70), true, 1, 0x70},
		{uint64(0x90f0), true, 2, 0xffffffffffff90f0},
		{uint64(0x90f0), false, 2, 0x90f0},
	}
	for _, tc := range testCases {
		out := convertInt(tc.in, tc.signed, tc.size)
		t.Logf("in=%#016x signed=%v size=%d -> %#016x\n", tc.in, tc.signed, tc.size, out)
		if out != tc.tgt {
			t.Errorf("expected=%#016x got=%#016x\n", tc.tgt, out)
		}
	}
}