]>
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
9 def print_buffer(buf
, length
, offset
=0, width
=16, stop_after_zeros
=0):
12 buf
= string_at(buf
, length
)
13 whole_buffer_empty
= True
14 stop_after_zeros
= int(stop_after_zeros
/ width
)
16 for addr
in range(offset
, end
, width
):
17 cur_line
= buf
[addr
: min(end
, addr
+ width
)]
21 if stop_after_zeros
and zero_lines
> stop_after_zeros
:
23 "<{} bytes of empty space encountered, stopping>".format(
24 stop_after_zeros
* width
32 print("<{} zero bytes omitted>".format(zero_lines
* width
))
37 byteline
+= "{:02X} ".format(byte
)
44 print("0x{:08X}\t{}\t{}".format(addr
, byteline
, asciiline
))
45 whole_buffer_empty
= False
47 if whole_buffer_empty
:
48 print("<whole buffer empty>")
50 print("<zero until end>")
59 def __init__(self
, b
: int):
69 def from_B(cls
, value
):
73 def from_KiB(cls
, value
):
74 return cls(value
* cls
._KiB
)
77 def from_MiB(cls
, value
):
78 return cls(value
* cls
._MiB
)
81 def from_GiB(cls
, value
):
82 return cls(value
* cls
._GiB
)
85 def from_TiB(cls
, value
):
86 return cls(value
* cls
._TiB
)
94 return self
.bytes
/ self
._KiB
98 return self
.bytes
/ self
._MiB
102 return self
.bytes
/ self
._GiB
106 return self
.bytes
/ self
._TiB
109 if self
.bytes
< self
._KiB
:
110 return "{} B".format(self
.B
)
111 elif self
.bytes
< self
._MiB
:
112 return "{} KiB".format(self
.KiB
)
113 elif self
.bytes
< self
._GiB
:
114 return "{} MiB".format(self
.MiB
)
115 elif self
.bytes
< self
._TiB
:
116 return "{} GiB".format(self
.GiB
)
118 return "{} TiB".format(self
.TiB
)
121 def print_structure(struct
, indent
=0):
123 for field
, field_type
in struct
._fields
_:
124 value
= getattr(struct
, field
)
125 if hasattr(value
, "_fields_"):
126 print("{}{: <20} :".format(" " * indent
, field
))
127 print_structure(value
, indent
=indent
+ 1)
130 print("{}{: <20} : {}".format(" " * indent
, field
, value
))
133 def struct_to_dict(struct
):
135 for field
, field_type
in struct
._fields
_:
136 value
= getattr(struct
, field
)
137 if hasattr(value
, "_fields_"):
138 d
[field
] = struct_to_dict(value
)