From 339cfe371fd57830d46c7f29b367e7ea8a4612e7 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 13:09:39 +0000 Subject: [PATCH 01/19] Renamed all Queue names to ArduinoQueue and added tests --- .gitignore | 6 + .travis.yml | 67 ++++++ .vscode/extensions.json | 7 + ArduinoQueue.h | 189 ++++++++++++++++ CMakeLists.txt | 14 ++ Queue.h | 205 ------------------ README.md | 59 +++-- .../intQueueItemsSize/intQueueItemsSize.ino | 2 +- examples/intQueueMemSize/intQueueMemSize.ino | 4 +- library.properties | 2 +- test/CMakeLists.txt | 22 ++ test/test_ArduinoQueue.cpp | 16 ++ 12 files changed, 362 insertions(+), 231 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 .vscode/extensions.json create mode 100644 ArduinoQueue.h create mode 100644 CMakeLists.txt delete mode 100644 Queue.h create mode 100644 test/CMakeLists.txt create mode 100644 test/test_ArduinoQueue.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3e2ace --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch +build/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0f0d740 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/ArduinoQueue.h b/ArduinoQueue.h new file mode 100644 index 0000000..95cfc22 --- /dev/null +++ b/ArduinoQueue.h @@ -0,0 +1,189 @@ +/* + Author: Einar Arnason + email: einsiarna@gmail.com + + A lightweight linked list type queue implementation, + meant for microcontrollers. + + Usage and further info: + https://github.com/EinarArnason/ArduinoQueue +*/ + +#pragma once + +#if defined(ARDUINO) && ARDUINO >= 100 +#include "Arduino.h" +#elif defined(ARDUINO) && ARDUINO < 100 +#include "WProgram.h" +#endif + +template class ArduinoQueue { + class Node { + public: + T item; + Node *next; + + Node() { next = nullptr; } + + ~Node() { next = nullptr; } + }; + + Node *_head; + Node *_tail; + unsigned int _max_items; + unsigned int _max_memory; + unsigned int _items_cnt; + +public: + ArduinoQueue(unsigned int max_items = 100, unsigned int max_memory = 0) { + _head = nullptr; + _tail = nullptr; + + /* + If the max memory has not + been defined or is 0, then + the queue size is set by + the max number of items: + */ + if (max_memory == 0) { + _max_items = max_items; + _max_memory = max_items * sizeof(T); + } + /* + If the max memory has been + set then the queue size is + defined by the memory size + when the max items is 0. + If the user gave a max item + size, then the queue size + will be capped by the number + of items. + */ + else { + _max_items = max_memory / sizeof(T); + _max_memory = _max_items * sizeof(T); + if (max_items != 0) { + if (_max_items > max_items) + _max_items = max_items; + } + } + _items_cnt = 0; + } + + ~ArduinoQueue() { + for (Node *node = _head; node != nullptr; node = _head) { + _head = node->next; + delete node; + } + } + + /* + Push an item to the queue. + Returns false if memory is + full, or true if the item + was added to queue. + */ + bool enqueue(T item) { + if (_items_cnt == _max_items) { + return false; + } + Node *node = new Node; + if (node == nullptr) { + return false; + } + + node->item = item; + + if (_head == nullptr) { + _head = node; + _tail = node; + _items_cnt++; + return true; + } + + _tail->next = node; + _tail = node; + _items_cnt++; + return true; + } + + /* + Pop the front of the queue. + Because exceptions are not + usually implemented for + microcontrollers, if queue + is empty, a dummy item is + returned. + */ + T dequeue() { + if ((_items_cnt == 0) || (_head == nullptr)) { + return T(); + } + + Node *node = _head; + _head = node->next; + T item = node->item; + delete node; + node = nullptr; + + if (_head == nullptr) { + _tail = nullptr; + } + + _items_cnt--; + return item; + } + + /* + Returns true if the queue + is empty, false otherwise. + */ + bool isEmpty() { return _head == nullptr; } + + /* + Returns true if the queue + is full, false otherwise. + */ + bool isFull() { return _items_cnt == _max_items; } + + /* + Returns the number of items + currently in the queue. + */ + unsigned int item_count() { return _items_cnt; } + + /* + Returns the size of the + queue item in bytes. + */ + unsigned int item_size() { return sizeof(T); } + + /* + Returns the size of the queue + (maximum number of items) + */ + unsigned int max_queue_size() { return _max_items; } + + /* + Returns the size of the queue + (maximum size in bytes) + */ + unsigned int max_memory_size() { return _max_memory; } + + /* + Get the item in the front + of the queue. + Because exceptions are not + usually implemented for + microcontrollers, if queue + is empty, a dummy item is + returned. + */ + T front() { + if ((_items_cnt == 0) || (_head == nullptr)) { + return T(); + } + T item = _head->item; + return item; + } +}; diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f9d0dc5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.0.0) +project(ArduinoQueue VERSION 1.1.0) + +include(CTest) +enable_testing() + +add_subdirectory(${PROJECT_SOURCE_DIR}/test) + +add_library(ArduinoQueue INTERFACE) +target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR}) + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +include(CPack) diff --git a/Queue.h b/Queue.h deleted file mode 100644 index 246a917..0000000 --- a/Queue.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - Author: Einar Arnason - email: einsiarna@gmail.com - - A lightweight linked list type queue implementation, - meant for microcontrollers. - - Usage and further info: - https://github.com/EinarArnason/ArduinoQueue -*/ - -#pragma once - -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" -#else -#include "WProgram.h" -#endif - -template -class DataQueue { - class Node { - public: - T item; - Node* next; - - Node() { - next = NULL; - } - - ~Node() { - next = NULL; - } - }; - Node* _head; - Node* _tail; - unsigned int _max_items; - unsigned int _max_memory; - unsigned int _items_cnt; - -public: - DataQueue(unsigned int max_items = 100, unsigned int max_memory = 0) { - _head = NULL; - _tail = NULL; - - /* - If the max memory has not - been defined or is 0, then - the queue size is set by - the max number of items: - */ - if (max_memory == 0) { - _max_items = max_items; - _max_memory = max_items * sizeof(T); - } - /* - If the max memory has been - set then the queue size is - defined by the memory size - when the max items is 0. - If the user gave a max item - size, then the queue size - will be capped by the number - of items. - */ - else { - _max_items = max_memory / sizeof(T); - _max_memory = _max_items * sizeof(T); - if (max_items != 0) { - if (_max_items > max_items) - _max_items = max_items; - } - } - _items_cnt = 0; - } - - ~DataQueue() { - for (Node* node = _head; node != NULL; node = _head) { - _head = node->next; - delete node; - } - } - - /* - Push an item to the queue. - Returns false if memory is - full, or true if the item - was added to queue. - */ - bool enqueue(T item) { - if (_items_cnt == _max_items) { - return false; - } - Node* node = new Node; - if (node == NULL) { - return false; - } - - node->item = item; - - if (_head == NULL) { - _head = node; - _tail = node; - _items_cnt++; - return true; - } - - _tail->next = node; - _tail = node; - _items_cnt++; - return true; - } - - /* - Pop the front of the queue. - Because exceptions are not - usually implemented for - microcontrollers, if queue - is empty, a dummy item is - returned. - */ - T dequeue() { - if ((_items_cnt == 0) || (_head == NULL)) { - return T(); - } - - Node* node = _head; - _head = node->next; - T item = node->item; - delete node; - node = NULL; - - if (_head == NULL) { - _tail = NULL; - } - - _items_cnt--; - return item; - } - - /* - Returns true if the queue - is empty, false otherwise. - */ - bool isEmpty() { - return _head == NULL; - } - - /* - Returns true if the queue - is full, false otherwise. - */ - bool isFull() { - return _items_cnt == _max_items; - } - - /* - Returns the number of items - currently in the queue. - */ - unsigned int item_count() { - return _items_cnt; - } - - /* - Returns the size of the - queue item in bytes. - */ - unsigned int item_size() { - return sizeof(T); - } - - /* - Returns the size of the queue - (maximum number of items) - */ - unsigned int max_queue_size() { - return _max_items; - } - - /* - Returns the size of the queue - (maximum size in bytes) - */ - unsigned int max_memory_size() { - return _max_memory; - } - - /* - Get the item in the front - of the queue. - Because exceptions are not - usually implemented for - microcontrollers, if queue - is empty, a dummy item is - returned. - */ - T front() { - if ((_items_cnt == 0) || (_head == NULL)) { - return T(); - } - T item = _head->item; - return item; - } -}; diff --git a/README.md b/README.md index ac8f538..7b59c85 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,64 @@ # ArduinoQueue + A lightweight linked list type queue implementation, meant for microcontrollers. Written as a C++ template class. ## Constructors: -Creates a queue up to ** items: -``` -DataQueue intQueue(maximum_number_of_items); -``` -Creates a queue up to ** bytes: -``` -DataQueue intQueue(0, maximum_size_in_bytes); + +Creates a queue up to __ items: + +```C++ +ArduinoQueue intQueue(maximum_number_of_items); ``` -Creates a queue up to ** items or ** bytes, whatever comes first: + +Creates a queue up to __ bytes: + +```C++ +ArduinoQueue intQueue(0, maximum_size_in_bytes); ``` -DataQueue intQueue(maximum_number_of_items, maximum_size_in_bytes); + +Creates a queue up to __ items or __ bytes, whatever comes first: + +```C++ +ArduinoQueue intQueue(maximum_number_of_items, maximum_size_in_bytes); ``` ## How to use: + Include the header file on your code: -``` + +```C++ #include ``` Then create the queue according to your needs, examples: -* To create a queue of ***int***, capable of holding 20 items: -``` -DataQueue intQueue(20); -``` +- To create a queue of **_int_**, capable of holding 20 items: -* To create a queue of ***int***, capable of holding 20 items or a maximum size of 10 bytes *(whatever comes first)*: -``` -DataQueue intQueue(20, 10); +```C++ +ArduinoQueue intQueue(20); ``` -* To create a queue of your ***defined structure***, capable of holding 50 items: +- To create a queue of **_int_**, capable of holding 20 items or a maximum size of 10 bytes _(whatever comes first)_: + +```C++ +ArduinoQueue intQueue(20, 10); ``` + +- To create a queue of your **_defined structure_**, capable of holding 50 items: + +```C++ struct car { char brand[10]; char model[10]; int nr_doors; }; -DataQueue myCarsQueue(50); +ArduinoQueue myCarsQueue(50); ``` Finally use the following functions: -``` + +```C++ intQueue.enqueue(1); // Adds number 1 to the queue intQueue.enqueue(123); // Adds number 123 to the queue int number = intQueue.dequeue(); // Will return number 1 and remove it from the queue @@ -54,7 +67,8 @@ int number = intQueue.dequeue(); // Will return number 123 and remove it from ``` You can use also the following functions to get more queue properties: -``` + +```C++ bool state = intQueue.isEmpty(); // Returns true if the queue is empty, false otherwise bool state = intQueue.isFull(); // Returns true if the queue is full, false otherwise unsigned int n = intQueue.item_count(); // Returns the number of items currently on the queue @@ -64,6 +78,7 @@ unsigned int n = intQueue.max_memory_size(); // Returns the maximum possible ``` ## Notes + Note that while the Queue class cleans up the nodes in memory after destructor or dequeue is called, it keeps a copy of the item being queued. So for example if you are queuing pointers, you will need to keep track of the memory behind them. -*For example if you create a queue of *int* on an ESP8266, where each *int* has a size of 4 bytes and you specify the queue sizes to be up to 10 items and 10 bytes on the constructor, actually the real values will be 2 items and 8 bytes. These will be the values returned by *max_queue_size()* and *max_memory_size()*. \ No newline at end of file +*For example if you create a queue of *int* on an ESP8266, where each *int* has a size of 4 bytes and you specify the queue sizes to be up to 10 items and 10 bytes on the constructor, actually the real values will be 2 items and 8 bytes. These will be the values returned by *max_queue_size()* and *max_memory_size()\*. diff --git a/examples/intQueueItemsSize/intQueueItemsSize.ino b/examples/intQueueItemsSize/intQueueItemsSize.ino index 934df57..38d5dfa 100644 --- a/examples/intQueueItemsSize/intQueueItemsSize.ino +++ b/examples/intQueueItemsSize/intQueueItemsSize.ino @@ -15,7 +15,7 @@ #define QUEUE_SIZE_ITEMS 10 // Queue creation: -DataQueue intQueue(QUEUE_SIZE_ITEMS); +ArduinoQueue intQueue(QUEUE_SIZE_ITEMS); void printQueueStats() { Serial.println(""); diff --git a/examples/intQueueMemSize/intQueueMemSize.ino b/examples/intQueueMemSize/intQueueMemSize.ino index 4bb4ca0..9a23e3b 100644 --- a/examples/intQueueMemSize/intQueueMemSize.ino +++ b/examples/intQueueMemSize/intQueueMemSize.ino @@ -12,13 +12,13 @@ https://github.com/EinarArnason/ArduinoQueue */ -#include "Queue.h" +#include "ArduinoQueue.h" #define QUEUE_SIZE_ITEMS 10 #define QUEUE_SIZE_BYTES 10 // Queue creation: -DataQueue intQueue(QUEUE_SIZE_ITEMS, QUEUE_SIZE_BYTES); +ArduinoQueue intQueue(QUEUE_SIZE_ITEMS, QUEUE_SIZE_BYTES); void printQueueStats() { Serial.println(""); diff --git a/library.properties b/library.properties index 13b293a..f38f005 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoQueue -version=1.0.4 +version=1.1.0 author=Einar Arnason maintainer=Einar Arnason sentence=Queue Library diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..116b946 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.14.0) +project(test_ArduinoQueue VERSION 0.1.0) + +# Testing library +include(FetchContent) +FetchContent_Declare( +catch2 +GIT_REPOSITORY https://github.com/catchorg/Catch2.git +GIT_TAG v2.9.1 +) +FetchContent_MakeAvailable(catch2) + +add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.cpp) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) + +target_link_libraries(${PROJECT_NAME} PRIVATE ArduinoQueue Catch2::Catch2) +add_test(NAME ArduinoQueueTest COMMAND ${PROJECT_NAME}) + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +include(CPack) diff --git a/test/test_ArduinoQueue.cpp b/test/test_ArduinoQueue.cpp new file mode 100644 index 0000000..d2f1b23 --- /dev/null +++ b/test/test_ArduinoQueue.cpp @@ -0,0 +1,16 @@ +// Let Catch provide main(): +#define CATCH_CONFIG_MAIN + +#include +#include + +TEST_CASE("Queue is empty", "[single-file]") { + ArduinoQueue ints; + REQUIRE(ints.isEmpty() == true); +} + +TEST_CASE("List has one element", "[single-file]") { + ArduinoQueue ints; + ints.enqueue(1); + REQUIRE(ints.isEmpty() == false); +} \ No newline at end of file From c8f5220925cba8babf6ac6393e2df74f4b0a3f87 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 13:37:24 +0000 Subject: [PATCH 02/19] Adding travis integration --- .travis.yml | 79 +++++++++++------------------------------------------ 1 file changed, 16 insertions(+), 63 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c486f1..f264bde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,67 +1,20 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# +language: cpp +compiler: + - clang -# -# Template #1: General project. Test it using existing `platformio.ini`. -# +addons: + apt: + sources: + - george-edison55-precise-backports + packages: + - cmake-data + - cmake -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run +before_script: + - mkdir build + - cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-10 -H./ -Bbuild -G Ninja - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N +script: + - cmake --build build --config Debug --target all + - ctest -C Debug -T test --output-on-failure From e928e5bc04cb75ab2968ca782a899722039d4f87 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 13:43:28 +0000 Subject: [PATCH 03/19] Added Ninja as dependancy --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f264bde..6faa72f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ addons: packages: - cmake-data - cmake + - ninja before_script: - mkdir build From c01fcf21c606a17338f870c16d684cccf265e00a Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 13:48:56 +0000 Subject: [PATCH 04/19] Removed compiler set explicitly --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6faa72f..9ad5447 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ addons: before_script: - mkdir build - - cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-10 -H./ -Bbuild -G Ninja + - cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H./ -Bbuild -G Ninja script: - cmake --build build --config Debug --target all From 13b992d568bf2f84367586305e51c6ba7dade015 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 13:55:58 +0000 Subject: [PATCH 05/19] Ninja is ninja-build on Ubuntu --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9ad5447..ab61c17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ addons: packages: - cmake-data - cmake - - ninja + - ninja-build before_script: - mkdir build From 9751f7352bf565f8df20231214b4c6349e29bfe6 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 14:12:40 +0000 Subject: [PATCH 06/19] Include newer packages --- .travis.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab61c17..92e60f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,12 @@ +os: linux language: cpp +compiler: clang -compiler: - - clang - +dist: bionic addons: - apt: - sources: - - george-edison55-precise-backports - packages: - - cmake-data - - cmake - - ninja-build + snaps: + - cmake + - ninja-build before_script: - mkdir build From 5f3e532b16b43839433afb8e5bee62916755ddf7 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 14:18:44 +0000 Subject: [PATCH 07/19] Include newer packages --- .travis.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92e60f6..b9e02f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,16 @@ compiler: clang dist: bionic addons: - snaps: - - cmake - - ninja-build + apt: + sources: + - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + packages: + - cmake + - ninja-build + - llvm-dev + - libclang-dev + - clang before_script: - mkdir build From 0264934c067ab2c7bfd1908bda874e5cbfe949fa Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 14:47:54 +0000 Subject: [PATCH 08/19] Added source --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b9e02f1..28579f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ addons: sources: - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + - sourceline: 'deb https://apt.kitware.com/ubuntu/ bionic main' + key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc' packages: - cmake - ninja-build From 999ddb228afee72f9f4c5aa366020217dd32886f Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 14:52:40 +0000 Subject: [PATCH 09/19] Reduce required cmake version --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 116b946..83dda27 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14.0) +cmake_minimum_required(VERSION 3.11.0) project(test_ArduinoQueue VERSION 0.1.0) # Testing library From 236fb363785c4df8cb04bcb22a95f971bbee3286 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 15:44:13 +0000 Subject: [PATCH 10/19] Include FetchContent_MakeAvailable for cmake < 3.14 --- .travis.yml | 18 +++++++++--------- test/CMakeLists.txt | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 28579f9..45879ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,16 +6,16 @@ dist: bionic addons: apt: sources: - - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - sourceline: 'deb https://apt.kitware.com/ubuntu/ bionic main' - key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc' + - sourceline: "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" + key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key" + - sourceline: "deb https://apt.kitware.com/ubuntu/ bionic main" + key_url: "https://apt.kitware.com/keys/kitware-archive-latest.asc" packages: - - cmake - - ninja-build - - llvm-dev - - libclang-dev - - clang + - cmake + - ninja-build + - llvm-dev + - libclang-dev + - clang before_script: - mkdir build diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 83dda27..5c32035 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,6 +3,9 @@ project(test_ArduinoQueue VERSION 0.1.0) # Testing library include(FetchContent) +if(${CMAKE_VERSION} VERSION_LESS 3.14) + include(cmake/add_FetchContent_MakeAvailable.cmake) +endif() FetchContent_Declare( catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git From f6ccbb9f6c0ad9c4b5444d43ad37ee693684ac3d Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 15:53:13 +0000 Subject: [PATCH 11/19] Try to find add_FetchContent_MakeAvailable.cmake --- test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5c32035..138d510 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,8 +4,8 @@ project(test_ArduinoQueue VERSION 0.1.0) # Testing library include(FetchContent) if(${CMAKE_VERSION} VERSION_LESS 3.14) - include(cmake/add_FetchContent_MakeAvailable.cmake) -endif() + include(add_FetchContent_MakeAvailable.cmake) +endif() FetchContent_Declare( catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git From fb90f9f6c5a6f36bfce7d22f6ec2dd0f73f599e0 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 18:15:37 +0000 Subject: [PATCH 12/19] Try installing cmake manually --- .travis.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45879ef..cc6b3bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,15 +8,21 @@ addons: sources: - sourceline: "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key" - - sourceline: "deb https://apt.kitware.com/ubuntu/ bionic main" - key_url: "https://apt.kitware.com/keys/kitware-archive-latest.asc" packages: - - cmake - ninja-build - llvm-dev - libclang-dev - clang +install: + - wget https://github.com/Kitware/CMake/releases/download/v3.17.1/cmake-3.17.1-Linux-x86_64.tar.gz + - tar -zxvf cmake-3.17.1-Linux-x86_64.tar.gz + - cd cmake-3.17.1 + - ./bootstrap + - make + - sudo make install + - cmake --version + before_script: - mkdir build - cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H./ -Bbuild -G Ninja From 81e2addb3ee3d58917e3160589aa09f5ee68145d Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 18:18:57 +0000 Subject: [PATCH 13/19] Fixed wrong cmake dir name --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cc6b3bb..cd7033b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ addons: install: - wget https://github.com/Kitware/CMake/releases/download/v3.17.1/cmake-3.17.1-Linux-x86_64.tar.gz - tar -zxvf cmake-3.17.1-Linux-x86_64.tar.gz - - cd cmake-3.17.1 + - cd cmake-3.17.1-Linux-x86_64 - ./bootstrap - make - sudo make install From df7b6c146ca3f33a024c56836dac07ffea8dfbfa Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 18:23:32 +0000 Subject: [PATCH 14/19] Get cmake source instead of binary --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index cd7033b..ccf51d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,9 @@ addons: - clang install: - - wget https://github.com/Kitware/CMake/releases/download/v3.17.1/cmake-3.17.1-Linux-x86_64.tar.gz - - tar -zxvf cmake-3.17.1-Linux-x86_64.tar.gz - - cd cmake-3.17.1-Linux-x86_64 + - wget https://github.com/Kitware/CMake/releases/download/v3.17.1/cmake-3.17.1.tar.gz + - tar -zxvf cmake-3.17.1.tar.gz + - cd cmake-3.17.1 - ./bootstrap - make - sudo make install From 472c7a9d3cee3ca4b109415352e21094992f388f Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 20:36:32 +0000 Subject: [PATCH 15/19] Update CMakeLists.txt --- test/CMakeLists.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 138d510..411bf61 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,15 +3,22 @@ project(test_ArduinoQueue VERSION 0.1.0) # Testing library include(FetchContent) -if(${CMAKE_VERSION} VERSION_LESS 3.14) - include(add_FetchContent_MakeAvailable.cmake) -endif() + FetchContent_Declare( catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v2.9.1 ) -FetchContent_MakeAvailable(catch2) +if(${CMAKE_VERSION} VERSION_LESS 3.14) + FetchContent_GetProperties(catch2) + if(NOT catch2_POPULATED) + FetchContent_Populate(catch2) + add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR}) + endif() +else() + FetchContent_MakeAvailable(catch2) +endif() + add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.cpp) From 91d6ccc21bee4d5f13a41a3cd2c3d1ac7b2a2abd Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 20:38:49 +0000 Subject: [PATCH 16/19] Update .travis.yml --- .travis.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index ccf51d5..c099bd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,20 +9,12 @@ addons: - sourceline: "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key" packages: + - cmake - ninja-build - llvm-dev - libclang-dev - clang -install: - - wget https://github.com/Kitware/CMake/releases/download/v3.17.1/cmake-3.17.1.tar.gz - - tar -zxvf cmake-3.17.1.tar.gz - - cd cmake-3.17.1 - - ./bootstrap - - make - - sudo make install - - cmake --version - before_script: - mkdir build - cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H./ -Bbuild -G Ninja From 0459433d52fc13cc3eb1a973f17f49a5828895a5 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 22:11:00 +0000 Subject: [PATCH 17/19] Tests must be run insided build folder --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ccf51d5..77ccffe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,4 +29,5 @@ before_script: script: - cmake --build build --config Debug --target all + - cd build - ctest -C Debug -T test --output-on-failure From ee0f92b3af66f4b89b6b7efee9f23e069d6baa65 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 22:45:37 +0000 Subject: [PATCH 18/19] Refined test process --- CMakeLists.txt | 2 +- README.md | 2 ++ library.properties | 2 +- test/CMakeLists.txt | 18 +++++++++--------- ...test_ArduinoQueue.cpp => test_IntQueue.cpp} | 0 5 files changed, 13 insertions(+), 11 deletions(-) rename test/{test_ArduinoQueue.cpp => test_IntQueue.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9d0dc5..94bb4d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0.0) -project(ArduinoQueue VERSION 1.1.0) +project(ArduinoQueue VERSION 1.2.0) include(CTest) enable_testing() diff --git a/README.md b/README.md index 7b59c85..17e9d53 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ArduinoQueue +[![Build Status](https://travis-ci.org/EinarArnason/ArduinoQueue.svg?branch=dev)](https://travis-ci.org/EinarArnason/ArduinoQueue) + A lightweight linked list type queue implementation, meant for microcontrollers. Written as a C++ template class. diff --git a/library.properties b/library.properties index f38f005..e89b979 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoQueue -version=1.1.0 +version=1.2.0 author=Einar Arnason maintainer=Einar Arnason sentence=Queue Library diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 411bf61..0600749 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.11.0) -project(test_ArduinoQueue VERSION 0.1.0) +project(test_ArduinoQueue VERSION 1.2.0) -# Testing library include(FetchContent) +# Testing library FetchContent_Declare( catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git @@ -19,13 +19,13 @@ else() FetchContent_MakeAvailable(catch2) endif() - -add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.cpp) - -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) - -target_link_libraries(${PROJECT_NAME} PRIVATE ArduinoQueue Catch2::Catch2) -add_test(NAME ArduinoQueueTest COMMAND ${PROJECT_NAME}) +set(TESTS test_IntQueue) +foreach(test ${TESTS}) + add_executable(${test} ${PROJECT_SOURCE_DIR}/${test}.cpp) + target_compile_features(${test} PRIVATE cxx_std_17) + target_link_libraries(${test} PRIVATE ArduinoQueue Catch2::Catch2) + add_test(NAME ${test} COMMAND ${test}) +endforeach(test ${TESTS}) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) diff --git a/test/test_ArduinoQueue.cpp b/test/test_IntQueue.cpp similarity index 100% rename from test/test_ArduinoQueue.cpp rename to test/test_IntQueue.cpp From 1111ec0ebbaaef6738e6235e345d5035b3da4b61 Mon Sep 17 00:00:00 2001 From: Einar Arnason Date: Mon, 27 Apr 2020 22:50:51 +0000 Subject: [PATCH 19/19] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 17e9d53..f18018e 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ ArduinoQueue intQueue(maximum_number_of_items, maximum_size_in_bytes); Include the header file on your code: ```C++ -#include +#include ``` Then create the queue according to your needs, examples: