Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
e4b3b1e9
Commit
e4b3b1e9
authored
Sep 26, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb2: another test.
parent
c3dae42c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
ccan/tdb2/test/run-30-exhaust-before-expand.c
ccan/tdb2/test/run-30-exhaust-before-expand.c
+84
-0
No files found.
ccan/tdb2/test/run-30-exhaust-before-expand.c
0 → 100644
View file @
e4b3b1e9
#include <ccan/tdb2/tdb.c>
#include <ccan/tdb2/free.c>
#include <ccan/tdb2/lock.c>
#include <ccan/tdb2/io.c>
#include <ccan/tdb2/check.c>
#include <ccan/tdb2/hash.c>
#include <ccan/tap/tap.h>
#include <err.h>
#include "logging.h"
static
uint64_t
fixedhash
(
const
void
*
key
,
size_t
len
,
uint64_t
seed
,
void
*
p
)
{
return
hash64_stable
((
const
unsigned
char
*
)
key
,
len
,
*
(
uint64_t
*
)
p
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
unsigned
int
i
,
j
;
struct
tdb_context
*
tdb
;
int
flags
[]
=
{
TDB_INTERNAL
,
TDB_DEFAULT
,
TDB_NOMMAP
,
TDB_INTERNAL
|
TDB_CONVERT
,
TDB_CONVERT
,
TDB_NOMMAP
|
TDB_CONVERT
};
uint64_t
seed
=
0
;
union
tdb_attribute
fixed_hattr
=
{
.
hash
=
{
.
base
=
{
TDB_ATTRIBUTE_HASH
},
.
hash_fn
=
fixedhash
,
.
hash_private
=
&
seed
}
};
fixed_hattr
.
base
.
next
=
&
tap_log_attr
;
plan_tests
(
sizeof
(
flags
)
/
sizeof
(
flags
[
0
])
*
5
+
1
);
for
(
i
=
0
;
i
<
sizeof
(
flags
)
/
sizeof
(
flags
[
0
]);
i
++
)
{
tdb_off_t
free
[
BUCKETS_FOR_ZONE
(
INITIAL_ZONE_BITS
)
+
1
];
bool
all_empty
;
TDB_DATA
k
,
d
;
k
.
dptr
=
(
void
*
)
&
j
;
k
.
dsize
=
sizeof
(
j
);
tdb
=
tdb_open
(
"run-30-exhaust-before-expand.tdb"
,
flags
[
i
],
O_RDWR
|
O_CREAT
|
O_TRUNC
,
0600
,
&
tap_log_attr
);
ok1
(
tdb
);
if
(
!
tdb
)
continue
;
/* We don't want the hash to expand, so we use one alloc to
* chew up over 90% of the space first. */
j
=
-
1
;
d
.
dsize
=
(
1
<<
INITIAL_ZONE_BITS
)
*
9
/
10
;
d
.
dptr
=
malloc
(
d
.
dsize
);
ok1
(
tdb_store
(
tdb
,
k
,
d
,
TDB_INSERT
)
==
0
);
ok1
(
tdb
->
map_size
==
sizeof
(
struct
tdb_header
)
+
(
1
<<
INITIAL_ZONE_BITS
)
+
1
);
/* Insert minimal-length records until we add a zone. */
for
(
j
=
0
;
tdb
->
map_size
==
sizeof
(
struct
tdb_header
)
+
(
1
<<
INITIAL_ZONE_BITS
)
+
1
;
j
++
)
{
if
(
tdb_store
(
tdb
,
k
,
k
,
TDB_INSERT
)
!=
0
)
err
(
1
,
"Failed to store record %i"
,
j
);
}
/* Now, free list should be completely exhausted in zone 0 */
ok1
(
tdb_read_convert
(
tdb
,
sizeof
(
struct
tdb_header
)
+
sizeof
(
struct
free_zone_header
),
&
free
,
sizeof
(
free
))
==
0
);
all_empty
=
true
;
for
(
j
=
0
;
j
<
sizeof
(
free
)
/
sizeof
(
free
[
0
]);
j
++
)
{
if
(
free
[
j
])
{
diag
(
"Free bucket %i not empty"
,
j
);
all_empty
=
false
;
}
}
ok1
(
all_empty
);
tdb_close
(
tdb
);
}
ok1
(
tap_log_messages
==
0
);
return
exit_status
();
}
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