Add 'webcam_vfs' run test

Issue #4458
This commit is contained in:
Christian Prochaska 2022-03-28 09:12:37 +02:00 committed by Christian Helmuth
parent 6a874498f7
commit 6c2ac345fd
8 changed files with 462 additions and 179 deletions

View File

@ -0,0 +1,185 @@
assert_spec x86
set build_components { }
# fuji4
proc libuvc_vendor_id {} { return "0x04f2" }
proc libuvc_product_id {} { return "0xb564" }
# c270
#proc libuvc_vendor_id {} { return "0x046d" }
#proc libuvc_product_id {} { return "0x0825" }
# quickcam
#proc libuvc_vendor_id {} { return "0x046d" }
#proc libuvc_product_id {} { return "0x09c1" }
# t470
#proc libuvc_vendor_id {} { return "0x0bda" }
#proc libuvc_product_id {} { return "0x58db" }
create_boot_directory
import_from_depot [depot_user]/src/[base_src] \
[depot_user]/src/init \
[depot_user]/src/nitpicker \
[depot_user]/src/dynamic_rom \
[depot_user]/src/rom_reporter \
[depot_user]/src/report_rom \
[depot_user]/src/pc_usb_host_drv \
[depot_user]/src/vesa_drv \
[depot_user]/pkg/usb_webcam
import_from_depot $test_imports
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components
build $build_components
append config {
<config verbose="yes" prio_levels="4">
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
<service name="VM"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="100"/>
}
append_platform_drv_config
append config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
<route>
<any-service> <parent/> </any-service>
</route>
</start>
<start name="usb_drv" priority="0" caps="200">
<binary name="pc_usb_host_drv"/>
<resource name="RAM" quantum="16M"/>
<!-- <resource name="CPU" quantum="10"/> -->
<provides><service name="Usb"/></provides>
<config bios_handoff="no">
<policy label_suffix="usb_webcam -> usb_device"
vendor_id="} [libuvc_vendor_id] {" product_id="} [libuvc_product_id] {"/>
</config>
<route>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="fb_drv" priority="-1" caps="150">
<binary name="vesa_fb_drv"/>
<resource name="RAM" quantum="20M"/>
<config/>
<route>
<service name="Capture"> <child name="nitpicker"/> </service>
<any-service> <parent/> <any-child /> </any-service>
</route>
</start>
<start name="nitpicker" priority="-1" caps="150">
<resource name="RAM" quantum="12M"/>
<provides>
<service name="Gui"/> <service name="Capture"/> <service name="Event"/>
</provides>
<config>
<capture/>
<report focus="yes" hover="yes" />
<domain name="" layer="3" content="client" label="no" focus="click" hover="always"/>
<default-policy domain=""/>
</config>
<route>
<service name="Report"> <child name="acpi_report_rom"/> </service>
<any-service> <parent/> <any-child /> </any-service>
</route>
</start>
<start name="} $test_binary {" priority="-1">
<resource name="RAM" quantum="8M"/>
<config period_ms="20" width="640" height="480"> }
append config $test_vfs_config
append config {
<view xpos="100" ypos="100"/> <!--view xpos="800" ypos="600"/-->
</config>
<route>
<service name="Gui"> <child name="nitpicker"/> </service>
<service name="Capture"> <child name="webcam"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="dynamic-webcam">
<binary name="dynamic_rom"/>
<resource name="RAM" quantum="1M"/>
<provides> <service name="ROM"/> </provides>
<config verbose="yes">
<rom name="capture">
<inline>
<capture enabled="true"/>
</inline>
<sleep milliseconds="8000"/>
<inline>
<capture enabled="no"/>
</inline>
<sleep milliseconds="3000"/>
</rom>
</config>
<route>
<service name="Timer"> <child name="timer"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>
<start name="rom_reporter">
<resource name="RAM" quantum="1MB"/>
<provides> <service name="Report"/> </provides>
<config>
<rom label="capture"/>
</config>
<route>
<service name="ROM" label="capture"> <child name="dynamic-webcam"/> </service>
<service name="Report"> <child name="webcam" label="capture"/> </service>
<any-service> <parent /> </any-service>
</route>
</start>
<start name="webcam" caps="800" priority="-1">
<binary name="init"/>
<resource name="RAM" quantum="64MB"/>
<route>
<service name="ROM" label="config"> <parent label="usb_webcam.config"/> </service>
<service name="Timer"> <child name="timer"/> </service>
<service name="Usb"> <child name="usb_drv"/> </service>
<any-service> <parent /> </any-service>
</route>
<provides> <service name="Capture"/> <service name="Report"/> </provides>
</start>
</config>}
install_config $config
append_platform_drv_boot_modules
append boot_modules { }
build_boot_image $boot_modules
append qemu_args { -usb -device usb-host,vendorid=[libuvc_vendor_id],productid=[libuvc_product_id] }
run_genode_until forever

View File

@ -1,182 +1,7 @@
assert_spec x86
set test_imports "[depot_user]/src/test-capture"
set build_components { }
set test_binary "test-capture"
# fuji4
proc libuvc_vendor_id {} { return "0x04f2" }
proc libuvc_product_id {} { return "0xb564" }
set test_vfs_config { }
# c270
#proc libuvc_vendor_id {} { return "0x046d" }
#proc libuvc_product_id {} { return "0x0825" }
# quickcam
#proc libuvc_vendor_id {} { return "0x046d" }
#proc libuvc_product_id {} { return "0x09c1" }
# t470
#proc libuvc_vendor_id {} { return "0x0bda" }
#proc libuvc_product_id {} { return "0x58db" }
create_boot_directory
import_from_depot [depot_user]/src/[base_src] \
[depot_user]/src/init \
[depot_user]/src/nitpicker \
[depot_user]/src/dynamic_rom \
[depot_user]/src/rom_reporter \
[depot_user]/src/report_rom \
[depot_user]/src/pc_usb_host_drv \
[depot_user]/src/vesa_drv \
[depot_user]/src/test-capture \
[depot_user]/pkg/usb_webcam
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components
build $build_components
append config {
<config verbose="yes" prio_levels="4">
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
<service name="VM"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="100"/>
}
append_platform_drv_config
append config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
<route>
<any-service> <parent/> </any-service>
</route>
</start>
<start name="usb_drv" priority="0" caps="200">
<binary name="pc_usb_host_drv"/>
<resource name="RAM" quantum="16M"/>
<!-- <resource name="CPU" quantum="10"/> -->
<provides><service name="Usb"/></provides>
<config bios_handoff="no">
<policy label_suffix="usb_webcam -> usb_device"
vendor_id="} [libuvc_vendor_id] {" product_id="} [libuvc_product_id] {"/>
</config>
<route>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="fb_drv" priority="-1" caps="150">
<binary name="vesa_fb_drv"/>
<resource name="RAM" quantum="20M"/>
<config/>
<route>
<service name="Capture"> <child name="nitpicker"/> </service>
<any-service> <parent/> <any-child /> </any-service>
</route>
</start>
<start name="nitpicker" priority="-1" caps="150">
<resource name="RAM" quantum="12M"/>
<provides>
<service name="Gui"/> <service name="Capture"/> <service name="Event"/>
</provides>
<config>
<capture/>
<report focus="yes" hover="yes" />
<domain name="" layer="3" content="client" label="no" focus="click" hover="always"/>
<default-policy domain=""/>
</config>
<route>
<service name="Report"> <child name="acpi_report_rom"/> </service>
<any-service> <parent/> <any-child /> </any-service>
</route>
</start>
<start name="test-capture" priority="-1">
<resource name="RAM" quantum="8M"/>
<config period_ms="20" width="640" height="480">
<view xpos="100" ypos="100"/> <!--view xpos="800" ypos="600"/-->
</config>
<route>
<service name="Gui"> <child name="nitpicker"/> </service>
<service name="Capture"> <child name="webcam"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="dynamic-webcam">
<binary name="dynamic_rom"/>
<resource name="RAM" quantum="1M"/>
<provides> <service name="ROM"/> </provides>
<config verbose="yes">
<rom name="capture">
<inline>
<capture enabled="true"/>
</inline>
<sleep milliseconds="8000"/>
<inline>
<capture enabled="no"/>
</inline>
<sleep milliseconds="3000"/>
</rom>
</config>
<route>
<service name="Timer"> <child name="timer"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>
<start name="rom_reporter">
<resource name="RAM" quantum="1MB"/>
<provides> <service name="Report"/> </provides>
<config>
<rom label="capture"/>
</config>
<route>
<service name="ROM" label="capture"> <child name="dynamic-webcam"/> </service>
<service name="Report"> <child name="webcam" label="capture"/> </service>
<any-service> <parent /> </any-service>
</route>
</start>
<start name="webcam" caps="800" priority="-1">
<binary name="init"/>
<resource name="RAM" quantum="64MB"/>
<route>
<service name="ROM" label="config"> <parent label="usb_webcam.config"/> </service>
<service name="Timer"> <child name="timer"/> </service>
<service name="Usb"> <child name="usb_drv"/> </service>
<any-service> <parent /> </any-service>
</route>
<provides> <service name="Capture"/> <service name="Report"/> </provides>
</start>
</config>}
install_config $config
append_platform_drv_boot_modules
append boot_modules { }
build_boot_image $boot_modules
append qemu_args { -usb -device usb-host,vendorid=[libuvc_vendor_id],productid=[libuvc_product_id] }
run_genode_until forever
source ${genode_dir}/repos/libports/run/webcam.inc

View File

@ -0,0 +1,8 @@
set test_imports "[depot_user]/src/test-vfs_capture \
[depot_user]/src/vfs_capture"
set test_binary "test-vfs_capture"
set test_vfs_config { <vfs><dir name="dev"><capture/></dir></vfs> }
source ${genode_dir}/repos/libports/run/webcam.inc

View File

@ -0,0 +1,2 @@
SRC_DIR = src/test/vfs_capture
include $(GENODE_DIR)/repos/base/recipes/src/content.inc

View File

@ -0,0 +1 @@
2022-03-26 d1f95998600be00ef2f130aa12d6c177e0c82bf2

View File

@ -0,0 +1,8 @@
base
os
blit
gui_session
input_session
framebuffer_session
capture_session
vfs

View File

@ -0,0 +1,251 @@
/*
* \brief Capture test
* \author Norman Feske
* \date 2020-06-26
*/
/*
* Copyright (C) 2020-2022 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 <base/env.h>
#include <base/component.h>
#include <base/log.h>
#include <base/attached_ram_dataspace.h>
#include <base/attached_rom_dataspace.h>
#include <base/heap.h>
#include <base/registry.h>
#include <gui_session/connection.h>
#include <capture_session/connection.h>
#include <timer_session/connection.h>
#include <os/vfs.h>
namespace Test {
using namespace Genode;
struct View;
struct Main;
}
class Test::View
{
private:
using View_handle = Gui::Session::View_handle;
Gui::Session_client &_gui;
View_handle const _handle = _gui.create_view(View_handle{});
Gui::Rect const _rect;
public:
View(Gui::Session_client &gui, Gui::Rect rect) : _gui(gui), _rect(rect)
{
using Command = Gui::Session::Command;
_gui.enqueue<Command::Geometry>(_handle, rect);
_gui.enqueue<Command::To_front>(_handle, View_handle());
_gui.execute();
}
virtual ~View() { }
};
struct Test::Main
{
Env &_env;
using Pixel = Capture::Pixel;
using Affected_rects = Capture::Session::Affected_rects;
Attached_rom_dataspace _config { _env, "config" };
Heap _heap { _env.ram(), _env.rm() };
Root_directory _root_dir { _env, _heap, _config.xml().sub_node("vfs") };
static Gui::Point _point_from_xml(Xml_node node)
{
return Gui::Point((int)node.attribute_value("xpos", 0L),
(int)node.attribute_value("ypos", 0L));
}
static Gui::Area _area_from_xml(Xml_node node, Gui::Area default_area)
{
return Gui::Area(node.attribute_value("width", default_area.w()),
node.attribute_value("height", default_area.h()));
}
struct Output
{
struct Invalid_config : Exception { };
Env &_env;
Allocator &_alloc;
Gui::Connection _gui { _env, "" };
Framebuffer::Mode const _mode;
void _validate_mode() const
{
if (_mode.area.count() == 0) {
error("invalid or missing 'width' and 'height' config attributes");
throw Invalid_config();
}
}
bool _gui_buffer_init = ( _validate_mode(), _gui.buffer(_mode, false), true );
Attached_dataspace _fb_ds { _env.rm(), _gui.framebuffer()->dataspace() };
Registry<Registered<View>> _views { };
Output(Env &env, Allocator &alloc, Xml_node const &config)
:
_env(env), _alloc(alloc),
_mode({ .area = _area_from_xml(config, Area { }) })
{
auto view_rect = [&] (Xml_node node)
{
return Gui::Rect(_point_from_xml(node),
_area_from_xml(node, _mode.area));
};
config.for_each_sub_node("view", [&] (Xml_node node) {
new (_alloc)
Registered<View>(_views, _gui, view_rect(node)); });
}
~Output()
{
_views.for_each([&] (Registered<View> &view) {
destroy(_alloc, &view); });
}
template <typename FN>
void with_surface(FN const &fn)
{
Surface<Pixel> surface(_fb_ds.local_addr<Pixel>(), _mode.area);
fn(surface);
}
};
Constructible<Output> _output { };
struct Capture_input
{
Env &_env;
Root_directory &_root_dir;
Gui::Area const _area;
Readonly_file _capture_file { _root_dir, "/dev/capture" };
size_t _capture_ds_size = 640 * 480 * 4;
Attached_ram_dataspace _capture_ds { _env.ram(), _env.rm(),
_capture_ds_size };
Texture<Pixel> const _texture { _capture_ds.local_addr<Pixel>(), nullptr, _area };
Gui::Point _at { };
Capture_input(Env &env, Root_directory &root_dir, Gui::Area area,
Xml_node const &config)
:
_env(env), _root_dir(root_dir), _area(area),
_at(_point_from_xml(config))
{ }
Affected_rects capture() {
_capture_file.read(_capture_ds.local_addr<char>(),
_capture_ds_size);
Affected_rects affected { };
affected.rects[0] = Rect(_at, _area);
return affected;
}
template <typename FN>
void with_texture(FN const &fn) const
{
fn(_texture);
}
};
Constructible<Capture_input> _capture_input { };
/*
* Periodic update
*/
Timer::Connection _timer { _env };
Signal_handler<Main> _timer_handler { _env.ep(), *this, &Main::_handle_timer };
void _handle_timer()
{
if (!_capture_input.constructed() || !_output.constructed())
return;
_capture_input->with_texture([&] (Texture<Pixel> const &texture) {
_output->with_surface([&] (Surface<Pixel> &surface) {
Affected_rects const affected = _capture_input->capture();
affected.for_each_rect([&] (Gui::Rect const rect) {
surface.clip(rect);
Blit_painter::paint(surface, texture, Gui::Point(0, 0));
});
affected.for_each_rect([&] (Gui::Rect const rect) {
_output->_gui.framebuffer()->refresh(rect.x1(), rect.y1(),
rect.w(), rect.h());
});
});
});
}
void _handle_config()
{
_config.update();
Xml_node const config = _config.xml();
_output.construct(_env, _heap, config);
_capture_input.construct(_env, _root_dir, _output->_mode.area, config);
unsigned long const period_ms = config.attribute_value("period_ms", 0U);
if (period_ms == 0)
warning("missing or invalid 'period_ms' config attribute");
_timer.trigger_periodic(1000*period_ms);
}
Signal_handler<Main> _config_handler { _env.ep(), *this, &Main::_handle_config };
Main(Env &env) : _env(env)
{
_timer.sigh(_timer_handler);
_config.sigh(_config_handler);
_handle_config();
}
};
void Component::construct(Genode::Env &env) { static Test::Main main(env); }

View File

@ -0,0 +1,3 @@
TARGET = test-vfs_capture
SRC_CC = main.cc
LIBS = base blit vfs