Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
go-daq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
.
Show more breadcrumbs
MIM
go-daq
Commits
a5758f28
Commit
a5758f28
authored
5 years ago
by
Sebastien Binet
Browse files
Options
Downloads
Patches
Plain Diff
dif: improve doc strings & Readout test coverage
parent
4d8950e9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dif/readout.go
+3
-1
3 additions, 1 deletion
dif/readout.go
dif/readout_test.go
+61
-11
61 additions, 11 deletions
dif/readout_test.go
with
64 additions
and
12 deletions
dif/readout.go
+
3
−
1
View file @
a5758f28
...
...
@@ -21,6 +21,7 @@ const (
hardrocASIC
asicKind
=
2
)
// Readout reads data out of a digital interface board (DIF).
type
Readout
struct
{
msg
log
.
MsgStream
dev
*
device
...
...
@@ -40,6 +41,7 @@ type Readout struct {
temp
[
2
]
float32
// temperatures
}
// NewReadout creates a new DIF readout.
func
NewReadout
(
name
string
,
prodID
uint32
,
msg
log
.
MsgStream
)
(
*
Readout
,
error
)
{
dev
,
err
:=
newDevice
(
0x0403
,
uint16
(
prodID
))
if
err
!=
nil
{
...
...
@@ -59,7 +61,7 @@ func NewReadout(name string, prodID uint32, msg log.MsgStream) (*Readout, error)
rdo
.
reg
.
pd2daq
=
0x4e
rdo
.
reg
.
daq2pd
=
0x4e
rdo
.
reg
.
pd2pa
=
0x4e
_
,
err
=
fmt
.
Sscanf
(
name
,
"FT101%d"
,
&
rdo
.
difID
)
_
,
err
=
fmt
.
Sscanf
(
name
,
"FT101%
03
d"
,
&
rdo
.
difID
)
if
err
!=
nil
{
_
=
dev
.
close
()
return
nil
,
xerrors
.
Errorf
(
"could not find DIF-id from %q: %w"
,
name
,
err
)
...
...
This diff is collapsed.
Click to expand it.
dif/readout_test.go
+
61
−
11
View file @
a5758f28
...
...
@@ -8,6 +8,7 @@ import (
"bytes"
"io"
"os"
"strings"
"testing"
"github.com/go-daq/tdaq/log"
...
...
@@ -25,17 +26,46 @@ func TestReadout(t *testing.T) {
ftdiOpen
=
ftdiOpenImpl
}()
{
const
name
=
"FT101xxx"
rdo
,
err
:=
NewReadout
(
name
,
0x6014
,
nil
)
if
err
==
nil
{
rdo
.
close
()
t
.
Fatalf
(
"expected an error"
)
}
want
:=
xerrors
.
Errorf
(
"could not find DIF-id from %q: %s"
,
name
,
xerrors
.
New
(
"expected integer"
))
if
got
,
want
:=
err
.
Error
(),
want
.
Error
();
got
!=
want
{
t
.
Fatalf
(
"invalid error:
\n
got= %v
\n
want=%v"
,
got
,
want
)
}
for
_
,
tc
:=
range
[]
struct
{
name
string
err
error
id
uint32
}{
{
name
:
"FT101xxx"
,
err
:
xerrors
.
Errorf
(
"could not find DIF-id from %q: %s"
,
"FT101xxx"
,
xerrors
.
New
(
"expected integer"
)),
},
{
name
:
"FT101"
,
err
:
xerrors
.
Errorf
(
"could not find DIF-id from %q: %s"
,
"FT101"
,
io
.
EOF
),
},
{
name
:
"FT10142"
,
id
:
42
,
},
{
name
:
"FT101042"
,
id
:
42
,
},
}
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
rdo
,
err
:=
NewReadout
(
tc
.
name
,
0x6014
,
nil
)
if
err
==
nil
&&
tc
.
err
!=
nil
{
rdo
.
close
()
t
.
Fatalf
(
"expected an error"
)
}
switch
{
case
tc
.
err
!=
nil
:
if
got
,
want
:=
err
.
Error
(),
tc
.
err
.
Error
();
got
!=
want
{
t
.
Fatalf
(
"invalid error:
\n
got= %v
\n
want=%v"
,
got
,
want
)
}
default
:
defer
rdo
.
close
()
if
rdo
.
difID
!=
tc
.
id
{
t
.
Fatalf
(
"invalid DIF-id: got=%d, want=%d"
,
rdo
.
difID
,
tc
.
id
)
}
}
})
}
const
(
...
...
@@ -47,6 +77,9 @@ func TestReadout(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"could not create readout: %+v"
,
err
)
}
if
got
,
want
:=
rdo
.
difID
,
uint32
(
42
);
got
!=
want
{
t
.
Fatalf
(
"invalid DIF-ID: got=%d, want=%d"
,
got
,
want
)
}
err
=
rdo
.
configureRegisters
()
if
err
!=
nil
{
...
...
@@ -121,6 +154,23 @@ func TestReadout(t *testing.T) {
}
}
func
TestInvalidReadout
(
t
*
testing
.
T
)
{
want
:=
xerrors
.
Errorf
(
"no such device"
)
ftdiOpen
=
func
(
vid
,
pid
uint16
)
(
ftdiDevice
,
error
)
{
return
nil
,
want
}
defer
func
()
{
ftdiOpen
=
ftdiOpenImpl
}()
rdo
,
err
:=
NewReadout
(
"FT101042"
,
0x6014
,
nil
)
if
err
==
nil
{
_
=
rdo
.
close
()
t
.
Fatalf
(
"expected an error, got=%v"
,
err
)
}
if
got
,
want
:=
err
.
Error
(),
want
.
Error
();
!
strings
.
Contains
(
got
,
want
)
{
t
.
Fatalf
(
"invalid error.
\n
got= %v
\n
want=%v
\n
"
,
got
,
want
)
}
}
type
fakeDevice
struct
{
buf
io
.
ReadWriter
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment