Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
videolan
vlc
Commits
d5567521
Commit
d5567521
authored
Jun 30, 2015
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: test case for the previous commit
parent
2d099490
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
145 additions
and
0 deletions
+145
-0
src/Makefile.am
src/Makefile.am
+3
-0
src/test/interrupt.c
src/test/interrupt.c
+142
-0
No files found.
src/Makefile.am
View file @
d5567521
...
...
@@ -539,6 +539,7 @@ check_PROGRAMS = \
test_block
\
test_dictionary
\
test_i18n_atof
\
test_interrupt
\
test_md5
\
test_picture_pool
\
test_timer
\
...
...
@@ -555,6 +556,8 @@ test_block_DEPENDENCIES =
test_dictionary_SOURCES
=
test
/dictionary.c
test_i18n_atof_SOURCES
=
test
/i18n_atof.c
test_interrupt_SOURCES
=
test
/interrupt.c
test_interrupt_LDADD
=
$(LDADD)
$(LIBS_libvlccore)
$(LIBPTHREAD)
test_md5_SOURCES
=
test
/md5.c
test_picture_pool_SOURCES
=
test
/picture_pool.c
test_timer_SOURCES
=
test
/timer.c
...
...
src/test/interrupt.c
0 → 100644
View file @
d5567521
/*****************************************************************************
* interrupt.c: Test for interrupt context API
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#undef NDEBUG
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <vlc_common.h>
#include <vlc_threads.h>
#include <vlc_interrupt.h>
static
vlc_sem_t
sem
;
static
void
test_context_simple
(
vlc_interrupt_t
*
ctx
)
{
vlc_interrupt_t
*
octx
;
vlc_interrupt_set
(
ctx
);
octx
=
vlc_interrupt_set
(
NULL
);
assert
(
octx
==
ctx
);
octx
=
vlc_interrupt_set
(
ctx
);
assert
(
octx
==
NULL
);
octx
=
vlc_interrupt_set
(
ctx
);
assert
(
octx
==
ctx
);
/* BIG FAT WARNING: This is only meant to test the vlc_cond_wait_i11e()
* function. This is NOT a good example of how to use the function in
* normal code. */
vlc_sem_post
(
&
sem
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
0
);
vlc_interrupt_raise
(
ctx
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
EINTR
);
vlc_sem_post
(
&
sem
);
vlc_interrupt_raise
(
ctx
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
EINTR
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
0
);
vlc_interrupt_raise
(
ctx
);
vlc_sem_post
(
&
sem
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
EINTR
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
0
);
octx
=
vlc_interrupt_set
(
NULL
);
assert
(
octx
==
ctx
);
octx
=
vlc_interrupt_set
(
NULL
);
assert
(
octx
==
NULL
);
}
static
void
*
test_thread_simple
(
void
*
data
)
{
vlc_interrupt_t
*
ctx
=
data
;
vlc_interrupt_set
(
ctx
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
EINTR
);
assert
(
vlc_sem_wait_i11e
(
&
sem
)
==
0
);
vlc_sem_wait
(
&
sem
);
test_context_simple
(
ctx
);
return
NULL
;
}
static
void
*
test_thread_cleanup
(
void
*
data
)
{
vlc_interrupt_t
*
ctx
=
data
;
test_context_simple
(
ctx
);
/* Test context clearing on exit */
vlc_interrupt_set
(
ctx
);
return
NULL
;
}
static
void
*
test_thread_cancel
(
void
*
data
)
{
vlc_interrupt_t
*
ctx
=
data
;
test_context_simple
(
ctx
);
/* Test context clearing on cancellation */
vlc_interrupt_set
(
ctx
);
for
(;;)
pause
();
vlc_assert_unreachable
();
}
int
main
(
void
)
{
vlc_interrupt_t
*
ctx
;
vlc_thread_t
th
;
alarm
(
2
);
ctx
=
vlc_interrupt_create
();
assert
(
ctx
!=
NULL
);
vlc_interrupt_destroy
(
ctx
);
vlc_sem_init
(
&
sem
,
0
);
ctx
=
vlc_interrupt_create
();
assert
(
ctx
!=
NULL
);
test_context_simple
(
ctx
);
assert
(
!
vlc_clone
(
&
th
,
test_thread_simple
,
ctx
,
VLC_THREAD_PRIORITY_LOW
));
vlc_interrupt_raise
(
ctx
);
vlc_sem_post
(
&
sem
);
vlc_sem_post
(
&
sem
);
vlc_join
(
th
,
NULL
);
assert
(
!
vlc_clone
(
&
th
,
test_thread_cleanup
,
ctx
,
VLC_THREAD_PRIORITY_LOW
));
vlc_join
(
th
,
NULL
);
assert
(
!
vlc_clone
(
&
th
,
test_thread_cancel
,
ctx
,
VLC_THREAD_PRIORITY_LOW
));
vlc_cancel
(
th
);
vlc_join
(
th
,
NULL
);
vlc_interrupt_destroy
(
ctx
);
vlc_sem_destroy
(
&
sem
);
return
0
;
}
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