file: Add an internal "mode"
[nbdkit.git] / tests / test.pl
blobb5997ca691df8350e0e52d343f701a57ff9d7856
1 use strict;
3 my $disk = "\0" x (1024*1024);
5 BEGIN {
6 # Call the debug function to check it works.
7 Nbdkit::debug ("hello world!");
9 # Check some expected constants are defined. Since these constants
10 # are defined by the nbdkit ABI, they should never change so checking
11 # their absolute values here ought to be fine.
12 die unless $Nbdkit::FLAG_MAY_TRIM == 1;
13 die unless $Nbdkit::FLAG_FUA == 2;
14 die unless $Nbdkit::FLAG_REQ_ONE == 4;
15 die unless $Nbdkit::FUA_NATIVE == 2;
16 die unless $Nbdkit::CACHE_EMULATE == 1;
17 die unless $Nbdkit::EXTENT_ZERO == 2;
20 sub config_complete
24 sub open
26 my $readonly = shift;
27 Nbdkit::debug ("perl plugin opened, readonly=" . $readonly);
28 my $h = { readonly => $readonly };
29 return $h;
32 sub close
34 my $h = shift;
37 sub get_size
39 my $h = shift;
40 return length ($disk);
43 sub can_write
45 my $h = shift;
46 return 1;
49 sub can_flush
51 my $h = shift;
52 return 1;
55 sub is_rotational
57 my $h = shift;
58 return 0;
61 sub can_trim
63 my $h = shift;
64 return 1;
67 sub pread
69 my $h = shift;
70 my $count = shift;
71 my $offset = shift;
72 return substr ($disk, $offset, $count);
75 sub pwrite
77 my $h = shift;
78 my $buf = shift;
79 my $count = length ($buf);
80 my $offset = shift;
81 substr ($disk, $offset, $count) = $buf;
84 sub flush
86 my $h = shift;
89 sub trim
91 my $h = shift;
92 my $count = shift;
93 my $offset = shift;