Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Verlässliche Systemsoftware
projects
osv
Commits
3c834c12
Commit
3c834c12
authored
12 years ago
by
Guy Zana
Browse files
Options
Downloads
Patches
Plain Diff
net: add msleep()/wakeup() test
parent
332e0a49
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/tst-bsd-synch.hh
+105
-0
105 additions, 0 deletions
tests/tst-bsd-synch.hh
tests/tst-hub.cc
+3
-0
3 additions, 0 deletions
tests/tst-hub.cc
with
108 additions
and
0 deletions
tests/tst-bsd-synch.hh
0 → 100644
+
105
−
0
View file @
3c834c12
#ifndef TST_SYNCH_H
#define TST_SYNCH_H
#include
"sched.hh"
#include
"debug.hh"
#include
"tst-hub.hh"
extern
"C"
{
#include
<bsd/porting/synch.h>
}
#define dbg_d(...) \
logger::instance()->log("tst-synch", logger_error, __VA_ARGS__)
#undef log
class
test_synch
:
public
unit_tests
::
vtest
{
public:
test_synch
()
{}
virtual
~
test_synch
()
{}
//
// Create 2 threads that wait for an event
// Release them one by one
//
void
test2
(
void
)
{
dbg_d
(
"test2 - start"
);
sched
::
detached_thread
*
t21
=
new
sched
::
detached_thread
([
this
]
{
dbg_d
(
"t21-before"
);
msleep
((
void
*
)
567
,
NULL
,
0
,
"test1"
,
0
);
dbg_d
(
"t21-after"
);
});
sched
::
detached_thread
*
t22
=
new
sched
::
detached_thread
([
this
]
{
dbg_d
(
"t22-before"
);
msleep
((
void
*
)
567
,
NULL
,
0
,
"test1"
,
0
);
dbg_d
(
"t22-after"
);
});
t21
->
start
();
t22
->
start
();
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
/* Wait on another channel, with a timeout... */
dbg_d
(
"test1 - waiting on event 234 with a timeout of 1 second"
);
msleep
((
void
*
)
888
,
NULL
,
0
,
"test1"
,
1
);
dbg_d
(
"test1 - releasing event 123"
);
wakeup_one
((
void
*
)
567
);
}
dbg_d
(
"test2 - end"
);
}
//
// Create 2 threads that wait for an event
// then block the main thread (wait for another event with timeout)
// then signal the first event
//
void
test1
(
void
)
{
dbg_d
(
"test1 - start"
);
sched
::
detached_thread
*
t11
=
new
sched
::
detached_thread
([
this
]
{
dbg_d
(
"t11-before"
);
msleep
((
void
*
)
123
,
NULL
,
0
,
"test1"
,
0
);
dbg_d
(
"t11-after"
);
});
sched
::
detached_thread
*
t12
=
new
sched
::
detached_thread
([
this
]
{
dbg_d
(
"t12-before"
);
msleep
((
void
*
)
123
,
NULL
,
0
,
"test1"
,
0
);
dbg_d
(
"t12-after"
);
});
t11
->
start
();
t12
->
start
();
/* Wait on another channel, with a timeout... */
dbg_d
(
"test1 - waiting on event 234 with a timeout of 1 second"
);
msleep
((
void
*
)
234
,
NULL
,
0
,
"test1"
,
1
);
dbg_d
(
"test1 - releasing event 123"
);
wakeup
((
void
*
)
123
);
dbg_d
(
"test1 - end"
);
}
void
run
(
void
)
{
#if 0
// Run the tests in detached threads
sched::detached_thread *t1 = new sched::detached_thread([this] { test1(); });
t1->start();
sched::detached_thread *t2 = new sched::detached_thread([this] { test2(); });
t2->start();
#endif
}
};
#undef dbg_d
#endif
This diff is collapsed.
Click to expand it.
tests/tst-hub.cc
+
3
−
0
View file @
3c834c12
...
...
@@ -5,6 +5,7 @@
#include
"tst-devices.hh"
#include
"tst-eventlist.hh"
#include
"tst-rwlock.hh"
#include
"tst-bsd-synch.hh"
using
namespace
unit_tests
;
...
...
@@ -15,6 +16,7 @@ void tests::execute_tests() {
test_devices
dev
;
test_eventlist
evlist
;
test_rwlock
rwlock
;
test_synch
synch
;
instance
().
register_test
(
&
threads
);
instance
().
register_test
(
&
malloc
);
...
...
@@ -22,6 +24,7 @@ void tests::execute_tests() {
instance
().
register_test
(
&
dev
);
instance
().
register_test
(
&
evlist
);
instance
().
register_test
(
&
rwlock
);
instance
().
register_test
(
&
synch
);
instance
().
run
();
}
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