Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC TDC 1ns 5cha
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC TDC 1ns 5cha
Commits
fc511034
Commit
fc511034
authored
Nov 22, 2023
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tst: allow users to specify slot
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
55591c20
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
9 deletions
+57
-9
conftest.py
pytest/conftest.py
+57
-9
No files found.
pytest/conftest.py
View file @
fc511034
...
...
@@ -2,7 +2,7 @@
SPDX-License-Identifier: LGPL-2.1-or-later
SPDX-FileCopyrightText: 2020 CERN
"""
from
pathlib
import
Path
import
pytest
import
subprocess
import
time
...
...
@@ -11,6 +11,42 @@ import os
from
PyFmcTdc
import
FmcTdc
def
valid_slot_type
(
slot
):
if
re
.
search
(
r"(VME|PCI)\.[0-9]+-FMC\.[0-9]+"
,
slot
)
is
None
:
raise
ValueError
()
return
slot
def
id_from_slot
(
slot
,
name
):
carrier
,
mezzanine
=
slot
.
split
(
"-"
)
carrier_bus
,
carrier_slot
=
carrier
.
split
(
"."
)
carrier_slot
=
int
(
carrier_slot
)
mezzanine_bus
,
mezzanine_slot
=
mezzanine
.
split
(
"."
)
mezzanine_slot
=
int
(
mezzanine_slot
)
if
carrier_bus
==
"PCI"
:
with
open
(
"/run/dynpci"
)
as
f
:
for
line
in
f
.
readlines
():
dynslot
,
pciid
=
line
.
strip
()
.
split
(
" "
)
if
int
(
dynslot
)
==
carrier_slot
:
break
pciid
=
f
"0000:{pciid}"
pathfmc
=
list
(
Path
(
"/sys/bus/pci/devices"
)
.
joinpath
(
pciid
)
\
.
glob
(
f
"spec-*/id:*/{name}.*.auto/fmc-slot-*.{mezzanine_slot}"
))
elif
carrier_bus
==
"VME"
:
pathfmc
=
list
(
Path
(
"/sys/bus/vme/devices"
)
.
joinpath
(
f
"slot.{carrier_slot:02d}"
)
\
.
joinpath
(
f
"vme.{carrier_slot:02d}"
)
\
.
glob
(
f
"svec-*/svec-*/id:*/{name}.*.auto/fmc-slot-*.{mezzanine_slot}"
))
else
:
raise
ValueError
()
assert
len
(
pathfmc
)
==
1
devname
=
list
(
Path
(
pathfmc
[
0
])
.
parent
.
glob
(
"hw-*/*-????/devname"
))
assert
len
(
devname
)
==
1
with
open
(
devname
[
0
])
as
f
:
fd_id
=
int
(
f
.
read
()
.
strip
()
.
split
(
"-"
)[
-
1
],
16
)
return
fd_id
def
pytest_generate_tests
(
metafunc
):
if
"fd_tdc_id"
in
metafunc
.
fixturenames
:
metafunc
.
parametrize
(
"fd_tdc_id"
,
pytest
.
fd_tdc_id
)
...
...
@@ -144,8 +180,12 @@ def fmctdc(tdc_and_gen):
def
pytest_addoption
(
parser
):
parser
.
addoption
(
"--tdc-id"
,
type
=
lambda
x
:
int
(
x
,
16
),
action
=
"append"
,
default
=
[],
help
=
"Fmc TDC Linux Identifier"
)
parser
.
addoption
(
"--slot-tdc"
,
type
=
valid_slot_type
,
action
=
'append'
,
default
=
[],
help
=
"Fmc TDC absolute slot (works only for SPEC and SVEC)"
)
parser
.
addoption
(
"--fd-id"
,
type
=
lambda
x
:
int
(
x
,
16
),
action
=
"append"
,
default
=
[],
help
=
"Fmc Fine-Delay Linux Identifier"
)
parser
.
addoption
(
"--slot-fd"
,
type
=
valid_slot_type
,
action
=
'append'
,
default
=
[],
help
=
"Fmc Fine-Delay absolute slot (works only for SPEC and SVEC)"
)
parser
.
addoption
(
"--dump-range"
,
type
=
int
,
default
=
10
,
help
=
"Timestamps to show before and after an error"
)
parser
.
addoption
(
"--channel"
,
type
=
int
,
default
=
[],
...
...
@@ -156,15 +196,23 @@ def pytest_addoption(parser):
parser
.
addoption
(
"--usr-acq-period-ns"
,
type
=
int
,
default
=
0
,
help
=
"Pulses period (ns) during a acquisition test."
)
def
id_list_get
(
config
,
opt_id
,
opt_slot
,
devname
):
id_list
=
config
.
getoption
(
opt_id
)
if
len
(
id_list
)
==
0
:
slot
=
config
.
getoption
(
opt_slot
)
if
len
(
slot
)
==
0
:
print
(
f
"Missing argument {opt_id} or {opt_slot}"
)
raise
Exception
()
id_list
=
[]
for
slot
in
slot
:
id_list
.
append
(
id_from_slot
(
slot
,
devname
))
return
id_list
def
pytest_configure
(
config
):
pytest
.
tdc_id
=
config
.
getoption
(
"--tdc-id"
)
if
len
(
pytest
.
tdc_id
)
==
0
:
print
(
"Missing argument --tdc-id"
)
raise
Exception
()
pytest
.
fd_id
=
config
.
getoption
(
"--fd-id"
)
if
len
(
pytest
.
tdc_id
)
==
0
:
print
(
"Missing argument --fd-id"
)
raise
Exception
()
pytest
.
tdc_id
=
id_list_get
(
config
,
"--tdc-id"
,
"--slot-tdc"
,
"fmc-tdc"
)
pytest
.
fd_id
=
id_list_get
(
config
,
"--fd-id"
,
"--slot-fd"
,
"fmc-fdelay-tdc"
)
if
len
(
pytest
.
tdc_id
)
!=
len
(
pytest
.
fd_id
):
print
(
"For each --fd-id there must be a --tdc-id"
)
raise
Exception
()
...
...
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