Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
d31e0a4e
Commit
d31e0a4e
authored
Dec 19, 2016
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for memclr.
parent
92e34070
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
internal/buffer/out_message_test.go
internal/buffer/out_message_test.go
+51
-0
No files found.
internal/buffer/out_message_test.go
View file @
d31e0a4e
package
buffer
import
(
"crypto/rand"
"fmt"
"io"
"testing"
"unsafe"
)
func
randBytes
(
n
int
)
(
b
[]
byte
,
err
error
)
{
b
=
make
([]
byte
,
n
)
_
,
err
=
io
.
ReadFull
(
rand
.
Reader
,
b
)
return
}
func
TestMemclr
(
t
*
testing
.
T
)
{
// All sizes up to 32 bytes.
var
sizes
[]
int
for
i
:=
0
;
i
<=
32
;
i
++
{
sizes
=
append
(
sizes
,
i
)
}
// And a few hand-chosen sizes.
sizes
=
append
(
sizes
,
[]
int
{
39
,
41
,
64
,
127
,
128
,
129
,
1
<<
20
-
1
,
1
<<
20
,
1
<<
20
+
1
,
}
...
)
// For each size, fill a buffer with random bytes and then zero it.
for
_
,
size
:=
range
sizes
{
size
:=
size
t
.
Run
(
fmt
.
Sprintf
(
"size=%d"
,
size
),
func
(
t
*
testing
.
T
)
{
// Generate
b
,
err
:=
randBytes
(
size
)
if
err
!=
nil
{
t
.
Fatalf
(
"randBytes: %v"
,
err
)
}
// Clear
var
p
unsafe
.
Pointer
if
len
(
b
)
!=
0
{
p
=
unsafe
.
Pointer
(
&
b
[
0
])
}
memclr
(
p
,
uintptr
(
len
(
b
)))
// Check
for
i
,
x
:=
range
b
{
if
x
!=
0
{
t
.
Fatalf
(
"non-zero byte %d at offset %d"
,
x
,
i
)
}
}
})
}
}
func
BenchmarkOutMessageReset
(
b
*
testing
.
B
)
{
// A single buffer, which should fit in some level of CPU cache.
b
.
Run
(
"Single buffer"
,
func
(
b
*
testing
.
B
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment