Separate app-manager and app-framework from WAMR (#3129)
As planned, the app-manager and app-framework are to be migrated to https://github.com/bytecodealliance/wamr-app-framework. ps. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2329 https://github.com/bytecodealliance/wasm-micro-runtime/wiki/TSC-meeting-notes
@ -1,50 +0,0 @@
|
||||
# IoT Application Store
|
||||
Wasm application management portal for WAMR
|
||||
|
||||
## Start the server
|
||||
|
||||
### Using docker
|
||||
1. install docker and docker-compose
|
||||
``` bash
|
||||
sudo apt install docker.io docker-compose
|
||||
```
|
||||
|
||||
2. start
|
||||
``` bash
|
||||
docker-compose up
|
||||
```
|
||||
### Using commands
|
||||
> Note: must use python3.5. If you don't have python3.5 on your machine, had better using docker
|
||||
1. install the required package
|
||||
``` bash
|
||||
pip3 install django
|
||||
```
|
||||
|
||||
2. Start device server
|
||||
``` bash
|
||||
cd wasm_django/server
|
||||
python3 wasm_server.py
|
||||
```
|
||||
|
||||
3. Start IoT application management web portal
|
||||
``` bash
|
||||
cd wasm_django
|
||||
python3 manage.py runserver 0.0.0.0:80
|
||||
```
|
||||
|
||||
## Start the runtime
|
||||
1. Download WAMR runtime from [help](http://localhost/help/) page
|
||||
> NOTE: You need to start the server before accessing this link!
|
||||
|
||||
2. Start a WAMR runtime from localhost
|
||||
``` bash
|
||||
chmod +x simple
|
||||
./simple
|
||||
```
|
||||
or from other computers
|
||||
``` bash
|
||||
./simple -a [your.server.ip.address]
|
||||
```
|
||||
|
||||
## Online demo
|
||||
http://82.156.57.236/
|
||||
@ -1,22 +0,0 @@
|
||||
version: '2.0'
|
||||
|
||||
services:
|
||||
web_portal:
|
||||
build: ./wasm_django
|
||||
network_mode: "host"
|
||||
depends_on:
|
||||
- 'device_server'
|
||||
restart: always
|
||||
volumes:
|
||||
- store:/app/static/upload/
|
||||
device_server:
|
||||
build:
|
||||
context: ./wasm_django
|
||||
dockerfile: ./server/Dockerfile
|
||||
network_mode: "host"
|
||||
restart: always
|
||||
volumes:
|
||||
- store:/app/static/upload/
|
||||
|
||||
volumes:
|
||||
store:
|
||||
@ -1,9 +0,0 @@
|
||||
FROM python:3.5
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
# hadolint ignore=DL3013
|
||||
RUN pip install django --no-cache-dir
|
||||
|
||||
ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:80"]
|
||||
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -1,5 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DevicesConfig(AppConfig):
|
||||
name = 'devices'
|
||||
@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -1,141 +0,0 @@
|
||||
<!--
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
-->
|
||||
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
|
||||
<title> Wasm-Micro-Runtime </title>
|
||||
<link rel="stylesheet" type="text/css" href="{%static 'css/application.css'%}"/>
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
|
||||
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body style="background-image: linear-gradient(to right, rgb(248, 248, 248) , rgb(194, 194, 190))">
|
||||
|
||||
<div id="container" style="background-image: url('{%static 'photo//totalblack.png'%}')">
|
||||
<div id="content">
|
||||
<div id= "mainnav">
|
||||
<ul>
|
||||
<li ><a href="https://github.com/intel/wasm-micro-runtime">GitHub</a></li>
|
||||
<li ><a href="/">Devices</a></li>
|
||||
<li ><a href="/appstore/">App Store</a></li>
|
||||
<li ><a href="/help/">Help</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="headers" style="background-image: url('{%static 'photo/milky-way-2695569_1280.jpg'%}')">
|
||||
<h1 id="maintitle">WebAssembly Micro Runtime - APP Store Demo</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-md-2 col-lg-2 col-xl-2"></div>
|
||||
<div class="col-sm-8 col-md-8 col-lg-8 col-xl-8" id="section">
|
||||
<div id="photo">
|
||||
<p>
|
||||
<img src="{%static 'photo/net_device.png'%}" ;height="65" width="65" />
|
||||
</p>
|
||||
</div>
|
||||
<div id="IPs">IP : </div>
|
||||
<div id="ports">Port : </div>
|
||||
<div id="installs">Installed apps : </div>
|
||||
</div>
|
||||
<div class="col-sm-2 col-md-2 col-lg-2 col-xl-2"></div>
|
||||
</div>
|
||||
|
||||
<div class="middlebox" style="display:none;">
|
||||
<div class="warning">Dialog Box</div>
|
||||
<div class="findapp"> APP </div>
|
||||
<button class="surebtn" type="button" value="sure">OK</button>
|
||||
</div>
|
||||
|
||||
<div class="deletebox" style="display:none;">
|
||||
<div class="warning2">Dialog Box</div>
|
||||
<div class="findapp"> APP </div>
|
||||
<button class="suresbtn" type="button" value="sure">OK</button>
|
||||
<button class="cancelsbtn" type="button" value="Cancel">Cancel</button>
|
||||
</div>
|
||||
|
||||
<div id="loading">
|
||||
<p class="loadapp"> app is downloading now </p>
|
||||
<div id="preloader">
|
||||
<div id="loader"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="main">
|
||||
<div class="mainbox">
|
||||
<div class= "close"> × </div>
|
||||
<div class="hotapps">HOT Applications</div>
|
||||
<div class="col-sm-6" id="searchbar">
|
||||
<form method="post" action="/apps/" id="form_addServiceInfoAll">
|
||||
{% csrf_token %}
|
||||
<div class="input-group">
|
||||
<input type="text" name="mykey" class="form-control" placeholder="Input the product name" required />
|
||||
<input type="hidden" name="voip" id="aa" value="">
|
||||
<input type="hidden" name="voport" id="bb" value="">
|
||||
<span class="input-group-btn">
|
||||
<input type="submit" class="btn btn-default" value="Search" />
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div id="scrollba">
|
||||
<div id="Dapplications">
|
||||
<div id="appslogo" style="width:45px; height:25px; float:left; "><img src="{%static 'photo/application.png'%}" ;height="35" width="35" /></div>
|
||||
<p id="appsinfo1" style="font-size:15px;font-family:'sansationlight';width:310px; height:25px; float:left; "> Product Name: </p>
|
||||
<p id="appsinfo2" style="font-size:15px;font-family:'sansationlight';width:120px; height:25px; float:left; "> Current Version: </p>
|
||||
<button class="mybtn2" type="button" onclick="getthis(this)" value="downloadit"> ↓ Install</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-sm-8 col-md-8 col-lg-8 col-xl-8" id="download">
|
||||
<p class = "explain pull-left" >List of Installed Apps:</p>
|
||||
<button id="btn" class="btn btn-outline-primary pull-right" style="float:right" type="button" value="add">Install Application</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="APPS" class="sourceapp">
|
||||
<div id="applications">
|
||||
<div id="applogo"><img src="{%static 'photo/app(1).png'%}" ;height="35" width="35" /></div>
|
||||
<div id="appinfo1"> Product Name: </div>
|
||||
<div id="appinfo2"> Staus: </div>
|
||||
<div id="appinfo3"> Current Version: </div>
|
||||
</div>
|
||||
<div id="delete" ><img class="mybtn" style="cursor:pointer" src="{%static 'photo/delete.png'%}" ;height="35" width="35" /></div>
|
||||
</div>
|
||||
|
||||
<footer class="footer"> Copyright© intel.com</footer>
|
||||
|
||||
|
||||
|
||||
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||
<script>
|
||||
var alist = {{alist|safe}}; /*alist is a list of downloaded apps under the current device*/
|
||||
var dlist = {{dlist|safe}}; /*dlist saves the device info that includes its IP, Port and number of apps*/
|
||||
var llist = {{llist|safe}}; /*llist is a list of apps avaliable for installing that are synchronously updated with appstore*/
|
||||
var open_status ={{open_status|safe}};/*check is the search bar working&searching,otherwise, close window and return to the main page*/
|
||||
var search_node ={{search_node|safe}};/*THe queried app node*/
|
||||
</script>
|
||||
<script type="text/javascript" src="{%static 'js/application.js'%}"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,98 +0,0 @@
|
||||
<!--
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
-->
|
||||
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
|
||||
|
||||
<title> Wasm-Micro-Runtime </title>
|
||||
<link rel="stylesheet" type="text/css" href="{%static 'css/appstore.css'%}"/>
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
|
||||
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body style="background-color:rgb(240, 240, 240)">
|
||||
|
||||
<div id="container" style="background-image: url('{%static 'photo//totalblack.png'%}')">
|
||||
<div id="content">
|
||||
<div id= "mainnav">
|
||||
<ul>
|
||||
<li ><a href="https://github.com/intel/wasm-micro-runtime">GitHub</a></li>
|
||||
<li ><a href="/">Devices</a></li>
|
||||
<li ><a href="/appstore/">App Store</a></li>
|
||||
<li ><a href="/help/">Help</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="headers" style="background-image: url('{%static 'photo/milky-way-2695569_1280.jpg'%}')">
|
||||
<h1 id="maintitle">WebAssembly Micro Runtime - APP Store Demo</h1>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div id="introinfo"></div> -->
|
||||
<!-- <div class="style-one"></div> -->
|
||||
|
||||
<div class="deletebox" style="display:none;">
|
||||
<div class="warning2">Dialog Box</div>
|
||||
<div class="findapp"> APP </div>
|
||||
<button class="suresbtn" type="button" value="sure">OK</button>
|
||||
<button class="delsbtn" type="button" value="Cancel">Cancel</button>
|
||||
</div>
|
||||
|
||||
<div id = "introstore">
|
||||
<div id="applicationlist">
|
||||
<div class="bar">
|
||||
<div class="leftpart">The products </div>
|
||||
<div style="position:relative; float:left; left:50px; font-size:14px; height:50px; top:10px;">Application List</div>
|
||||
<div class="rightpart">
|
||||
<form action="/upload" method = "POST" enctype="multipart/form-data">
|
||||
{%csrf_token%}
|
||||
<div class="stylehere">
|
||||
<input type ="file" required name="myfile" class = "file">
|
||||
<a href="#" class="choosestyle">Choose File</a>
|
||||
</div>
|
||||
<div class="stylehere">
|
||||
<input type="submit" value = "upload" class="btn btn-info">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class = "appbook">
|
||||
<div id="applications">
|
||||
<div id="appimage" ><img class="mysoftware" src="{%static 'photo/software-icon-32081.png'%}" ;height="50" width="40"/></div>
|
||||
<p id="appinfo1" style="position:relative; font-size:15px;width:35%; height:25px; float:left; left:5%;"> Product Name: </p>
|
||||
<p id="appinfo2" style="position:relative; font-size:15px;width:30%; height:25px; float:left; left:5%;"> Product Version: </p>
|
||||
<p id="lable" style="position:relative;font-size:11px;font-family:'logo';width:10%; height:25px; float:left; left:5%;"> Preloaded Apps </p>
|
||||
<button id="delbutton" type="button" style="position: relative; height:25px; float:left; left:5%;" onclick="deleteClick(this)" method = "get" name="delete">Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="footer">
|
||||
Copyright© intel.com
|
||||
</footer>
|
||||
|
||||
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||
<script>
|
||||
var elist = {{staticlist|safe}}/*saves all the apps that preloaded and are not able to be removed from applestore*/
|
||||
var flist = {{flist|safe}} /*a list of locally uploaded apps installed by users*/
|
||||
var ulist = {{ulist|safe}} /*Declare about is the app avaliable for uploading to the appstore: wasm_file OR preloaded already*/
|
||||
</script>
|
||||
<script type="text/javascript" src="{%static 'js/appstore.js'%}"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,125 +0,0 @@
|
||||
<!--
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
-->
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<title>wasm-micro-runtime</title>
|
||||
|
||||
<style type="text/css">
|
||||
html, body{overflow:hidden;margin:0;background:#000;}
|
||||
body{font-family:'Open Sans', 'Helvetica Neue', 'Hiragino Sans GB', 'LiHei Pro', Arial, sans-serif;color:#333;}
|
||||
#wrapper{position:absolute;left:0;width:320px;text-align:center;top:50%;left:50%;margin-left:-160px;margin-top:-160px;-webkit-user-select:none;-moz-user-select:none;user-select:none;}
|
||||
h1{font-family:'Montserrat', 'Helvetica Neue', Arial, sans-serif;font-weight:700;font-size:50px;letter-spacing:9px;text-transform:uppercase;color:#eee;margin:12px 0;left:4px;}
|
||||
h2{color:#999;font-weight:normal;font-size:20px;letter-spacing:.200em;margin-bottom:30px;left:3px;}
|
||||
h1, h2{position:relative;}
|
||||
p{font-size:14px;line-height:2em;margin:0;letter-spacing:2px;}
|
||||
canvas{position:absolute;top:0;left:0;z-index:0;width:100%;height:100%;pointer-events:none;}
|
||||
a{color:#999;text-decoration:none;transition:color .2s ease;}
|
||||
a:hover{color:#f33;}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="./js/jquery.min.js"></script>
|
||||
|
||||
<div id="wrapper">
|
||||
<h1>404</h1>
|
||||
<h2>Server Not Found</h2>
|
||||
<p><a href="https://github.com/intel/wasm-micro-runtime" target="_blank">Github</a></p>
|
||||
</div>
|
||||
|
||||
|
||||
<canvas width="1920" height="917"></canvas>
|
||||
|
||||
<script type="text/javascript">
|
||||
document.addEventListener('touchmove', function (e) {
|
||||
e.preventDefault()
|
||||
})
|
||||
var c = document.getElementsByTagName('canvas')[0],
|
||||
x = c.getContext('2d'),
|
||||
pr = window.devicePixelRatio || 1,
|
||||
w = window.innerWidth,
|
||||
h = window.innerHeight,
|
||||
f = 90,
|
||||
q,
|
||||
m = Math,
|
||||
r = 0,
|
||||
u = m.PI*2,
|
||||
v = m.cos,
|
||||
z = m.random
|
||||
c.width = w*pr
|
||||
c.height = h*pr
|
||||
x.scale(pr, pr)
|
||||
x.globalAlpha = 0.6
|
||||
function i(){
|
||||
x.clearRect(0,0,w,h)
|
||||
q=[{x:0,y:h*.7+f},{x:0,y:h*.7-f}]
|
||||
while(q[1].x<w+f) d(q[0], q[1])
|
||||
}
|
||||
function d(i,j){
|
||||
x.beginPath()
|
||||
x.moveTo(i.x, i.y)
|
||||
x.lineTo(j.x, j.y)
|
||||
var k = j.x + (z()*2-0.25)*f,
|
||||
n = y(j.y)
|
||||
x.lineTo(k, n)
|
||||
x.closePath()
|
||||
r-=u/-50
|
||||
x.fillStyle = '#'+(v(r)*127+128<<16 | v(r+u/3)*127+128<<8 | v(r+u/3*2)*127+128).toString(16)
|
||||
x.fill()
|
||||
q[0] = q[1]
|
||||
q[1] = {x:k,y:n}
|
||||
}
|
||||
function y(p){
|
||||
var t = p + (z()*2-1.1)*f
|
||||
return (t>h||t<0) ? y(p) : t
|
||||
}
|
||||
document.onclick = i
|
||||
document.ontouchstart = i
|
||||
i()
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var snow = function() {
|
||||
if(1==1) {
|
||||
$("body").append('<canvas id="christmasCanvas" style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;"></canvas>');
|
||||
var b = document.getElementById("christmasCanvas"), a = b.getContext("2d"), d = window.innerWidth, c = window.innerHeight;
|
||||
b.width = d;
|
||||
b.height = c;
|
||||
for(var e = [], b = 0;b < 70;b++) {
|
||||
e.push({x:Math.random() * d, y:Math.random() * c, r:Math.random() * 4 + 1, d:Math.random() * 70})
|
||||
}
|
||||
var h = 0;
|
||||
window.intervral4Christmas = setInterval(function() {
|
||||
a.clearRect(0, 0, d, c);
|
||||
a.fillStyle = "rgba(255, 255, 255, 0.6)";
|
||||
a.shadowBlur = 5;
|
||||
a.shadowColor = "rgba(255, 255, 255, 0.9)";
|
||||
a.beginPath();
|
||||
for(var b = 0;b < 70;b++) {
|
||||
var f = e[b];
|
||||
a.moveTo(f.x, f.y);
|
||||
a.arc(f.x, f.y, f.r, 0, Math.PI * 2, !0)
|
||||
}
|
||||
a.fill();
|
||||
h += 0.01;
|
||||
for(b = 0;b < 70;b++) {
|
||||
if(f = e[b], f.y += Math.cos(h + f.d) + 1 + f.r / 2, f.x += Math.sin(h) * 2, f.x > d + 5 || f.x < -5 || f.y > c) {
|
||||
e[b] = b % 3 > 0 ? {x:Math.random() * d, y:-10, r:f.r, d:f.d} : Math.sin(h) > 0 ? {x:-5, y:Math.random() * c, r:f.r, d:f.d} : {x:d + 5, y:Math.random() * c, r:f.r, d:f.d}
|
||||
}
|
||||
}
|
||||
}, 70)
|
||||
}
|
||||
}
|
||||
snow();
|
||||
</script><canvas id="christmasCanvas" style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;" width="1920" height="917"></canvas>
|
||||
|
||||
|
||||
</body></html>
|
||||
@ -1,102 +0,0 @@
|
||||
<!--
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
-->
|
||||
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title> Wasm-Micro-Runtime </title>
|
||||
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<!-- <link rel="stylesheet" type="text/css" href="{%static%/css/index.css"/> -->
|
||||
<!-- <link rel="stylesheet" type="text/css" href="/home/xujun/mysite/static/css/index.css"/> -->
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
|
||||
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
|
||||
|
||||
<head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row clearfix">
|
||||
<div class="col-md-12 column">
|
||||
<div class="jumbotron">
|
||||
<h1>
|
||||
How to use?
|
||||
</h1>
|
||||
<p>
|
||||
1. Download a simple runtime (build for ubuntu 20.04 64 bits, other platforms please build
|
||||
from the <a href="https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/samples/simple">source code</a>)
|
||||
</p>
|
||||
<p>
|
||||
2. In the terminal: <code>cd ~/Download && ./simple -a 82.156.57.236</code>
|
||||
</p>
|
||||
<div class="span12">
|
||||
<div class="alert alert-info">
|
||||
<!-- <button class="close" type="button" data-dismiss="alert">×</button> -->
|
||||
<h5>
|
||||
Notes:
|
||||
</h5> We also have a <strong>UI-enabled runtime</strong>, please <a
|
||||
href="../static/upload/wasm_runtime_wgl">download here</a> and enjoy.</strong> It may require
|
||||
a few more setups.
|
||||
<p>Before running the UI-enabled runtime, please install some required softwares:</p>
|
||||
<p><code>sudo apt-get install libsdl2-2.0-0:i386</code> </p>
|
||||
<p>For more details please refer to this <a
|
||||
href="https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/samples/littlevgl">guide</a>
|
||||
</p>
|
||||
<p><code>cd ~/Download && ./wasm_runtime_wgl -a 82.156.57.236</code></p>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
3. Return to device page, find your device according to the IP address and click it, you
|
||||
will enter application installation page
|
||||
</p>
|
||||
<p>
|
||||
4. In the application installation page, click the Install Application button, and chose an
|
||||
app to install. (The "ui_app" is only for UI_enabled_runtimes, simple runtime can't install
|
||||
this app)
|
||||
</p>
|
||||
<p>
|
||||
5. If you want to upload a new application, go to App Store page, choose a file and click
|
||||
upload
|
||||
</p>
|
||||
<p>
|
||||
<a class="btn btn-primary btn-large" href="/">Go Back</a>
|
||||
<a class="btn btn-primary btn-large" href="../static/upload/simple">Download
|
||||
simple_runtime</a>
|
||||
<a class="btn btn-primary btn-large" href="../static/upload/wasm_runtime_wgl">Download
|
||||
UI_enabled_runtime</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Like this project?</h4>
|
||||
<p class="card-text">Join us and build a powerful and interesting world for embedded
|
||||
devices!</p>
|
||||
<iframe
|
||||
src="https://ghbtns.com/github-btn.html?user=intel&repo=wasm-micro-runtime&type=star&count=true&size=large"
|
||||
frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
|
||||
<iframe
|
||||
src="https://ghbtns.com/github-btn.html?user=intel&repo=wasm-micro-runtime&type=fork&count=true&size=large"
|
||||
frameborder="0" scrolling="0" width="158px" height="30px"></iframe>
|
||||
<p>
|
||||
<a href="https://github.com/intel/wasm-micro-runtime" class="btn btn-success">View
|
||||
on GitHub</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,91 +0,0 @@
|
||||
<!--
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
-->
|
||||
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
|
||||
<title> Wasm-Micro-Runtime </title>
|
||||
<link rel="stylesheet" type="text/css" href="{%static 'css/index.css'%}"/>
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
|
||||
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<div id="container" style="background-image: url('{%static 'photo/totalblack.png'%}')">
|
||||
<div id="content">
|
||||
<div id= "mainnav">
|
||||
<ul>
|
||||
<li ><a href="https://github.com/intel/wasm-micro-runtime">GitHub</a></li>
|
||||
<li ><a href="/">Devices</a></li>
|
||||
<li ><a href="/appstore/">App Store</a></li>
|
||||
<li ><a href="/help/">Help</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="headers" style="background-image: url('{%static 'photo/milky-way-2695569_1280.jpg'%}')">
|
||||
<h1 id="maintitle">WebAssembly Micro Runtime - APP Store Demo</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-1 col-md-1 col-lg-1 col-xl-1"></div>
|
||||
<div class="col-sm-4 col-md-4 col-lg-4 col-xl-4">
|
||||
<div id="photo2">
|
||||
<p>
|
||||
<img src="{%static 'photo/net_device.png'%}" ;height="45" width="45" />
|
||||
</p>
|
||||
</div>
|
||||
<div id="devic"><p style="font-size:22px;">The devices</p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="dividebar"></div>
|
||||
|
||||
|
||||
<div id="devices" class="devics">
|
||||
<div class="deviceClick" style="cursor:pointer" onclick="deviceClick(this)">
|
||||
<div id="section">
|
||||
<div id="photo">
|
||||
<p>
|
||||
<img src="{%static 'photo/net_device.png'%}" ;height="60" width="60" />
|
||||
</p>
|
||||
</div>
|
||||
<div id="IPs">IP : </div>
|
||||
<div id="ports">Port : </div>
|
||||
<div id="installs">Installed apps : </div>
|
||||
</div>
|
||||
<div class="smenu">
|
||||
<p id="del" style="cursor:pointer">
|
||||
<img class = "toapps" src="{%static 'photo/menu.png'%}" href= "javascript:void(0);" height="30" width="30" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <button class="prev" type="button" value="prev" onclick="prevpage(this)">Previous</button>-->
|
||||
<!-- <button class="next" type="button" value="next" onclick="nextpage(this)">Next</button> -->
|
||||
|
||||
<footer class="footer">
|
||||
Copyright© intel.com
|
||||
</footer>
|
||||
|
||||
|
||||
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||
<script>
|
||||
var dlist = {{dlist|safe}};/*Devices List that render to the current page*/
|
||||
</script>
|
||||
<script type="text/javascript" src="{%static 'js/index.js'%}"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -1,273 +0,0 @@
|
||||
'''
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
'''
|
||||
|
||||
# _*_
|
||||
from django.shortcuts import render, render_to_response
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
|
||||
import json
|
||||
import socket
|
||||
import os
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
avaliable_list = [
|
||||
{'ID': 'timer', 'Version': '1.0'},
|
||||
{'ID': 'connection', 'Version': '1.0'},
|
||||
{'ID': 'event_publisher', 'Version': '3.0'},
|
||||
{'ID': 'event_subscriber', 'Version': '1.0'},
|
||||
{'ID': 'request_handler', 'Version': '1.0'},
|
||||
{'ID': 'sensor', 'Version': '1.0'},
|
||||
{'ID': 'ui_app', 'Version': '1.0'}
|
||||
]
|
||||
|
||||
# Help
|
||||
def help(req):
|
||||
# return "Help" page
|
||||
return render(req, "help.html")
|
||||
|
||||
# View
|
||||
def index(req):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
host = '127.0.0.1'
|
||||
port = 8889
|
||||
msg = ""
|
||||
err = ""
|
||||
|
||||
try:
|
||||
s.connect((host, port))
|
||||
s.send(bytes("query:all", encoding='utf8'))
|
||||
s.settimeout(10)
|
||||
msg = s.recv(1024)
|
||||
except socket.timeout as e:
|
||||
err = "empty"
|
||||
print("no client connected")
|
||||
except socket.error as e:
|
||||
err = "refused"
|
||||
print("server not started")
|
||||
|
||||
s.close()
|
||||
|
||||
device_list = []
|
||||
if msg != "":
|
||||
devices = msg.decode('utf-8').split("*")
|
||||
for dev in devices:
|
||||
dev_info = eval(dev)
|
||||
addr = dev_info['addr']
|
||||
port = dev_info['port']
|
||||
apps = dev_info['num']
|
||||
device_list.append({'IP': addr, 'Port': port, 'apps': apps})
|
||||
else:
|
||||
if err == "refused":
|
||||
return render(req, "empty.html")
|
||||
|
||||
dlist = device_list
|
||||
|
||||
return render(req, 'mysite.html', {'dlist': json.dumps(dlist)})
|
||||
|
||||
|
||||
def apps(req):
|
||||
open_status = ''
|
||||
search_node = []
|
||||
if req.method == "POST":
|
||||
dev_search = req.POST['mykey']
|
||||
dev_addr = req.POST['voip']
|
||||
dev_port = req.POST['voport']
|
||||
open_status = 'open'
|
||||
for i in avaliable_list:
|
||||
if i['ID'] == dev_search:
|
||||
search_node = [{'ID':dev_search, 'Version': '1.0'}]
|
||||
print("search_node:",search_node)
|
||||
break
|
||||
else:
|
||||
search_node = ["Nothing find"]
|
||||
print( "final:",search_node)
|
||||
else:
|
||||
dev_addr = req.GET['ip']
|
||||
dev_port = req.GET['port']
|
||||
open_status = 'close'
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
host = '127.0.0.1'
|
||||
port = 8889
|
||||
msg = ""
|
||||
err = ""
|
||||
|
||||
try:
|
||||
s.connect((host, port))
|
||||
s.send(bytes("query:"+dev_addr+":"+str(dev_port), encoding='utf8'))
|
||||
msg = s.recv(1024)
|
||||
except socket.error as e:
|
||||
print("unable to connect to server")
|
||||
msg = b"fail"
|
||||
s.close()
|
||||
|
||||
app_list = []
|
||||
|
||||
if msg != "":
|
||||
if msg.decode() == "fail":
|
||||
return render(req, "empty.html")
|
||||
else:
|
||||
dic = eval(msg.decode(encoding='utf8'))
|
||||
app_num = dic["num"]
|
||||
for i in range(app_num):
|
||||
app_list.append(
|
||||
{'pname': dic["applet"+str(i+1)], 'status': 'Installed', 'current_version': '1.0'})
|
||||
|
||||
alist = app_list
|
||||
device_info = []
|
||||
device_info.append(
|
||||
{'IP': dev_addr, 'Port': str(dev_port), 'apps': app_num})
|
||||
|
||||
print(device_info)
|
||||
return render(req, 'application.html', {'alist': json.dumps(alist), 'dlist': json.dumps(device_info), 'llist': json.dumps(avaliable_list),
|
||||
"open_status":json.dumps(open_status),"search_node": json.dumps(search_node),})
|
||||
|
||||
|
||||
def appDownload(req):
|
||||
dev_addr = req.GET['ip']
|
||||
dev_port = req.GET['port']
|
||||
app_name = req.GET['name']
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
host = '127.0.0.1'
|
||||
port = 8889
|
||||
msg = ""
|
||||
|
||||
app_path = os.path.abspath(os.path.join(os.getcwd(), "static", "upload"))
|
||||
if app_path[-1] != '/':
|
||||
app_path += '/'
|
||||
|
||||
try:
|
||||
s.connect((host, port))
|
||||
s.send(bytes("install:"+dev_addr+":"+str(dev_port)+":"+app_name +
|
||||
":"+app_path + app_name + ".wasm", encoding='utf8'))
|
||||
msg = s.recv(1024)
|
||||
except socket.error as e:
|
||||
print("unable to connect to server")
|
||||
s.close()
|
||||
|
||||
success = "ok"
|
||||
fail = "Fail!"
|
||||
status = [success, fail]
|
||||
print(msg)
|
||||
if msg == b"fail":
|
||||
return HttpResponse(json.dumps({
|
||||
"status": fail
|
||||
}))
|
||||
elif msg == b"success":
|
||||
return HttpResponse(json.dumps({
|
||||
"status": success
|
||||
}))
|
||||
else:
|
||||
return HttpResponse(json.dumps({
|
||||
"status": eval(msg.decode())["error message"].split(':')[1]
|
||||
}))
|
||||
|
||||
|
||||
def appDelete(req):
|
||||
dev_addr = req.GET['ip']
|
||||
dev_port = req.GET['port']
|
||||
app_name = req.GET['name']
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
host = '127.0.0.1'
|
||||
port = 8889
|
||||
s.connect((host, port))
|
||||
s.send(bytes("uninstall:"+dev_addr+":" +
|
||||
str(dev_port)+":"+app_name, encoding='utf8'))
|
||||
msg = s.recv(1024)
|
||||
s.close()
|
||||
r = HttpResponse("ok")
|
||||
return r
|
||||
|
||||
static_list = [{'ID': 'timer', 'Version': '1.0'}, {'ID': 'connection', 'Version': '1.0'}, {'ID': 'event_publisher', 'Version': '3.0'}, {
|
||||
'ID': 'event_subscriber', 'Version': '1.0'}, {'ID': 'reuqest_handler', 'Version': '1.0'}, {'ID': 'sensor', 'Version': '1.0'}, {'ID': 'ui_app', 'Version': '1.0'}]
|
||||
|
||||
def store(req):
|
||||
|
||||
store_path = os.path.join('static', 'upload')
|
||||
status = []
|
||||
|
||||
print(user_file_list)
|
||||
return render(req, 'appstore.html', {'staticlist': json.dumps(static_list), 'flist': json.dumps(user_file_list),'ulist':json.dumps(status)})
|
||||
|
||||
user_file_list = []
|
||||
files_list = []
|
||||
def uploadapps(req):
|
||||
status = []
|
||||
local_list = ['timer','connection','event_publisher','event_subscriber','reuqest_handler','sensor']
|
||||
req.encoding = 'utf-8'
|
||||
if req.method == 'POST':
|
||||
myfile = req.FILES.get("myfile", None)
|
||||
obj = req.FILES.get('myfile')
|
||||
store_path = os.path.join('static', 'upload')
|
||||
file_path = os.path.join('static', 'upload', obj.name)
|
||||
|
||||
if not os.path.exists(store_path):
|
||||
os.makedirs(store_path)
|
||||
|
||||
file_name = obj.name.split(".")[0]
|
||||
file_prefix = obj.name.split(".")[-1]
|
||||
|
||||
|
||||
if file_prefix != "wasm":
|
||||
status = ["Not a wasm file"]
|
||||
elif file_name in local_list:
|
||||
status = ["This App is preloaded"]
|
||||
elif file_name in files_list:
|
||||
status = ["This App is already uploaded"]
|
||||
else:
|
||||
status = []
|
||||
avaliable_list.append({'ID': file_name, 'Version': '1.0'})
|
||||
user_file_list.append({'ID': file_name, 'Version': '1.0'})
|
||||
files_list.append(file_name)
|
||||
|
||||
print(user_file_list)
|
||||
f = open(file_path, 'wb')
|
||||
for chunk in obj.chunks():
|
||||
f.write(chunk)
|
||||
f.close()
|
||||
return render(req, 'appstore.html', {'staticlist': json.dumps(static_list), 'flist': json.dumps(user_file_list),'ulist':json.dumps(status)})
|
||||
|
||||
appname_list = []
|
||||
|
||||
def addapps(request):
|
||||
types = ''
|
||||
print("enter addapps")
|
||||
request.encoding = 'utf-8'
|
||||
app_dic = {'ID': '', 'Version': ''}
|
||||
|
||||
# if request.method == 'get':
|
||||
if "NAME" in request.GET:
|
||||
a_name = request.GET['NAME']
|
||||
if a_name != "" and a_name not in appname_list:
|
||||
appname_list.append(a_name)
|
||||
message = request.GET['NAME'] + request.GET['Version']
|
||||
app_dic['ID'] = request.GET['NAME']
|
||||
app_dic['Version'] = request.GET['Version']
|
||||
avaliable_list.append(app_dic)
|
||||
else:
|
||||
types = "Exist"
|
||||
print(avaliable_list)
|
||||
return render(request, 'appstore.html', {'alist': json.dumps(avaliable_list)})
|
||||
|
||||
def removeapps(req):
|
||||
app_name = req.GET['name']
|
||||
app_version = req.GET['version']
|
||||
remove_app = {'ID': app_name, 'Version': app_version}
|
||||
avaliable_list.remove(remove_app)
|
||||
user_file_list.remove(remove_app)
|
||||
files_list.remove(app_name)
|
||||
return render(req, 'appstore.html', {'alist': json.dumps(avaliable_list),'flist': json.dumps(user_file_list)})
|
||||
|
||||
# Test
|
||||
# if __name__ == "__main__":
|
||||
# print(device_list[0]['IP'])
|
||||
# print(device['IP'])
|
||||
@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,136 +0,0 @@
|
||||
"""
|
||||
Django settings for mysite project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 2.2.2.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/2.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/2.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from django.conf.global_settings import STATIC_ROOT
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '8m05#6yx5wcygj*a+v6+=-y(#o+(z58-3!epq$u@5)64!mmu8q'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
|
||||
'devices',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'mysite.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'mysite.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
APPEND_SLASH = False
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
HERE = os.path.join(HERE,'../')
|
||||
STATICFILES_DIRS = (os.path.join(HERE,'static/'),)
|
||||
#STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),)
|
||||
#STATIC_ROOT = (os.path.join(os.path.dirname(_file_),'static')
|
||||
#templates
|
||||
TEMPLATE_DIRS=[
|
||||
'/home/xujun/mysite/templates',
|
||||
]
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
#config:utf-8
|
||||
|
||||
"""mysite URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/2.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
#from django.conf.urls import include,url
|
||||
from django.urls import path,include
|
||||
from devices import views as devices_views
|
||||
#from login import views as login_views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
path('admin/', admin.site.urls),
|
||||
path('',devices_views.index),
|
||||
path('apps/',devices_views.apps),
|
||||
path('appDownload/', devices_views.appDownload),
|
||||
path('appDelete/', devices_views.appDelete),
|
||||
path('appstore/',devices_views.store),
|
||||
## path('apps/appstore/',devices_views.storeofdevic),
|
||||
## path('search/',devices_views.search),
|
||||
path('upload',devices_views.uploadapps),
|
||||
path('removeapps/',devices_views.removeapps),
|
||||
path('help/',devices_views.help),
|
||||
|
||||
]
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
"""
|
||||
WSGI config for mysite project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
@ -1,6 +0,0 @@
|
||||
FROM python:3.5
|
||||
|
||||
WORKDIR /app
|
||||
COPY server/wasm_server.py /app/server/
|
||||
|
||||
ENTRYPOINT ["python", "server/wasm_server.py"]
|
||||
@ -1,621 +0,0 @@
|
||||
'''
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
'''
|
||||
import select
|
||||
import socket
|
||||
import queue
|
||||
from time import sleep
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
from ctypes import *
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
attr_type_list = [
|
||||
"ATTR_TYPE_BYTE", # = ATTR_TYPE_INT8
|
||||
"ATTR_TYPE_SHORT",# = ATTR_TYPE_INT16
|
||||
"ATTR_TYPE_INT", # = ATTR_TYPE_INT32
|
||||
"ATTR_TYPE_INT64",
|
||||
"ATTR_TYPE_UINT8",
|
||||
"ATTR_TYPE_UINT16",
|
||||
"ATTR_TYPE_UINT32",
|
||||
"ATTR_TYPE_UINT64",
|
||||
"ATTR_TYPE_FLOAT",
|
||||
"ATTR_TYPE_DOUBLE",
|
||||
"ATTR_NONE",
|
||||
"ATTR_NONE",
|
||||
"ATTR_TYPE_BOOLEAN",
|
||||
"ATTR_TYPE_STRING",
|
||||
"ATTR_TYPE_BYTEARRAY"
|
||||
]
|
||||
|
||||
|
||||
Phase_Non_Start = 0
|
||||
Phase_Leading = 1
|
||||
Phase_Type = 2
|
||||
Phase_Size = 3
|
||||
Phase_Payload = 4
|
||||
|
||||
|
||||
|
||||
class imrt_link_message(object):
|
||||
def __init__(self):
|
||||
self.leading = bytes([0x12, 0x34])
|
||||
self.phase = Phase_Non_Start
|
||||
self.size_in_phase = 0
|
||||
self.message_type = bytes()
|
||||
self.message_size = bytes()
|
||||
self.payload = bytes()
|
||||
self.msg = bytes()
|
||||
|
||||
def set_recv_phase(self, phase):
|
||||
self.phase = phase
|
||||
|
||||
def on_imrt_link_byte_arrive(self, ch):
|
||||
self.msg += ch
|
||||
if self.phase == Phase_Non_Start:
|
||||
if ch == b'\x12':
|
||||
self.set_recv_phase(Phase_Leading)
|
||||
else:
|
||||
return -1
|
||||
elif self.phase == Phase_Leading:
|
||||
if ch == b'\x34':
|
||||
self.set_recv_phase(Phase_Type)
|
||||
else:
|
||||
self.set_recv_phase(Phase_Non_Start)
|
||||
return -1
|
||||
elif self.phase == Phase_Type:
|
||||
self.message_type += ch
|
||||
self.size_in_phase += 1
|
||||
|
||||
if self.size_in_phase == 2:
|
||||
(self.message_type, ) = struct.unpack('!H', self.message_type)
|
||||
self.size_in_phase = 0
|
||||
self.set_recv_phase(Phase_Size)
|
||||
elif self.phase == Phase_Size:
|
||||
self.message_size += ch
|
||||
self.size_in_phase += 1
|
||||
|
||||
if self.size_in_phase == 4:
|
||||
(self.message_size, ) = struct.unpack('!I', self.message_size)
|
||||
self.size_in_phase = 0
|
||||
self.set_recv_phase(Phase_Payload)
|
||||
|
||||
if self.message_size == b'\x00':
|
||||
self.set_recv_phase(Phase_Non_Start)
|
||||
return 0
|
||||
|
||||
self.set_recv_phase(Phase_Payload)
|
||||
|
||||
elif self.phase == Phase_Payload:
|
||||
self.payload += ch
|
||||
self.size_in_phase += 1
|
||||
|
||||
if self.size_in_phase == self.message_size:
|
||||
self.set_recv_phase(Phase_Non_Start)
|
||||
return 0
|
||||
|
||||
return 2
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
def read_file_to_buffer(file_name):
|
||||
file_object = open(file_name, 'rb')
|
||||
buffer = None
|
||||
|
||||
if not os.path.exists(file_name):
|
||||
logging.error("file {} not found.".format(file_name))
|
||||
return "file not found"
|
||||
|
||||
try:
|
||||
buffer = file_object.read()
|
||||
finally:
|
||||
file_object.close()
|
||||
|
||||
return buffer
|
||||
|
||||
def decode_attr_container(msg):
|
||||
|
||||
attr_dict = {}
|
||||
|
||||
buf = msg[26 : ]
|
||||
(total_len, tag_len) = struct.unpack('@IH', buf[0 : 6])
|
||||
tag_name = buf[6 : 6 + tag_len].decode()
|
||||
buf = buf[6 + tag_len : ]
|
||||
(attr_num, ) = struct.unpack('@H', buf[0 : 2])
|
||||
buf = buf[2 : ]
|
||||
|
||||
logging.info("parsed attr:")
|
||||
logging.info("total_len:{}, tag_len:{}, tag_name:{}, attr_num:{}"
|
||||
.format(str(total_len), str(tag_len), str(tag_name), str(attr_num)))
|
||||
|
||||
for i in range(attr_num):
|
||||
(key_len, ) = struct.unpack('@H', buf[0 : 2])
|
||||
key_name = buf[2 : 2 + key_len - 1].decode()
|
||||
buf = buf[2 + key_len : ]
|
||||
(type_index, ) = struct.unpack('@c', buf[0 : 1])
|
||||
|
||||
attr_type = attr_type_list[int(type_index[0])]
|
||||
buf = buf[1 : ]
|
||||
|
||||
if attr_type == "ATTR_TYPE_BYTE": # = ATTR_TYPE_INT8
|
||||
(attr_value, ) = struct.unpack('@c', buf[0 : 1])
|
||||
buf = buf[1 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_SHORT": # = ATTR_TYPE_INT16
|
||||
(attr_value, ) = struct.unpack('@h', buf[0 : 2])
|
||||
buf = buf[2 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_INT": # = ATTR_TYPE_INT32
|
||||
(attr_value, ) = struct.unpack('@i', buf[0 : 4])
|
||||
buf = buf[4 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_INT64":
|
||||
(attr_value, ) = struct.unpack('@q', buf[0 : 8])
|
||||
buf = buf[8 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_UINT8":
|
||||
(attr_value, ) = struct.unpack('@B', buf[0 : 1])
|
||||
buf = buf[1 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_UINT16":
|
||||
(attr_value, ) = struct.unpack('@H', buf[0 : 2])
|
||||
buf = buf[2 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_UINT32":
|
||||
(attr_value, ) = struct.unpack('@I', buf[0 : 4])
|
||||
buf = buf[4 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_UINT64":
|
||||
(attr_value, ) = struct.unpack('@Q', buf[0 : 8])
|
||||
buf = buf[8 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_FLOAT":
|
||||
(attr_value, ) = struct.unpack('@f', buf[0 : 4])
|
||||
buf = buf[4 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_DOUBLE":
|
||||
(attr_value, ) = struct.unpack('@d', buf[0 : 8])
|
||||
buf = buf[8 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_BOOLEAN":
|
||||
(attr_value, ) = struct.unpack('@?', buf[0 : 1])
|
||||
buf = buf[1 : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_STRING":
|
||||
(str_len, ) = struct.unpack('@H', buf[0 : 2])
|
||||
attr_value = buf[2 : 2 + str_len - 1].decode()
|
||||
buf = buf[2 + str_len : ]
|
||||
# continue
|
||||
elif attr_type == "ATTR_TYPE_BYTEARRAY":
|
||||
(byte_len, ) = struct.unpack('@I', buf[0 : 4])
|
||||
attr_value = buf[4 : 4 + byte_len]
|
||||
buf = buf[4 + byte_len : ]
|
||||
# continue
|
||||
|
||||
attr_dict[key_name] = attr_value
|
||||
|
||||
logging.info(str(attr_dict))
|
||||
return attr_dict
|
||||
|
||||
class Request():
|
||||
mid = 0
|
||||
url = ""
|
||||
action = 0
|
||||
fmt = 0
|
||||
payload = ""
|
||||
payload_len = 0
|
||||
sender = 0
|
||||
|
||||
def __init__(self, url, action, fmt, payload, payload_len):
|
||||
self.url = url
|
||||
self.action = action
|
||||
self.fmt = fmt
|
||||
# if type(payload) == bytes:
|
||||
# self.payload = bytes(payload, encoding = "utf8")
|
||||
# else:
|
||||
self.payload_len = payload_len
|
||||
if self.payload_len > 0:
|
||||
self.payload = payload
|
||||
|
||||
|
||||
def pack_request(self):
|
||||
url_len = len(self.url) + 1
|
||||
buffer_len = url_len + self.payload_len
|
||||
|
||||
req_buffer = struct.pack('!2BH2IHI',1, self.action, self.fmt, self.mid, self.sender, url_len, self.payload_len)
|
||||
for i in range(url_len - 1):
|
||||
req_buffer += struct.pack('!c', bytes(self.url[i], encoding = "utf8"))
|
||||
req_buffer += bytes([0])
|
||||
for i in range(self.payload_len):
|
||||
req_buffer += struct.pack('!B', self.payload[i])
|
||||
|
||||
return req_buffer, len(req_buffer)
|
||||
|
||||
|
||||
def send(self, conn, is_install):
|
||||
leading = struct.pack('!2B', 0x12, 0x34)
|
||||
|
||||
if not is_install:
|
||||
msg_type = struct.pack('!H', 0x0002)
|
||||
else:
|
||||
msg_type = struct.pack('!H', 0x0004)
|
||||
buff, buff_len = self.pack_request()
|
||||
lenth = struct.pack('!I', buff_len)
|
||||
|
||||
try:
|
||||
conn.send(leading)
|
||||
conn.send(msg_type)
|
||||
conn.send(lenth)
|
||||
conn.send(buff)
|
||||
except socket.error as e:
|
||||
logging.error("device closed")
|
||||
for dev in tcpserver.devices:
|
||||
if dev.conn == conn:
|
||||
tcpserver.devices.remove(dev)
|
||||
return -1
|
||||
|
||||
|
||||
def query(conn):
|
||||
req = Request("/applet", 1, 0, "", 0)
|
||||
if req.send(conn, False) == -1:
|
||||
return "fail"
|
||||
time.sleep(0.05)
|
||||
try:
|
||||
receive_context = imrt_link_message()
|
||||
start = time.time()
|
||||
while True:
|
||||
if receive_context.on_imrt_link_byte_arrive(conn.recv(1)) == 0:
|
||||
break
|
||||
elif time.time() - start >= 5.0:
|
||||
return "fail"
|
||||
query_resp = receive_context.msg
|
||||
print(query_resp)
|
||||
except OSError as e:
|
||||
logging.error("OSError exception occur")
|
||||
return "fail"
|
||||
|
||||
res = decode_attr_container(query_resp)
|
||||
|
||||
logging.info('Query device infomation success')
|
||||
return res
|
||||
|
||||
def install(conn, app_name, wasm_file):
|
||||
wasm = read_file_to_buffer(wasm_file)
|
||||
if wasm == "file not found":
|
||||
return "failed to install: file not found"
|
||||
|
||||
print("wasm file len:")
|
||||
print(len(wasm))
|
||||
req = Request("/applet?name=" + app_name, 3, 98, wasm, len(wasm))
|
||||
if req.send(conn, True) == -1:
|
||||
return "fail"
|
||||
time.sleep(0.05)
|
||||
try:
|
||||
receive_context = imrt_link_message()
|
||||
start = time.time()
|
||||
while True:
|
||||
if receive_context.on_imrt_link_byte_arrive(conn.recv(1)) == 0:
|
||||
break
|
||||
elif time.time() - start >= 5.0:
|
||||
return "fail"
|
||||
msg = receive_context.msg
|
||||
except OSError as e:
|
||||
logging.error("OSError exception occur")
|
||||
# TODO: check return message
|
||||
|
||||
if len(msg) == 24 and msg[8 + 1] == 65:
|
||||
logging.info('Install application success')
|
||||
return "success"
|
||||
else:
|
||||
res = decode_attr_container(msg)
|
||||
logging.warning('Install application failed: %s' % (str(res)))
|
||||
print(str(res))
|
||||
|
||||
return str(res)
|
||||
|
||||
|
||||
def uninstall(conn, app_name):
|
||||
req = Request("/applet?name=" + app_name, 4, 99, "", 0)
|
||||
if req.send(conn, False) == -1:
|
||||
return "fail"
|
||||
time.sleep(0.05)
|
||||
try:
|
||||
receive_context = imrt_link_message()
|
||||
start = time.time()
|
||||
while True:
|
||||
if receive_context.on_imrt_link_byte_arrive(conn.recv(1)) == 0:
|
||||
break
|
||||
elif time.time() - start >= 5.0:
|
||||
return "fail"
|
||||
msg = receive_context.msg
|
||||
except OSError as e:
|
||||
logging.error("OSError exception occur")
|
||||
# TODO: check return message
|
||||
|
||||
if len(msg) == 24 and msg[8 + 1] == 66:
|
||||
logging.info('Uninstall application success')
|
||||
return "success"
|
||||
else:
|
||||
res = decode_attr_container(msg)
|
||||
logging.warning('Uninstall application failed: %s' % (str(res)))
|
||||
print(str(res))
|
||||
|
||||
return str(res)
|
||||
|
||||
class Device:
|
||||
def __init__(self, conn, addr, port):
|
||||
self.conn = conn
|
||||
self.addr = addr
|
||||
self.port = port
|
||||
self.app_num = 0
|
||||
self.apps = []
|
||||
|
||||
cmd = []
|
||||
|
||||
class TCPServer:
|
||||
def __init__(self, server, server_address, inputs, outputs, message_queues):
|
||||
# Create a TCP/IP
|
||||
self.server = server
|
||||
self.server.setblocking(False)
|
||||
|
||||
# Bind the socket to the port
|
||||
self.server_address = server_address
|
||||
print('starting up on %s port %s' % self.server_address)
|
||||
self.server.bind(self.server_address)
|
||||
|
||||
# Listen for incoming connections
|
||||
self.server.listen(10)
|
||||
|
||||
self.cmd_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.cmd_sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
|
||||
|
||||
self.cmd_sock.bind(('127.0.0.1', 8889))
|
||||
self.cmd_sock.listen(5)
|
||||
|
||||
|
||||
# Sockets from which we expect to read
|
||||
self.inputs = inputs
|
||||
self.inputs.append(self.cmd_sock)
|
||||
|
||||
# Sockets to which we expect to write
|
||||
# 处理要发送的消息
|
||||
self.outputs = outputs
|
||||
# Outgoing message queues (socket: Queue)
|
||||
self.message_queues = message_queues
|
||||
|
||||
self.devices = []
|
||||
self.conn_dict = {}
|
||||
|
||||
def handler_recever(self, readable):
|
||||
# Handle inputs
|
||||
for s in readable:
|
||||
if s is self.server:
|
||||
# A "readable" socket is ready to accept a connection
|
||||
connection, client_address = s.accept()
|
||||
self.client_address = client_address
|
||||
print('connection from', client_address)
|
||||
# this is connection not server
|
||||
# connection.setblocking(0)
|
||||
self.inputs.append(connection)
|
||||
|
||||
# Give the connection a queue for data we want to send
|
||||
# self.message_queues[connection] = queue.Queue()
|
||||
|
||||
res = query(connection)
|
||||
|
||||
if res != "fail":
|
||||
dev = Device(connection, client_address[0], client_address[1])
|
||||
self.devices.append(dev)
|
||||
self.conn_dict[client_address] = connection
|
||||
|
||||
dev_info = {}
|
||||
dev_info['addr'] = dev.addr
|
||||
dev_info['port'] = dev.port
|
||||
dev_info['apps'] = 0
|
||||
|
||||
logging.info('A new client connected from ("%s":"%s")' % (dev.conn, dev.port))
|
||||
|
||||
elif s is self.cmd_sock:
|
||||
connection, client_address = s.accept()
|
||||
print("web server socket connected")
|
||||
logging.info("Django server connected")
|
||||
self.inputs.append(connection)
|
||||
self.message_queues[connection] = queue.Queue()
|
||||
|
||||
else:
|
||||
data = s.recv(1024)
|
||||
if data != b'':
|
||||
# A readable client socket has data
|
||||
logging.info('received "%s" from %s' % (data, s.getpeername()))
|
||||
|
||||
# self.message_queues[s].put(data)
|
||||
# # Add output channel for response
|
||||
|
||||
# if s not in self.outputs:
|
||||
# self.outputs.append(s)
|
||||
|
||||
if(data.decode().split(':')[0] == "query"):
|
||||
if data.decode().split(':')[1] == "all":
|
||||
resp = []
|
||||
print('start query all devices')
|
||||
for dev in self.devices:
|
||||
dev_info = query(dev.conn)
|
||||
if dev_info == "fail":
|
||||
continue
|
||||
dev_info["addr"] = dev.addr
|
||||
dev_info["port"] = dev.port
|
||||
resp.append(str(dev_info))
|
||||
|
||||
print(resp)
|
||||
|
||||
if self.message_queues[s] is not None:
|
||||
# '*' is used in web server to sperate the string
|
||||
self.message_queues[s].put(bytes("*".join(resp), encoding = 'utf8'))
|
||||
if s not in self.outputs:
|
||||
self.outputs.append(s)
|
||||
else:
|
||||
client_addr = (data.decode().split(':')[1],int(data.decode().split(':')[2]))
|
||||
|
||||
if client_addr in self.conn_dict.keys():
|
||||
print('start query device from (%s:%s)' % (client_addr[0], client_addr[1]))
|
||||
resp = query(self.conn_dict[client_addr])
|
||||
print(resp)
|
||||
|
||||
if self.message_queues[s] is not None:
|
||||
self.message_queues[s].put(bytes(str(resp), encoding = 'utf8'))
|
||||
if s not in self.outputs:
|
||||
self.outputs.append(s)
|
||||
else: # no connection
|
||||
if self.message_queues[s] is not None:
|
||||
self.message_queues[s].put(bytes(str("fail"), encoding = 'utf8'))
|
||||
if s not in self.outputs:
|
||||
self.outputs.append(s)
|
||||
elif(data.decode().split(':')[0] == "install"):
|
||||
client_addr = (data.decode().split(':')[1],int(data.decode().split(':')[2]))
|
||||
app_name = data.decode().split(':')[3]
|
||||
app_file = data.decode().split(':')[4]
|
||||
|
||||
if client_addr in self.conn_dict.keys():
|
||||
print('start install application %s to ("%s":"%s")' % (app_name, client_addr[0], client_addr[1]))
|
||||
res = install(self.conn_dict[client_addr], app_name, app_file)
|
||||
if self.message_queues[s] is not None:
|
||||
logging.info("response {} to cmd server".format(res))
|
||||
self.message_queues[s].put(bytes(res, encoding = 'utf8'))
|
||||
if s not in self.outputs:
|
||||
self.outputs.append(s)
|
||||
elif(data.decode().split(':')[0] == "uninstall"):
|
||||
client_addr = (data.decode().split(':')[1],int(data.decode().split(':')[2]))
|
||||
app_name = data.decode().split(':')[3]
|
||||
|
||||
if client_addr in self.conn_dict.keys():
|
||||
print("start uninstall")
|
||||
res = uninstall(self.conn_dict[client_addr], app_name)
|
||||
if self.message_queues[s] is not None:
|
||||
logging.info("response {} to cmd server".format(res))
|
||||
self.message_queues[s].put(bytes(res, encoding = 'utf8'))
|
||||
if s not in self.outputs:
|
||||
self.outputs.append(s)
|
||||
|
||||
|
||||
# if self.message_queues[s] is not None:
|
||||
# self.message_queues[s].put(data)
|
||||
# if s not in self.outputs:
|
||||
# self.outputs.append(s)
|
||||
else:
|
||||
logging.warning(data)
|
||||
|
||||
# Interpret empty result as closed connection
|
||||
try:
|
||||
for dev in self.devices:
|
||||
if s == dev.conn:
|
||||
self.devices.remove(dev)
|
||||
# Stop listening for input on the connection
|
||||
if s in self.outputs:
|
||||
self.outputs.remove(s)
|
||||
self.inputs.remove(s)
|
||||
|
||||
# Remove message queue
|
||||
if s in self.message_queues.keys():
|
||||
del self.message_queues[s]
|
||||
s.close()
|
||||
except OSError as e:
|
||||
logging.error("OSError raised, unknown connection")
|
||||
return "got it"
|
||||
|
||||
def handler_send(self, writable):
|
||||
# Handle outputs
|
||||
for s in writable:
|
||||
try:
|
||||
message_queue = self.message_queues.get(s)
|
||||
send_data = ''
|
||||
if message_queue is not None:
|
||||
send_data = message_queue.get_nowait()
|
||||
except queue.Empty:
|
||||
self.outputs.remove(s)
|
||||
else:
|
||||
# print "sending %s to %s " % (send_data, s.getpeername)
|
||||
# print "send something"
|
||||
if message_queue is not None:
|
||||
s.send(send_data)
|
||||
else:
|
||||
print("client has closed")
|
||||
# del message_queues[s]
|
||||
# writable.remove(s)
|
||||
# print "Client %s disconnected" % (client_address)
|
||||
return "got it"
|
||||
|
||||
def handler_exception(self, exceptional):
|
||||
# # Handle "exceptional conditions"
|
||||
for s in exceptional:
|
||||
print('exception condition on', s.getpeername())
|
||||
# Stop listening for input on the connection
|
||||
self.inputs.remove(s)
|
||||
if s in self.outputs:
|
||||
self.outputs.remove(s)
|
||||
s.close()
|
||||
|
||||
# Remove message queue
|
||||
del self.message_queues[s]
|
||||
return "got it"
|
||||
|
||||
|
||||
def event_loop(tcpserver, inputs, outputs):
|
||||
while inputs:
|
||||
# Wait for at least one of the sockets to be ready for processing
|
||||
print('waiting for the next event')
|
||||
readable, writable, exceptional = select.select(inputs, outputs, inputs)
|
||||
if readable is not None:
|
||||
tcp_recever = tcpserver.handler_recever(readable)
|
||||
if tcp_recever == 'got it':
|
||||
print("server have received")
|
||||
if writable is not None:
|
||||
tcp_send = tcpserver.handler_send(writable)
|
||||
if tcp_send == 'got it':
|
||||
print("server have send")
|
||||
if exceptional is not None:
|
||||
tcp_exception = tcpserver.handler_exception(exceptional)
|
||||
if tcp_exception == 'got it':
|
||||
print("server have exception")
|
||||
|
||||
|
||||
sleep(0.1)
|
||||
|
||||
def run_wasm_server():
|
||||
server_address = ('localhost', 8888)
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
|
||||
inputs = [server]
|
||||
outputs = []
|
||||
message_queues = {}
|
||||
tcpserver = TCPServer(server, server_address, inputs, outputs, message_queues)
|
||||
|
||||
task = threading.Thread(target=event_loop,args=(tcpserver,inputs,outputs))
|
||||
task.start()
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
filename='wasm_server.log',
|
||||
filemode='a',
|
||||
format=
|
||||
'%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'
|
||||
)
|
||||
server_address = ('0.0.0.0', 8888)
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
|
||||
inputs = [server]
|
||||
outputs = []
|
||||
message_queues = {}
|
||||
tcpserver = TCPServer(server, server_address, inputs, outputs, message_queues)
|
||||
logging.info("TCP Server start at {}:{}".format(server_address[0], "8888"))
|
||||
|
||||
task = threading.Thread(target=event_loop,args=(tcpserver,inputs,outputs))
|
||||
task.start()
|
||||
|
||||
# event_loop(tcpserver, inputs, outputs)
|
||||
@ -1,400 +0,0 @@
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
{% load static %}
|
||||
<style>
|
||||
#container{
|
||||
position:relative;
|
||||
margin:0px;
|
||||
height:110px;
|
||||
}
|
||||
#content {
|
||||
margin:0px 20% 0px 18%;
|
||||
border:solid 1.5px;
|
||||
border-color: white black white black;
|
||||
height:50%;
|
||||
}
|
||||
#mainnav{
|
||||
display:table;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#mainnav li{
|
||||
display: table-cell;
|
||||
padding-left:10px;
|
||||
}
|
||||
#mainnav ul li a{
|
||||
width:120px;
|
||||
height:30px;
|
||||
background:black;
|
||||
color:white;
|
||||
margin:0px 50px;
|
||||
font-size:21px;
|
||||
font-family:'sansationlight';
|
||||
display:block;
|
||||
text-align:center;
|
||||
text-decoration:none;
|
||||
}
|
||||
#mainnav ul li a:hover{
|
||||
width:120px;
|
||||
height:33px;
|
||||
line-height:30px;
|
||||
border:solid 1.5px;
|
||||
border-color: black black white black;
|
||||
color:#3FC3DF;
|
||||
background:black;
|
||||
}
|
||||
.headers{
|
||||
background-image: url("{%static 'photo/milky-way-2695569_1280.jpg'%}");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 100%;
|
||||
color:white;
|
||||
clear:both;
|
||||
height:50%;
|
||||
text-align:center;
|
||||
padding:10px;
|
||||
margin:0px;
|
||||
}
|
||||
#maintitle{
|
||||
font-size:25px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
|
||||
#section {
|
||||
position:relative;
|
||||
top:5px;
|
||||
width:100%;
|
||||
float:left;
|
||||
height:120px;
|
||||
border-style:double solid;
|
||||
border-color:black rgb(194, 194, 190) black rgb(248, 248, 248) ;
|
||||
border-width:0.5px;
|
||||
padding:10px;
|
||||
}
|
||||
#photo{
|
||||
position: relative;
|
||||
float: left;
|
||||
top:18%;
|
||||
left:10%;
|
||||
widows: 60px;
|
||||
}
|
||||
#IPs{
|
||||
position: relative;
|
||||
left: 20%;
|
||||
top:10%;
|
||||
width:35%;
|
||||
font-size:17px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
#ports{
|
||||
position: relative;
|
||||
left: 20%;
|
||||
top:30%;
|
||||
bottom: 5%;
|
||||
width:35%;
|
||||
font-size:17px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
#installs{
|
||||
position: relative;
|
||||
float: left;
|
||||
left:55%;
|
||||
bottom:40%;
|
||||
font-size:17px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
|
||||
#download{
|
||||
position:relative;
|
||||
text-align: center;
|
||||
left:15%;
|
||||
width:70%;
|
||||
top:40px;
|
||||
height:40px;
|
||||
/*border-color:#192C4F;*/
|
||||
}
|
||||
.explain{
|
||||
width:250px;
|
||||
height:40px;
|
||||
top:50%;
|
||||
float:left;
|
||||
font-size:18px;
|
||||
}
|
||||
#btn{
|
||||
float:right;
|
||||
}
|
||||
|
||||
|
||||
#APPS {
|
||||
position:relative;
|
||||
top:30px;
|
||||
left:16.67%;
|
||||
width:75%;
|
||||
}
|
||||
#applications{
|
||||
position:relative;
|
||||
float:left;
|
||||
background-color:white;
|
||||
width:88.9%;
|
||||
height:45px;
|
||||
padding:2px;
|
||||
margin:5px 0px;
|
||||
border-style:double solid;
|
||||
border-color:black;
|
||||
border-width:0.5px;
|
||||
}
|
||||
#applogo{
|
||||
position:relative;
|
||||
float:left;
|
||||
top:10%
|
||||
}
|
||||
#appinfo1{ position:relative; float:left; left:40px; width:34%;font-size:15px;height:25px;top:33%}
|
||||
#appinfo2{ position:relative; float:left; left:20px; width:24%;font-size:15px;height:25px;top:33%}
|
||||
#appinfo3{ position:relative; float:left; left:20px; width:34%;font-size:15px;height:25px;top:33%}
|
||||
|
||||
#delete{
|
||||
position:relative;
|
||||
margin:8px 0px;
|
||||
float:right;
|
||||
right:7%;
|
||||
}
|
||||
.main{
|
||||
position: absolute;
|
||||
float:left;
|
||||
width:650px;
|
||||
height:350px;
|
||||
z-index: 9999;
|
||||
background-color: white;
|
||||
display:none;
|
||||
border:solid 1px rgb(4, 30, 66);
|
||||
border-width: 1.5px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.close{
|
||||
background-color: black;
|
||||
color:white;
|
||||
border-top-right-radius: 10px;
|
||||
border-top-left-radius: 10px;
|
||||
}
|
||||
.hotapps{
|
||||
background-color:rgb(202, 202, 202);
|
||||
font-size: 16px;
|
||||
font-family:'days';
|
||||
height:30px;
|
||||
text-align: justify;
|
||||
border:solid 2px;
|
||||
border-color: rgb(202, 202, 202) rgb(202, 202, 202) rgb(202, 202, 202) black;
|
||||
}
|
||||
#scrollba{
|
||||
overflow-x: None;
|
||||
overflow-y: scroll;
|
||||
height: 270px;
|
||||
width:650px;
|
||||
}
|
||||
#Dapplications{
|
||||
width:630px;
|
||||
margin:4px 10px 0px 10px;
|
||||
height:45px;
|
||||
border:solid 1px;
|
||||
border-color: rgb(221, 221, 221) white white white;
|
||||
/* background-color: rgb(233, 233, 233); */
|
||||
}
|
||||
.mybtn2{
|
||||
position: relative;
|
||||
float:left;
|
||||
left:45px;
|
||||
top:3px;
|
||||
height:33px;
|
||||
border-radius: 10px;
|
||||
background-color: rgb(22, 109, 121);
|
||||
color:white;
|
||||
}
|
||||
#types{
|
||||
background-color: rgb(3, 90, 90);
|
||||
color:white;
|
||||
text-align: left
|
||||
}
|
||||
|
||||
|
||||
#loading{
|
||||
position:relative;
|
||||
float:left;
|
||||
width: 100%;
|
||||
display:None;
|
||||
height:40px;
|
||||
top:10px;
|
||||
z-index:1010;
|
||||
}
|
||||
.loadapp{
|
||||
font-size:20px;
|
||||
text-align: center;
|
||||
color:rgb(24, 77, 24);
|
||||
}
|
||||
#preloader {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#loader {
|
||||
display: block;
|
||||
position: relative;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
margin: -75px 0 0 -75px;
|
||||
border-radius: 50%;
|
||||
border: 3px solid transparent;
|
||||
border-top-color: rgb(135, 155, 241);
|
||||
-webkit-animation: spin 2s linear infinite;
|
||||
animation: spin 2s linear infinite;
|
||||
}
|
||||
#loader:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
left: 5px;
|
||||
right: 5px;
|
||||
bottom: 5px;
|
||||
border-radius: 50%;
|
||||
border: 3px solid transparent;
|
||||
border-top-color: rgb(23, 62, 146);
|
||||
-webkit-animation: spin 3s linear infinite;
|
||||
animation: spin 3s linear infinite;
|
||||
}
|
||||
#loader:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
left: 15px;
|
||||
right: 15px;
|
||||
bottom: 15px;
|
||||
border-radius: 50%;
|
||||
border: 3px solid transparent;
|
||||
border-top-color: rgb(21, 44, 87);
|
||||
-webkit-animation: spin 1.5s linear infinite;
|
||||
animation: spin 1.5s linear infinite;
|
||||
}
|
||||
@-webkit-keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
-ms-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
-ms-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
-ms-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
-ms-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.middlebox{
|
||||
position:absolute;
|
||||
z-index:1003;
|
||||
height:180px;
|
||||
width:340px;
|
||||
background-color: white;
|
||||
border-radius: 7px;
|
||||
border-style:double;
|
||||
border-color:rgb(2, 37, 11) solid;
|
||||
border-width: 0.8px;
|
||||
display: none;
|
||||
}
|
||||
.warning{
|
||||
position: absolute;
|
||||
left:10%;
|
||||
top:6%;
|
||||
FONT-size:18px;
|
||||
color:rgb(0, 85, 0);
|
||||
height:20%;
|
||||
width:80%;
|
||||
border-style:none none dashed none;
|
||||
border-width: 1px;
|
||||
border-color:rgb(0, 85, 0);
|
||||
}
|
||||
.surebtn{
|
||||
position:relative;
|
||||
float:left;
|
||||
left:44%;
|
||||
top:75%;
|
||||
}
|
||||
.findapp{
|
||||
position:absolute;
|
||||
left:10%;
|
||||
height:25%;
|
||||
top:40%;
|
||||
width:80%;
|
||||
font-size:15px;
|
||||
text-align: center;
|
||||
border-style:none none solid none;
|
||||
border-color:rgb(182, 182, 182);
|
||||
border-width:0.5px;
|
||||
}
|
||||
|
||||
.deletebox{
|
||||
position:absolute;
|
||||
z-index:1003;
|
||||
height:180px;
|
||||
width:340px;
|
||||
background-color: white;
|
||||
border-radius: 7px;
|
||||
border-style:double;
|
||||
border-color:rgb(43, 9, 1) solid;
|
||||
border-width: 0.8px;
|
||||
display: none;
|
||||
}
|
||||
.warning2{
|
||||
position: absolute;
|
||||
left:10%;
|
||||
top:6%;
|
||||
FONT-size:18px;
|
||||
color:rgb(185, 0, 0);
|
||||
height:20%;
|
||||
width:80%;
|
||||
border-style:none none dashed none;
|
||||
border-width: 1px;
|
||||
border-color:rgb(185, 0, 0);
|
||||
}
|
||||
.suresbtn{
|
||||
position:relative;
|
||||
float:left;
|
||||
left:24%;
|
||||
top:75%;
|
||||
color:green
|
||||
}
|
||||
.cancelsbtn{
|
||||
position:relative;
|
||||
float:right;
|
||||
right:20%;
|
||||
top:75%;
|
||||
color:red
|
||||
}
|
||||
.footer {
|
||||
position:absolute;
|
||||
bottom:0px;
|
||||
left:0px;
|
||||
background-color:black;
|
||||
color:white;
|
||||
clear:both;
|
||||
text-align:center;
|
||||
padding:1px;
|
||||
width:100%;
|
||||
height:4%;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
|
||||
@ -1,216 +0,0 @@
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
{% load static %}
|
||||
<style>
|
||||
#container{
|
||||
position:relative;
|
||||
margin:0px;
|
||||
height:110px;
|
||||
}
|
||||
#content {
|
||||
margin:0px 20% 0px 18%;
|
||||
border:solid 1.5px;
|
||||
border-color: white black white black;
|
||||
height:50%;
|
||||
}
|
||||
#mainnav{
|
||||
display:table;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#mainnav li{
|
||||
display: table-cell;
|
||||
padding-left:10px;
|
||||
}
|
||||
#mainnav ul li a{
|
||||
width:120px;
|
||||
height:30px;
|
||||
background:black;
|
||||
color:white;
|
||||
margin:0px 50px;
|
||||
font-size:21px;
|
||||
font-family:'sansationlight';
|
||||
display:block;
|
||||
text-align:center;
|
||||
text-decoration:none;
|
||||
}
|
||||
#mainnav ul li a:hover{
|
||||
width:120px;
|
||||
height:33px;
|
||||
line-height:30px;
|
||||
border:solid 1.5px;
|
||||
border-color: black black white black;
|
||||
color:#3FC3DF;
|
||||
background:black;
|
||||
}
|
||||
.headers{
|
||||
background-image: url("{%static 'photo/milky-way-2695569_1280.jpg'%}");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 100%;
|
||||
color:white;
|
||||
clear:both;
|
||||
height:50%;
|
||||
text-align:center;
|
||||
padding:10px;
|
||||
margin:0px;
|
||||
}
|
||||
#maintitle{
|
||||
font-size:25px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
|
||||
#introstore{
|
||||
z-index:1003;
|
||||
top:10px;
|
||||
margin:10px 220px 10px 220px;
|
||||
height:108px;
|
||||
}
|
||||
#applicationlist{
|
||||
margin:26px 0px 0px 0px;
|
||||
height:100%;
|
||||
}
|
||||
.bar{
|
||||
height:50px;
|
||||
top:2px;
|
||||
}
|
||||
.leftpart{
|
||||
position:relative;
|
||||
float:left;
|
||||
left:30px;
|
||||
font-size:22px;
|
||||
display:inline-block;
|
||||
height:30px;
|
||||
border:solid 1px black;
|
||||
border-style: none none solid none;
|
||||
}
|
||||
.rightpart{
|
||||
position:relative;
|
||||
float:right;
|
||||
height:50px;
|
||||
right:20px;
|
||||
font-size:17px;
|
||||
}
|
||||
.rightpart .file{
|
||||
width: 120px;
|
||||
height: 35px;
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
opacity: 0;
|
||||
z-index: 2;
|
||||
}
|
||||
.stylehere{
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 120px;
|
||||
overflow: hidden;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
}
|
||||
.choosestyle{
|
||||
position: absolute;
|
||||
width: 120px;height: 35px;
|
||||
background-color: rgb(0, 121, 202);color:white;
|
||||
text-align: center;
|
||||
left: 0px;top: 0px;
|
||||
font-size:14px;
|
||||
border-radius: 4px
|
||||
}
|
||||
.appbook{
|
||||
margin:0px;
|
||||
border:solid;
|
||||
border-width: 1.5px;
|
||||
border-color: white rgb(194, 194, 194) white rgb(194, 194, 194);
|
||||
background-image:linear-gradient(to right, rgb(245, 243, 240),white)
|
||||
}
|
||||
#applications{
|
||||
margin:1px;
|
||||
left:0px;
|
||||
width:100%;
|
||||
height:50px;
|
||||
border-style:none none solid none;
|
||||
border-color:rgb(172, 172, 172);
|
||||
border-width:0.5px;
|
||||
padding:5px;
|
||||
}
|
||||
#delbutton{
|
||||
width:100px;
|
||||
height:40px;
|
||||
}
|
||||
#appimage{
|
||||
float:left;
|
||||
left:5%;
|
||||
}
|
||||
#lable{
|
||||
color: red;
|
||||
opacity:50}
|
||||
.suresbtn{
|
||||
position:relative;
|
||||
float:left;
|
||||
left:50px;
|
||||
top:135px;
|
||||
color:green
|
||||
}
|
||||
.deletebox{
|
||||
position:absolute;
|
||||
z-index:1003;
|
||||
height:180px;
|
||||
width:340px;
|
||||
background-color: white;
|
||||
border-radius: 7px;
|
||||
border-style:double;
|
||||
border-color:rgb(43, 9, 1) solid;
|
||||
border-width: 0.8px;
|
||||
display: none;
|
||||
}
|
||||
.warning2{
|
||||
position: absolute;
|
||||
left:10%;
|
||||
top:6%;
|
||||
FONT-size:18px;
|
||||
color:rgb(185, 0, 0);
|
||||
height:20%;
|
||||
width:80%;
|
||||
border-style:none none dashed none;
|
||||
border-width: 1px;
|
||||
border-color:rgb(185, 0, 0);
|
||||
}
|
||||
.findapp{
|
||||
position:absolute;
|
||||
left:10%;
|
||||
height:25%;
|
||||
top:40%;
|
||||
width:80%;
|
||||
font-size:15px;
|
||||
text-align: center;
|
||||
border-style:none none solid none;
|
||||
border-color:rgb(182, 182, 182);
|
||||
border-width:0.5px;
|
||||
}
|
||||
.suresbtn{
|
||||
position:relative;
|
||||
float:left;
|
||||
left:24%;
|
||||
top:75%;
|
||||
color:green
|
||||
}
|
||||
.delsbtn{
|
||||
position:relative;
|
||||
float:right;
|
||||
right:20%;
|
||||
top:75%;
|
||||
color:red
|
||||
}
|
||||
.footer {
|
||||
position:absolute;
|
||||
bottom:0px;
|
||||
left:0px;
|
||||
background-color:black;
|
||||
color:white;
|
||||
clear:both;
|
||||
text-align:center;
|
||||
padding:1px;
|
||||
width:100%;
|
||||
height:4%;
|
||||
z-index: 999;
|
||||
}
|
||||
@ -1,197 +0,0 @@
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
{% load static %}
|
||||
<style>
|
||||
#container{
|
||||
position:relative;
|
||||
margin:0px;
|
||||
height:110px;
|
||||
}
|
||||
#content {
|
||||
margin:0px 20% 0px 18%;
|
||||
border:solid 1.5px;
|
||||
border-color: white black white black;
|
||||
height:50%;
|
||||
}
|
||||
#mainnav{
|
||||
display:table;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#mainnav li{
|
||||
display: table-cell;
|
||||
padding-left:10px;
|
||||
}
|
||||
#mainnav ul li a{
|
||||
width:120px;
|
||||
height:30px;
|
||||
background:black;
|
||||
color:white;
|
||||
margin:0px 50px;
|
||||
font-size:21px;
|
||||
font-family:'sansationlight';
|
||||
display:block;
|
||||
text-align:center;
|
||||
text-decoration:none;
|
||||
}
|
||||
#mainnav ul li a:hover{
|
||||
width:120px;
|
||||
height:33px;
|
||||
line-height:30px;
|
||||
border:solid 1.5px;
|
||||
border-color: black black white black;
|
||||
color:#3FC3DF;
|
||||
background:black;
|
||||
}
|
||||
.headers{
|
||||
background-image: url("{%static 'photo/milky-way-2695569_1280.jpg'%}");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 100%;
|
||||
color:white;
|
||||
clear:both;
|
||||
height:50%;
|
||||
text-align:center;
|
||||
padding:10px;
|
||||
margin:0px;
|
||||
}
|
||||
#maintitle{
|
||||
font-size:25px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
|
||||
#photo2{
|
||||
position: relative;
|
||||
float: left;
|
||||
top:10%;
|
||||
left:20%;
|
||||
}
|
||||
#devic{
|
||||
position: relative;
|
||||
font-size:22px;
|
||||
float: left;
|
||||
left:25%;
|
||||
top:30%;
|
||||
width:40%;
|
||||
}
|
||||
#dividebar{
|
||||
position: absolute;
|
||||
top:210px;
|
||||
margin:10px;
|
||||
width:100%;
|
||||
height:1px
|
||||
}
|
||||
|
||||
#devices {
|
||||
position:relative;
|
||||
bottom: 2px;
|
||||
background-color: #F2F2F2;
|
||||
height:125px;
|
||||
width:80%;
|
||||
margin:8px 10%;
|
||||
}
|
||||
#section {
|
||||
position:relative;
|
||||
background-color:white;
|
||||
top:14px;
|
||||
left:13%;
|
||||
width: 70%;
|
||||
float:left;
|
||||
height:96px;
|
||||
border-style:double solid;
|
||||
border-color:black;
|
||||
border-width:0.5px;
|
||||
padding:10px;
|
||||
}
|
||||
#photo{
|
||||
position: relative;
|
||||
float: left;
|
||||
top:0px;
|
||||
left:6%;
|
||||
}
|
||||
#ID{
|
||||
position:relative;
|
||||
float:left;
|
||||
left:12%;
|
||||
height:20px;
|
||||
width:8%;
|
||||
top:75%;
|
||||
z-index:9999;
|
||||
/* display:none; */
|
||||
font-size:15px;
|
||||
color:rgba(7, 38, 85, 0.87);
|
||||
}
|
||||
#IPs{
|
||||
position: relative;
|
||||
left: 14%;
|
||||
top:10%;
|
||||
width:30%;
|
||||
font-size:17px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
#ports{
|
||||
position: relative;
|
||||
left: 14%;
|
||||
top:25%;
|
||||
bottom: 5px;
|
||||
width:30%;
|
||||
font-size:17px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
#installs{
|
||||
position: relative;
|
||||
float: right;
|
||||
right: 20%;
|
||||
bottom:57%;
|
||||
font-size:17px;
|
||||
font-family:'sansationlight';
|
||||
}
|
||||
.smenu{
|
||||
position: relative;
|
||||
float: right;
|
||||
top:45px;
|
||||
right: 5%;
|
||||
width: 6%;
|
||||
}
|
||||
|
||||
.prev{
|
||||
position:absolute;
|
||||
left:72%;
|
||||
clear:both;
|
||||
text-align:center;
|
||||
padding:1px;
|
||||
width:100px;
|
||||
height:30px;
|
||||
color:grey;
|
||||
background-color:white;
|
||||
border-radius:5px;
|
||||
z-index: 996;
|
||||
}
|
||||
|
||||
.next{
|
||||
position:absolute;
|
||||
left:80%;
|
||||
clear:both;
|
||||
text-align:center;
|
||||
padding:1px;
|
||||
width:100px;
|
||||
height:30px;
|
||||
color:grey;
|
||||
background-color:white;
|
||||
border-radius:5px;
|
||||
z-index: 996;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position:absolute;
|
||||
bottom:0px;
|
||||
left:0px;
|
||||
background-color:black;
|
||||
color:white;
|
||||
clear:both;
|
||||
text-align:center;
|
||||
padding:1px;
|
||||
width:100%;
|
||||
height:4%;
|
||||
z-index: 999;
|
||||
}
|
||||
</style>
|
||||
@ -1,217 +0,0 @@
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
/*
|
||||
* Dom Location
|
||||
*
|
||||
*/
|
||||
|
||||
function setDivCenter(divname)
|
||||
// make qn element center aligned
|
||||
{
|
||||
var Top =($(window).height()-$(divname).height())/2;
|
||||
var Left = ($(window).width()-$(divname).width())/2;
|
||||
var scrollTop = $(document).scrollTop();
|
||||
var scrollLeft = $(document).scrollLeft();
|
||||
$(divname).css({posisiton:'absolute','top':Top+scrollTop,'left':Left+scrollLeft});
|
||||
|
||||
};
|
||||
|
||||
setDivCenter(".middlebox");
|
||||
setDivCenter(".deletebox");
|
||||
|
||||
function setmain(divname){
|
||||
// Set the pop-up window of apps for download at the right place
|
||||
var x = $('#btn').offset().top;
|
||||
var Top = x + $('#btn').height()+15;
|
||||
var y = $('#btn').offset().left;
|
||||
var Left = y + ($('#btn').width()/2)-($(divname).width()/2);
|
||||
console.log(Top,Left)
|
||||
$(divname).css({'top':Top,'left':Left});
|
||||
}
|
||||
setmain(".main")
|
||||
|
||||
/*
|
||||
* download apps
|
||||
*
|
||||
*/
|
||||
|
||||
function getthis(val)
|
||||
//Telling background which app to be loaded from appstore_list and to be installed in the current device.
|
||||
{
|
||||
|
||||
/* Get the ip adress and the port of a device, as well as the application ID to be downloaded on this device*/
|
||||
var ip,port,name,version;
|
||||
var ipArr=$("#IPs").text().split(":");
|
||||
ip=ipArr[1];
|
||||
var portArr=$("#ports").text().split(":");
|
||||
port=portArr[1];
|
||||
name = $(val).parent().find("#appsinfo1").text().split(":")[1];
|
||||
version = $(val).parent().find("#appsinfo2").text().split(":")[1];
|
||||
$(".main").fadeOut();
|
||||
|
||||
for (num in alist){
|
||||
if (alist[num]['pname'].trim() == name.trim())
|
||||
{alert("This app has been downloaded.");
|
||||
return;}};
|
||||
$("#loading").fadeIn();
|
||||
var sNode = document.getElementById("APPS");
|
||||
var tempNode= sNode.cloneNode(true);
|
||||
sNode.parentNode.appendChild(tempNode);
|
||||
$("#appinfo1").html("Product Name : "+ name);
|
||||
$("#appinfo2").html("Status : "+"Installing");
|
||||
$("#appinfo3").html("Current_Version : "+ version);
|
||||
|
||||
$.get("/appDownload/",{'ip':ip.trim(),'port':port.trim(),'name':name.trim(),},function (ret) {
|
||||
var status = $.trim(ret.split(":")[1].split("}")[0]);
|
||||
$(".loadapp").html(name+" is downloading now");
|
||||
var msg = JSON.parse(status)
|
||||
console.log(msg)
|
||||
if (JSON.parse(status)=="ok"){
|
||||
$(".middlebox").fadeIn();
|
||||
$(".sourceapp").fadeOut();
|
||||
$("#loading").fadeOut();
|
||||
$(".findapp").html("Download "+name +" successfully");
|
||||
$(".surebtn").click(function (){
|
||||
$(".middlebox").fadeOut();
|
||||
window.location.reload();
|
||||
})}
|
||||
else if (JSON.parse(status)=="Fail!"){
|
||||
alert("Download failed!");
|
||||
$("#loading").fadeOut();
|
||||
sNode.remove();
|
||||
}
|
||||
else {
|
||||
alert("Install app failed:" + msg)
|
||||
$("#loading").fadeOut();
|
||||
sNode.remove();
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
window.onload = function clone()
|
||||
//Add & Delete apps to the device.
|
||||
{
|
||||
/*Install Apps*/
|
||||
var sourceNode = document.getElementById("APPS");
|
||||
if (alist.length != 0)
|
||||
{
|
||||
$("#appinfo1").html("Product Name : "+ alist[0]['pname']);
|
||||
$("#appinfo2").html("Status : "+ alist[0]['status']);
|
||||
$("#appinfo3").html("Current_Version : "+ alist[0]['current_version']);
|
||||
$("#delete").attr('class','delet0');
|
||||
$("#APPS").attr('class','app0');
|
||||
|
||||
for (var i=1; i<alist.length; i++)
|
||||
{
|
||||
var cloneNode= sourceNode.cloneNode(true);
|
||||
sourceNode.parentNode.appendChild(cloneNode);
|
||||
$("#appinfo1").html("Product Name : "+ alist[i]['pname']);
|
||||
$("#appinfo2").html("Status : "+ alist[i]['status']);
|
||||
$("#appinfo3").html("Current_Version : "+ alist[i]['current_version']);
|
||||
$("#delete").attr('class','delet'+i);
|
||||
$("#APPS").attr('class','app'+i);
|
||||
}
|
||||
}
|
||||
$("#IPs").html("IP : "+ dlist[0]['IP']);
|
||||
$("#ports").html("Port : "+ dlist[0]['Port']);
|
||||
$("#installs").html("Installed Apps : "+ dlist[0]['apps']);
|
||||
|
||||
|
||||
|
||||
$(".mybtn").click(function ()
|
||||
{
|
||||
/*uninstall apps*/
|
||||
var thisitem = $(this).parent().attr('class');
|
||||
var indexa = thisitem.match(/\d+\b/);
|
||||
var pname = $(".app"+indexa).find('#appinfo1').text();
|
||||
|
||||
var ip,port;
|
||||
var ipArr=$("#IPs").text().split(":");
|
||||
ip=ipArr[1];
|
||||
var portArr=$("#ports").text().split(":");
|
||||
port=portArr[1];
|
||||
|
||||
var name = pname.split(':')[1].trim();
|
||||
$(".deletebox").fadeIn();
|
||||
$(".findapp").html("Are you sure to delete "+name);
|
||||
$(".suresbtn").click(function (){
|
||||
$(".app"+indexa).remove();
|
||||
$.get("/appDelete/",{'ip':ip.trim(),'port':port.trim(),"name":pname.split(':')[1].trim()},function (ret) {
|
||||
console.log(ret);});
|
||||
$(".deletebox").fadeOut();
|
||||
window.location.reload();
|
||||
})
|
||||
$(".cancelsbtn").click(function (){
|
||||
$(".deletebox").fadeOut(); })
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
function getdownloadapps()
|
||||
{
|
||||
/*Acquire apps for download from Appstore simultaneously whenever appstore is updated*/
|
||||
if (search_node[0] == "Nothing find"){
|
||||
alert(search_node[0])
|
||||
}
|
||||
if (search_node.length == 1 && search_node[0] != "Nothing find" ){
|
||||
$("#appsinfo1").html("Product Name : "+ search_node[0]['ID']);
|
||||
$("#appsinfo2").html("Version : "+ search_node[0]['Version']);
|
||||
}
|
||||
else{
|
||||
var sourceNode = document.getElementById("Dapplications");
|
||||
if (llist.length != 0)
|
||||
{
|
||||
$("#appsinfo1").html("Product Name : "+ llist[0]['ID']);
|
||||
$("#appsinfo2").html("Version : "+ llist[0]['Version']);
|
||||
$("#Dapplications").attr('class','dapp0');
|
||||
|
||||
for (var i=1; i<llist.length; i++)
|
||||
{
|
||||
var cloneNode= sourceNode.cloneNode(true);
|
||||
sourceNode.parentNode.appendChild(cloneNode);
|
||||
$("#appsinfo1").html("Product Name : "+ llist[i]['ID']);
|
||||
$("#appsinfo2").html("Version : "+ llist[i]['Version']);
|
||||
$("#Dapplications").attr('class','dapp'+i);
|
||||
}
|
||||
}};
|
||||
};
|
||||
|
||||
getdownloadapps();
|
||||
|
||||
function givevalue(){
|
||||
var ip=dlist[0]['IP'].trim();
|
||||
var port=dlist[0]['Port'].trim();
|
||||
document.getElementById("aa").value = ip;
|
||||
document.getElementById("bb").value = port;
|
||||
if (open_status == "open"){
|
||||
$(".main").fadeIn();
|
||||
$(".close").click(function(){
|
||||
$(".main").fadeOut();
|
||||
var newurl = "?"+"ip="+ip+"&port="+port;
|
||||
window.location.href= newurl;});
|
||||
$(".mybtn2").click(function(){
|
||||
if (alist.length >=3){
|
||||
alert("Install app failed: exceed max app installations.")
|
||||
}
|
||||
$(".main").fadeOut();
|
||||
getthis(".mybtn2");
|
||||
var newurl = "?"+"ip="+ip+"&port="+port;
|
||||
window.location.href= newurl;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
givevalue();
|
||||
|
||||
function popbox(){
|
||||
/*Open and close the "install apps" window*/
|
||||
$(".btn").click(function(){
|
||||
$(".main").fadeIn();
|
||||
});
|
||||
$(".close").click(function(){
|
||||
$(".main").fadeOut();
|
||||
});
|
||||
};
|
||||
popbox();
|
||||
@ -1,125 +0,0 @@
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
function setDivCenter(divname)
|
||||
//Center a dom
|
||||
{
|
||||
var Top =($(window).height()-$(divname).height())/2;
|
||||
var Left = ($(window).width()-$(divname).width())/2;
|
||||
var scrollTop = $(document).scrollTop();
|
||||
var scrollLeft = $(document).scrollLeft();
|
||||
$(divname).css({posisiton:'absolute','top':Top+scrollTop,'left':Left+scrollLeft});
|
||||
|
||||
};
|
||||
setDivCenter(".deletebox");
|
||||
|
||||
function setDivheight(divname)
|
||||
//set the height of "appbook" to contain all its child elements.
|
||||
{
|
||||
var leng = elist.length + flist.length;
|
||||
var heig = 51 * leng;
|
||||
$(divname).css({height:'heig'});
|
||||
};
|
||||
setDivheight(".appbook");
|
||||
|
||||
function setfooterposition(divname)
|
||||
//Locate footer on the right place
|
||||
{
|
||||
var Top = flist.length* $("#devices").height()+300;
|
||||
var scrollTop = $(document).scrollTop();
|
||||
if (flist.length >=4){
|
||||
$(divname).css({posisiton:'absolute','top':Top+scrollTop});
|
||||
}
|
||||
}
|
||||
setfooterposition(".footer");
|
||||
|
||||
function deleteClick (obj)
|
||||
//Remove an app from apppstore if clicks the "OK" button
|
||||
{
|
||||
var indexapp = $(obj).attr('class').match(/\d+\b/);
|
||||
var removeitem = $(".applic"+indexapp);
|
||||
var name=removeitem.find('#appinfo1').text().split(":")[1].trim();
|
||||
var version=removeitem.find('#appinfo2').text().split(":")[1].trim();
|
||||
|
||||
if (flist.length >= 1){
|
||||
$(".deletebox").fadeIn();
|
||||
$(".findapp").html("Are you sure to delete "+name);
|
||||
$(".suresbtn").click(function (){
|
||||
removeitem.remove();
|
||||
$.get("/removeapps/",{'name':name,'version':version},function (ret) {
|
||||
console.log(ret);});
|
||||
$(".deletebox").fadeOut();
|
||||
window.location.href="/appstore/";
|
||||
})
|
||||
$(".delsbtn").click(function (){
|
||||
$(".deletebox").fadeOut(); })}
|
||||
};
|
||||
|
||||
function upload_file()
|
||||
//Make sure the uploading file is eligible
|
||||
{
|
||||
var type = ulist[0];
|
||||
console.log(type);
|
||||
if (type == "Not a wasm file"){
|
||||
alert(type);
|
||||
window.location.href="/appstore/";
|
||||
}
|
||||
if (type == "This App is preloaded"){
|
||||
alert(type);
|
||||
window.location.href="/appstore/";
|
||||
}
|
||||
if (type == "This App is already uploaded"){
|
||||
alert(type);
|
||||
window.location.href="/appstore/";
|
||||
}
|
||||
};
|
||||
upload_file();
|
||||
|
||||
|
||||
function clone()
|
||||
//Render a interface that shows all the apps for installing in appstore,
|
||||
//including preloaded ones and locally uploaded ones.
|
||||
{
|
||||
|
||||
var sourceNode = document.getElementById("applications");
|
||||
$("#appinfo1").html("product name : "+ elist[0]['ID']);
|
||||
$("#appinfo2").html("product Version : "+ elist[0]['Version']);
|
||||
$("#delbutton").attr('class','del0');
|
||||
$("#applications").attr('class','applic0');
|
||||
|
||||
|
||||
for (var i=1; i<elist.length; i++)
|
||||
{
|
||||
var cloneNode= sourceNode.cloneNode(true);
|
||||
sourceNode.parentNode.appendChild(cloneNode);
|
||||
$("#appinfo1").html("product name : "+ elist[i]['ID']);
|
||||
$("#appinfo2").html("product Version : "+ elist[i]['Version']);
|
||||
$("#delbutton").attr('class','del'+i);
|
||||
$("#applications").attr('class','applic'+i);
|
||||
|
||||
}
|
||||
|
||||
for (var i = elist.length; i< elist.length + flist.length; i++)
|
||||
{
|
||||
var cloneNode= sourceNode.cloneNode(true);
|
||||
sourceNode.parentNode.appendChild(cloneNode);
|
||||
$("#appinfo1").html("product name : "+ flist[i - elist.length]['ID']);
|
||||
$("#appinfo2").html("product Version : "+ flist[i - elist.length]['Version']);
|
||||
$("#lable").html("Custom Apps").css("color","green");
|
||||
$("#delbutton").attr('class','del'+i);
|
||||
$("#applications").attr('class','applic'+i);
|
||||
|
||||
}
|
||||
|
||||
for(var i = 0; i < elist.length; i++)
|
||||
{
|
||||
var tmp_node = document.getElementsByClassName("del" + i)[0]
|
||||
tmp_node.disabled = true
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
clone();
|
||||
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
function setfooterposition(divname)
|
||||
//Locate footer on the right place
|
||||
{
|
||||
var Top = dlist.length* $("#devices").height()+300;
|
||||
var scrollTop = $(document).scrollTop();
|
||||
if (dlist.length >=4){
|
||||
$(divname).css({posisiton:'absolute','top':Top+scrollTop});
|
||||
}
|
||||
}
|
||||
setfooterposition(".footer");
|
||||
|
||||
window.onload = function clone()
|
||||
//Show the list of connected devices
|
||||
{
|
||||
var sourceNode = document.getElementById("devices");
|
||||
$("#IPs").html("IP : "+ dlist[0]['IP']);
|
||||
$("#ports").html("Port : "+ dlist[0]['Port']);
|
||||
$("#installs").html("Installed Apps : "+ dlist[0]['apps']);
|
||||
$("#devices").attr('class','devic0');
|
||||
$("#dbutton").attr('class','bt0');
|
||||
$("#choose").attr('class','chos0');
|
||||
|
||||
for (var i=1; i<dlist.length; i++)
|
||||
{
|
||||
var cloneNode= sourceNode.cloneNode(true);
|
||||
sourceNode.parentNode.appendChild(cloneNode);
|
||||
$("#IPs").html("IP : "+ dlist[i]['IP']);
|
||||
$("#ports").html("Port : "+ dlist[i]['Port']);
|
||||
$("#installs").html("Installed Apps : "+ dlist[i]['apps']);
|
||||
$("#devices").attr('class','devic'+i);
|
||||
$("#dbutton").attr('class','bt'+i);
|
||||
$("#choose").attr('class','chos'+i);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function deviceClick(obj){
|
||||
//Render to the application.html
|
||||
var deviceObj=$(obj);
|
||||
var ip=deviceObj.find('#IPs').text();
|
||||
ip=ip.split(':')[1].split(' ')[1]
|
||||
var port=deviceObj.find('#ports').text();
|
||||
port=port.split(':')[1].split(' ')[1]
|
||||
var newurl = "apps/?"+"ip="+ip+"&port="+port;
|
||||
window.location.href= newurl;
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 523 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
@ -1,56 +0,0 @@
|
||||
# Component Test
|
||||
|
||||
The purpose of this test suite is to verify the basic components of WAMR work well in combination. It is highly recommended to run pass all suites before each commitment.
|
||||
|
||||
Prerequisites
|
||||
==============
|
||||
- clang is available to build wasm application.
|
||||
- python is installed to run test script.
|
||||
|
||||
|
||||
Run the test
|
||||
=============
|
||||
```
|
||||
start.py [-h] [-s SUITE_ID [SUITE_ID ...]] [-t CASE_ID [CASE_ID ...]]
|
||||
[-n REPEAT_TIME] [--shuffle_all]
|
||||
[--cases_list CASES_LIST_FILE_PATH] [--skip_proc]
|
||||
[-b BINARIES] [-d] [--rebuild]
|
||||
```
|
||||
It builds out the simple project binary including WAMR runtime binary ```simple``` and the testing tool ```host_tool``` before running the test suites.
|
||||
|
||||
Test output is like:
|
||||
```
|
||||
Test Execution Summary:
|
||||
Success: 8
|
||||
Cases fails: 0
|
||||
Setup fails: 0
|
||||
Case load fails: 0
|
||||
|
||||
|
||||
------------------------------------------------------------
|
||||
The run folder is [run-03-23-16-29]
|
||||
that's all. bye
|
||||
kill to quit..
|
||||
Killed
|
||||
```
|
||||
|
||||
The detailed report and log is generated in ```run``` folder. The binaries copy is also put in that folder.
|
||||
|
||||
Usage samples
|
||||
==============
|
||||
|
||||
Run default test suite:
|
||||
</br>
|
||||
```python start.py```
|
||||
|
||||
Rebuild all test apps and then run default test suite:
|
||||
</br>
|
||||
```python start.py --rebuild```
|
||||
|
||||
Run a specified test suite:
|
||||
</br>
|
||||
```python start.py -s 01-life-cycle```
|
||||
|
||||
Run a specified test case:
|
||||
</br>
|
||||
```python start.py -t 01-install```
|
||||
@ -1,11 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
__all__ = [
|
||||
"net_manager", "wifi_daemon_utils"
|
||||
]
|
||||
|
||||
__author__ = ""
|
||||
__package__ = "model"
|
||||
__version__ = "1.0"
|
||||
@ -1,11 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
__all__ = [
|
||||
"net_manager", "wifi_daemon_utils"
|
||||
]
|
||||
|
||||
__author__ = ""
|
||||
__package__ = "model"
|
||||
__version__ = "1.0"
|
||||
@ -1,29 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import os
|
||||
import json
|
||||
from test.test_support import _run_suite
|
||||
|
||||
class CTestCaseBase(object):
|
||||
def __init__(self, suite):
|
||||
self.m_suite = suite
|
||||
return
|
||||
def on_get_case_description(self):
|
||||
return "Undefined"
|
||||
|
||||
def on_setup_case(self):
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
return True, ''
|
||||
|
||||
def get_suite(self):
|
||||
return self.m_suite
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
from __future__ import print_function
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import pprint
|
||||
import random
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
from .test_utils import *
|
||||
from .test_api import *
|
||||
|
||||
|
||||
|
||||
|
||||
def read_cases_from_file(file_path):
|
||||
if not os.path.exists(file_path):
|
||||
return False, None
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
content = f.readlines()
|
||||
|
||||
content = [x.strip() for x in content]
|
||||
print(content)
|
||||
if len(content) == 0:
|
||||
return False, None
|
||||
|
||||
return True, content
|
||||
|
||||
|
||||
|
||||
@ -1,288 +0,0 @@
|
||||
from __future__ import print_function
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import pprint
|
||||
import random
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
|
||||
from .test_api import *
|
||||
import this
|
||||
|
||||
|
||||
'''
|
||||
The run evironment dir structure:
|
||||
|
||||
run/
|
||||
run{date-time}/
|
||||
suites/
|
||||
{suite name}/
|
||||
-- target/ (the target software being tested)
|
||||
-- tools/ (the tools for testing the target software)
|
||||
'''
|
||||
|
||||
|
||||
framework=None
|
||||
|
||||
def get_framework():
|
||||
global framework
|
||||
return framework
|
||||
|
||||
def my_import(name):
|
||||
mod = __import__(name)
|
||||
components = name.split('.')
|
||||
for comp in components[1:]:
|
||||
mod = getattr(mod, comp)
|
||||
return mod
|
||||
|
||||
|
||||
# we maintain a root path apart from framework location
|
||||
# so the suites can be located in anywhere
|
||||
class CTestFramework(object):
|
||||
|
||||
def __init__(self, path):
|
||||
self.running_case = ''
|
||||
self.running_suite = ''
|
||||
self.target_suites = {}
|
||||
self.target_cases = {}
|
||||
self.root_path = path
|
||||
self.running_folder=''
|
||||
self.report = None
|
||||
self.sucess_cases = 0
|
||||
self.failed_cases = 0
|
||||
self.setup_fails = 0
|
||||
self.load_fails = 0;
|
||||
global framework
|
||||
framework = self
|
||||
|
||||
api_set_root_path(path)
|
||||
|
||||
print("root_path is " + self.root_path)
|
||||
|
||||
def gen_execution_stats(self):
|
||||
return '\nTest Execution Summary: ' \
|
||||
'\n\tSuccess: {}' \
|
||||
'\n\tCases fails: {}' \
|
||||
'\n\tSetup fails: {}' \
|
||||
'\n\tCase load fails: {}'.format(
|
||||
self.sucess_cases, self.failed_cases, self.setup_fails, self.load_fails)
|
||||
|
||||
def report_result(self, success, message, case_description):
|
||||
if self.report is None:
|
||||
return
|
||||
|
||||
case_pass = "pass"
|
||||
if not success:
|
||||
case_pass = "fail"
|
||||
|
||||
self.report.write(case_pass + ": [" + self.running_case + "]\n\treason: " + \
|
||||
message + "\n\tcase: " + case_description + "\n")
|
||||
return
|
||||
|
||||
def get_running_path(self):
|
||||
return self.root_path + "/run/" + self.running_folder
|
||||
|
||||
def load_suites(self):
|
||||
self.target_suites = os.listdir(self.root_path + "/suites")
|
||||
return
|
||||
|
||||
def run_case(self, suite_instance, case):
|
||||
# load the test case module
|
||||
case_description = ''
|
||||
suite = suite_instance.m_name
|
||||
api_log("\n>>start run [" + case + "] >>")
|
||||
module_name = 'suites.' + suite + ".cases." + case + ".case"
|
||||
try:
|
||||
module = my_import(module_name)
|
||||
except Exception as e:
|
||||
report_fail("load case fail: " + str(e))
|
||||
api_log_error("load case fail: " + str(e))
|
||||
self.load_fails = self.load_fails +1
|
||||
print(traceback.format_exc())
|
||||
return False
|
||||
|
||||
try:
|
||||
case = module.CTestCase(suite_instance)
|
||||
except Exception as e:
|
||||
report_fail("initialize case fail: " + str(e))
|
||||
api_log_error("initialize case fail: " + str(e))
|
||||
self.load_fails = self.load_fails +1
|
||||
return False
|
||||
|
||||
# call the case on setup callback
|
||||
try:
|
||||
case_description = case.on_get_case_description()
|
||||
result, message = case.on_setup_case()
|
||||
except Exception as e:
|
||||
result = False
|
||||
message = str(e);
|
||||
if not result:
|
||||
api_log_error(message)
|
||||
report_fail (message, case_description)
|
||||
self.failed_cases = self.failed_cases+1
|
||||
return False
|
||||
|
||||
# call the case execution callaback
|
||||
try:
|
||||
result, message = case.on_run_case()
|
||||
except Exception as e:
|
||||
result = False
|
||||
message = str(e);
|
||||
if not result:
|
||||
report_fail (message, case_description)
|
||||
api_log_error(message)
|
||||
self.failed_cases = self.failed_cases+1
|
||||
else:
|
||||
report_success(case_description)
|
||||
self.sucess_cases = self.sucess_cases +1
|
||||
|
||||
# call the case cleanup callback
|
||||
try:
|
||||
clean_result, message = case.on_cleanup_case()
|
||||
except Exception as e:
|
||||
clean_result = False
|
||||
message = str(e)
|
||||
|
||||
if not clean_result:
|
||||
api_log(message)
|
||||
|
||||
return result
|
||||
|
||||
def run_suite(self, suite, cases):
|
||||
# suite setup
|
||||
message = ''
|
||||
api_log("\n>>> Suite [" + suite + "] starting >>>")
|
||||
running_folder = self.get_running_path()+ "/suites/" + suite;
|
||||
|
||||
module_name = 'suites.' + suite + ".suite_setup"
|
||||
try:
|
||||
module = my_import(module_name)
|
||||
except Exception as e:
|
||||
report_fail("load suite [" + suite +"] fail: " + str(e))
|
||||
self.load_fails = self.load_fails +1
|
||||
return False
|
||||
|
||||
try:
|
||||
suite_instance = module.CTestSuite(suite, \
|
||||
self.root_path + '/suites/' + suite, running_folder)
|
||||
except Exception as e:
|
||||
report_fail("initialize suite fail: " + str(e))
|
||||
self.load_fails = self.load_fails +1
|
||||
return False
|
||||
|
||||
result, message = suite_instance.load_settings()
|
||||
if not result:
|
||||
report_fail("load settings fail: " + str(e))
|
||||
self.load_fails = self.load_fails +1
|
||||
return False
|
||||
|
||||
try:
|
||||
result, message = suite_instance.on_suite_setup()
|
||||
except Exception as e:
|
||||
result = False
|
||||
message = str(e);
|
||||
if not result:
|
||||
api_log_error(message)
|
||||
report_fail (message)
|
||||
self.setup_fails = self.setup_fails + 1
|
||||
return False
|
||||
|
||||
self.running_suite = suite
|
||||
|
||||
cases.sort()
|
||||
|
||||
# run cases
|
||||
for case in cases:
|
||||
if not os.path.isdir(self.root_path + '/suites/' + suite + '/cases/' + case):
|
||||
continue
|
||||
|
||||
self.running_case = case
|
||||
self.run_case(suite_instance, case)
|
||||
self.running_case = ''
|
||||
|
||||
# suites cleanup
|
||||
self.running_suite = ''
|
||||
try:
|
||||
result, message = suite_instance.on_suite_cleanup()
|
||||
except Exception as e:
|
||||
result = False
|
||||
message = str(e);
|
||||
if not result:
|
||||
api_log_error(message)
|
||||
report_fail (message)
|
||||
self.setup_fails = self.setup_fails + 1
|
||||
return
|
||||
|
||||
def start_run(self):
|
||||
if self.target_suites is None:
|
||||
print("\n\nstart run: no target suites, exit..")
|
||||
return
|
||||
|
||||
cur_time = time.localtime()
|
||||
time_prefix = "{:02}-{:02}-{:02}-{:02}".format(
|
||||
cur_time.tm_mon, cur_time.tm_mday, cur_time.tm_hour, cur_time.tm_min)
|
||||
|
||||
debug = api_get_value('debug', False)
|
||||
if debug:
|
||||
self.running_folder = 'debug'
|
||||
else:
|
||||
self.running_folder = 'run-' + time_prefix
|
||||
|
||||
folder = self.root_path + "/run/" +self.running_folder;
|
||||
|
||||
if os.path.exists(folder):
|
||||
shutil.rmtree(folder, ignore_errors=True)
|
||||
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder )
|
||||
os.makedirs(folder + "/suites")
|
||||
|
||||
api_init_log(folder + "/test.log")
|
||||
|
||||
self.report = open(folder + "/report.txt", 'a')
|
||||
|
||||
self.target_suites.sort()
|
||||
|
||||
for suite in self.target_suites:
|
||||
if not os.path.isdir(self.root_path + '/suites/' + suite):
|
||||
continue
|
||||
self.report.write("suite " + suite + " cases:\n")
|
||||
if self.target_cases is None:
|
||||
cases = os.listdir(self.root_path + "/suites/" + suite + "/cases")
|
||||
self.run_suite(suite, cases)
|
||||
else:
|
||||
self.run_suite(suite, self.target_cases)
|
||||
self.report.write("\n")
|
||||
|
||||
self.report.write("\n\n")
|
||||
summary = self.gen_execution_stats()
|
||||
self.report.write(summary);
|
||||
self.report.flush()
|
||||
self.report.close()
|
||||
print(summary)
|
||||
|
||||
|
||||
def report_fail(message, case_description=''):
|
||||
global framework
|
||||
if framework is not None:
|
||||
framework.report_result(False, message, case_description)
|
||||
|
||||
api_log_error(message)
|
||||
|
||||
return
|
||||
|
||||
def report_success(case_description=''):
|
||||
global framework
|
||||
if framework is not None:
|
||||
framework.report_result(True , "OK", case_description)
|
||||
return
|
||||
@ -1,40 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
class CTestSuiteBase(object):
|
||||
def __init__(self, name, suite_path, run_path):
|
||||
self.suite_path=suite_path
|
||||
self.run_path=run_path
|
||||
self.m_name = name
|
||||
self.settings = {}
|
||||
|
||||
def get_settings_item(self, item):
|
||||
if item in self.settings:
|
||||
return self.settings[item]
|
||||
else:
|
||||
return None
|
||||
|
||||
def load_settings(self):
|
||||
path = self.suite_path + "/settings.cfg"
|
||||
if os.path.isfile(path):
|
||||
try:
|
||||
fp = open(path, 'r')
|
||||
self.settings = json.load(fp)
|
||||
fp.close()
|
||||
except Exception, e:
|
||||
return False, 'Load settings fail: ' + e.message
|
||||
return True, 'OK'
|
||||
else:
|
||||
return True, 'No file'
|
||||
|
||||
def on_suite_setup(self):
|
||||
return True, 'OK'
|
||||
|
||||
def on_suite_cleanup(self):
|
||||
return True, 'OK'
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
from __future__ import print_function
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import logging
|
||||
import threading
|
||||
from .test_utils import *
|
||||
|
||||
global logger
|
||||
logger = None
|
||||
|
||||
def api_init_log(log_path):
|
||||
global logger
|
||||
print("api_init_log: " + log_path)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.setLevel(level = logging.INFO)
|
||||
handler = logging.FileHandler(log_path)
|
||||
handler.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(logging.INFO)
|
||||
|
||||
logger.addHandler(handler)
|
||||
logger.addHandler(console)
|
||||
|
||||
return
|
||||
|
||||
def api_log(message):
|
||||
global logger
|
||||
if logger is None:
|
||||
print(message)
|
||||
else:
|
||||
logger.info (message)
|
||||
return
|
||||
|
||||
def api_log_error(message):
|
||||
global logger
|
||||
if logger is None:
|
||||
print(message)
|
||||
else:
|
||||
logger.error (message)
|
||||
return
|
||||
|
||||
def api_logv(message):
|
||||
global logger
|
||||
if logger is None:
|
||||
print(message)
|
||||
else:
|
||||
logger.info(message)
|
||||
return
|
||||
|
||||
#####################################3
|
||||
global g_case_runner_event
|
||||
def api_wait_case_event(timeout):
|
||||
global g_case_runner_event
|
||||
g_case_runner_event.clear()
|
||||
g_case_runner_event.wait(timeout)
|
||||
|
||||
def api_notify_case_runner():
|
||||
global g_case_runner_event
|
||||
g_case_runner_event.set()
|
||||
|
||||
def api_create_case_event():
|
||||
global g_case_runner_event
|
||||
g_case_runner_event = threading.Event()
|
||||
|
||||
#######################################
|
||||
|
||||
def api_init_globals():
|
||||
global _global_dict
|
||||
_global_dict = {}
|
||||
|
||||
def api_set_value(name, value):
|
||||
_global_dict[name] = value
|
||||
|
||||
def api_get_value(name, defValue=None):
|
||||
try:
|
||||
return _global_dict[name]
|
||||
except KeyError:
|
||||
return defValue
|
||||
|
||||
|
||||
#########################################
|
||||
global root_path
|
||||
def api_set_root_path(root):
|
||||
global root_path
|
||||
root_path = root
|
||||
|
||||
def api_get_root_path():
|
||||
global root_path
|
||||
return root_path;
|
||||
|
||||
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
from __future__ import print_function
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
from subprocess import check_output, CalledProcessError
|
||||
|
||||
def t_getPIDs(process):
|
||||
try:
|
||||
pidlist = map(int, check_output(["pidof", process]).split())
|
||||
except CalledProcessError:
|
||||
pidlist = []
|
||||
#print process + ':list of PIDs = ' + ', '.join(str(e) for e in pidlist)
|
||||
return pidlist
|
||||
|
||||
|
||||
def t_kill_process_by_name(p_keywords):
|
||||
pid_list = []
|
||||
ps_info = subprocess.check_output(shlex.split("ps aux")).split("\n")
|
||||
for p in ps_info:
|
||||
if p_keywords in p:
|
||||
tmp = p.split(" ")
|
||||
tmp = [x for x in tmp if len(x) > 0]
|
||||
pid_list.append(tmp[1])
|
||||
|
||||
for pid in pid_list:
|
||||
cmd = "kill -9 {}".format(pid)
|
||||
subprocess.call(shlex.split(cmd))
|
||||
|
||||
return pid_list
|
||||
|
||||
|
||||
|
||||
#proc -> name of the process
|
||||
#kill = 1 -> search for pid for kill
|
||||
#kill = 0 -> search for name (default)
|
||||
|
||||
def t_process_exists(proc, kill = 0):
|
||||
ret = False
|
||||
processes = t_getPIDs(proc)
|
||||
|
||||
for pid in processes:
|
||||
if kill == 0:
|
||||
return True
|
||||
else:
|
||||
print("kill [" + proc + "], pid=" + str(pid))
|
||||
os.kill((pid), 9)
|
||||
ret = True
|
||||
return ret
|
||||
|
||||
def t_copy_files(source_dir, pattern, dest_dir):
|
||||
files = os.listdir(source_dir)
|
||||
for file in files:
|
||||
if file in ('/', '.', '..'):
|
||||
continue
|
||||
|
||||
if pattern in ('*', '') or files.endswith(pattern):
|
||||
shutil.copy(source_dir+"/"+ file, dest_dir)
|
||||
|
||||
|
||||
|
||||
@ -1,150 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import json
|
||||
import time
|
||||
|
||||
from framework import test_api
|
||||
from framework.test_utils import *
|
||||
|
||||
output = "output.txt"
|
||||
|
||||
def start_env():
|
||||
os.system("./start.sh")
|
||||
|
||||
def stop_env():
|
||||
os.system("./stop.sh")
|
||||
time.sleep(0.5)
|
||||
os.chdir("../") #reset path for other cases in the same suite
|
||||
|
||||
def check_is_timeout():
|
||||
line_num = 0
|
||||
ft = open(output, 'r')
|
||||
lines = ft.readlines()
|
||||
|
||||
for line in reversed(lines):
|
||||
if (line[0:36] == "--------one operation begin.--------"):
|
||||
break
|
||||
line_num = line_num + 1
|
||||
|
||||
ft.close()
|
||||
if (lines[-(line_num)] == "operation timeout"):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def parse_ret(file):
|
||||
ft = open(file, 'a')
|
||||
ft.writelines("\n")
|
||||
ft.writelines("--------one operation finish.--------")
|
||||
ft.writelines("\n")
|
||||
ft.close()
|
||||
|
||||
ft = open(file, 'r')
|
||||
for line in reversed(ft.readlines()):
|
||||
if (line[0:16] == "response status "):
|
||||
ret = line[16:]
|
||||
ft.close()
|
||||
return int(ret)
|
||||
|
||||
def run_host_tool(cmd, file):
|
||||
ft = open(file, 'a')
|
||||
ft.writelines("--------one operation begin.--------")
|
||||
ft.writelines("\n")
|
||||
ft.close()
|
||||
os.system(cmd + " -o" + file)
|
||||
if (check_is_timeout() == True):
|
||||
return -1
|
||||
return parse_ret(file)
|
||||
|
||||
def install_app(app_name, file_name):
|
||||
return run_host_tool("./host_tool -i " + app_name + " -f ../test-app/" + file_name, output)
|
||||
|
||||
def uninstall_app(app_name):
|
||||
return run_host_tool("./host_tool -u " + app_name, output)
|
||||
|
||||
def query_app():
|
||||
return run_host_tool("./host_tool -q ", output)
|
||||
|
||||
def send_request(url, action, payload):
|
||||
if (payload is None):
|
||||
return run_host_tool("./host_tool -r " + url + " -A " + action, output)
|
||||
else:
|
||||
return run_host_tool("./host_tool -r " + url + " -A " + action + " -p " + payload, output)
|
||||
|
||||
def register(url, timeout, alive_time):
|
||||
return run_host_tool("./host_tool -s " + url + " -t " + str(timeout) + " -a " + str(alive_time), output)
|
||||
|
||||
def deregister(url):
|
||||
return run_host_tool("./host_tool -d " + url, output)
|
||||
|
||||
def get_response_payload():
|
||||
line_num = 0
|
||||
ft = open(output, 'r')
|
||||
lines = ft.readlines()
|
||||
|
||||
for line in reversed(lines):
|
||||
if (line[0:16] == "response status "):
|
||||
break
|
||||
line_num = line_num + 1
|
||||
|
||||
payload_lines = lines[-(line_num):-1]
|
||||
ft.close()
|
||||
|
||||
return payload_lines
|
||||
|
||||
def check_query_apps(expected_app_list):
|
||||
if (check_is_timeout() == True):
|
||||
return False
|
||||
json_lines = get_response_payload()
|
||||
json_str = " ".join(json_lines)
|
||||
json_dict = json.loads(json_str)
|
||||
app_list = []
|
||||
|
||||
for key, value in json_dict.items():
|
||||
if key[0:6] == "applet":
|
||||
app_list.append(value)
|
||||
|
||||
if (sorted(app_list) == sorted(expected_app_list)):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_response_payload(expected_payload):
|
||||
if (check_is_timeout() == True):
|
||||
return False
|
||||
json_lines = get_response_payload()
|
||||
json_str = " ".join(json_lines)
|
||||
|
||||
if (json_str.strip() != ""):
|
||||
json_dict = json.loads(json_str)
|
||||
else:
|
||||
json_dict = {}
|
||||
|
||||
if (json_dict == expected_payload):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_get_event():
|
||||
line_num = 0
|
||||
ft = open(output, 'r')
|
||||
lines = ft.readlines()
|
||||
|
||||
for line in reversed(lines):
|
||||
if (line[0:16] == "response status "):
|
||||
break
|
||||
line_num = line_num + 1
|
||||
|
||||
payload_lines = lines[-(line_num):-1]
|
||||
ft.close()
|
||||
|
||||
if (payload_lines[1][0:17] == "received an event"):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@ -1,301 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "host_api.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "er-coap-constants.h"
|
||||
|
||||
static char *
|
||||
read_file_to_buffer(const char *filename, int *ret_size);
|
||||
int send_request_to_applet_success = 0;
|
||||
const char *label_for_request = "request1";
|
||||
int event_listener_counter = 0;
|
||||
char *applet_buf[1024 * 1024];
|
||||
const char *host_agent_ip = "127.0.0.1";
|
||||
void
|
||||
f_aee_response_handler(void *usr_ctx, aee_response_t *response)
|
||||
{
|
||||
if (response == NULL) {
|
||||
printf("########## request timeout!!! \n");
|
||||
}
|
||||
else {
|
||||
char *str = (char *)usr_ctx;
|
||||
printf("#### dump response ####\n");
|
||||
printf("#### user data: %s \n", str);
|
||||
printf("#### status: %d \n", response->status);
|
||||
if (response->payload != NULL)
|
||||
attr_container_dump((attr_container_t *)response->payload);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
f_aee_event_listener(const char *url, void *event, int fmt)
|
||||
{
|
||||
printf("######## event is received. url: %s, fmt:%d ############\n", url,
|
||||
fmt);
|
||||
|
||||
attr_container_t *attr_obj = (attr_container_t *)event;
|
||||
|
||||
attr_container_dump(attr_obj);
|
||||
/*
|
||||
if (0 == strcmp(url, "alert/overheat"))
|
||||
{
|
||||
event_listener_counter++;
|
||||
printf("event :%d \n", event_listener_counter);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
static int
|
||||
print_menu_and_select(void)
|
||||
{
|
||||
char s[256];
|
||||
int choice;
|
||||
do {
|
||||
printf("\n");
|
||||
printf("1. Install TestApplet1\n");
|
||||
printf("2. Install TestApplet2\n");
|
||||
printf("3. Install TestApplet3\n");
|
||||
printf("4. Uninstall TestApplet1\n");
|
||||
printf("5. Uninstall TestApplet2\n");
|
||||
printf("6. Uninstall TestApplet3\n");
|
||||
printf("7. Send Request to TestApplet1\n");
|
||||
printf("8. Register Event to TestApplet1\n");
|
||||
printf("9. UnRegister Event to TestApplet1\n");
|
||||
printf("a. Query Applets\n");
|
||||
printf("t. Auto Test\n");
|
||||
printf("q. Exit\n");
|
||||
printf("Please Select: ");
|
||||
|
||||
if (fgets(s, sizeof(s), stdin)) {
|
||||
if (!strncmp(s, "q", 1))
|
||||
return 0;
|
||||
if (!strncmp(s, "a", 1))
|
||||
return 10;
|
||||
if (!strncmp(s, "t", 1))
|
||||
return 20;
|
||||
choice = atoi(s);
|
||||
if (choice >= 1 && choice <= 9)
|
||||
return choice;
|
||||
}
|
||||
} while (1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
install_applet(int index)
|
||||
{
|
||||
char applet_name[64];
|
||||
char applet_file_name[64];
|
||||
char *buf;
|
||||
int size;
|
||||
int ret;
|
||||
|
||||
printf("Installing TestApplet%d...\n", index);
|
||||
snprintf(applet_name, sizeof(applet_name), "TestApplet%d", index);
|
||||
snprintf(applet_file_name, sizeof(applet_file_name), "./TestApplet%d.wasm",
|
||||
index);
|
||||
buf = read_file_to_buffer(applet_file_name, &size);
|
||||
if (!buf) {
|
||||
printf("Install Applet failed: read file %s error.\n",
|
||||
applet_file_name);
|
||||
return;
|
||||
}
|
||||
|
||||
// step2. install applet
|
||||
ret = aee_applet_install(buf, "wasm", size, applet_name, 5000);
|
||||
if (ret) {
|
||||
printf("%s install success\n", applet_name);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static void
|
||||
uninstall_applet(int index)
|
||||
{
|
||||
int ret;
|
||||
char applet_name[64];
|
||||
snprintf(applet_name, sizeof(applet_name), "TestApplet%d", index);
|
||||
ret = aee_applet_uninstall(applet_name, "wasm", 5000);
|
||||
if (ret) {
|
||||
printf("uninstall %s success\n", applet_name);
|
||||
}
|
||||
else {
|
||||
printf("uninstall %s failed\n", applet_name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
send_request(int index)
|
||||
{
|
||||
char url[64];
|
||||
int ret;
|
||||
aee_request_t req;
|
||||
const char *user_context = "label for request";
|
||||
attr_container_t *attr_obj =
|
||||
attr_container_create("Send Request to Applet");
|
||||
attr_container_set_string(&attr_obj, "String key", "Hello");
|
||||
attr_container_set_int(&attr_obj, "Int key", 1000);
|
||||
attr_container_set_int64(&attr_obj, "Int64 key", 0x77BBCCDD11223344LL);
|
||||
|
||||
// specify the target wasm app
|
||||
snprintf(url, sizeof(url), "/app/TestApplet%d/url1", index);
|
||||
|
||||
// not specify the target wasm app
|
||||
// snprintf(url, sizeof(url), "url1");
|
||||
aee_request_init(&req, url, COAP_PUT);
|
||||
aee_request_set_payload(&req, attr_obj,
|
||||
attr_container_get_serialize_length(attr_obj),
|
||||
PAYLOAD_FORMAT_ATTRIBUTE_OBJECT);
|
||||
ret = aee_request_send(&req, f_aee_response_handler, (void *)user_context,
|
||||
10000);
|
||||
|
||||
if (ret) {
|
||||
printf("send request to TestApplet1 success\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
register_event(const char *event_path)
|
||||
{
|
||||
hostclient_register_event(event_path, f_aee_event_listener);
|
||||
}
|
||||
|
||||
static void
|
||||
unregister_event(const char *event_path)
|
||||
{
|
||||
hostclient_unregister_event(event_path);
|
||||
}
|
||||
|
||||
static void
|
||||
query_applets()
|
||||
{
|
||||
aee_applet_list_t applet_lst;
|
||||
aee_applet_list_init(&applet_lst);
|
||||
aee_applet_list(5000, &applet_lst);
|
||||
aee_applet_list_clean(&applet_lst);
|
||||
}
|
||||
|
||||
static char *
|
||||
read_file_to_buffer(const char *filename, int *ret_size)
|
||||
{
|
||||
FILE *fl = NULL;
|
||||
char *buffer = NULL;
|
||||
int file_size = 0;
|
||||
if (!(fl = fopen(filename, "rb"))) {
|
||||
printf("file open failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fseek(fl, 0, SEEK_END);
|
||||
file_size = ftell(fl);
|
||||
|
||||
if (file_size == 0) {
|
||||
printf("file length 0\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(buffer = (char *)malloc(file_size))) {
|
||||
fclose(fl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fseek(fl, 0, SEEK_SET);
|
||||
|
||||
if (!fread(buffer, 1, file_size, fl)) {
|
||||
printf("file read failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(fl);
|
||||
*ret_size = file_size;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
auto_test()
|
||||
{
|
||||
int i;
|
||||
int interval = 1000; /* ms */
|
||||
while (1) {
|
||||
uninstall_applet(1);
|
||||
uninstall_applet(2);
|
||||
uninstall_applet(3);
|
||||
install_applet(1);
|
||||
install_applet(2);
|
||||
install_applet(3);
|
||||
|
||||
for (i = 0; i < 60 * 1000 / interval; i++) {
|
||||
query_applets();
|
||||
send_request(1);
|
||||
send_request(2);
|
||||
send_request(3);
|
||||
usleep(interval * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
exit_program()
|
||||
{
|
||||
hostclient_shutdown();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
main()
|
||||
{
|
||||
bool ret;
|
||||
|
||||
// step1. host client init
|
||||
ret = hostclient_initialize(host_agent_ip, 3456);
|
||||
|
||||
if (!ret) {
|
||||
printf("host client initialize failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
int choice = print_menu_and_select();
|
||||
printf("\n");
|
||||
|
||||
if (choice == 0)
|
||||
exit_program();
|
||||
if (choice <= 3)
|
||||
install_applet(choice);
|
||||
else if (choice <= 6)
|
||||
uninstall_applet(choice - 3);
|
||||
else if (choice <= 7)
|
||||
send_request(1);
|
||||
else if (choice <= 8)
|
||||
register_event("alert/overheat");
|
||||
else if (choice <= 9)
|
||||
unregister_event("alert/overheat");
|
||||
else if (choice == 10)
|
||||
query_applets();
|
||||
else if (choice == 20)
|
||||
auto_test();
|
||||
} while (1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
|
||||
// Debug program: F5 or Debug > Start Debugging menu
|
||||
|
||||
// Tips for Getting Started:
|
||||
// 1. Use the Solution Explorer window to add/manage files
|
||||
// 2. Use the Team Explorer window to connect to source control
|
||||
// 3. Use the Output window to see build output and other messages
|
||||
// 4. Use the Error List window to view errors
|
||||
// 5. Go to Project > Add New Item to create new code files, or
|
||||
// Project > Add Existing Item to add existing code files to the project
|
||||
// 6. In the future, to open this project again, go to File > Open > Project
|
||||
// and select the .sln file
|
||||
@ -1,44 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
CC = gcc
|
||||
CFLAGS := -Wall -g
|
||||
|
||||
# Add this to make compiler happy
|
||||
CFLAGS += -DWASM_ENABLE_INTERP=1
|
||||
|
||||
host_api_c=../../../../host-agent/host-api-c
|
||||
attr_container_dir=../../../../wamr/core/app-framework/app-native-shared
|
||||
coap_dir=../../../../host-agent/coap
|
||||
shared_dir=../../../../wamr/core/shared
|
||||
|
||||
# core
|
||||
INCLUDE_PATH = -I$(host_api_c)/src -I$(attr_container_dir)/ \
|
||||
-I$(coap_dir)/er-coap -I$(coap_dir)/er-coap/extension \
|
||||
-I$(shared_dir)/include \
|
||||
-I$(shared_dir)/utils \
|
||||
-I$(shared_dir)/platform/include/ \
|
||||
-I$(shared_dir)/platform/linux/
|
||||
|
||||
LIB := $(host_api_c)/src/libhostapi.a
|
||||
EXE := ./hostapp
|
||||
|
||||
App_C_Files := host_app_sample.c
|
||||
|
||||
OBJS := $(App_C_Files:.c=.o)
|
||||
|
||||
all: $(EXE)
|
||||
|
||||
%.o: %.c
|
||||
@$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE_PATH)
|
||||
|
||||
$(EXE): $(OBJS)
|
||||
@rm -f $(EXE)
|
||||
@$(CC) $(OBJS) -o $(EXE) $(LIB) -lpthread -lrt
|
||||
@rm -f $(OBJS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(OBJS) $(EXE)
|
||||
@ -1,7 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
#!/bin/sh
|
||||
|
||||
@ -1,152 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
It is the entrance of the iagent test framework.
|
||||
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import datetime
|
||||
import os
|
||||
import pprint
|
||||
import random
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.append('../../../app-sdk/python')
|
||||
from framework.test_utils import *
|
||||
from framework.framework import *
|
||||
|
||||
|
||||
def signal_handler(signal, frame):
|
||||
print('Pressed Ctrl+C!')
|
||||
sys.exit(0)
|
||||
|
||||
def Register_signal_handler():
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
# signal.pause()
|
||||
|
||||
|
||||
def flatten_args_list(l):
|
||||
if l is None:
|
||||
return None
|
||||
|
||||
return [x for y in l for x in y]
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description = "to run specific case(s) "\
|
||||
"in specific suite(s) with FC test framework")
|
||||
parser.add_argument('-s', dest = 'suite_id', action = 'append',
|
||||
nargs = '+',
|
||||
help = 'one or multiple suite ids, which are also setup ids.'\
|
||||
'by default if it isn\'t passed from argument, all '\
|
||||
'suites are going to be run.')
|
||||
parser.add_argument('-t', dest = 'case_id', action = 'append',
|
||||
nargs = '+',
|
||||
help = 'one or multiple cases ids.'\
|
||||
'by default if it isn\'t passed from argument, all '\
|
||||
'cases in specific suites are going to be run.')
|
||||
parser.add_argument('-n', dest = 'repeat_time', action = 'store',
|
||||
default = 1,
|
||||
help = 'how many times do you want to run. there is 40s '\
|
||||
'break time between two rounds. each round includs '\
|
||||
'init_setup, run_test_case and deinit_setup.')
|
||||
parser.add_argument('--shuffle_all', dest = 'shuffle_all',
|
||||
default = False, action = 'store_true',
|
||||
help = 'shuffle_all test cases in per test suite '\
|
||||
'by default, all cases under per suite should '\
|
||||
'be executed by input order.')
|
||||
parser.add_argument('--cases_list', dest='cases_list_file_path',
|
||||
default=None,
|
||||
action='store',
|
||||
help="read cases list from a flie ")
|
||||
parser.add_argument('--skip_proc', dest='skip_proc',
|
||||
default = False, action = 'store_true',
|
||||
help='do not start the test process.'\
|
||||
'sometimes the gw_broker process will be started in eclipse for debug purpose')
|
||||
parser.add_argument('-b', dest = 'binaries', action = 'store',
|
||||
help = 'The path of target folder ')
|
||||
parser.add_argument('-d', dest = 'debug', action = 'store_true',
|
||||
help = 'wait user to attach the target process after launch processes ')
|
||||
parser.add_argument('--rebuild', dest = 'rebuild', action = 'store_true',
|
||||
help = 'rebuild all test binaries')
|
||||
args = parser.parse_args()
|
||||
|
||||
print("------------------------------------------------------------")
|
||||
print("parsing arguments ... ...")
|
||||
print(args)
|
||||
|
||||
'''
|
||||
logger = logging.getLogger('coapthon.server.coap')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(logging.DEBUG)
|
||||
logger.addHandler(console)
|
||||
'''
|
||||
print("------------------------------------------------------------")
|
||||
print("preparing wamr binary and test tools ... ...")
|
||||
os.system("cd ../../samples/simple/ && bash build.sh -p host-interp")
|
||||
|
||||
Register_signal_handler()
|
||||
|
||||
api_init_globals();
|
||||
|
||||
api_create_case_event();
|
||||
|
||||
suites_list = flatten_args_list(args.suite_id)
|
||||
cases_list = flatten_args_list(args.case_id)
|
||||
|
||||
dirname, filename = os.path.split(os.path.abspath(sys.argv[0]))
|
||||
api_set_root_path(dirname);
|
||||
|
||||
framework = CTestFramework(dirname);
|
||||
framework.repeat_time = int(args.repeat_time)
|
||||
framework.shuffle_all = args.shuffle_all
|
||||
framework.skip_proc=args.skip_proc
|
||||
|
||||
api_set_value('keep_env', args.skip_proc)
|
||||
api_set_value('debug', args.debug)
|
||||
api_set_value('rebuild', args.rebuild)
|
||||
|
||||
binary_path = args.binaries
|
||||
if binary_path is None:
|
||||
binary_path = os.path.abspath(dirname + '/../..')
|
||||
|
||||
print("checking execution binary path: " + binary_path)
|
||||
if not os.path.exists(binary_path):
|
||||
print("The execution binary path was not available. quit...")
|
||||
os._exit(0)
|
||||
api_set_value('binary_path', binary_path)
|
||||
|
||||
if suites_list is not None:
|
||||
framework.target_suites = suites_list
|
||||
else:
|
||||
framework.load_suites()
|
||||
|
||||
framework.target_cases = cases_list
|
||||
framework.start_run()
|
||||
|
||||
print("\n\n------------------------------------------------------------")
|
||||
print("The run folder is [" + framework.running_folder +"]")
|
||||
print("that's all. bye")
|
||||
|
||||
print("kill to quit..")
|
||||
t_kill_process_by_name("start.py")
|
||||
|
||||
sys.exit(0)
|
||||
os._exit()
|
||||
|
||||
|
||||
@ -1,94 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#uninstall inexistent App1
|
||||
ret = uninstall_app("App1")
|
||||
if (ret != 160):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps([])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "01_install.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#install App2
|
||||
ret = install_app("App2", "01_install.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1","App2"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#uninstall App2
|
||||
ret = uninstall_app("App2")
|
||||
if (ret != 66):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,73 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "02_request.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App1
|
||||
ret = send_request("/res1", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
expect_response_payload = {"key1":"value1","key2":"value2"}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App1
|
||||
ret = send_request("/res2", "DELETE", None)
|
||||
if (ret != 66):
|
||||
return False, ''
|
||||
expect_response_payload = {}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,67 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "03_event.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#register event
|
||||
ret = register("/alert/overheat", 2000, 5000)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_get_event()
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#deregister event
|
||||
ret = deregister("/alert/overheat")
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,80 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "04_request_internal_resp.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#install App2
|
||||
ret = install_app("App2", "04_request_internal_req.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1","App2"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App2
|
||||
ret = send_request("/res1", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
time.sleep(2)
|
||||
expect_response_payload = {"key1":"value1","key2":"value2"}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App2
|
||||
ret = send_request("/res2", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
time.sleep(2)
|
||||
expect_response_payload = {"key1":"value1","key2":"value2"}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,70 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "05_event_internal_provider.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#install App2
|
||||
ret = install_app("App2", "05_event_internal_subscriber.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1","App2"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App2
|
||||
ret = send_request("/res1", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
time.sleep(2)
|
||||
expect_response_payload = {"key1":"value1","key2":"value2"}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,70 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "06_timer.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App1
|
||||
ret = send_request("/res1", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
ret = send_request("/check_timer", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
expect_response_payload = {"num":2}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,65 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "07_sensor.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App1
|
||||
ret = send_request("/res1", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
time.sleep(2)
|
||||
expect_response_payload = {"key1":"value1","key2":"value2"}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,78 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import logging
|
||||
import json
|
||||
|
||||
from framework.case_base import *
|
||||
from framework.test_api import *
|
||||
from harness.harness_api import *
|
||||
|
||||
class CTestCase(CTestCaseBase):
|
||||
def __init__(self, suite):
|
||||
CTestCaseBase.__init__(self, suite)
|
||||
|
||||
def get_case_name(self):
|
||||
case_path = os.path.dirname(os.path.abspath( __file__ ))
|
||||
return os.path.split(case_path)[1]
|
||||
|
||||
def on_get_case_description(self):
|
||||
return "startup the executables"
|
||||
|
||||
def on_setup_case(self):
|
||||
os.chdir(self.get_case_name())
|
||||
start_env()
|
||||
api_log_error("on_setup_case OK")
|
||||
return True, ''
|
||||
|
||||
def on_cleanup_case(self):
|
||||
stop_env()
|
||||
api_log_error("on_cleanup_case OK")
|
||||
return True, ''
|
||||
|
||||
# called by the framework
|
||||
def on_run_case(self):
|
||||
time.sleep(0.5)
|
||||
|
||||
#install App1
|
||||
ret = install_app("App1", "08_on_destroy.wasm")
|
||||
if (ret != 65):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps(["App1"])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#send request to App1
|
||||
ret = send_request("/res1", "GET", None)
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
time.sleep(2)
|
||||
expect_response_payload = {"key1":"value1"}
|
||||
ret = check_response_payload(expect_response_payload)
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
#uninstall App1
|
||||
ret = uninstall_app("App1")
|
||||
if (ret != 66):
|
||||
return False, ''
|
||||
|
||||
#query Apps
|
||||
ret = query_app()
|
||||
if (ret != 69):
|
||||
return False, ''
|
||||
ret = check_query_apps([])
|
||||
if (ret == False):
|
||||
return False, ''
|
||||
|
||||
return True, ''
|
||||
@ -1,56 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import types
|
||||
import time
|
||||
import glob
|
||||
|
||||
from framework.test_api import *
|
||||
from framework.test_utils import *
|
||||
from harness.harness_api import *
|
||||
from framework.suite import *
|
||||
|
||||
class CTestSuite(CTestSuiteBase):
|
||||
setup_path = ""
|
||||
def __init__(self, name, suite_path, run_path):
|
||||
CTestSuiteBase.__init__(self, name, suite_path, run_path)
|
||||
|
||||
def on_suite_setup(self):
|
||||
global setup_path
|
||||
setup_path = os.getcwd()
|
||||
cases = os.listdir(self.suite_path + "/cases/")
|
||||
cases.sort()
|
||||
|
||||
if api_get_value("rebuild", False):
|
||||
path_tmp = os.getcwd()
|
||||
os.chdir(self.suite_path + "/test-app")
|
||||
os.system(self.suite_path + "/test-app" + "/build.sh")
|
||||
os.chdir(path_tmp)
|
||||
|
||||
os.makedirs(self.run_path + "/test-app")
|
||||
|
||||
for case in cases:
|
||||
if case != "__init__.pyc" and case != "__init__.py":
|
||||
os.makedirs(self.run_path + "/" + case)
|
||||
#copy each case's host_tool, simple, wasm files, start/stop scripts to the run directory,
|
||||
shutil.copy(setup_path + "/../../samples/simple/out/simple", self.run_path + "/" + case)
|
||||
shutil.copy(setup_path + "/../../samples/simple/out/host_tool", self.run_path + "/" + case)
|
||||
for file in glob.glob(self.suite_path + "/test-app/" + "/*.wasm"):
|
||||
shutil.copy(file, self.run_path + "/test-app")
|
||||
shutil.copy(self.suite_path + "/tools/product/start.sh", self.run_path + "/" + case)
|
||||
shutil.copy(self.suite_path + "/tools/product/stop.sh", self.run_path + "/" + case)
|
||||
|
||||
os.chdir(self.run_path)
|
||||
|
||||
return True, 'OK'
|
||||
|
||||
def on_suite_cleanup(self):
|
||||
global setup_path
|
||||
os.chdir(setup_path)
|
||||
api_log("stopping env..")
|
||||
|
||||
return True, 'OK'
|
||||
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
printf("Hello, I was installed.\n");
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
response_t response[1];
|
||||
attr_container_t *payload;
|
||||
|
||||
printf("### user resource 1 handler called\n");
|
||||
|
||||
printf("###### dump request ######\n");
|
||||
printf("sender: %lu\n", request->sender);
|
||||
printf("url: %s\n", request->url);
|
||||
printf("action: %d\n", request->action);
|
||||
printf("payload:\n");
|
||||
if (request->payload != NULL && request->payload_len > 0
|
||||
&& request->fmt == FMT_ATTR_CONTAINER)
|
||||
attr_container_dump((attr_container_t *)request->payload);
|
||||
printf("#### dump request end ###\n");
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_string(&payload, "key1", "value1");
|
||||
attr_container_set_string(&payload, "key2", "value2");
|
||||
|
||||
make_response_for_request(request, response);
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
|
||||
void
|
||||
res2_handler(request_t *request)
|
||||
{
|
||||
response_t response[1];
|
||||
make_response_for_request(request, response);
|
||||
set_response(response, DELETED_2_02, 0, NULL, 0);
|
||||
api_response_send(response);
|
||||
|
||||
printf("### user resource 2 handler called\n");
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/res1", res1_handler);
|
||||
api_register_resource_handler("/res2", res2_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
|
||||
int num = 0;
|
||||
|
||||
void
|
||||
publish_overheat_event()
|
||||
{
|
||||
attr_container_t *event;
|
||||
|
||||
event = attr_container_create("event");
|
||||
attr_container_set_string(&event, "warning", "temperature is over high");
|
||||
|
||||
printf("###app publish event begin ###\n");
|
||||
|
||||
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
|
||||
attr_container_get_serialize_length(event));
|
||||
|
||||
printf("###app publish event end ###\n");
|
||||
|
||||
attr_container_destroy(event);
|
||||
}
|
||||
|
||||
/* Timer callback */
|
||||
void
|
||||
timer1_update(user_timer_t timer)
|
||||
{
|
||||
printf("Timer update %d\n", num++);
|
||||
publish_overheat_event();
|
||||
}
|
||||
|
||||
void
|
||||
start_timer()
|
||||
{
|
||||
user_timer_t timer;
|
||||
|
||||
/* set up a timer */
|
||||
timer = api_timer_create(1000, true, false, timer1_update);
|
||||
api_timer_restart(timer, 1000);
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
start_timer();
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
|
||||
uint32 mid;
|
||||
unsigned long sender;
|
||||
|
||||
void
|
||||
my_response_handler(response_t *response, void *user_data)
|
||||
{
|
||||
attr_container_t *payload;
|
||||
printf("### user resource 1 handler called\n");
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_string(&payload, "key1", "value1");
|
||||
attr_container_set_string(&payload, "key2", "value2");
|
||||
|
||||
response->mid = mid;
|
||||
response->reciever = sender;
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
|
||||
static void
|
||||
test_send_request(const char *url, const char *tag)
|
||||
{
|
||||
request_t request[1];
|
||||
|
||||
init_request(request, (char *)url, COAP_PUT, 0, NULL, 0);
|
||||
api_send_request(request, my_response_handler, (void *)tag);
|
||||
}
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
mid = request->mid;
|
||||
sender = request->sender;
|
||||
test_send_request("url1", "a general request");
|
||||
}
|
||||
|
||||
void
|
||||
res2_handler(request_t *request)
|
||||
{
|
||||
mid = request->mid;
|
||||
sender = request->sender;
|
||||
test_send_request("/app/App1/url1", "a general request");
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/res1", res1_handler);
|
||||
api_register_resource_handler("/res2", res2_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
response_t response[1];
|
||||
attr_container_t *payload;
|
||||
|
||||
printf("[resp] ### user resource 1 handler called\n");
|
||||
|
||||
printf("[resp] ###### dump request ######\n");
|
||||
printf("[resp] sender: %lu\n", request->sender);
|
||||
printf("[resp] url: %s\n", request->url);
|
||||
printf("[resp] action: %d\n", request->action);
|
||||
printf("[resp] payload:\n");
|
||||
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
|
||||
attr_container_dump((attr_container_t *)request->payload);
|
||||
printf("[resp] #### dump request end ###\n");
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_string(&payload, "key1", "value1");
|
||||
attr_container_set_string(&payload, "key2", "value2");
|
||||
|
||||
make_response_for_request(request, response);
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("[resp] response payload len %d\n",
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("[resp] reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/url1", res1_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
|
||||
int num = 0;
|
||||
|
||||
void
|
||||
publish_overheat_event()
|
||||
{
|
||||
attr_container_t *event;
|
||||
|
||||
event = attr_container_create("event");
|
||||
attr_container_set_string(&event, "warning", "temperature is over high");
|
||||
|
||||
printf("###app publish event begin ###\n");
|
||||
|
||||
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
|
||||
attr_container_get_serialize_length(event));
|
||||
|
||||
printf("###app publish event end ###\n");
|
||||
|
||||
attr_container_destroy(event);
|
||||
}
|
||||
|
||||
/* Timer callback */
|
||||
void
|
||||
timer1_update(user_timer_t timer)
|
||||
{
|
||||
printf("Timer update %d\n", num++);
|
||||
publish_overheat_event();
|
||||
}
|
||||
|
||||
void
|
||||
start_timer()
|
||||
{
|
||||
user_timer_t timer;
|
||||
|
||||
/* set up a timer */
|
||||
timer = api_timer_create(1000, true, false, timer1_update);
|
||||
api_timer_restart(timer, 1000);
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
start_timer();
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
|
||||
uint32 mid;
|
||||
unsigned long sender;
|
||||
|
||||
void
|
||||
over_heat_event_handler(request_t *request)
|
||||
{
|
||||
response_t response[1];
|
||||
attr_container_t *payload;
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_string(&payload, "key1", "value1");
|
||||
attr_container_set_string(&payload, "key2", "value2");
|
||||
|
||||
response->mid = mid;
|
||||
response->reciever = sender;
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
mid = request->mid;
|
||||
sender = request->sender;
|
||||
api_subscribe_event("alert/overheat", over_heat_event_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/res1", res1_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
|
||||
/* User global variable */
|
||||
int num = 0;
|
||||
|
||||
/* Timer callback */
|
||||
void
|
||||
timer1_update(user_timer_t timer)
|
||||
{
|
||||
if (num < 2)
|
||||
num++;
|
||||
}
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
user_timer_t timer;
|
||||
|
||||
/* set up a timer */
|
||||
timer = api_timer_create(1000, true, false, timer1_update);
|
||||
api_timer_restart(timer, 1000);
|
||||
|
||||
response_t response[1];
|
||||
|
||||
make_response_for_request(request, response);
|
||||
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, NULL, 0);
|
||||
|
||||
api_response_send(response);
|
||||
}
|
||||
|
||||
void
|
||||
res2_handler(request_t *request)
|
||||
{
|
||||
response_t response[1];
|
||||
attr_container_t *payload;
|
||||
|
||||
if (num == 2) {
|
||||
attr_container_t *payload;
|
||||
printf("### user resource 1 handler called\n");
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_int(&payload, "num", num);
|
||||
|
||||
make_response_for_request(request, response);
|
||||
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/res1", res1_handler);
|
||||
api_register_resource_handler("/check_timer", res2_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
#include "wa-inc/sensor.h"
|
||||
|
||||
uint32 mid;
|
||||
unsigned long sender;
|
||||
|
||||
/* Sensor event callback*/
|
||||
void
|
||||
sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data)
|
||||
{
|
||||
printf("### app get sensor event\n");
|
||||
|
||||
response_t response[1];
|
||||
attr_container_t *payload;
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_string(&payload, "key1", "value1");
|
||||
attr_container_set_string(&payload, "key2", "value2");
|
||||
|
||||
response->mid = mid;
|
||||
response->reciever = sender;
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
mid = request->mid;
|
||||
sender = request->sender;
|
||||
|
||||
sensor_t sensor;
|
||||
char *user_data;
|
||||
attr_container_t *config;
|
||||
|
||||
printf("### app on_init 1\n");
|
||||
/* open a sensor */
|
||||
user_data = malloc(100);
|
||||
printf("### app on_init 2\n");
|
||||
sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
|
||||
printf("### app on_init 3\n");
|
||||
|
||||
/* config the sensor */
|
||||
sensor_config(sensor, 2000, 0, 0);
|
||||
printf("### app on_init 4\n");
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/res1", res1_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
/* real destroy work including killing timer and closing sensor is
|
||||
* accomplished in wasm app library version of on_destroy() */
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_app.h"
|
||||
#include "wa-inc/request.h"
|
||||
#include "wa-inc/sensor.h"
|
||||
|
||||
uint32 mid;
|
||||
unsigned long sender;
|
||||
sensor_t sensor;
|
||||
|
||||
/* Sensor event callback*/
|
||||
void
|
||||
sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data)
|
||||
{
|
||||
printf("### app get sensor event\n");
|
||||
|
||||
response_t response[1];
|
||||
attr_container_t *payload;
|
||||
|
||||
payload = attr_container_create("wasm app response payload");
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
attr_container_set_string(&payload, "key1", "value1");
|
||||
|
||||
response->mid = mid;
|
||||
response->reciever = sender;
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload,
|
||||
attr_container_get_serialize_length(payload));
|
||||
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
|
||||
api_response_send(response);
|
||||
|
||||
attr_container_destroy(payload);
|
||||
}
|
||||
|
||||
void
|
||||
res1_handler(request_t *request)
|
||||
{
|
||||
mid = request->mid;
|
||||
sender = request->sender;
|
||||
|
||||
char *user_data;
|
||||
attr_container_t *config;
|
||||
|
||||
printf("### app on_init 1\n");
|
||||
/* open a sensor */
|
||||
user_data = malloc(100);
|
||||
printf("### app on_init 2\n");
|
||||
sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
|
||||
printf("### app on_init 3\n");
|
||||
}
|
||||
|
||||
void
|
||||
on_init()
|
||||
{
|
||||
/* register resource uri */
|
||||
api_register_resource_handler("/res1", res1_handler);
|
||||
}
|
||||
|
||||
void
|
||||
on_destroy()
|
||||
{
|
||||
if (NULL != sensor) {
|
||||
sensor_close(sensor);
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
. ../../../set_dev_env.sh
|
||||
|
||||
CC=/opt/wasi-sdk/bin/clang
|
||||
APP_DIR=$PWD
|
||||
WAMR_DIR=${APP_DIR}/../../../../../
|
||||
SDK_DIR=${WAMR_DIR}/wamr-sdk/out/simple-host-interp
|
||||
APP_FRAMEWORK_DIR=${SDK_DIR}/app-sdk/wamr-app-framework
|
||||
DEPS_DIR=${WAMR_DIR}/core/deps
|
||||
|
||||
for i in `ls *.c`
|
||||
do
|
||||
APP_SRC="$i"
|
||||
OUT_FILE=${i%.*}.wasm
|
||||
/opt/wasi-sdk/bin/clang -O3 \
|
||||
-Wno-int-conversion \
|
||||
-I${APP_FRAMEWORK_DIR}/include \
|
||||
-I${DEPS_DIR} \
|
||||
-O3 -z stack-size=4096 -Wl,--initial-memory=65536 \
|
||||
--sysroot=${SDK_DIR}/app-sdk/libc-builtin-sysroot \
|
||||
-L${APP_FRAMEWORK_DIR}/lib -lapp_framework \
|
||||
-Wl,--allow-undefined-file=${SDK_DIR}/app-sdk/libc-builtin-sysroot/share/defined-symbols.txt \
|
||||
-Wl,--strip-all,--no-entry -nostdlib \
|
||||
-Wl,--export=on_init -Wl,--export=on_destroy \
|
||||
-Wl,--export=on_request -Wl,--export=on_response \
|
||||
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
|
||||
-Wl,--export=on_connection_data \
|
||||
-o ${OUT_FILE} \
|
||||
${APP_SRC}
|
||||
if [ -f ${OUT_FILE} ]; then
|
||||
echo "build ${OUT_FILE} success"
|
||||
else
|
||||
echo "build ${OUT_FILE} fail"
|
||||
fi
|
||||
done
|
||||
@ -1,10 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
#
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
./simple -s > /dev/null 2>&1 &
|
||||