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

tests: extend timer test, make it more stressful

noticed an assert in the download file test that was related to timers,
this test reproduce the same bug.
parent 94a7015e
No related branches found
No related tags found
No related merge requests found
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
#include "tst-hub.hh" #include "tst-hub.hh"
#include "drivers/clock.hh" #include "drivers/clock.hh"
#include "debug.hh" #include "debug.hh"
#include "sched.hh"
class test_timer : public unit_tests::vtest { class test_timer : public unit_tests::vtest {
public: public:
void run() void test1(void)
{ {
auto t1 = clock::get()->time(); auto t1 = clock::get()->time();
auto t2 = clock::get()->time(); auto t2 = clock::get()->time();
...@@ -28,6 +29,48 @@ public: ...@@ -28,6 +29,48 @@ public:
t2 = clock::get()->time(); t2 = clock::get()->time();
debug("Timer test: nanosleep(100000) -> %d\n", t2 - t1); debug("Timer test: nanosleep(100000) -> %d\n", t2 - t1);
} }
static const int max_testers = 5000;
static const int tester_iteration = 10;
void stress_thread(void)
{
srandom(clock::get()->time());
for (int i=0; i<tester_iteration; i++) {
u64 ns = (random() % 1000000000) - 500000000; // -5 to +5 ms
sched::timer t(*sched::thread::current());
t.set(clock::get()->time() + ns);
sched::thread::wait_until([&] { return (t.expired()); });
}
}
// stress test the timer class
void test2(void)
{
debug("Starting stress test\n");
for (int i=0; i<max_testers; i++) {
_testers[i] = new sched::thread([&] { this->stress_thread(); });
_testers[i]->start();
}
// join
for (int i=0; i<max_testers; i++) {
_testers[i]->join();
delete _testers[i];
}
debug("End stress test\n");
}
sched::thread *_testers[max_testers];
void run()
{
//test1();
test2();
}
}; };
#endif #endif
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