diff --git a/.travis.yml b/.travis.yml index fc6fc382..7227b7e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,44 +1,51 @@ +os: linux language: python python: -- '2.7' + - '3.8' cache: directories: - - "~/.npm" - - "~/.platformio" -install: -- ./travis_install.sh + - ~/.npm + - ~/.platformio env: global: - - BUILDER_TOTAL_THREADS=4 - - ESPURNA_PIO_PATCH_ISSUE_1610=y - - ESPURNA_PIO_SHARED_LIBRARIES=y + - BUILDER_TOTAL_THREADS=4 + - ESPURNA_PIO_PATCH_ISSUE_1610=y + - ESPURNA_PIO_SHARED_LIBRARIES=y +install: + - ./travis_install.sh script: -- ./travis_script.sh + - ./travis_script.sh stages: -- name: Test WebUI - if: tag IS NOT present -- name: Test PlatformIO Build - if: tag IS NOT present -- name: Release - if: tag IS present AND tag =~ ^\d+\.\d+\.\d+$ + - name: Test Host + if: tag IS NOT present + - name: Test WebUI + if: tag IS NOT present + - name: Test PlatformIO Build + if: tag IS NOT present + - name: Release + if: tag IS present AND tag =~ ^\d+\.\d+\.\d+$ jobs: include: - - stage: Test WebUI - - stage: Test PlatformIO Build - env: TEST_ENV=travis-2_3_0 - - env: TEST_ENV=travis-latest - - env: TEST_ENV=travis-git TEST_EXTRA_ARGS="-a test/build/extra/secure_client.h" - - stage: Release - env: BUILDER_THREAD=0 - - env: BUILDER_THREAD=1 - - env: BUILDER_THREAD=2 - - env: BUILDER_THREAD=3 + - stage: Test Host + - stage: Test WebUI + - stage: Test PlatformIO Build + env: TEST_ENV=travis-2_3_0 + - env: TEST_ENV=travis-latest + - env: >- + TEST_ENV=travis-git TEST_EXTRA_ARGS="-a + test/build/extra/secure_client.h" + - stage: Release + env: BUILDER_THREAD=0 + - env: BUILDER_THREAD=1 + - env: BUILDER_THREAD=2 + - env: BUILDER_THREAD=3 before_deploy: -- mv firmware/*/espurna-*.bin firmware/ + - mv firmware/*/espurna-*.bin firmware/ deploy: provider: releases api_key: - secure: LMCdaQnCxSQ5EuKhqcFR6VTfDCWc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HFUwIp7FIaoKhwhjTKe/ZHZ75zU4wdBTXof4dnSQOudoGGjRyyj7V0eR/Mhuni45N2Bldy9hDaldgtWMuEdx3ABW1IrPXtPDVTXM6QjUHm0nj5zzCgoCvQEw3jycA7Wlgbzo8MQkKH3u4MtupJcEGHJAqMbk+JlRpIfdWTiqtI697CReRGYSWT6YxF68TeJo77JPPph724BIBMtKtIk2+4RkHxz5RqM8O2vt+AFNjnWNIvVQtY8= file_glob: true file: firmware/espurna-*.bin skip_cleanup: true @@ -49,6 +56,8 @@ deploy: notifications: pushover: api_key: - secure: wtAleSibUqDOH7KskYMIFXwNqqZMA/2flCJzu835hSFWDFTjdXGeYLmQxCI7FGTWHcvWgf5pt3KR3OXtABVDfwqLj0HZjEubIypm56mZKsEaP32JlQiAw+Qz1KSU/5gEKEI3NU5MuL1rIebSEo9iVgwVDMn51GI9qv0LbjLKfXpxBmJXL/OmBRggVMswScCppXJLVlyMSRj9qT0Ds/lz+SL1g6vZHPO8r3z1BSOMA0eWNUYd/Huhe1XAHYzS4mS3aybPsPKldpv0igsvE5BHT37rb43QA0pHxv2M09QlBRNBI6kHgxzCw2OJ4uz5/K2U/4LBMDJrAj6rUGAhKn8Wuiw4B/kZb+WsvRCcCTHGYTc20KWrrV4aOojQRLht1FgNg7Ub+NNm5T9LBG+XKKHARTv1Kv09nCpPVD8NvF5YPRsSb7ZL6s/wUGSNuu365aVs3BnnazXb+ha33Hg0bCBEwmlW6FKdQ7S8OYsoIobTUcporRs8p089EQ8vNxN0osHnKPX5M0ZOxbBOIt5fQO2B+Cdn+m4hx/DETM5HMLZ/GpsbY9eiN7HWaaQPicSrSLprY6tzfvcHePk9Y6t8rjCKzehwlYtrfiMRvrPhZuOLcB4s3OmJngxvOCGxdWkh/6F2CY6sDslyviaK0ZwX93Gn7uNThAviFpZNUlPWP6jHIkA= + secure: >- + wtAleSibUqDOH7KskYMIFXwNqqZMA/2flCJzu835hSFWDFTjdXGeYLmQxCI7FGTWHcvWgf5pt3K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DiAg3qf1hu8j+AALblY73gNSAgv4F+/SnmnfKy5Cz/oRQQfboiC/VphNa25Fzq3s3uahQfLha4tyHrc1LltSM6bztErRSPqDp96qVTQORVHr6jqJhl6c9R0XXrnc0Pc5lpBoPKOqug1yPp15k9AAssGxtXZqg2loHjwmS+Qm1i77mNGKNhzqDpmLHEzmIejc4n4lIZmze+dLucStiNnkN6TF3nvIh37CNjH6slT5t7WfJg= + secure: >- + atCRvGYPuAT1DH5UupNIV80sqrIgwdYrxO69tq+lIBfi3BIJ4LLlvUQwigWak6otfJbEqAQKVNi8I8J4g7ASHx1wn335vpAqLAbhJqfbLznAcU9nZ+bdc8+NJ57qY66ZZJNpljbMC0HWgw2kgyiCLJ1wS3zsQAyuzyGuMcmc43zFOQMA7QUaefE6LGlHPn0i6Ub04QgQ1413IEu2/FR5i4hVXrgRQzaPy07pSPbvFTvoxfWDgWjTQM+R2AG8uStesO+2yzeb8Nu2pJDvFf3R1N8P2e3zg5YN86DLNRQ+Kxl7M1FJ/txbJ/4D1jdNwAmtUzEoYnsKCcCnMHWGuSlJF8fgXSVBDi9KVH7Y6rlWXzMcqesR5lzNTlD7JQ01yw2WrO6Nj7fvan+QNGp3d5F4Kf3WE+5rkmM5Sbo5rb9YOGt688i1qJ3Xf1MTkQNCzDiAg3qf1hu8j+AALblY73gNSAgv4F+/SnmnfKy5Cz/oRQQfboiC/VphNa25Fzq3s3uahQfLha4tyHrc1LltSM6bztErRSPqDp96qVTQORVHr6jqJhl6c9R0XXrnc0Pc5lpBoPKOqug1yPp15k9AAssGxtXZqg2loHjwmS+Qm1i77mNGKNhzqDpmLHEzmIejc4n4lIZmze+dLucStiNnkN6TF3nvIh37CNjH6slT5t7WfJg= diff --git a/code/test/platformio.ini b/code/test/platformio.ini index 5cbef5b1..b7a74be1 100644 --- a/code/test/platformio.ini +++ b/code/test/platformio.ini @@ -6,6 +6,7 @@ platform = native lib_compat_mode = off lib_deps = StreamString - https://github.com/bxparks/UnixHostDuino + https://github.com/bxparks/UnixHostDuino#d740398e build_flags = + -std=gnu++11 -I../espurna/ diff --git a/code/test/unit/basic/basic.cpp b/code/test/unit/basic/basic.cpp new file mode 100644 index 00000000..7ecf5eef --- /dev/null +++ b/code/test/unit/basic/basic.cpp @@ -0,0 +1,16 @@ +#include +#include + +// Ensure build system works +// ref: https://github.com/bxparks/UnixHostDuino/pull/6 + +void test_linkage() { + pinMode(0, INPUT); + pinMode(0, OUTPUT); +} + +int main(int argc, char** argv) { + UNITY_BEGIN(); + RUN_TEST(test_linkage); + UNITY_END(); +} diff --git a/code/test/unit/tuya_test.cpp b/code/test/unit/tuya/tuya.cpp similarity index 97% rename from code/test/unit/tuya_test.cpp rename to code/test/unit/tuya/tuya.cpp index 88abc7a8..88fcbc8f 100644 --- a/code/test/unit/tuya_test.cpp +++ b/code/test/unit/tuya/tuya.cpp @@ -18,7 +18,7 @@ using namespace Tuya; -bool test_datatype(const DataFrame& frame, const Type expect_type) { +static bool datatype_same(const DataFrame& frame, const Type expect_type) { const auto type = dataType(frame); return expect_type == type; } @@ -73,7 +73,7 @@ void test_static_dataframe_bool() { "Version should stay 0 unless explicitly set"); TEST_ASSERT_MESSAGE(frame.commandEquals(Command::SetDP), "commandEquals should return true with the same arg as in the constructor"); - TEST_ASSERT_MESSAGE(test_datatype(frame, Type::BOOL), + TEST_ASSERT_MESSAGE(datatype_same(frame, Type::BOOL), "DataProtocol should translate to Type::BOOL"); } @@ -94,27 +94,28 @@ void test_static_dataframe_int() { } -void test_dataframe_const() { +void test_static_dataframe_heartbeat() { - const DataFrame frame(Command::SetDP); + DataFrame frame(Command::Heartbeat); TEST_ASSERT_EQUAL_MESSAGE(0, frame.length, - "Frame with Command::SetDP should not have any data attached to it"); + "Frame with Command::Heartbeat should not have any data attached to it"); TEST_ASSERT_EQUAL_MESSAGE(0, std::distance(frame.cbegin(), frame.cend()), "Frame with Command::SetDP should not have any data attached to it"); + //test_hexdump("static", static_frame.serialize()); } -void test_static_dataframe_heartbeat() { +void test_dataframe_const() { - DataFrame frame(Command::Heartbeat); + const DataFrame frame(Command::SetDP); TEST_ASSERT_EQUAL_MESSAGE(0, frame.length, - "Frame with Command::Heartbeat should not have any data attached to it"); + "Frame with Command::SetDP should not have any data attached to it"); TEST_ASSERT_EQUAL_MESSAGE(0, std::distance(frame.cbegin(), frame.cend()), "Frame with Command::SetDP should not have any data attached to it"); - //test_hexdump("static", static_frame.serialize()); } + void test_dataframe_copy() { DataFrame frame(Command::Heartbeat); @@ -149,7 +150,7 @@ void test_dataframe_raw_data() { DataFrame frame(data.cbegin()); TEST_ASSERT_MESSAGE(frame.commandEquals(Command::ReportDP), "This message should be parsed as data protocol"); - TEST_ASSERT_MESSAGE(test_datatype(frame, Type::BOOL), + TEST_ASSERT_MESSAGE(datatype_same(frame, Type::BOOL), "This message should have boolean datatype attached to it"); TEST_ASSERT_EQUAL_MESSAGE(5, frame.length, "Boolean DP contains 5 bytes"); @@ -176,6 +177,7 @@ class BufferedStream : public Stream { // Print interface size_t write(uint8_t c) { _buffer.push((int)c); + return 1; } size_t write(const unsigned char* data, unsigned long size) { for (size_t n = 0; n < size; ++n) { @@ -219,6 +221,7 @@ void test_transport() { int main(int argc, char** argv) { UNITY_BEGIN(); + RUN_TEST(test_states); RUN_TEST(test_static_dataframe_bool); RUN_TEST(test_static_dataframe_int); @@ -227,6 +230,7 @@ int main(int argc, char** argv) { RUN_TEST(test_dataframe_copy); RUN_TEST(test_dataframe_raw_data); RUN_TEST(test_transport); + UNITY_END(); } diff --git a/code/test/unit/url/url.cpp b/code/test/unit/url/url.cpp new file mode 100644 index 00000000..a0c4fe9b --- /dev/null +++ b/code/test/unit/url/url.cpp @@ -0,0 +1,21 @@ +#include +#include + +#include "libs/URL.h" + +void test_parse() { + URL url("http://api.thingspeak.com/update"); + TEST_ASSERT_EQUAL_STRING("api.thingspeak.com", url.host.c_str()); + TEST_ASSERT_EQUAL_STRING("/update", url.path.c_str()); + TEST_ASSERT_EQUAL(80, url.port); +} + +int main(int argc, char** argv) { + + UNITY_BEGIN(); + + RUN_TEST(test_parse); + + UNITY_END(); + +} diff --git a/travis_install.sh b/travis_install.sh index 251bdd14..ce1043ce 100755 --- a/travis_install.sh +++ b/travis_install.sh @@ -14,7 +14,9 @@ pio_install() { cd code -if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then +if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test host" ]; then + pio_install +elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then npm_install elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test platformio build" ]; then pio_install diff --git a/travis_script.sh b/travis_script.sh index 3881873e..9efaf00f 100755 --- a/travis_script.sh +++ b/travis_script.sh @@ -4,7 +4,9 @@ set -x -e -v cd code -if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then +if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test host" ]; then + cd test/ && pio test +elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then ./build.sh -f environments elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test platformio build" ]; then # shellcheck disable=SC2086