diff --git a/.gitignore b/.gitignore index 7fa3c5c7..91602800 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,6 @@ _build_endpoint/ endpoint.*.update .repo legato/ +leaf-data +leaf-workspace.json +*.tgz diff --git a/Makefile b/Makefile index 48b31d93..d6e48a04 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,12 @@ LEGATO_FLAGS += -DEP_TARGET=$(EP_TARGET) LEGATO_FLAGS := $(foreach flags, $(LEGATO_FLAGS), -C $(flags)) # Include the build command from the specific target -include endpoint/platform/$(EP_TARGET)/build.mk +ifeq ($(EP_TARGET), simulator) + include endpoint/platform/simulator/build.mk +else + include endpoint/platform/default/build.mk +endif + export EP_TARGET all: $(DEPS) cert diff --git a/docs/endpoint-hal.md b/docs/endpoint-hal.md deleted file mode 100644 index e1067a49..00000000 --- a/docs/endpoint-hal.md +++ /dev/null @@ -1,91 +0,0 @@ -# Hardware Abstract Layer(HAL) for Endpoint - -Hardware Abstract Layer(HAL) defines a standard interface for hardware vendors to implement new device, which enables Tangle-accelerator to be aware of lower-level driver implementations. HAL provides operators such as UART, GPIO, secure storage and other low-level operators. The endpoint is a daemon, offering monitor for the device and being able to send message to Tangle-Accelerator. HAL layer lets the user only need to implement their device operators from abstract interface which is defined inside `device.h` but not need to know how endpoint works. - -## How to implement new device - -Create a directory for the new device under `platform`. -```bash -$ mkdir -p platform/mydevice -``` -* Create `impl.c` and `build.mk` under the new device directory. -* Include `device.h` into the new device header or the new device source file. - -For `build.mk` you should define the `platform-build-command`. Here are the example from the WP7702 module: - -```makefile -platform-build-command = \ - cd endpoint && leaf shell -c "mkapp -v -t wp77xx $(LEGATO_FLAGS) endpoint.adef" -``` - -Here are some operations needed to be implemented for new device: - -* device_operations -* init : initialize device -* fini : finalize device -* get_key : get device key -* get_device_id : get device id(IMEI or other identifier) -* uart_operations -* init : initialize uart -* write : write command to uart device -* read : read from uart device -* clean : flush buffer -* secure_store_operations -* init : initialize secure storage -* write : write item to secure storage -* read : read item from secure storage -* delete : delete item inside secure storage - -Here are the functions needed to be registered/unregistered inside `impl.c`: - -* register_device : register device on startup -* unregister_device : unregistered device -* DECLARE_DEVICE : this must be declared inside `impl.c` - -impl.c - -```c -#include "endpoint/hal/device.h" - -static status_t simulator_init(void) { - status_t err = register_device(&simulator_device_type); - if (err != SC_OK) LE_ERROR("register simulator device error:%d", err); - return err; -} - -static void simulator_release(void) { - status_t ret = unregister_device(&simulator_device_type); - LE_INFO("unregister simulator return: %d", ret); -} - -static const struct device_operations simulator_ops = { - .init = simulator_init, - .fini = simulator_release, - .get_key = simulator_get_key, - .get_device_id = simulator_get_device_id, -}; - -static const struct uart_operations simulator_uart = { - .init = uart_init, - .write = uart_write, - .read = uart_read, - .clean = uart_clean, -}; - -static const struct secure_store_operations simulator_sec_ops = { - .init = sec_init, - .write = sec_write, - .read = sec_read, - .delete = sec_delete, -}; - -struct device_type simulator_device_type = { - .name = "simulator", - .op = &simulator_ops, - .uart = &simulator_uart, - .sec_ops = &simulator_sec_ops, -}; - -// must be declared at the end of impl.c -DECLARE_DEVICE(simulator); -``` diff --git a/endpoint/endpoint.adef b/endpoint/endpoint.adef index 819e680e..9337a4ae 100644 --- a/endpoint/endpoint.adef +++ b/endpoint/endpoint.adef @@ -11,12 +11,42 @@ processes: } } +requires: +{ + file: + { + // needed for curl itself: + /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ + /usr/bin/curl /usr/bin/curl + + // needed for networking: + /lib/libnss_compat.so.2 /lib/ + /lib/libnss_files.so.2 /lib/ + /lib/libnss_dns.so.2 /lib/ + /lib/libresolv.so.2 /lib/ + /etc/nsswitch.conf /etc/ + /etc/hosts /etc/ + /etc/resolv.conf /etc/ + + /bin/sh /bin/sh + /bin/date /bin/date + } + device: + { + [rw] /dev/null /dev/null + [r] /dev/urandom /dev/urandom + [r] /dev/random /dev/random + } +} + #if ${LEGATO_TARGET} = localhost #else bindings: { endpoint.endpointComp.le_secStore -> secStore.le_secStore endpoint.endpointComp.le_sim -> modemService.le_sim + endpoint.endpointComp.le_mdc -> modemService.le_mdc + endpoint.endpointComp.le_data -> dataConnectionService.le_data } #endif diff --git a/endpoint/endpointComp/Component.cdef b/endpoint/endpointComp/Component.cdef index 95cb2b97..5879751f 100644 --- a/endpoint/endpointComp/Component.cdef +++ b/endpoint/endpointComp/Component.cdef @@ -1,10 +1,13 @@ sources: { ${CURDIR}/../endpoint_core.c - ${CURDIR}/../hal/device.c // include the specific platform - ${CURDIR}/../platform/${EP_TARGET}/impl.c +#if ${LEGATO_TARGET} = localhost + ${CURDIR}/../platform/simulator/impl.c +#else + ${CURDIR}/../platform/default/impl.c +#endif ${CURDIR}/../../output_base/external/org_iota_common/utils/logger_helper.c @@ -102,6 +105,8 @@ requires: { le_secStore.api modemServices/le_sim.api + modemServices/le_mdc.api + le_data.api [manual-start] } } #endif diff --git a/endpoint/endpointComp/endpoint.c b/endpoint/endpointComp/endpoint.c index 3e90ce3f..973de94c 100644 --- a/endpoint/endpointComp/endpoint.c +++ b/endpoint/endpointComp/endpoint.c @@ -7,11 +7,12 @@ */ #include "endpoint.h" -#include "hal/device.h" #include "common/ta_errors.h" #include "endpoint/cipher.h" #include "endpoint/endpoint_core.h" +#include "endpoint/platform/impl.h" + #include "le_test.h" #include "legato.h" @@ -125,26 +126,27 @@ COMPONENT_INIT { memcpy(iv, test_iv, AES_IV_SIZE); srand(time(NULL)); - device_t* device = ta_device(STRINGIZE(EP_TARGET)); - if (device == NULL) { - LE_ERROR("Can not get specific device"); - } else { - device->op->get_key(private_key); - device->op->get_device_id(device_id); + get_device_key(private_key); + get_device_id(device_id); + #ifdef ENABLE_ENDPOINT_TEST - LE_TEST_INIT; - LE_TEST_INFO("=== ENDPOINT TEST BEGIN ==="); - LE_TEST(SC_OK == send_transaction_information(host, port, ssl_seed, value, message, message_fmt, tag, address, - next_address, private_key, device_id_ptr, iv)); - LE_TEST_EXIT; + LE_TEST_INIT; + LE_INFO("=== ENDPOINT TEST BEGIN ==="); + status_t ret = send_transaction_information(host, port, ssl_seed, value, message, message_fmt, tag, address, + next_address, private_key, device_id_ptr, iv); + + if (ret == SC_OK) + printf("success\n"); + else + printf("failed\n"); + LE_TEST_EXIT; #else - while (true) { - // TODO: listen input from UART here - status_t ret = send_transaction_information(host, port, ssl_seed, value, message, message_fmt, tag, address, - next_address, private_key, device_id_ptr, iv); - LE_INFO("Send transaction information return: %d", ret); - sleep(10); - } -#endif + while (true) { + // TODO: listen input from UART here + status_t ret = send_transaction_information(host, port, ssl_seed, value, message, message_fmt, tag, address, + next_address, private_key, device_id_ptr, iv); + LE_INFO("Send transaction information return: %d", ret); + sleep(10); } +#endif } diff --git a/endpoint/hal/BUILD b/endpoint/hal/BUILD deleted file mode 100644 index 1c3b0a3f..00000000 --- a/endpoint/hal/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "hal", - srcs = ["device.c"], - hdrs = ["device.h"], - deps = [ - "//common:ta_errors", - ], -) diff --git a/endpoint/hal/device.c b/endpoint/hal/device.c deleted file mode 100644 index a64d9362..00000000 --- a/endpoint/hal/device.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors - * All Rights Reserved. - * This is free software; you can redistribute it and/or modify it under the - * terms of the MIT license. A copy of the license can be found in the file - * "LICENSE" at the root of this distribution. - */ - -#include "legato.h" - -#include "device.h" -#include "le_log.h" - -static struct device_type *devices; - -static struct device_type **find_device(const char *name, unsigned len) { - struct device_type **p; - for (p = &devices; *p; p = &(*p)->next) - if (strlen((*p)->name) == len && !strncmp((*p)->name, name, len)) break; - return p; -} - -device_t *ta_device(const char *type) { - struct device_type **p; - if (devices->next) { - LE_ERROR("No device type registered!"); - return NULL; - } - p = find_device(type, strlen(type)); - if (*p == NULL) { - LE_ERROR("Device type %s not found", type); - return NULL; - } - LE_DEBUG("Successfully get %s device", type); - return *p; -} - -status_t register_device(struct device_type *dv) { - status_t res = SC_OK; - struct device_type **p; - if (dv->next) { - return SC_ENDPOINT_DEVICE_INIT; - } - p = find_device(dv->name, strlen(dv->name)); - if (*p) { - res = SC_ENDPOINT_DEVICE_INIT; - } else { - *p = dv; - } - return res; -} - -status_t unregister_device(struct device_type *dv) { - for (struct device_type **tmp = &devices; *tmp != NULL; tmp = &(*tmp)->next) { - if (dv == *tmp) { - *tmp = dv->next; - dv->next = NULL; - return SC_OK; - } - } - return SC_ENDPOINT_DEVICE_FINI; -} diff --git a/endpoint/platform/BUILD b/endpoint/platform/BUILD deleted file mode 100644 index e145a251..00000000 --- a/endpoint/platform/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "device", - deps = [ - "//endpoint/hal", - "//endpoint/simluator", - ], -) diff --git a/endpoint/platform/wp77xx/build.mk b/endpoint/platform/default/build.mk similarity index 73% rename from endpoint/platform/wp77xx/build.mk rename to endpoint/platform/default/build.mk index f56add2e..d1ae3bed 100644 --- a/endpoint/platform/wp77xx/build.mk +++ b/endpoint/platform/default/build.mk @@ -5,4 +5,5 @@ # "LICENSE" at the root of this distribution. platform-build-command = \ - cd endpoint && leaf shell -c "mkapp -v -t wp77xx $(LEGATO_FLAGS) endpoint.adef" + cd endpoint && \ + mkapp -t $(EP_TARGET) $(LEGATO_FLAGS) -i ${LEGATO_ROOT}/interfaces/modemServices endpoint.adef diff --git a/endpoint/platform/wp77xx/impl.c b/endpoint/platform/default/impl.c similarity index 76% rename from endpoint/platform/wp77xx/impl.c rename to endpoint/platform/default/impl.c index 910f1976..6c0a3853 100644 --- a/endpoint/platform/wp77xx/impl.c +++ b/endpoint/platform/default/impl.c @@ -16,15 +16,12 @@ #include #include #include -#include "endpoint/hal/device.h" + +#include "endpoint/platform/impl.h" #include "legato.h" #include "interfaces.h" -#include "le_log.h" -#include "le_mdmDefs_interface.h" -#include "le_secStore_common.h" -#include "le_sim_common.h" #define MAXLINE 1024 @@ -33,21 +30,11 @@ #define READ_BUFFER_SIZE 32 #define DEFAULT_PORT "/dev/ttyHS0" -extern struct device_type wp77xx_device_type; - static le_sim_Id_t SimId; /* UART file descriptor */ static int uart_fd; -static status_t wp77xx_init(void) { - status_t err = register_device(&wp77xx_device_type); - LE_ERROR_IF(err != SC_OK, "register wp77xx device error: %d", err); - return err; -} - -static void wp77xx_release(void) { LE_INFO("Finalize the device success"); } - -static status_t wp77xx_get_key(uint8_t *key) { +status_t get_device_key(uint8_t *key) { // FIXME:Need to implement the private key generate algorithm if (key == NULL) { LE_ERROR("Failed to get key"); @@ -72,7 +59,7 @@ static status_t cm_sim_GetSimImsi(char *sim_id) { return ret; } -static status_t wp77xx_get_device_id(char *device_id) { +status_t get_device_id(char *device_id) { if (cm_sim_GetSimImsi(device_id) != SC_OK) { return SC_ENDPOINT_GET_DEVICE_ID_ERROR; } @@ -113,7 +100,7 @@ static status_t set_interface_attribs(int fd, int speed) { return SC_OK; } -static status_t uart_init(const char *device) { +status_t uart_init(const char *device) { if (device == NULL) device = DEFAULT_PORT; int fd; @@ -129,7 +116,7 @@ static status_t uart_init(const char *device) { return SC_OK; } -static void uart_write(const int fd, const char *cmd) { +void uart_write(const int fd, const char *cmd) { /* simple output */ ssize_t cmd_len = strlen(cmd); ssize_t wlen = write(fd, cmd, cmd_len); @@ -139,7 +126,7 @@ static void uart_write(const int fd, const char *cmd) { tcdrain(fd); /* delay for output */ } -static char *uart_read(const int fd) { +char *uart_read(const int fd) { unsigned char buf[READ_BUFFER_SIZE]; char *response = NULL; @@ -155,7 +142,7 @@ static char *uart_read(const int fd) { return response; } -static void uart_clean(const int fd) { +void uart_clean(const int fd) { if (tcflush(fd, TCIOFLUSH) != 0) { LE_ERROR("tcflush error"); } @@ -208,33 +195,3 @@ status_t sec_delete(const char *name) { return SC_ENDPOINT_SEC_FAULT; } } - -static const struct device_operations wp77xx_ops = { - .init = wp77xx_init, - .fini = wp77xx_release, - .get_key = wp77xx_get_key, - .get_device_id = wp77xx_get_device_id, -}; - -static const struct uart_operations wp77xx_uart = { - .init = uart_init, - .write = uart_write, - .read = uart_read, - .clean = uart_clean, -}; - -static const struct secure_store_operations wp77xx_sec_ops = { - .init = sec_init, - .write = sec_write, - .read = sec_read, - .delete = sec_delete, -}; - -struct device_type wp77xx_device_type = { - .name = "wp77xx", - .op = &wp77xx_ops, - .uart = &wp77xx_uart, - .sec_ops = &wp77xx_sec_ops, -}; - -DECLARE_DEVICE(wp77xx); diff --git a/endpoint/platform/impl.h b/endpoint/platform/impl.h new file mode 100644 index 00000000..8a1f4b4b --- /dev/null +++ b/endpoint/platform/impl.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ +#include +#include "common/ta_errors.h" + +status_t get_device_key(uint8_t *key); + +status_t get_device_id(char *id); + +status_t uart_init(const char *device); + +void uart_write(const int fd, const char *cmd); + +char *uart_read(const int fd); + +void uart_clean(const int fd); + +status_t sec_init(void); + +status_t sec_write(const char *name, const uint8_t *buf, size_t buf_size); + +status_t sec_read(const char *name, uint8_t *buf, size_t *buf_size); + +status_t sec_delete(const char *name); diff --git a/endpoint/platform/simulator/BUILD b/endpoint/platform/simulator/BUILD deleted file mode 100644 index 0424b4f1..00000000 --- a/endpoint/platform/simulator/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "simulator", - srcs = ["simulator.c"], - deps = [ - "//endpoint/hal", - ], -) diff --git a/endpoint/platform/simulator/build.mk b/endpoint/platform/simulator/build.mk index 89d76315..0619a359 100644 --- a/endpoint/platform/simulator/build.mk +++ b/endpoint/platform/simulator/build.mk @@ -10,4 +10,4 @@ export LEGATO_TARGET := localhost platform-build-command = \ sh -c "endpoint/build-legato.sh"; \ - cd endpoint && mkapp -v -t localhost -C -DENABLE_ENDPOINT_TEST $(LEGATO_FLAGS) endpoint.adef; + cd endpoint && mkapp -t $(LEGATO_TARGET) -C -DENABLE_ENDPOINT_TEST $(LEGATO_FLAGS) endpoint.adef; diff --git a/endpoint/platform/simulator/impl.c b/endpoint/platform/simulator/impl.c index bce7fb5e..5c575fa2 100644 --- a/endpoint/platform/simulator/impl.c +++ b/endpoint/platform/simulator/impl.c @@ -10,8 +10,10 @@ #include #include #include + +#include "endpoint/platform/impl.h" + #include "common/ta_errors.h" -#include "endpoint/hal/device.h" #include "legato.h" #include "le_hashmap.h" @@ -22,45 +24,36 @@ /* Setting data to produce predictable results for simulator */ // device id static const char *device_id = "470010171566423"; + // private key static const uint8_t private_key[32] = {82, 142, 184, 64, 74, 105, 126, 65, 154, 116, 14, 193, 208, 41, 8, 115, 158, 252, 228, 160, 79, 5, 167, 185, 13, 159, 135, 113, 49, 209, 58, 68}; // Buffer for uart static char UART_BUFFER[UART_BUFFER_SIZE]; + // Hashmap to simulate secure storage static le_hashmap_Ref_t simulator_sec_table; -extern struct device_type simulator_device_type; - -static status_t simulator_init(void) { - status_t err = register_device(&simulator_device_type); - if (err != SC_OK) LE_ERROR("register simulator device error:%d", err); - return err; -} - -static void simulator_release(void) { - status_t ret = unregister_device(&simulator_device_type); - LE_INFO("unregister simulator return: %d", ret); -} +void impl_stub_init(void) __attribute__((constructor)); -static status_t simulator_get_key(uint8_t *key) { +status_t get_device_key(uint8_t *key) { memcpy(key, private_key, 16); LE_INFO("Get device key success"); return SC_OK; } -static status_t simulator_get_device_id(char *id) { +status_t get_device_id(char *id) { memcpy(id, device_id, 16); LE_INFO("Get device id success"); return SC_OK; } -static status_t uart_init(const char *device) { +status_t uart_init(const char *device) { LE_INFO("UART init device %s success", device); return SC_OK; } -static void uart_write(const int fd, const char *cmd) { +void uart_write(const int fd, const char *cmd) { /* simple output */ size_t cmd_len = strlen(cmd); if (cmd_len > UART_BUFFER_SIZE) { @@ -70,21 +63,21 @@ static void uart_write(const int fd, const char *cmd) { snprintf(UART_BUFFER, cmd_len, "%s", cmd); } -static char *uart_read(const int fd) { +char *uart_read(const int fd) { char *response = UART_BUFFER; return response; } -static void uart_clean(const int fd) { LE_INFO("UART clean success"); } +void uart_clean(const int fd) { LE_INFO("UART clean success"); } -static status_t sec_init(void) { +status_t sec_init(void) { LE_INFO("Initialize secure storage"); simulator_sec_table = le_hashmap_Create("Simulator secure storage", 32, le_hashmap_HashString, le_hashmap_EqualsString); return SC_OK; } -static status_t sec_write(const char *name, const uint8_t *buf, size_t buf_size) { +status_t sec_write(const char *name, const uint8_t *buf, size_t buf_size) { uint8_t *data = malloc(buf_size); if (data == NULL) { LE_ERROR("Cannot fetch enough memory"); @@ -103,7 +96,7 @@ static status_t sec_write(const char *name, const uint8_t *buf, size_t buf_size) return SC_OK; } -static status_t sec_read(const char *name, uint8_t *buf, size_t *buf_size) { +status_t sec_read(const char *name, uint8_t *buf, size_t *buf_size) { LE_INFO("Read %s from secure storage", name); uint8_t *data = le_hashmap_Get(simulator_sec_table, name); @@ -116,7 +109,7 @@ static status_t sec_read(const char *name, uint8_t *buf, size_t *buf_size) { return SC_OK; } -static status_t sec_delete(const char *name) { +status_t sec_delete(const char *name) { LE_INFO("Delete %s in secure storage", name); uint8_t *data = le_hashmap_Remove(simulator_sec_table, name); @@ -128,32 +121,4 @@ static status_t sec_delete(const char *name) { return SC_OK; } -static const struct device_operations simulator_ops = { - .init = simulator_init, - .fini = simulator_release, - .get_key = simulator_get_key, - .get_device_id = simulator_get_device_id, -}; - -static const struct uart_operations simulator_uart = { - .init = uart_init, - .write = uart_write, - .read = uart_read, - .clean = uart_clean, -}; - -static const struct secure_store_operations simulator_sec_ops = { - .init = sec_init, - .write = sec_write, - .read = sec_read, - .delete = sec_delete, -}; - -struct device_type simulator_device_type = { - .name = "simulator", - .op = &simulator_ops, - .uart = &simulator_uart, - .sec_ops = &simulator_sec_ops, -}; - -DECLARE_DEVICE(simulator); +void test_stub_init(void) { status_t sec_init(void); } diff --git a/endpoint/platform/wp77xx/BUILD b/endpoint/platform/wp77xx/BUILD deleted file mode 100644 index 18c99767..00000000 --- a/endpoint/platform/wp77xx/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "wp77xx", - srcs = ["wp77xx.c"], - deps = [ - "//endpoint/hal", - ], -) diff --git a/tests/endpoint/common.sh b/tests/endpoint/common.sh index bd5ade59..84f1184b 100644 --- a/tests/endpoint/common.sh +++ b/tests/endpoint/common.sh @@ -27,14 +27,19 @@ function setup_leaf() { echo "Please install Legato leaf first" exit 1 fi - leaf --non-interactive setup legato-latest -p "$1" + + error_message=$(leaf --non-interactive setup "$1" -p "$2" 2>&1) + if ! echo "$error_message" | grep "Profile name "$1" already exists in current workspace"; then + echo "Error occurred when setup leaf profile" + exit 1 + fi } function validate_host() { if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then return 0 fi - if host "$1" > /dev/null 2>&1; then + if host "$1" >/dev/null 2>&1; then return 0 fi echo "Please enter a valid host or ip address" diff --git a/tests/endpoint/test-WP77.sh b/tests/endpoint/test-WP77.sh deleted file mode 100755 index 8c5ec052..00000000 --- a/tests/endpoint/test-WP77.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Usage: ./test-WP77.sh [HOST or IP] [PORT] - -if [ "$#" -ne 2 ]; then - echo "Usage: ./test-WP77.sh [HOST or IP] [PORT]" >&2 - exit 1 -fi - -set -uo pipefail - -COMMON_FILE="tests/endpoint/common.sh" - -if [ ! -f "$COMMON_FILE" ]; then - echo "$COMMON_FILE is not exists." - exit 1 -fi -source $COMMON_FILE - -# Check ip is validity or not -validate_host "$1" -validate_port "$2" - -# setup WP77 leaf shell -setup_leaf "swi-wp77_3.4.0" - -make TESTS=true EP_TARGET=wp77xx EP_TA_HOST="$1" EP_TA_PORT="$2" legato && - tar zcf endpoint.tgz endpoint/_build_endpoint/wp77xx/app/endpoint/staging/read-only/ diff --git a/tests/endpoint/test-endpoint.sh b/tests/endpoint/test-endpoint.sh index ee1f110c..5918642c 100755 --- a/tests/endpoint/test-endpoint.sh +++ b/tests/endpoint/test-endpoint.sh @@ -21,7 +21,7 @@ validate_host "$1" validate_port "$2" # Create endpoint app -make EP_TA_HOST="$1" EP_TA_PORT="$2" legato +make EP_TARGET=simulator TESTS=true EP_TA_HOST="$1" EP_TA_PORT="$2" legato # Run endpoint app test here endpoint/_build_endpoint/localhost/app/endpoint/staging/read-only/bin/endpoint diff --git a/tests/endpoint/test-legato-target.sh b/tests/endpoint/test-legato-target.sh new file mode 100755 index 00000000..2b0fd693 --- /dev/null +++ b/tests/endpoint/test-legato-target.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Usage: ./test-legato-target.sh [HOST or IP] [PORT] [LEGATO_TARGET] + +if [ "$#" -ne 3 ]; then + echo "Usage: ./test-legato-target.sh [HOST or IP] [PORT] [LEGATO_TARGET]" >&2 + echo "For example: ./test-legato-target.sh localhost 8000 wp77xx" >&2 + exit 1 +fi + +COMMON_FILE="tests/endpoint/common.sh" + +if [ ! -f "$COMMON_FILE" ]; then + echo "$COMMON_FILE is not exists." + exit 1 +fi +source $COMMON_FILE + +# Check ip is validity or not +validate_host "$1" +validate_port "$2" + +set -euo pipefail + +if ! env | grep LEAF > /dev/null; +then + echo "error: You must to setup the correct leaf profile and enter the leaf shell first" + exit 1 +fi + +make TESTS=true EP_TA_HOST="$1" EP_TA_PORT="$2" EP_TARGET="$3" legato