summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-10-11 17:07:16 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-01-26 21:40:08 +0100
commit1d4de11a907e41c06063a2cd5028dc4101690f50 (patch)
tree69af98bbe6512cdbcab33267574c131f85ffd597 /src/tests
parentbfc9c138b1a9e87f9d387e2f900c14807c9da9b9 (diff)
Prepare the Integration with systemd
This is an intermediate commit providing basic functionnalities for setting up integration of the framework with systemd. - file afm-unit.conf is a mustache template - translation of config.xml to json object - mustache (extended) application of the json to the template - post processing of the result for extracting unit files This processing is currently available as a test (and a tool) and will be integrated after more developement, test and validation. Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/CMakeLists.txt20
-rw-r--r--src/tests/test-unit/CMakeLists.txt22
-rw-r--r--src/tests/test-unit/config.xml46
-rw-r--r--src/tests/test-unit/sample.unit94
-rw-r--r--src/tests/test-unit/test-unit.c89
5 files changed, 271 insertions, 0 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
new file mode 100644
index 0000000..09d4d0b
--- /dev/null
+++ b/src/tests/CMakeLists.txt
@@ -0,0 +1,20 @@
+###########################################################################
+# Copyright 2016, 2017 IoT.bzh
+#
+# author: José Bollo <jose.bollo@iot.bzh>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###########################################################################
+
+add_subdirectory(test-unit)
+
diff --git a/src/tests/test-unit/CMakeLists.txt b/src/tests/test-unit/CMakeLists.txt
new file mode 100644
index 0000000..3f6db69
--- /dev/null
+++ b/src/tests/test-unit/CMakeLists.txt
@@ -0,0 +1,22 @@
+###########################################################################
+# Copyright 2016, 2017 IoT.bzh
+#
+# author: José Bollo <jose.bollo@iot.bzh>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###########################################################################
+
+include_directories(../..)
+add_executable(test-unit test-unit.c)
+target_link_libraries(test-unit wgtpkg wgt utils)
+add_test(NAME test-unit COMMAND test-unit ${CMAKE_CURRENT_SOURCE_DIR}/sample.unit ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/src/tests/test-unit/config.xml b/src/tests/test-unit/config.xml
new file mode 100644
index 0000000..24a383d
--- /dev/null
+++ b/src/tests/test-unit/config.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widget xmlns="http://www.w3.org/ns/widgets" id="bzh.iot.geoloc" version="0.0.1-alpha">
+ <name>Sample Service</name>
+ <icon src="service.png"/>
+ <content src="index.html" type="text/html"/>
+ <description>
+ This is the Smarthome QML demo application.
+ It shows some user interfaces for controlling an automated house.
+ The user interface is completely done with QML.
+ </description>
+ <author>Qt team</author>
+ <license>GPL</license>
+ <feature name="urn:AGL:widget:required-binding">
+ <param name="#target" value="main" />
+ <param name="gps" value="ws" />
+ <param name="phone" value="dbus" />
+ <param name="identity" value="link" />
+ <param name="log:https://oic@agl.iot.bzh/cloud/log" value="cloud" />
+ </feature>
+ <feature name="urn:AGL:widget:required-permission">
+ <param name="#target" value="main" />
+ <param name="urn:AGL:permission::platform:no-oom" value="required" />
+ <param name="urn:AGL:permission::partner:real-time" value="required" />
+ <param name="urn:AGL:permission::public:applications:read" value="required" />
+ <param name="urn:AGL:permission::public:display" value="required" />
+ </feature>
+ <feature name="urn:AGL:widget:provided-binding">
+ <param name="#target" value="geoloc" />
+ <param name="description" value="binding of name geoloc" />
+ <param name="content.src" value="libs/binding-geoloc.so" />
+ <param name="content.type" value="application/vnd.agl.service" />
+ </feature>
+ <feature name="urn:AGL:widget:required-binding">
+ <param name="#target" value="geoloc" />
+ <param name="identity" value="auto" />
+ </feature>
+ <feature name="urn:AGL:widget:required-permission">
+ <param name="#target" value="geoloc" />
+ <param name="urn:AGL:permission:real-time" value="required" />
+ <param name="urn:AGL:permission:syscall:*" value="required" />
+ </feature>
+ <feature name="urn:AGL:widget:defined-permission">
+ <param name="urn:AGL:permission:geoloc:public:settings" value="public" />
+ </feature>
+</widget>
+
diff --git a/src/tests/test-unit/sample.unit b/src/tests/test-unit/sample.unit
new file mode 100644
index 0000000..2ee2a2a
--- /dev/null
+++ b/src/tests/test-unit/sample.unit
@@ -0,0 +1,94 @@
+{{#targets.list}}
+
+%begin systemd-unit
+
+# auto generated by wgtpkg-unit for {{id}} version {{version}} target {{:#target}}
+%nl
+
+[unit]
+Description={{description}}
+X-Name={{name.content}}
+X-Name-Short={{name.short}}
+X-Id={{id}}
+X-Idaver={{idaver}}
+X-Target-Name={{:#target}}
+X-Author={{{author.content}}}
+X-Author-email={{author.email}}
+%nl
+
+# Adds check to smack
+ConditionSecurity=smack
+%nl
+
+# Automatic bound to required bindings
+{{#required-binding.list}}
+BindsTo=afm-binding-{{name}}
+After=afm-binding-{{name}}
+{{/required-binding.list}}
+%nl
+
+[Service]
+SmackProcessLabel=User::App::{{id}}
+
+{{#required-permission.dict}}
+ {{#urn:AGL:permission::platform:no-oom}} OOMScoreAdjust=-500 {{/urn:AGL:permission::platform:no-oom}}
+ {{#urn:AGL:permission::partner:real-time}} IOSchedulingClass=realtime {{/urn:AGL:permission::partner:real-time}}
+ {{^urn:AGL:permission::partner:real-time}} RestrictRealtime=on {{/urn:AGL:permission::partner:real-time}}
+ {{#urn:AGL:permission::public:display}} SupplementaryGroups=display {{/urn:AGL:permission::public:display}}
+ {{^urn:AGL:permission::public:syscall:clock}} SystemCallFilter=~@clock {{/urn:AGL:permission::public:syscall:clock}}
+ {{^urn:AGL:permission::public:internet}} RestrictAddressFamilies=AF_UNIX {{/urn:AGL:permission::public:internet}}
+{{/required-permission.dict}}
+%nl
+
+WorkingDirectory={{widget-app-data-dir}}
+
+{{#content.type=text/html}}
+
+%systemd-unit user
+
+%systemd-unit service afm-appli-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}
+
+ExecStart=/usr/bin/afb-daemon --port=%P --random-token \
+ --rootdir={{widget-install-dir}} \
+ --workdir={{{widget-app-data-dir}}} \
+ --roothttp=htdocs \
+ {{#required-permission.dict.urn:AGL:permission::public:applications:read}}\
+ --alias=/icons:{{widget-icons-dir}} \
+ \{{/required-permission.dict.urn:AGL:permission::public:applications:read}}
+ {{#required-binding}}\
+ --ws-client=unix:%t/bindings/{{:#target}}
+ \{{/required-binding}}
+ --exec /usr/bin/web-runtime http://localhost:@p/{{content.src}}?token=@t
+
+{{/content.type=text/html}}
+
+{{#content.type=application/vnd.agl.service}}
+
+%systemd-unit user
+%systemd-unit service afm-binding-{{:#target}}
+
+ExecStart=/usr/bin/afb-daemon \
+ --rootdir={{widget-install-dir}} \
+ --workdir={{{widget-app-data-dir}}} \
+ --no-httpd \
+ --ws-server=unix:%t/bindings/{{:#target}}
+
+%end systemd-unit
+%begin systemd-unit
+
+# auto generated by wgtpkg-unit for {{id}} version {{version}} target {{:#target}}
+#
+%systemd-unit user
+%systemd-unit socket afm-binding-{{:#target}}
+
+
+[socket]
+SmackLabel=*
+ListenStream=%t/bindings/{{:#target}}
+
+{{/content.type=application/vnd.agl.service}}
+
+%end systemd-unit
+
+{{/targets.list}}
+
diff --git a/src/tests/test-unit/test-unit.c b/src/tests/test-unit/test-unit.c
new file mode 100644
index 0000000..09b7c86
--- /dev/null
+++ b/src/tests/test-unit/test-unit.c
@@ -0,0 +1,89 @@
+/*
+ Copyright 2016, 2017 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <json-c/json.h>
+
+#include <wgt.h>
+#include <utils-json.h>
+#include <wgt-json.h>
+#include <wgtpkg-mustach.h>
+#include <wgtpkg-unit.h>
+
+
+#define error(...) fprintf(stderr,__VA_ARGS__),exit(1)
+
+
+
+static int process1(const struct unitdesc *desc)
+{
+ int isuser = desc->scope == unitscope_user;
+ int issystem = desc->scope == unitscope_system;
+ int issock = desc->type == unittype_socket;
+ int isserv = desc->type == unittype_service;
+ const char *name = desc->name;
+ const char *content = desc->content;
+
+printf("\n##########################################################");
+printf("\n### usr=%d sys=%d soc=%d srv=%d name %s%s", isuser, issystem, issock, isserv, name?:"?", issock?".socket":isserv?".service":"");
+printf("\n##########################################################");
+printf("\n%s\n\n",content);
+ return 0;
+}
+
+static int process(void *closure, const struct unitdesc descs[], unsigned count)
+{
+ while (count--)
+ process1(descs++);
+ return 0;
+}
+
+int main(int ac, char **av)
+{
+ struct json_object *obj;
+ int rc;
+
+ rc = unit_generator_on(*++av);
+ if (rc < 0)
+ error("can't read template %s: %m",*av);
+ while(*++av) {
+ obj = wgt_path_to_json(*av);
+ if (!obj)
+ error("can't read widget config at %s: %m",*av);
+
+ j_add_string_m(obj, "#metadata.install-dir", "INSTALL-DIR");
+ j_add_string_m(obj, "#metadata.app-data-dir", "%h/app-data");
+ j_add_string_m(obj, "#metadata.icons-dir", "ICONS-DIR");
+ j_add_string_m(obj, "#metadata.http-port", "HTTP-PORT");
+
+ puts(json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY));
+ rc = unit_generator_process(obj, process, NULL);
+ if (rc)
+ error("can't apply generate units, error %d",rc);
+ json_object_put(obj);
+ }
+ return 0;
+}
+
+