4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 func mcf(metacontext
string, offset
uint64, e
[]uint32, error
*int) int {
32 panic("expected *error == 0")
34 if metacontext
== "base:allocation" {
41 func mc_compare(a1
[]uint32, a2
[]uint32) bool {
42 if len(a1
) != len(a2
) {
45 for i
:= 0; i
< len(a1
); i
++ {
54 func mc_to_string(a
[]uint32) string {
55 ss
:= make([]string, len(a
))
56 for i
:= 0; i
< len(a
); i
++ {
57 ss
[i
] = fmt
.Sprint(a
[i
])
59 return strings
.Join(ss
, ", ")
62 func Test460BlockStatus(t
*testing
.T
) {
63 srcdir
:= os
.Getenv("abs_top_srcdir")
64 script
:= srcdir
+ "/tests/meta-base-allocation.sh"
68 t
.Fatalf("could not create handle: %s", err
)
72 err
= h
.AddMetaContext("base:allocation")
76 err
= h
.ConnectCommand([]string{
77 "nbdkit", "-s", "--exit-with-parent", "-v",
84 err
= h
.BlockStatus(65536, 0, mcf
, nil)
88 if !mc_compare(entries
, []uint32{
95 t
.Fatalf("unexpected entries (1): %s", mc_to_string(entries
))
98 err
= h
.BlockStatus(1024, 32256, mcf
, nil)
102 if !mc_compare(entries
, []uint32{
106 t
.Fatalf("unexpected entries (2): %s", mc_to_string(entries
))
109 var optargs BlockStatusOptargs
110 optargs
.FlagsSet
= true
111 optargs
.Flags
= CMD_FLAG_REQ_ONE
112 err
= h
.BlockStatus(1024, 32256, mcf
, &optargs
)
116 if !mc_compare(entries
, []uint32{512, 3}) {
117 t
.Fatalf("unexpected entries (3): %s", mc_to_string(entries
))