Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
timeout.c
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
timeout.c
Commits
50147e1d
Commit
50147e1d
authored
Feb 26, 2016
by
William Ahern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test_foreach' of
git://github.com/nmathewson/timeout
into nmathewson-test_foreach
parents
948cacb5
3c533b61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
3 deletions
+52
-3
test-timeout.c
test-timeout.c
+52
-3
No files found.
test-timeout.c
View file @
50147e1d
...
@@ -80,15 +80,18 @@ static int check_randomized(const struct rand_cfg *cfg)
...
@@ -80,15 +80,18 @@ static int check_randomized(const struct rand_cfg *cfg)
struct
timeout
*
t
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
struct
timeout
));
struct
timeout
*
t
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
struct
timeout
));
timeout_t
*
timeouts
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
timeout_t
));
timeout_t
*
timeouts
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
timeout_t
));
uint8_t
*
fired
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
uint8_t
));
uint8_t
*
fired
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
uint8_t
));
uint8_t
*
found
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
uint8_t
));
uint8_t
*
deleted
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
uint8_t
));
uint8_t
*
deleted
=
calloc
(
cfg
->
n_timeouts
,
sizeof
(
uint8_t
));
struct
timeouts
*
tos
=
timeouts_open
(
0
,
&
err
);
struct
timeouts
*
tos
=
timeouts_open
(
0
,
&
err
);
timeout_t
now
=
cfg
->
start_at
;
timeout_t
now
=
cfg
->
start_at
;
int
n_added_pending
=
0
;
int
n_added_pending
=
0
,
cnt_added_pending
=
0
;
int
n_added_expired
=
0
;
int
n_added_expired
=
0
,
cnt_added_expired
=
0
;
struct
timeouts_it
it_p
,
it_e
,
it_all
;
int
p_done
=
0
,
e_done
=
0
,
all_done
=
0
;
struct
timeout
*
to
=
NULL
;
struct
timeout
*
to
=
NULL
;
const
int
rel
=
cfg
->
relative
;
const
int
rel
=
cfg
->
relative
;
if
(
!
t
||
!
timeouts
||
!
tos
||
!
fired
||
!
deleted
)
if
(
!
t
||
!
timeouts
||
!
tos
||
!
fired
||
!
found
||
!
deleted
)
FAIL
();
FAIL
();
timeouts_update
(
tos
,
cfg
->
start_at
);
timeouts_update
(
tos
,
cfg
->
start_at
);
...
@@ -123,6 +126,51 @@ static int check_randomized(const struct rand_cfg *cfg)
...
@@ -123,6 +126,51 @@ static int check_randomized(const struct rand_cfg *cfg)
if
(
!!
n_added_expired
!=
timeouts_expired
(
tos
))
if
(
!!
n_added_expired
!=
timeouts_expired
(
tos
))
FAIL
();
FAIL
();
/* Test foreach, interleaving a few iterators. */
TIMEOUTS_IT_INIT
(
&
it_p
,
TIMEOUTS_PENDING
);
TIMEOUTS_IT_INIT
(
&
it_e
,
TIMEOUTS_EXPIRED
);
TIMEOUTS_IT_INIT
(
&
it_all
,
TIMEOUTS_ALL
);
while
(
!
(
p_done
&&
e_done
&&
all_done
))
{
if
(
!
p_done
)
{
to
=
timeouts_next
(
tos
,
&
it_p
);
if
(
to
)
{
i
=
to
-
&
t
[
0
];
++
found
[
i
];
++
cnt_added_pending
;
}
else
{
p_done
=
1
;
}
}
if
(
!
e_done
)
{
to
=
timeouts_next
(
tos
,
&
it_e
);
if
(
to
)
{
i
=
to
-
&
t
[
0
];
++
found
[
i
];
++
cnt_added_expired
;
}
else
{
e_done
=
1
;
}
}
if
(
!
all_done
)
{
to
=
timeouts_next
(
tos
,
&
it_all
);
if
(
to
)
{
i
=
to
-
&
t
[
0
];
++
found
[
i
];
}
else
{
all_done
=
1
;
}
}
}
for
(
i
=
0
;
i
<
cfg
->
n_timeouts
;
++
i
)
{
if
(
found
[
i
]
!=
2
)
FAIL
();
}
if
(
cnt_added_expired
!=
n_added_expired
)
FAIL
();
if
(
cnt_added_pending
!=
n_added_pending
)
FAIL
();
while
(
NULL
!=
(
to
=
timeouts_get
(
tos
)))
{
while
(
NULL
!=
(
to
=
timeouts_get
(
tos
)))
{
i
=
to
-
&
t
[
0
];
i
=
to
-
&
t
[
0
];
assert
(
&
t
[
i
]
==
to
);
assert
(
&
t
[
i
]
==
to
);
...
@@ -217,6 +265,7 @@ static int check_randomized(const struct rand_cfg *cfg)
...
@@ -217,6 +265,7 @@ static int check_randomized(const struct rand_cfg *cfg)
if
(
t
)
free
(
t
);
if
(
t
)
free
(
t
);
if
(
timeouts
)
free
(
timeouts
);
if
(
timeouts
)
free
(
timeouts
);
if
(
fired
)
free
(
fired
);
if
(
fired
)
free
(
fired
);
if
(
found
)
free
(
found
);
if
(
deleted
)
free
(
deleted
);
if
(
deleted
)
free
(
deleted
);
return
rv
;
return
rv
;
}
}
...
...
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