]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/tests/functional/pyocf/utils.py
2 # Copyright(c) 2019 Intel Corporation
3 # SPDX-License-Identifier: BSD-3-Clause-Clear
6 from ctypes
import string_at
15 stop_after_count_ignored
=0,
18 end
= int(offset
) + int(length
)
21 buf
= string_at(buf
, length
)
22 whole_buffer_ignored
= True
23 stop_after_count_ignored
= int(stop_after_count_ignored
/ width
)
25 for addr
in range(offset
, end
, width
):
26 cur_line
= buf
[addr
: min(end
, addr
+ width
)]
29 if not any(x
!= ignore
for x
in cur_line
):
31 stop_after_count_ignored
32 and ignored_lines
> stop_after_count_ignored
35 "<{} bytes of '0x{:02X}' encountered, stopping>".format(
36 stop_after_count_ignored
* width
, ignore
45 "<{} of '0x{:02X}' bytes omitted>".format(
46 ignored_lines
* width
, ignore
53 byteline
+= "{:02X} ".format(byte
)
60 print_fcn("0x{:08X}\t{}\t{}".format(addr
, byteline
, asciiline
))
61 whole_buffer_ignored
= False
63 if whole_buffer_ignored
:
64 print_fcn("<whole buffer ignored>")
66 print_fcn("<'0x{:02X}' until end>".format(ignore
))
76 def __init__(self
, b
: int, sector_aligned
: bool = False):
79 ((b
+ self
._SECTOR
_SIZE
- 1) // self
._SECTOR
_SIZE
)
92 def from_B(cls
, value
, sector_aligned
=False):
93 return cls(value
, sector_aligned
)
96 def from_KiB(cls
, value
, sector_aligned
=False):
97 return cls(value
* cls
._KiB
, sector_aligned
)
100 def from_MiB(cls
, value
, sector_aligned
=False):
101 return cls(value
* cls
._MiB
, sector_aligned
)
104 def from_GiB(cls
, value
, sector_aligned
=False):
105 return cls(value
* cls
._GiB
, sector_aligned
)
108 def from_TiB(cls
, value
, sector_aligned
=False):
109 return cls(value
* cls
._TiB
, sector_aligned
)
112 def from_sector(cls
, value
):
113 return cls(value
* cls
._SECTOR
_SIZE
)
121 return self
.bytes
/ self
._KiB
125 return self
.bytes
/ self
._MiB
129 return self
.bytes
/ self
._GiB
133 return self
.bytes
/ self
._TiB
137 return self
.bytes
// self
._SECTOR
_SIZE
140 if self
.bytes
< self
._KiB
:
141 return "{} B".format(self
.B
)
142 elif self
.bytes
< self
._MiB
:
143 return "{} KiB".format(self
.KiB
)
144 elif self
.bytes
< self
._GiB
:
145 return "{} MiB".format(self
.MiB
)
146 elif self
.bytes
< self
._TiB
:
147 return "{} GiB".format(self
.GiB
)
149 return "{} TiB".format(self
.TiB
)
152 def print_structure(struct
, indent
=0):
154 for field
, field_type
in struct
._fields
_:
155 value
= getattr(struct
, field
)
156 if hasattr(value
, "_fields_"):
157 print("{}{: <20} :".format(" " * indent
, field
))
158 print_structure(value
, indent
=indent
+ 1)
161 print("{}{: <20} : {}".format(" " * indent
, field
, value
))
164 def struct_to_dict(struct
):
166 for field
, field_type
in struct
._fields
_:
167 value
= getattr(struct
, field
)
168 if hasattr(value
, "_fields_"):
169 d
[field
] = struct_to_dict(value
)