Skip to content

Commit 8ddee20

Browse files
authored
Merge pull request #129 from TOPLLab/develop
Version 0.2.2
2 parents 5156d70 + 39d0385 commit 8ddee20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5496
-1279
lines changed

.github/workflows/compile.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ concurrency:
55
group: ${{ github.workflow }}-${{ github.ref }}
66
cancel-in-progress: true # Cancel in-flight jobs for the same branch or PR
77

8-
env:
9-
BENCHMARKS_CACHE: "build-benchmarks"
10-
118
jobs:
129
formatting-check:
1310
name: Formatting Check
@@ -29,7 +26,7 @@ jobs:
2926
strategy:
3027
fail-fast: false
3128
matrix:
32-
os: [ubuntu-18.04, ubuntu-20.04, macos-latest]
29+
os: [ubuntu-20.04, ubuntu-22.04, macos-latest]
3330
steps:
3431
- name: Checkout
3532
uses: actions/checkout@v2
@@ -45,7 +42,7 @@ jobs:
4542

4643
compile-with-arduino:
4744
name: (Arduino) Compile on ${{matrix.board.platform-name}}
48-
needs: formatting-check
45+
needs: [formatting-check]
4946
runs-on: ubuntu-latest
5047
env:
5148
SKETCHES_REPORTS_PATH: sketches-reports
@@ -56,6 +53,7 @@ jobs:
5653
- name: HTTPClient
5754
- name: PubSubClient
5855
- name: Adafruit NeoPixel
56+
- source-url: https://github.com/me-no-dev/AsyncTCP.git
5957
strategy:
6058
fail-fast: false
6159
matrix:
@@ -72,7 +70,11 @@ jobs:
7270
sketches: |
7371
- platforms/Arduino
7472
steps:
75-
- uses: actions/checkout@v2
73+
- name: Checkout
74+
uses: actions/checkout@v2
75+
with:
76+
submodules: 'recursive'
77+
7678
- name: Compile sketches
7779
uses: arduino/compile-sketches@v1
7880
with:
@@ -84,6 +86,7 @@ jobs:
8486
${{ env.LIBRARIES }}
8587
enable-deltas-report: true
8688
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
89+
8790
- name: Upload sketches report to workflow artifact
8891
uses: actions/upload-artifact@v2
8992
with:
@@ -107,9 +110,10 @@ jobs:
107110
submodules: 'recursive'
108111

109112
- name: Build WARDuino for ESP-IDF
110-
uses: espressif/esp-idf-ci-action@main
113+
uses: espressif/esp-idf-ci-action@v1
111114
with:
112115
esp_idf_version: latest
113116
target: esp32
117+
command: idf.py build -DBUILD_ESP=ON
114118
path: .
115119

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea/
22
.vscode/
3+
.ccls
34

45
*.bin
56
*.ipch
@@ -28,3 +29,7 @@ _deps
2829
.AppleDouble
2930
.LSOverride
3031

32+
*.old
33+
34+
core
35+
venv

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "tests/sexpr-parser"]
22
path = tests/integration/sexpr-parser
33
url = [email protected]:benthepoet/c-sexpr-parser.git
4+
[submodule "lib/json"]
5+
path = lib/json
6+
url = https://github.com/nlohmann/json

CMakeLists.txt

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
cmake_minimum_required(VERSION 3.15)
44
option(BUILD_ESP "Build for esp" OFF)
55
option(BUILD_EMULATOR "Build for emulator" OFF)
6+
option(BUILD_UNITTEST "Build for testing" OFF)
67

7-
if (NOT BUILD_ESP AND NOT BUILD_EMULATOR)
8+
9+
if (NOT BUILD_ESP AND NOT BUILD_EMULATOR AND NOT BUILD_UNITTEST)
810
message(WARNING "No build target set. Nothing to do.")
911
endif ()
1012

@@ -13,7 +15,7 @@ if (BUILD_ESP)
1315
if (NOT EXISTS $ENV{IDF_PATH}/tools/cmake/project.cmake)
1416
message(FATAL_ERROR "Can't find $IDF_PATH/tools/cmake/project.cmake. Make sure ESP-IDF is installed and $IDF_PATH is set.")
1517
endif ()
16-
18+
1719
message(VERBOSE "Using ESP-IDF toolchain")
1820

1921
set(EXTRA_COMPONENT_DIRS "platforms/ESP-IDF")
@@ -25,23 +27,29 @@ project(WARDuino)
2527

2628
# Build the emulator version of WARDuino
2729
if (BUILD_EMULATOR)
30+
set(EXTERNAL_LIB_HEADERS lib/json/single_include)
31+
2832
find_package(Threads REQUIRED)
33+
2934
set(SOURCE_FILES
35+
src/WARDuino/WARDuino.cpp
36+
src/WARDuino/CallbackHandler.cpp
37+
src/Primitives/emulated.cpp
38+
src/Interpreter/instructions.cpp
3039
src/Memory/mem.cpp
3140
src/Utils/util.cpp
3241
src/Utils/util_arduino.cpp
33-
src/Debug/debugger.cpp
3442
src/Utils/macros.cpp
35-
src/WARDuino/WARDuino.cpp
36-
src/WARDuino/CallbackHandler.cpp
37-
src/Primitives/primitives.cpp
38-
src/Interpreter/instructions.cpp
39-
)
43+
src/Utils/sockets.cpp
44+
src/Debug/debugger.cpp
45+
src/Edward/proxy.cpp
46+
src/Edward/proxy_supervisor.cpp
47+
src/Edward/RFC.cpp)
48+
4049
set(TEST_FRAMEWORK
41-
tests/integration/wasm_tests.cpp
42-
tests/integration/assertion.cpp
43-
tests/integration/sexpr-parser/src/sexpr.c
44-
)
50+
tests/integration/wasm_tests.cpp
51+
tests/integration/assertion.cpp
52+
tests/integration/sexpr-parser/src/sexpr.c)
4553

4654
add_definitions(-DINFO=0)
4755
add_definitions(-DDEBUG=0)
@@ -52,11 +60,71 @@ if (BUILD_EMULATOR)
5260
set(CMAKE_CXX_STANDARD 11)
5361

5462
# Set default compile flags for GCC
55-
if(CMAKE_COMPILER_IS_GNUCXX)
63+
if (CMAKE_COMPILER_IS_GNUCXX)
5664
add_compile_options(-g -v -Wall -Wextra -Wunused)
57-
endif(CMAKE_COMPILER_IS_GNUCXX)
65+
endif (CMAKE_COMPILER_IS_GNUCXX)
5866

5967
# WARDuino CLI
6068
add_executable(wdcli platforms/CLI-Emulator/main.cpp ${SOURCE_FILES} ${TEST_FRAMEWORK})
6169
target_link_libraries(wdcli PRIVATE Threads::Threads)
70+
target_include_directories(wdcli PRIVATE ${EXTERNAL_LIB_HEADERS})
6271
endif (BUILD_EMULATOR)
72+
73+
if(BUILD_UNITTEST)
74+
enable_testing()
75+
76+
message(VERBOSE "Building for unit tests ")
77+
78+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for tooling support
79+
set(EXTERNAL_LIB_HEADERS lib/json/single_include)
80+
81+
set(SOURCE_FILES
82+
src/WARDuino/WARDuino.cpp
83+
src/WARDuino/CallbackHandler.cpp
84+
src/Primitives/emulated.cpp
85+
src/Interpreter/instructions.cpp
86+
src/Memory/mem.cpp
87+
src/Utils/util.cpp
88+
src/Utils/util_arduino.cpp
89+
src/Utils/macros.cpp
90+
src/Utils/sockets.cpp
91+
src/Debug/debugger.cpp
92+
src/Edward/proxy.cpp
93+
src/Edward/proxy_supervisor.cpp
94+
src/Edward/RFC.cpp)
95+
96+
# Use C++11
97+
set(CMAKE_CXX_STANDARD 11)
98+
99+
# Set default compile flags for GCC
100+
if (CMAKE_COMPILER_IS_GNUCXX)
101+
add_compile_options(-g -v -Wall -Wextra -Wunused)
102+
endif (CMAKE_COMPILER_IS_GNUCXX)
103+
104+
105+
include(FetchContent)
106+
FetchContent_Declare(
107+
googletest
108+
GIT_REPOSITORY https://github.com/google/googletest.git
109+
GIT_TAG release-1.12.1
110+
)
111+
112+
# For Windows: Prevent overriding the parent project's compiler/linker settings
113+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
114+
FetchContent_MakeAvailable(googletest)
115+
116+
set(PATH_TO_UNIT_TEST ${PROJECT_SOURCE_DIR}/tests/vm_unit_tests)
117+
118+
file(GLOB TEST_SRC_FILES ${PATH_TO_UNIT_TEST}/*.cpp)
119+
120+
message(DEBUG "Unit test source codes: " ${TEST_SRC_FILES})
121+
122+
foreach(TEST_FILE ${TEST_SRC_FILES})
123+
get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE)
124+
message(DEBUG "Add executable for " ${TEST_FILE})
125+
add_executable(${TEST_NAME} ${TEST_FILE} ${SOURCE_FILES})
126+
target_link_libraries(${TEST_NAME} gtest_main)
127+
target_include_directories(${TEST_NAME} PRIVATE ${EXTERNAL_LIB_HEADERS})
128+
add_test(${TEST_NAME} ${TEST_NAME})
129+
endforeach()
130+
endif(BUILD_UNITTEST)

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<a href="https://github.com/TOPLLab/WARDuino/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MPL_2.0-blue.svg"></a>
77
</p>
88

9-
This project is released under the Mozilla Public License 2.0, and is being developed as part of an active research project at the University of Ghent's [TOPL](https://github.com/TOPLLab) lab.
9+
This project is released under the Mozilla Public License 2.0, and is being developed as part of an active research project at the University of Ghent's [TOPL Lab](https://github.com/TOPLLab).
1010

1111
The WARDuino virtual machine is a WebAssembly runtime for microcontrollers, which runs both under the Arduino and ESP-IDF toolchains.
12-
The WARDuino project also includes a [VS Code extension](https://github.com/TOPLLab/WARDuino-VSCode) to use the remote debugging facilities offered by the virtual machine.
12+
The WARDuino project also includes a [VS Code extension](https://github.com/TOPLLab/WARDuino-VSCode) to use both the remote debugging and the out-of-place debugging facilities offered by the virtual machine.
1313

1414
<p align="center">
1515
<a href="./README.md#build-and-development-instructions">Installation</a> | <a href="./examples/">Examples</a> | <a href="./README.md#webassembly-specification-tests">Run Specification tests</a> | <a href="./documentation/">Documentation</a>
@@ -22,7 +22,7 @@ Supported platforms: Linux (Ubuntu), macOS, ESP-IDF, Arduino
2222
The project uses CMake. Quick install looks like this:
2323

2424
```bash
25-
git clone [email protected]:TOPLLab/WARDuino.git
25+
git clone --recursive [email protected]:TOPLLab/WARDuino.git
2626
cd WARDuino
2727
mkdir build-emu
2828
cd build-emu
@@ -36,6 +36,8 @@ The WARDuino VM can be compiled with both the Arduino and ESP-IDF toolchains, an
3636

3737
### Build for ESP-IDF
3838

39+
> warning: primitive support for IDF is under construction
40+
3941
Before you can compile and flash with ESP-IDF, you must install and enable [the toolchain](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-macos-setup.html).
4042
You also need to disable the watchdog timer:
4143

@@ -62,22 +64,35 @@ Or simply run `idf.py flash`.
6264
### Build for Arduino
6365

6466
First, install the [arduino-cli](https://arduino.github.io/arduino-cli/0.21/installation/).
67+
You will also need python3 with the pyserial pacakge.
6568

6669
Second, create the config file:
6770

6871
```bash
6972
arduino-cli config init
7073
```
7174

72-
If you need additional boards, such as the esp32 boards, you can add them in the generated config file. More information [here](https://arduino.github.io/arduino-cli/0.21/getting-started/).
75+
If you need additional boards, such as the esp32 boards, you can add them in the generated config file. More information on how to install the esp32 boards can be found <a href="./documentation/InstallArduinoESP32.md">here</a>.
76+
(_note: WARDuino requires at least version 2.0.2 of the esp32 board manager when using esp32 devices)_
7377

7478
Thirdly, make sure you install the `PubSubClient` and `Adafruit NeoPixel` library. (used for MQTT and pixel primitives)
7579

7680
```bash
77-
arduino-cli lib install "PubSubClient"
78-
arduino-cli lib install "Adafruit NeoPixel"
81+
arduino-cli lib install "PubSubClient" # for MQTT
82+
arduino-cli lib install "Adafruit NeoPixel" # for some primitives
7983
```
8084

85+
To build for Arduino with WIFI support you need to also install the following third-party libraries.
86+
(Wou might need to set `enable_unsafe_install` to `true` in your arduino config ) <!-- Todo remove one day ---!>
87+
88+
```bash
89+
arduino-cli lib install FreeRTOS
90+
arduino-cli lib install --git-url https://github.com/me-no-dev/AsyncTCP.git
91+
```
92+
93+
If you haven't done so already, clone (or symlink) this repository to `~/Arduino/libraries` to make WARDuino availible to Arduino.
94+
95+
8196
After this initial installation steps you can start using WARDuino with the Arduino toolchain.
8297
You can upload the example file as follows, starting from the project root:
8398

benchmarks/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ bin/
33

44
output
55
*.csv
6+
7+
*.json
8+
*.data

benchmarks/all_bench.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ to_csv() {
1818
sed -i -n '0~2{N;s/\n/,/p}' $1
1919
}
2020

21-
sleep 5
22-
./espruino_bench.sh $tmpdir/espruino
23-
to_csv $tmpdir/espruino
21+
#sleep 5
22+
#./espruino_bench.sh $tmpdir/espruino
23+
#to_csv $tmpdir/espruino
2424

2525
sleep 5
2626
./warduino_bench.sh $tmpdir/warduino
2727
to_csv $tmpdir/warduino
2828

29+
sleep 5
30+
./edward_bench.sh $tmpdir/edward
31+
to_csv $tmpdir/edward
32+
2933
sleep 5
3034
./wasm3_bench.sh $tmpdir/wasm3
3135
to_csv $tmpdir/wasm3
@@ -38,6 +42,8 @@ echo "# Espruino"
3842
cat $tmpdir/espruino
3943
echo "# Warduino"
4044
cat $tmpdir/warduino
45+
echo "# Edward"
46+
cat $tmpdir/edward
4147
echo "# Wasm3"
4248
cat $tmpdir/wasm3
4349
echo "# Native"

benchmarks/benchmarks.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#include <iostream>
44

5-
#include "../debug.h"
5+
#include "../src/Debug/debugger.h"
6+
#include "../src/Utils/macros.h"
67
#include "../src/WARDuino.h"
78
#include "timer.h"
89

@@ -48,7 +49,7 @@ int run_benchmarks(size_t num_benchmarks, string benchmarks[],
4849
char path[MAX_PATH];
4950
unsigned char bytes[MAX_BYTE_CODE_SIZE];
5051
unsigned int bytes_length;
51-
auto *w = new WARDuino();
52+
auto *w = WARDuino::instance();
5253
size_t correct = 0;
5354
for (size_t i = 0; i < num_benchmarks; i++) {
5455
string name = benchmarks[i];

0 commit comments

Comments
 (0)