Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
Vim
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Someone-Else
Vim
Commits
b3c5284c
Commit
b3c5284c
authored
14 years ago
by
Bram Moolenaar
Browse files
Options
Downloads
Patches
Plain Diff
Add missing files for patch 7.3.143.
parent
b05b10a3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/memfile_test.c
+145
-0
145 additions, 0 deletions
src/memfile_test.c
src/testdir/test77.in
+27
-0
27 additions, 0 deletions
src/testdir/test77.in
src/testdir/test77.ok
+1
-0
1 addition, 0 deletions
src/testdir/test77.ok
with
173 additions
and
0 deletions
src/memfile_test.c
0 → 100644
+
145
−
0
View file @
b3c5284c
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* memfile_test.c: Unittests for memfile.c
* Mostly by Ivan Krasilnikov.
*/
#undef NDEBUG
#include
<assert.h>
/* Must include main.c because it contains much more than just main() */
#define NO_VIM_MAIN
#include
"main.c"
/* This file has to be included because the tested functions are static */
#include
"memfile.c"
#define index_to_key(i) ((i) ^ 15167)
#define TEST_COUNT 50000
static
void
test_mf_hash
__ARGS
((
void
));
/*
* Test mf_hash_*() functions.
*/
static
void
test_mf_hash
()
{
mf_hashtab_T
ht
;
mf_hashitem_T
*
item
;
blocknr_T
key
;
long_u
i
;
long_u
num_buckets
;
mf_hash_init
(
&
ht
);
/* insert some items and check invariants */
for
(
i
=
0
;
i
<
TEST_COUNT
;
i
++
)
{
assert
(
ht
.
mht_count
==
i
);
/* check that number of buckets is a power of 2 */
num_buckets
=
ht
.
mht_mask
+
1
;
assert
(
num_buckets
>
0
&&
(
num_buckets
&
(
num_buckets
-
1
))
==
0
);
/* check load factor */
assert
(
ht
.
mht_count
<=
(
num_buckets
<<
MHT_LOG_LOAD_FACTOR
));
if
(
i
<
(
MHT_INIT_SIZE
<<
MHT_LOG_LOAD_FACTOR
))
{
/* first expansion shouldn't have occurred yet */
assert
(
num_buckets
==
MHT_INIT_SIZE
);
assert
(
ht
.
mht_buckets
==
ht
.
mht_small_buckets
);
}
else
{
assert
(
num_buckets
>
MHT_INIT_SIZE
);
assert
(
ht
.
mht_buckets
!=
ht
.
mht_small_buckets
);
}
key
=
index_to_key
(
i
);
assert
(
mf_hash_find
(
&
ht
,
key
)
==
NULL
);
/* allocate and add new item */
item
=
(
mf_hashitem_T
*
)
lalloc_clear
(
sizeof
(
mf_hashtab_T
),
FALSE
);
assert
(
item
!=
NULL
);
item
->
mhi_key
=
key
;
mf_hash_add_item
(
&
ht
,
item
);
assert
(
mf_hash_find
(
&
ht
,
key
)
==
item
);
if
(
ht
.
mht_mask
+
1
!=
num_buckets
)
{
/* hash table was expanded */
assert
(
ht
.
mht_mask
+
1
==
num_buckets
*
MHT_GROWTH_FACTOR
);
assert
(
i
+
1
==
(
num_buckets
<<
MHT_LOG_LOAD_FACTOR
));
}
}
/* check presence of inserted items */
for
(
i
=
0
;
i
<
TEST_COUNT
;
i
++
)
{
key
=
index_to_key
(
i
);
item
=
mf_hash_find
(
&
ht
,
key
);
assert
(
item
!=
NULL
);
assert
(
item
->
mhi_key
==
key
);
}
/* delete some items */
for
(
i
=
0
;
i
<
TEST_COUNT
;
i
++
)
{
if
(
i
%
100
<
70
)
{
key
=
index_to_key
(
i
);
item
=
mf_hash_find
(
&
ht
,
key
);
assert
(
item
!=
NULL
);
assert
(
item
->
mhi_key
==
key
);
mf_hash_rem_item
(
&
ht
,
item
);
assert
(
mf_hash_find
(
&
ht
,
key
)
==
NULL
);
mf_hash_add_item
(
&
ht
,
item
);
assert
(
mf_hash_find
(
&
ht
,
key
)
==
item
);
mf_hash_rem_item
(
&
ht
,
item
);
assert
(
mf_hash_find
(
&
ht
,
key
)
==
NULL
);
vim_free
(
item
);
}
}
/* check again */
for
(
i
=
0
;
i
<
TEST_COUNT
;
i
++
)
{
key
=
index_to_key
(
i
);
item
=
mf_hash_find
(
&
ht
,
key
);
if
(
i
%
100
<
70
)
{
assert
(
item
==
NULL
);
}
else
{
assert
(
item
!=
NULL
);
assert
(
item
->
mhi_key
==
key
);
}
}
/* free hash table and all remaining items */
mf_hash_free_all
(
&
ht
);
}
int
main
()
{
test_mf_hash
();
return
0
;
}
This diff is collapsed.
Click to expand it.
src/testdir/test77.in
0 → 100644
+
27
−
0
View file @
b3c5284c
Inserts 2 million lines with consecutive integers starting from 1
(essentially, the output of GNU's seq 1 2000000), writes them to Xtest
and writes its cksum to test.out.
We need 2 million lines to trigger a call to mf_hash_grow(). If it would mess
up the lines the checksum would differ.
cksum is part of POSIX and so should be available on most Unixes.
If it isn't available then the test will be skipped.
STARTTEST
:so small.vim
:if !executable("cksum")
: e! test.ok
: w! test.out
: qa!
:endif
:set fileformat=unix undolevels=-1
ggdG
:let i = 1
:while i <= 2000000 | call append(i, range(i, i + 99)) | let i += 100 | endwhile
ggdd
:w! Xtest
:!cksum Xtest > test.out
:qa!
ENDTEST
This diff is collapsed.
Click to expand it.
src/testdir/test77.ok
0 → 100644
+
1
−
0
View file @
b3c5284c
3678979763 14888896 Xtest
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment