This file is indexed.

/usr/share/gocode/src/github.com/klauspost/compress/flate/asm_test.go is in golang-github-klauspost-compress-dev 1.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright 2015, Klaus Post, see LICENSE for details.

//+build amd64

package flate

import (
	"math/rand"
	"testing"
)

func TestCRC(t *testing.T) {
	if !useSSE42 {
		t.Skip("Skipping CRC test, no SSE 4.2 available")
	}
	for _, x := range deflateTests {
		y := x.out
		if len(y) >= minMatchLength {
			t.Logf("In: %v, Out:0x%08x", y[0:minMatchLength], crc32sse(y[0:minMatchLength]))
		}
	}
}

func TestCRCBulk(t *testing.T) {
	if !useSSE42 {
		t.Skip("Skipping CRC test, no SSE 4.2 available")
	}
	for _, x := range deflateTests {
		y := x.out
		y = append(y, y...)
		y = append(y, y...)
		y = append(y, y...)
		y = append(y, y...)
		y = append(y, y...)
		y = append(y, y...)
		if !testing.Short() {
			y = append(y, y...)
			y = append(y, y...)
		}
		y = append(y, 1)
		if len(y) >= minMatchLength {
			for j := len(y) - 1; j >= 4; j-- {

				// Create copy, so we easier detect of-of-bound reads
				test := make([]byte, j)
				test2 := make([]byte, j)
				copy(test, y[:j])
				copy(test2, y[:j])

				// We allocate one more than we need to test for unintentional overwrites
				dst := make([]hash, j-3+1)
				ref := make([]hash, j-3+1)
				for i := range dst {
					dst[i] = hash(i + 100)
					ref[i] = hash(i + 101)
				}
				// Last entry must NOT be overwritten.
				dst[j-3] = 0x1234
				ref[j-3] = 0x1234

				// Do two encodes we can compare
				crc32sseAll(test, dst)
				crc32sseAll(test2, ref)

				// Check all values
				for i, got := range dst {
					if i == j-3 {
						if dst[i] != 0x1234 {
							t.Fatalf("end of expected dst overwritten, was %08x", uint32(dst[i]))
						}
						continue
					}
					expect := crc32sse(y[i : i+4])
					if got != expect && got == hash(i)+100 {
						t.Errorf("Len:%d Index:%d, expected 0x%08x but not modified", len(y), i, uint32(expect))
					} else if got != expect {
						t.Errorf("Len:%d Index:%d, got 0x%08x expected:0x%08x", len(y), i, uint32(got), uint32(expect))
					}
					expect = ref[i]
					if got != expect {
						t.Errorf("Len:%d Index:%d, got 0x%08x expected:0x%08x", len(y), i, got, expect)
					}
				}
			}
		}
	}
}

func TestMatchLen(t *testing.T) {
	if !useSSE42 {
		t.Skip("Skipping Matchlen test, no SSE 4.2 available")
	}
	// Maximum length tested
	var maxLen = 512

	// Skips per iteration
	is, js, ks := 3, 2, 1
	if testing.Short() {
		is, js, ks = 7, 5, 3
	}

	a := make([]byte, maxLen)
	b := make([]byte, maxLen)
	bb := make([]byte, maxLen)
	rand.Seed(1)
	for i := range a {
		a[i] = byte(rand.Int63())
		b[i] = byte(rand.Int63())
	}

	// Test different lengths
	for i := 0; i < maxLen; i += is {
		// Test different dst offsets.
		for j := 0; j < maxLen-1; j += js {
			copy(bb, b)
			// Test different src offsets
			for k := i - 1; k >= 0; k -= ks {
				copy(bb[j:], a[k:i])
				maxTest := maxLen - j
				if maxTest > maxLen-k {
					maxTest = maxLen - k
				}
				got := matchLenSSE4(a[k:], bb[j:], maxTest)
				expect := matchLenReference(a[k:], bb[j:], maxTest)
				if got > maxTest || got < 0 {
					t.Fatalf("unexpected result %d (len:%d, src offset: %d, dst offset:%d)", got, maxTest, k, j)
				}
				if got != expect {
					t.Fatalf("Mismatch, expected %d, got %d", expect, got)
				}
			}
		}
	}
}

// matchLenReference is a reference matcher.
func matchLenReference(a, b []byte, max int) int {
	for i := 0; i < max; i++ {
		if a[i] != b[i] {
			return i
		}
	}
	return max
}

func TestHistogram(t *testing.T) {
	if !useSSE42 {
		t.Skip("Skipping Matchlen test, no SSE 4.2 available")
	}
	// Maximum length tested
	const maxLen = 65536
	var maxOff = 8

	// Skips per iteration
	is, js := 5, 3
	if testing.Short() {
		is, js = 9, 1
		maxOff = 1
	}

	a := make([]byte, maxLen+maxOff)
	rand.Seed(1)
	for i := range a {
		a[i] = byte(rand.Int63())
	}

	// Test different lengths
	for i := 0; i <= maxLen; i += is {
		// Test different offsets
		for j := 0; j < maxOff; j += js {
			var got [256]int32
			var reference [256]int32

			histogram(a[j:i+j], got[:])
			histogramReference(a[j:i+j], reference[:])
			for k := range got {
				if got[k] != reference[k] {
					t.Fatalf("mismatch at len:%d, offset:%d, value %d: (got) %d != %d (expected)", i, j, k, got[k], reference[k])
				}
			}
		}
	}
}

// histogramReference is a reference
func histogramReference(b []byte, h []int32) {
	if len(h) < 256 {
		panic("Histogram too small")
	}
	for _, t := range b {
		h[t]++
	}
}