File: nonrace_test.go

package info (click to toggle)
golang-modernc-internal 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: makefile: 124
file content (51 lines) | stat: -rw-r--r-- 855 bytes parent folder | download
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
// Copyright 2016 The Internal Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !race

package buffer // import "modernc.org/internal/buffer"

import (
	"testing"
)

// Does not work with race detector b/c things get purged from the pool.
func Test(t *testing.T) {
	a := [1 << 10]*[]byte{}
	m := map[*[]byte]struct{}{}
	for i := range a {
		p := CGet(i)
		if _, ok := m[p]; ok {
			t.Fatal(i)
		}

		a[i] = p
		m[p] = struct{}{}
		b := *p
		for j := range b {
			b[j] = 123
		}
	}
	for i := range a {
		Put(a[i])
	}
	for i := range a {
		p := CGet(i)
		if _, ok := m[p]; !ok {
			t.Fatal(i)
		}

		delete(m, p)
		b := *p
		if g, e := len(b), i; g != e {
			t.Fatal(g, e)
		}

		for j, v := range b[:cap(b)] {
			if v != 0 {
				t.Fatal(i, j, v)
			}
		}
	}
}