/* * \brief Test for combining ram_fs, fs_rom, and fs_report * \author Norman Feske * \date 2017-06-28 */ /* * Copyright (C) 2017 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. */ #include #include #include #include #include namespace Test { struct Main; using namespace Genode; } struct Test::Main { Env &_env; Timer::Connection _timer { _env }; Constructible _devices_reporter; Constructible _focus_reporter; typedef String<80> Version; void _report(Reporter &reporter, Version const &version) { Reporter::Xml_generator xml(reporter, [&] () { xml.attribute("version", version); }); } Constructible _devices_rom; Constructible _focus_rom; Signal_handler
_devices_rom_update_handler { _env.ep(), *this, &Main::_handle_devices_rom_update }; Signal_handler
_focus_rom_update_handler { _env.ep(), *this, &Main::_handle_focus_rom_update }; Constructible > _one_shot_timeout; void _handle_init() { log("(1) check initial content of \"devices\" ROM"); _devices_rom.construct(_env, "devices"); if (_devices_rom->xml().attribute_value("version", Version()) != "initial") { error("ROM does not contain expected initial conent"); throw Exception(); } log("(2) issue new \"devices\" report before installing a ROM signal handler"); _devices_reporter.construct(_env, "devices"); _devices_reporter->enabled(true); _report(*_devices_reporter, "version 2"); log("(3) wait a bit to let the report reach the RAM fs"); _one_shot_timeout.construct(_timer, *this, &Main::_handle_timer_1); _one_shot_timeout->schedule(Microseconds(500*1000)); } void _handle_timer_1(Duration) { log("(4) install ROM signal handler, is expected to trigger immediately"); _devices_rom->sigh(_devices_rom_update_handler); } void _handle_devices_rom_update() { log("(5) received ROM update as expected"); _devices_rom->update(); if (_devices_rom->xml().attribute_value("version", Version()) != "version 2") { error("unexpected content of \"devices\" ROM after update"); throw Exception(); } log("(6) request not-yet-available \"focus\" ROM"); _focus_rom.construct(_env, "focus"); _focus_rom->sigh(_focus_rom_update_handler); log("(7) wait a bit until generating the focus report"); _one_shot_timeout.construct(_timer, *this, &Main::_handle_timer_2); _one_shot_timeout->schedule(Microseconds(500*1000)); } void _handle_timer_2(Duration) { log("(8) generate \"focus\" report, is expected to trigger ROM notification"); _focus_reporter.construct(_env, "focus"); _focus_reporter->enabled(true); _report(*_focus_reporter, "focus version 1"); } void _handle_focus_rom_update() { _focus_rom->update(); if (_focus_rom->xml().attribute_value("version", Version()) != "focus version 1") { error("unexpected content of \"focus\" ROM"); throw Exception(); } log("(9) received expected focus ROM content"); /* test completed successfully */ _env.parent().exit(0); } Main(Env &env) : _env(env) { log("--- test-fs_report started ---"); _handle_init(); } }; void Component::construct(Genode::Env &env) { static Test::Main main(env); }