1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests: add test application for Elk package

This commit is contained in:
Alexandre Abadie 2021-09-27 13:21:25 +02:00
parent 4989258ae1
commit ce28a54ed9
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
6 changed files with 96 additions and 0 deletions

5
tests/pkg_elk/Makefile Normal file
View File

@ -0,0 +1,5 @@
include ../Makefile.tests_common
USEPKG += elk
include $(RIOTBASE)/Makefile.include

20
tests/pkg_elk/Makefile.ci Normal file
View File

@ -0,0 +1,20 @@
BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-leonardo \
arduino-nano \
arduino-uno \
atmega328p \
atmega328p-xplained-mini \
msb-430 \
msb-430h \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-l011k4 \
nucleo-l031k6 \
samd10-xmini \
stk3200 \
stm32f030f4-demo \
stm32g0316-disco \
telosb \
z1 \
#

4
tests/pkg_elk/README.md Normal file
View File

@ -0,0 +1,4 @@
pkg_elk
=======
This test application shows a basic usage of the Elk tiny javascript engine.

View File

@ -0,0 +1 @@
CONFIG_PACKAGE_ELK=y

48
tests/pkg_elk/main.c Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2013-2021 Cesanta Software Limited
* All rights reserved
*
* This software is dual-licensed: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. For the terms of this
* license, see <http://www.gnu.org/licenses/>.
*
* You are free to use this software under the terms of the GNU General
* Public License, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* Alternatively, you can license this software under a commercial
* license, please contact us at https://cesanta.com/contact.html
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Test application for the Elk Javascript engine
*
* Taken from README at https://github.com/cesanta/elk
* @}
*/
#include <stdio.h>
#include "elk.h"
static char mem[256];
/* C function that adds two numbers. Will be called from JS */
int sum(int a, int b)
{
return a + b;
}
int main(void)
{
struct js *js = js_create(mem, sizeof(mem)); /* Create JS instance */
jsval_t v = js_import(js, (uintptr_t)sum, "iii"); /* Import C function "sum" */
js_set(js, js_glob(js), "f", v); /* Under the name "f" */
jsval_t result = js_eval(js, "f(3, 4);", ~0); /* Call "f" */
printf("result: %s\n", js_str(js, result)); /* result: 7 */
return 0;
}

18
tests/pkg_elk/tests/01-run.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# Copyright (C) 2021 Inria
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect_exact("result: 7")
if __name__ == "__main__":
sys.exit(run(testfunc))