Skip to content
Snippets Groups Projects
Commit 3c834c12 authored by Guy Zana's avatar Guy Zana
Browse files

net: add msleep()/wakeup() test

parent 332e0a49
No related branches found
No related tags found
No related merge requests found
#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
......@@ -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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment