Skip to content

Run unit tests via valgrind to check for memory leaks #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install valgrind
run: |
sudo apt-get install valgrind

- name: Run unit tests
run: |
mkdir "$BUILD_PATH"
cd "$BUILD_PATH"
cmake ..
make
bin/testArduinoIoTCloud
valgrind --leak-check=yes --error-exitcode=1 bin/testArduinoIoTCloud

- name: Check code coverage
run: |
Expand Down
4 changes: 2 additions & 2 deletions extras/test/src/test_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") {
GIVEN("CloudProtocol::V2") {
bool test = true;
ArduinoCloudProperty *p = new CloudWrapperBool(test);
std::unique_ptr<ArduinoCloudProperty> p(new CloudWrapperBool(test));
sync_callback_called = false;
change_callback_called = false;

Expand Down Expand Up @@ -192,7 +192,7 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") {
GIVEN("CloudProtocol::V2") {
bool test = true;
ArduinoCloudProperty *p = new CloudWrapperBool(test);
std::unique_ptr<ArduinoCloudProperty> p(new CloudWrapperBool(test));
sync_callback_called = false;
change_callback_called = false;

Expand Down
16 changes: 9 additions & 7 deletions extras/test/src/test_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <catch.hpp>

#include <memory>

#include <util/CBORTestUtil.h>
#include <ArduinoCloudThing.h>
#include "types/CloudWrapperBool.h"
Expand Down Expand Up @@ -483,15 +485,15 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
String str_test;
str_test = "str_test";

ArduinoCloudProperty *i = new CloudWrapperInt(int_test);
ArduinoCloudProperty *b = new CloudWrapperBool(bool_test);
ArduinoCloudProperty *f = new CloudWrapperFloat(float_test);
ArduinoCloudProperty *s = new CloudWrapperString(str_test);
std::unique_ptr<ArduinoCloudProperty> i(new CloudWrapperInt(int_test));
std::unique_ptr<ArduinoCloudProperty> b(new CloudWrapperBool(bool_test));
std::unique_ptr<ArduinoCloudProperty> f(new CloudWrapperFloat(float_test));
std::unique_ptr<ArduinoCloudProperty> s(new CloudWrapperString(str_test));

thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS);
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS);
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS);
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS);
thing.addPropertyReal(*f, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS);
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS);
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS);

thing.updateTimestampOnLocallyChangedProperties();

Expand Down
16 changes: 9 additions & 7 deletions extras/test/src/test_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <catch.hpp>

#include <memory>

#include <util/CBORTestUtil.h>
#include <ArduinoCloudThing.h>
#include "types/CloudWrapperBool.h"
Expand Down Expand Up @@ -377,15 +379,15 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]")
String str_test;
str_test = "str_test";

ArduinoCloudProperty *i = new CloudWrapperInt(int_test);
ArduinoCloudProperty *b = new CloudWrapperBool(bool_test);
ArduinoCloudProperty *f = new CloudWrapperFloat(float_test);
ArduinoCloudProperty *s = new CloudWrapperString(str_test);
std::unique_ptr<ArduinoCloudProperty> i(new CloudWrapperInt(int_test));
std::unique_ptr<ArduinoCloudProperty> b(new CloudWrapperBool(bool_test));
std::unique_ptr<ArduinoCloudProperty> f(new CloudWrapperFloat(float_test));
std::unique_ptr<ArduinoCloudProperty> s(new CloudWrapperString(str_test));

thing.addPropertyReal(*i, "int_test", Permission::ReadWrite);
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite);
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite);
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite);
thing.addPropertyReal(*f, "float_test", Permission::ReadWrite);
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite);
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite);

thing.updateTimestampOnLocallyChangedProperties();

Expand Down