diff --git a/repos/os/src/test/alarm/main.cc b/repos/os/src/test/alarm/main.cc deleted file mode 100644 index 2fdd2fd703..0000000000 --- a/repos/os/src/test/alarm/main.cc +++ /dev/null @@ -1,117 +0,0 @@ -/* - * \brief Test for alarm library - * \author Norman Feske - * \date 2008-11-05 - */ - -/* - * Copyright (C) 2008-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#include -#include -#include -#include -#include - -using namespace Genode; - - -class Alarm_thread : Thread_deprecated<4096>, public Alarm_scheduler -{ - private: - - Timer::Connection _timer; - Alarm::Time _curr_time; /* jiffies value */ - - enum { TIMER_GRANULARITY_MSEC = 10 }; - - /** - * Thread entry function - */ - void entry() - { - while (true) { - _timer.msleep(TIMER_GRANULARITY_MSEC); - Alarm_scheduler::handle(_curr_time); - _curr_time += TIMER_GRANULARITY_MSEC; - } - } - - public: - - /** - * Constructor - */ - Alarm_thread(): Thread_deprecated("alarm"), _curr_time(0) { start(); } - - Alarm::Time curr_time() { return _curr_time; } -}; - - -class One_shot_alarm : public Alarm -{ - private: - - const char *_name; - - public: - - One_shot_alarm(const char *name, Alarm_scheduler *scheduler, Time absolute_timeout): - _name(name) - { - printf("scheduling one-shot alarm %s for %d msecs\n", - _name, (int)absolute_timeout); - scheduler->schedule_absolute(this, absolute_timeout); - } - - protected: - - bool on_alarm(unsigned) override - { - printf("one-shot alarm %s triggered\n", _name); - return false; - } -}; - - -class Periodic_alarm : public Alarm -{ - private: - - const char *_name; - - public: - - Periodic_alarm(const char *name, Alarm_scheduler *scheduler, Time period): - _name(name) - { - printf("scheduling periodic alarm %s for period of %d msecs\n", _name, (int)period); - scheduler->schedule(this, period); - } - - protected: - - bool on_alarm(unsigned) override - { - printf("periodic alarm %s triggered\n", _name); - return true; - } -}; - - -int main(int, char **) -{ - static Alarm_thread alarm_thread; - - static Periodic_alarm pa1("Period_1s", &alarm_thread, 1000); - static Periodic_alarm pa2("Period_700ms",&alarm_thread, 700); - static One_shot_alarm os1("One_shot_3s", &alarm_thread, alarm_thread.curr_time() + 3*1000); - static One_shot_alarm os2("One_shot_5s", &alarm_thread, alarm_thread.curr_time() + 5*1000); - - sleep_forever(); - return 0; -} diff --git a/repos/os/src/test/alarm/target.mk b/repos/os/src/test/alarm/target.mk deleted file mode 100644 index f1c1e6d407..0000000000 --- a/repos/os/src/test/alarm/target.mk +++ /dev/null @@ -1,3 +0,0 @@ -TARGET = test-alarm -SRC_CC = main.cc -LIBS = base alarm diff --git a/repos/os/src/test/audio_out/main.cc b/repos/os/src/test/audio_out/main.cc index e415e1d500..1f7bf471fd 100644 --- a/repos/os/src/test/audio_out/main.cc +++ b/repos/os/src/test/audio_out/main.cc @@ -16,53 +16,51 @@ */ #include -#include -#include #include -#include +#include +#include +#include #include -#include - - -using namespace Genode; - +#include +using Filename = Genode::String<64>; using namespace Genode; using namespace Audio_out; -static const bool verbose = false; - -enum { - CHN_CNT = 2, /* number of channels */ - FRAME_SIZE = sizeof(float), - PERIOD_CSIZE = FRAME_SIZE * PERIOD, /* size of channel packet (bytes) */ - PERIOD_FSIZE = CHN_CNT * PERIOD_CSIZE, /* size of period in file (bytes) */ -}; +static constexpr bool const verbose = false; +static constexpr char const * channel_names[2] = { "front left", "front right" }; -static const char *channel_names[] = { "front left", "front right" }; - - -class Track : Thread_deprecated<8192> +class Track : public Thread { private: + enum { + CHN_CNT = 2, /* number of channels */ + FRAME_SIZE = sizeof(float), + PERIOD_CSIZE = FRAME_SIZE * PERIOD, /* size of channel packet (bytes) */ + PERIOD_FSIZE = CHN_CNT * PERIOD_CSIZE, /* size of period in file (bytes) */ + }; + + Env & _env; Constructible _audio_out[CHN_CNT]; - String<64> const _name; + Filename const & _name; - Attached_rom_dataspace _sample_ds { _name.string() }; + Attached_rom_dataspace _sample_ds { _env, _name.string() }; char const * const _base = _sample_ds.local_addr(); size_t const _size = _sample_ds.size(); public: - Track(const char *name) : Thread_deprecated("track"), _name(name) + Track(Env & env, Filename const & name) + : Thread(env, "track", sizeof(size_t)*2048), _env(env), _name(name) { - for (int i = 0; i < CHN_CNT; ++i) { - /* allocation signal for first channel only */ - _audio_out[i].construct(channel_names[i], i == 0); - } + /* allocation signal for first channel only */ + for (int i = 0; i < CHN_CNT; ++i) + _audio_out[i].construct(env, channel_names[i], i == 0); + + start(); } void entry() @@ -128,78 +126,59 @@ class Track : Thread_deprecated<8192> log("played '", _name, "' ", ++cnt, " time(s)"); } } - - void ready() - { - start(); - } }; -static int process_config(const char ***files) +struct Main { enum { MAX_FILES = 16 }; - static char file_mem[64][MAX_FILES]; - static const char *file_p[MAX_FILES]; - int cnt = 0; + Env & env; + Heap heap { env.ram(), env.rm() }; + Attached_rom_dataspace config { env, "config" }; + Filename filenames[MAX_FILES]; + unsigned track_count = 0; - Xml_node config_node = config()->xml_node(); + void handle_config(); - for (unsigned i = 0; i < config_node.num_sub_nodes(); ++i) { - - if (!(i < MAX_FILES)) { - warning("test supports max ", (int)MAX_FILES, " files. Skipping..."); - break; - } - - Xml_node file_node = config_node.sub_node(i); - - if (!config_node.has_type("config")) { - error("root node of config file is not a tag"); - return -1; - } - - if (file_node.has_type("filename")) { - memcpy(file_mem[cnt], file_node.content_addr(), file_node.content_size()); - file_p[cnt] = file_mem[cnt]; - file_mem[cnt][file_node.content_size()] = '\0'; - cnt++; - } - } - - *files = file_p; - return cnt; -} + Main(Env & env); +}; -int main(int argc, char **argv) +void Main::handle_config() { - log("--- Audio_out test ---"); - - const char *defaults[] = { "1.raw", "2.raw" }; - const char **files = defaults; - int cnt = 2; - try { - cnt = process_config(&files); + config.xml().for_each_sub_node("filename", + [this] (Xml_node const & node) + { + if (!(track_count < MAX_FILES)) { + warning("test supports max ", (int)MAX_FILES, + " files. Skipping..."); + return; + } + + filenames[track_count++] = + Filename(Cstring(node.content_addr(), node.content_size())); + }); } catch (...) { warning("couldn't get input files, failing back to defaults"); + filenames[0] = Filename("1.raw"); + filenames[1] = Filename("2.raw"); + track_count = 2; } - - Track *track[cnt]; - - for (int i = 0; i < cnt; ++i) { - track[i] = new (env()->heap()) Track(files[i]); - } - - /* start playback after constrution of all tracks */ - for (int i = 0; i < cnt; i++) - track[i]->ready(); - - sleep_forever(); - return 0; } +Main::Main(Env & env) : env(env) +{ + log("--- Audio_out test ---"); + + handle_config(); + + for (unsigned i = 0; i < track_count; ++i) + new (heap) Track(env, filenames[i]); +} + + +void Component::construct(Env & env) { static Main main(env); } diff --git a/repos/os/src/test/audio_out_click/main.cc b/repos/os/src/test/audio_out_click/main.cc index 4b044b77bb..0fb4368ef0 100644 --- a/repos/os/src/test/audio_out_click/main.cc +++ b/repos/os/src/test/audio_out_click/main.cc @@ -16,48 +16,50 @@ */ #include -#include -#include #include +#include +#include +#include #include #include #include -#include - +using Filename = Genode::String<64>; using namespace Genode; using namespace Audio_out; -static const bool verbose = false; - -enum { - CHANNELS = 2, /* number of channels */ - FRAME_SIZE = sizeof(float), - PERIOD_CSIZE = FRAME_SIZE * PERIOD, /* size of channel packet (bytes) */ - PERIOD_FSIZE = CHANNELS * PERIOD_CSIZE, /* size of period in file (bytes) */ -}; - - -static const char *channel_names[] = { "front left", "front right" }; +static constexpr bool const verbose = false; +static constexpr char const * channel_names[2] = { "front left", "front right" }; class Click { private: + enum { + CHANNELS = 2, /* number of channels */ + FRAME_SIZE = sizeof(float), + PERIOD_CSIZE = FRAME_SIZE * PERIOD, /* size of channel packet (bytes) */ + PERIOD_FSIZE = CHANNELS * PERIOD_CSIZE, /* size of period in file (bytes) */ + }; + + Env & _env; Constructible _audio_out[CHANNELS]; - Attached_rom_dataspace _sample_ds; + Filename const & _name; + + Attached_rom_dataspace _sample_ds { _env, _name.string() }; char const * const _base = _sample_ds.local_addr(); size_t const _size = _sample_ds.size(); public: - Click(char const *file) : _sample_ds(file) + Click(Env & env, Filename const & name) + : _env(env), _name(name) { for (int i = 0; i < CHANNELS; ++i) { /* allocation signal for first channel only */ - _audio_out[i].construct(channel_names[i], i == 0); + _audio_out[i].construct(env, channel_names[i], i == 0); _audio_out[i]->start(); } } @@ -113,26 +115,19 @@ class Click } }; -int main(int argc, char **argv) + +struct Main { - log("--- Audio_out click test ---"); - - Genode::Signal_context sig_ctx; - Genode::Signal_receiver sig_rec; - - Genode::Signal_context_capability sig_cap = sig_rec.manage(&sig_ctx); - - Input::Connection input; - Input::Event *ev_buf; - - input.sigh(sig_cap); - ev_buf = static_cast(Genode::env()->rm_session()->attach(input.dataspace())); - - Click click("click.raw"); - - for (;;) { - Genode::Signal sig = sig_rec.wait_for_signal(); + Env & env; + Signal_handler
handler { env.ep(), *this, &Main::handle }; + Input::Connection input { env }; + Input::Event * ev_buf = + static_cast(env.rm().attach(input.dataspace())); + Filename const name { "click.raw" }; + Click click { env, name }; + void handle() + { for (int i = 0, num_ev = input.flush(); i < num_ev; ++i) { Input::Event &ev = ev_buf[i]; if (ev.type() == Input::Event::PRESS) { @@ -142,5 +137,13 @@ int main(int argc, char **argv) } } - return 0; -} + Main(Env & env) : env(env) + { + log("--- Audio_out click test ---"); + + input.sigh(handler); + } +}; + + +void Component::construct(Env & env) { static Main main(env); } diff --git a/repos/os/src/test/blk/bench/main.cc b/repos/os/src/test/blk/bench/main.cc index 573b23822e..685ec1d863 100644 --- a/repos/os/src/test/blk/bench/main.cc +++ b/repos/os/src/test/blk/bench/main.cc @@ -1,10 +1,23 @@ -#include -#include -#include -#include -#include +/* + * \brief Benchmark for block connection + * \author Sebastian Sumpf + * \author Stefan Kalkowski + * \date 2015-03-24 + */ -#include +/* + * Copyright (C) 2015-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include +#include +#include +#include +#include +#include using namespace Genode; @@ -16,24 +29,22 @@ enum { }; -namespace Test { - class Throughput; - struct Main; -} - - -class Test::Throughput +class Throughput { private: typedef Genode::size_t size_t; - Allocator_avl _alloc{env()->heap() }; - Block::Connection _session { &_alloc, TX_BUFFER }; - Timer::Connection _timer; + Env & _env; + Heap _heap { _env.ram(), _env.rm() }; + Allocator_avl _alloc { &_heap }; + Block::Connection _session { _env, &_alloc, TX_BUFFER }; + Timer::Connection _timer { _env }; - Signal_rpc_member _disp_ack; - Signal_rpc_member _disp_submit; + Signal_handler _disp_ack { _env.ep(), *this, + &Throughput::_ack }; + Signal_handler _disp_submit { _env.ep(), *this, + &Throughput::_submit }; bool _read_done = false; bool _write_done = false; @@ -47,7 +58,7 @@ class Test::Throughput void _submit() { - static size_t count = REQUEST_SIZE / _blk_size; + static size_t count = REQUEST_SIZE / _blk_size; if (_read_done && (_write_done || !TEST_WRITE)) return; @@ -69,12 +80,7 @@ class Test::Throughput } catch (...) { } } - void _ready_to_submit(unsigned) - { - _submit(); - } - - void _ack_avail(unsigned) + void _ack() { while (_session.tx()->ack_avail()) { @@ -103,11 +109,10 @@ class Test::Throughput return; _stop = _timer.elapsed_ms(); - ::printf("%s %lu KB in %lu ms (%.02f MB/s)\n", - !_read_done ? "Read" : "Wrote", - _bytes / 1024, _stop - _start, - ((double)_bytes / (1024 * 1024)) / ((double)(_stop - _start) / 1000)); - + log(!_read_done ? "Read" : "Wrote", " ", _bytes / 1024, " KB in ", + _stop - _start, " ms (", + ((double)_bytes / (1024 * 1024)) / ((double)(_stop - _start) / 1000), + " MB/s)"); /* start write */ if (!_read_done ) { @@ -118,18 +123,17 @@ class Test::Throughput if (TEST_WRITE) _submit(); else - ::printf("Done\n"); + log("Done"); } else if (!_write_done && TEST_WRITE) { _write_done = true; - ::printf("Done\n"); + log("Done"); } } public: - Throughput(Server::Entrypoint &ep) - : _disp_ack(ep, *this, &Throughput::_ack_avail), - _disp_submit(ep, *this, &Throughput::_ready_to_submit) + Throughput(Env & env) + : _env(env) { _session.tx_channel()->sigh_ack_avail(_disp_ack); _session.tx_channel()->sigh_ready_to_submit(_disp_submit); @@ -145,16 +149,4 @@ class Test::Throughput }; -struct Test::Main -{ - Main(Server::Entrypoint &ep) - { - new (env()->heap()) Throughput(ep); - } -}; - - -void Libc::Component::construct(Libc::Env &env) -{ - static Test::Main server(env.ep()); -} +void Component::construct(Env &env) { static Throughput test(env); } diff --git a/repos/os/src/test/blk/bench/target.mk b/repos/os/src/test/blk/bench/target.mk index 8c4e316540..cba9d1721f 100644 --- a/repos/os/src/test/blk/bench/target.mk +++ b/repos/os/src/test/blk/bench/target.mk @@ -1,3 +1,3 @@ TARGET = test-blk-bench SRC_CC = main.cc -LIBS = base libc +LIBS = base diff --git a/repos/os/src/test/blk/cli/main.cc b/repos/os/src/test/blk/cli/main.cc index 62b6fdee15..890bc6f8f8 100644 --- a/repos/os/src/test/blk/cli/main.cc +++ b/repos/os/src/test/blk/cli/main.cc @@ -86,16 +86,17 @@ class Test void _ready_to_submit() { _handle = false; } void _timeout() { throw Timeout(); } - Test(Genode::Entrypoint &ep, + Test(Genode::Env &env, Genode::Heap &heap, Genode::size_t bulk_buffer_size, unsigned timeout_ms) - : _ep(ep), + : _ep(env.ep()), _alloc(&heap), - _session(&_alloc, _shared_buffer_size(bulk_buffer_size)), - _disp_ack(ep, *this, &Test::_ack_avail), - _disp_submit(ep, *this, &Test::_ready_to_submit), - _disp_timeout(ep, *this, &Test::_timeout) + _session(env, &_alloc, _shared_buffer_size(bulk_buffer_size)), + _disp_ack(env.ep(), *this, &Test::_ack_avail), + _disp_submit(env.ep(), *this, &Test::_ready_to_submit), + _disp_timeout(env.ep(), *this, &Test::_timeout), + _timer(env) { _session.tx_channel()->sigh_ack_avail(_disp_ack); _session.tx_channel()->sigh_ready_to_submit(_disp_submit); @@ -119,8 +120,8 @@ struct Read_test : Test { bool done; - Read_test(Genode::Entrypoint &ep, Genode::Heap &heap, unsigned timeo_ms) - : Test(ep, heap, BULK_BLK_NR*blk_sz, timeo_ms), done(false) { } + Read_test(Genode::Env &env, Genode::Heap &heap, unsigned timeo_ms) + : Test(env, heap, BULK_BLK_NR*blk_sz, timeo_ms), done(false) { } void perform() { @@ -195,8 +196,8 @@ struct Write_test : Test Req_buffer read_packets; Req_buffer write_packets; - Write_test(Genode::Entrypoint &ep, Genode::Heap &heap, unsigned timeo_ms) - : Test(ep, heap, BULK_BLK_NR*blk_sz, timeo_ms) + Write_test(Genode::Env &env, Genode::Heap &heap, unsigned timeo_ms) + : Test(env, heap, BULK_BLK_NR*blk_sz, timeo_ms) { if (BULK_BLK_NR < BATCH*NR_PER_REQ || BATCH > Block::Session::TX_QUEUE_SIZE || @@ -330,8 +331,8 @@ struct Violation_test : Test int p_in_fly; - Violation_test(Genode::Entrypoint &ep, Genode::Heap &heap, unsigned timeo) - : Test(ep, heap, 20*blk_sz, timeo), p_in_fly(0) {} + Violation_test(Genode::Env &env, Genode::Heap &heap, unsigned timeo) + : Test(env, heap, 20*blk_sz, timeo), p_in_fly(0) {} void req(Block::sector_t nr, Genode::size_t cnt, bool write) { @@ -374,9 +375,9 @@ struct Violation_test : Test template -void perform(Genode::Entrypoint &ep, Genode::Heap &heap, unsigned timeo_ms = 0) +void perform(Genode::Env &env, Genode::Heap &heap, unsigned timeo_ms = 0) { - TEST * test = new (&heap) TEST(ep, heap, timeo_ms); + TEST * test = new (&heap) TEST(env, heap, timeo_ms); test->perform(); destroy(&heap, test); } @@ -397,7 +398,7 @@ void Component::construct(Genode::Env &env) */ { Allocator_avl alloc(&heap); - Block::Connection blk(&alloc); + Block::Connection blk(env, &alloc); blk.info(&blk_cnt, &blk_sz, &blk_ops); } @@ -415,11 +416,11 @@ void Component::construct(Genode::Env &env) blk_cnt, " (testing ", test_cnt, " sectors)"); perform >(env.ep(), heap); - perform >(env.ep(), heap); - perform >(env.ep(), heap); - perform >(env.ep(), heap); - perform(env.ep(), heap, 1000); + Block::Session::TX_QUEUE_SIZE-10> >(env, heap); + perform >(env, heap); + perform >(env, heap); + perform >(env, heap); + perform(env, heap, 1000); log("Tests finished successfully!"); } catch(Genode::Parent::Service_denied) { diff --git a/repos/os/src/test/blk/srv/main.cc b/repos/os/src/test/blk/srv/main.cc index f7bc82881c..4420b20088 100644 --- a/repos/os/src/test/blk/srv/main.cc +++ b/repos/os/src/test/blk/srv/main.cc @@ -124,7 +124,7 @@ struct Main } factory { env, heap }; Block::Root root { env.ep(), heap, factory }; - Timer::Connection timer; + Timer::Connection timer { env }; Genode::Signal_handler dispatcher { env.ep(), *factory.driver, &Driver::handler };