Skip to content

Commit

Permalink
Improved Yarp coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Dec 6, 2023
1 parent 77d0e61 commit 4ae0f9b
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,7 @@ jobs:
-Dsonar.junit.reportPaths=build/JUnitTestResults.xml \
-Dsonar.exclusions="src/yarp*/**/* src/carriers/**/* src/devices/**/* src/idls/**/* src/libyarp*/**/* src/robottestingframework-plugins/**/* tests/**/*" \
-Dsonar.coverage.exclusions="\
src/libYARP_dev/src/yarp/dev/tests/*,\
src/devices/*/tests/*,\
src/carriers/*/tests/*,\
src/portmonitors/*/tests/*,\
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ jobs:
-Dsonar.junit.reportPaths=build/JUnitTestResults.xml \
-Dsonar.exclusions="src/yarp*/**/* src/carriers/**/* src/devices/**/* src/idls/**/* src/libyarp*/**/* src/robottestingframework-plugins/**/* tests/**/*" \
-Dsonar.coverage.exclusions="\
src/libYARP_dev/src/yarp/dev/tests/*,\
src/devices/*/tests/*,\
src/carriers/*/tests/*,\
src/portmonitors/*/tests/*,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ TEST_CASE("dev::RemoteControlBoardTest", "[yarp::dev]")
yarp::dev::tests::exec_iInteractionMode_test_1(iint, iinfo);
yarp::dev::tests::exec_iMotor_test_1(imot);
yarp::dev::tests::exec_iMotorEncoders_test_1(imotenc);
yarp::dev::tests::exec_iPidControl_test_1(ipid);
yarp::dev::tests::exec_iPidControl_test_1(ipid, iinfo);
yarp::dev::tests::exec_iPidControl_test_2(ipid);
yarp::dev::tests::exec_iPwmControl_test_1(ipwm,icmd);
yarp::dev::tests::exec_iCurrentControl_test_1(icurr,icmd);
//yarp::dev::tests::exec_iRemoteCalibrator_test_1(icalib);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ TEST_CASE("dev::ControlBoardRemapperTest2", "[yarp::dev]")
yarp::dev::tests::exec_iInteractionMode_test_1(iint,iinfo);
yarp::dev::tests::exec_iMotor_test_1(imot);
yarp::dev::tests::exec_iMotorEncoders_test_1(imotenc);
yarp::dev::tests::exec_iPidControl_test_1(ipid);
yarp::dev::tests::exec_iPidControl_test_1(ipid, iinfo);
yarp::dev::tests::exec_iPidControl_test_2(ipid);
yarp::dev::tests::exec_iPwmControl_test_1(ipwm, icmd);
yarp::dev::tests::exec_iCurrentControl_test_1(icurr, icmd);
//yarp::dev::tests::exec_iRemoteCalibrator_test_1(iremotecalib);
Expand Down
2 changes: 2 additions & 0 deletions src/devices/fakeMicrophone/tests/fakeMicrophone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ TEST_CASE("dev::fakeMicrophone", "[yarp::dev]")

CHECK(igrb->stopRecording());

CHECK(igrb->resetRecordingAudioBuffer());

//"Close all polydrivers and check"
{
CHECK(dd.close());
Expand Down
13 changes: 7 additions & 6 deletions src/devices/fakeMotionControl/tests/fakeMotionControl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TEST_CASE("dev::fakeMotionControl", "[yarp::dev]")
IPositionControl* ipos=nullptr;
IVelocityControl* ivel = nullptr;
ITorqueControl* itrq=nullptr;
IAxisInfo* iaxis = nullptr;
IAxisInfo* iinfo = nullptr;
IEncodersTimed* ienc = nullptr;
IControlMode* icmd = nullptr;
IInteractionMode* iint = nullptr;
Expand All @@ -78,7 +78,7 @@ TEST_CASE("dev::fakeMotionControl", "[yarp::dev]")
ddmc.view(ipos); REQUIRE(ipos);
ddmc.view(ivel); REQUIRE(ivel);
ddmc.view(itrq); REQUIRE(itrq);
ddmc.view(iaxis); REQUIRE(iaxis);
ddmc.view(iinfo); REQUIRE(iinfo);
ddmc.view(ienc); REQUIRE(ienc);
ddmc.view(icmd); REQUIRE(icmd);
ddmc.view(iint); REQUIRE(iint);
Expand All @@ -93,13 +93,14 @@ TEST_CASE("dev::fakeMotionControl", "[yarp::dev]")
yarp::dev::tests::exec_iPositionControl_test_1(ipos, icmd);
yarp::dev::tests::exec_iVelocityControl_test_1(ivel, icmd);
yarp::dev::tests::exec_iTorqueControl_test_1(itrq, icmd);
yarp::dev::tests::exec_iAxisInfo_test_1(iaxis);
yarp::dev::tests::exec_iAxisInfo_test_1(iinfo);
yarp::dev::tests::exec_iEncodersTimed_test_1(ienc);
yarp::dev::tests::exec_iControlMode_test_1(icmd, iaxis);
yarp::dev::tests::exec_iInteractionMode_test_1(iint, iaxis);
yarp::dev::tests::exec_iControlMode_test_1(icmd, iinfo);
yarp::dev::tests::exec_iInteractionMode_test_1(iint, iinfo);
yarp::dev::tests::exec_iMotor_test_1(imot);
yarp::dev::tests::exec_iMotorEncoders_test_1(imotenc);
yarp::dev::tests::exec_iPidControl_test_1(ipid);
yarp::dev::tests::exec_iPidControl_test_1(ipid, iinfo);
yarp::dev::tests::exec_iPidControl_test_2(ipid);
yarp::dev::tests::exec_iPwmControl_test_1(ipwm, icmd);
yarp::dev::tests::exec_iCurrentControl_test_1(icurr, icmd);
//yarp::dev::tests::exec_iRemoteCalibrator_test_1(iremotecalib);
Expand Down
2 changes: 2 additions & 0 deletions src/devices/fakeSpeaker/tests/fakeSpeaker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ TEST_CASE("dev::fakeSpeaker", "[yarp::dev]")
CHECK(iplay->startPlayback());
CHECK(iplay->stopPlayback());

CHECK(iplay->resetPlaybackAudioBuffer());

//"Close all polydrivers and check"
{
CHECK(dd.close());
Expand Down
72 changes: 70 additions & 2 deletions src/libYARP_dev/src/yarp/dev/tests/IPidControlTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,86 @@

#include <yarp/dev/IPidControl.h>
#include <yarp/dev/IControlMode.h>
#include <yarp/dev/IAxisInfo.h>
#include <catch2/catch_amalgamated.hpp>

using namespace yarp::dev;
using namespace yarp::os;

namespace yarp::dev::tests
{
inline void exec_iPidControl_test_1(IPidControl* ipid)
inline void exec_iPidControl_test_1(IPidControl* ipid, IAxisInfo* iaxis)
{
REQUIRE(ipid != nullptr);
REQUIRE(iaxis != nullptr);

int ax;
bool b = false;

b = iaxis->getAxes(&ax);
CHECK(b);
REQUIRE(ax > 0);

yarp::dev::PidControlTypeEnum pp = yarp::dev::PidControlTypeEnum::VOCAB_PIDTYPE_POSITION;
b = ipid->disablePid(pp,0);
CHECK(b);

b = ipid->enablePid(pp,0);
CHECK(b);

bool enabled;
b = ipid->isPidEnabled(pp, 0, &enabled);
CHECK(b);

yarp::dev::Pid retpid;
b=ipid->getPid(pp,0, &retpid);
CHECK(b);

auto retpids = std::vector<yarp::dev::Pid>(ax);
b= ipid->getPids(pp, retpids.data());
CHECK(b);

yarp::dev::Pid setpid;
yarp::dev::Pid setpid2(retpid);
b = ipid->setPid(pp, 0, setpid);
CHECK(b);

auto setpids = std::vector<yarp::dev::Pid>(ax);
b = ipid->setPids(pp, setpids.data());
CHECK(b);

b = ipid->resetPid(pp,0);
CHECK(b);

b = ipid->setPidOffset(pp,0,0);
CHECK(b);

double getpidref=0;
b = ipid->getPidReference(pp, 0, &getpidref);
CHECK(b);

auto getpidrefs = std::vector<double>(ax);
b = ipid->getPidReferences(pp, getpidrefs.data());
CHECK(b);

double setpidref=0;
b = ipid->setPidReference(pp, 0, setpidref);
CHECK(b);

auto setpidrefs = std::vector<double>(ax);
b = ipid->setPidReferences(pp, setpidrefs.data());
CHECK(b);

double errlim=0;
b = ipid->getPidErrorLimit(pp, 0, &errlim);
CHECK(b);

auto errlims = std::vector<double>(ax);
b = ipid->getPidErrorLimits(pp, errlims.data());
CHECK(b);
}

inline void exec_iPidControl_test_2(IPidControl* ipid)
{
yarp::dev::Pid testpid;
testpid.setKp(1); CHECK(testpid.kp ==1);
testpid.setKd(2); CHECK(testpid.kd == 2);
Expand All @@ -58,6 +107,25 @@ namespace yarp::dev::tests
yarp::dev::Pid emptypid;
testpid2.clear();
CHECK(testpid2 == emptypid);

yarp::dev::Pid testpid3 (1,2,3,4,5,6);
CHECK(testpid3.kp == 1);
CHECK(testpid3.kd == 2);
CHECK(testpid3.ki == 3);
CHECK(testpid3.max_int == 4);
CHECK(testpid3.scale == 5);
CHECK(testpid3.max_output == 6);

yarp::dev::Pid testpid4 (1,2,3,4,5,6,7,8,9);
CHECK(testpid4.kp == 1);
CHECK(testpid4.kd == 2);
CHECK(testpid4.ki == 3);
CHECK(testpid4.max_int == 4);
CHECK(testpid4.scale == 5);
CHECK(testpid4.max_output == 6);
CHECK(testpid4.stiction_up_val == 7);
CHECK(testpid4.stiction_down_val == 8);
CHECK(testpid4.kff == 9);
}

}
Expand Down

0 comments on commit 4ae0f9b

Please sign in to comment.