diff --git a/tests/pkg_elk/Makefile b/tests/pkg_elk/Makefile new file mode 100644 index 0000000000..75d4b4c2b2 --- /dev/null +++ b/tests/pkg_elk/Makefile @@ -0,0 +1,5 @@ +include ../Makefile.tests_common + +USEPKG += elk + +include $(RIOTBASE)/Makefile.include diff --git a/tests/pkg_elk/Makefile.ci b/tests/pkg_elk/Makefile.ci new file mode 100644 index 0000000000..5e86ab29d5 --- /dev/null +++ b/tests/pkg_elk/Makefile.ci @@ -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 \ + # diff --git a/tests/pkg_elk/README.md b/tests/pkg_elk/README.md new file mode 100644 index 0000000000..1b443fc436 --- /dev/null +++ b/tests/pkg_elk/README.md @@ -0,0 +1,4 @@ +pkg_elk +======= + +This test application shows a basic usage of the Elk tiny javascript engine. diff --git a/tests/pkg_elk/app.config.test b/tests/pkg_elk/app.config.test new file mode 100644 index 0000000000..f80311febc --- /dev/null +++ b/tests/pkg_elk/app.config.test @@ -0,0 +1 @@ +CONFIG_PACKAGE_ELK=y diff --git a/tests/pkg_elk/main.c b/tests/pkg_elk/main.c new file mode 100644 index 0000000000..b0a6896f1a --- /dev/null +++ b/tests/pkg_elk/main.c @@ -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 . + * + * 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 +#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; +} diff --git a/tests/pkg_elk/tests/01-run.py b/tests/pkg_elk/tests/01-run.py new file mode 100755 index 0000000000..d517a66b61 --- /dev/null +++ b/tests/pkg_elk/tests/01-run.py @@ -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))