Skip to content

Commit

Permalink
move parameter unittest into systemcmds
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed Jun 12, 2017
1 parent f26cd01 commit 4937449
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 388 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ src/modules/uORB/topics/*
src/platforms/nuttx/px4_messages/*
src/platforms/ros/px4_messages/*
Firmware.zip
unittests/build
*.generated.h
.vagrant
*.pretty
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
[submodule "Tools/sitl_gazebo"]
path = Tools/sitl_gazebo
url = https://github.com/PX4/sitl_gazebo.git
[submodule "unittests/googletest"]
path = unittests/googletest
url = https://github.com/google/googletest.git
ignore = untracked
[submodule "src/lib/matrix"]
path = src/lib/matrix
url = https://github.com/PX4/Matrix.git
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ px4_add_git_submodule(TARGET git_gazebo PATH "Tools/sitl_gazebo")
px4_add_git_submodule(TARGET git_gencpp PATH "Tools/gencpp")
px4_add_git_submodule(TARGET git_genmsg PATH "Tools/genmsg")
px4_add_git_submodule(TARGET git_gps_devices PATH "src/drivers/gps/devices")
px4_add_git_submodule(TARGET git_gtest PATH "unittests/gtest")
px4_add_git_submodule(TARGET git_jmavsim PATH "Tools/jMAVSim")
px4_add_git_submodule(TARGET git_matrix PATH "src/lib/matrix")
px4_add_git_submodule(TARGET git_mavlink PATH "mavlink/include/mavlink/v1.0")
Expand Down
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,22 @@ format:

# Testing
# --------------------------------------------------------------------
.PHONY: unittest run_tests_posix tests tests_coverage

unittest:
echo "UNIT TEST DISABLED"
.PHONY: run_tests_posix tests tests_coverage

run_tests_posix:
$(MAKE) --no-print-directory posix_sitl_default test_results

tests: unittest run_tests_posix
tests: run_tests_posix

tests_coverage:
@$(MAKE) --no-print-directory posix_sitl_default test_coverage_genhtml PX4_CMAKE_BUILD_TYPE=Coverage

coveralls_upload:
@cpp-coveralls --include src/ \
--exclude src/lib/DriverFramework \
--exclude src/lib/ecl \
--exclude src/lib/Matrix \
--exclude=src/lib/DriverFramework \
--exclude=src/lib/ecl \
--exclude=src/lib/Matrix \
--exclude=src/modules/uavcan/libuavcan \
--exclude-pattern ".*/unittests/googletest/.*" \
--root . --build-root build_posix_sitl_default/ --follow-symlinks

codecov_upload:
Expand Down
2 changes: 1 addition & 1 deletion Tools/fix_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ echo "TMPDIR=\"$TMPDIR\""

# Make a list of all source and header files that we need to fix.
# List of directories that we don't want to touch.
EXCLUDE_FOLDERS=".git unittests Tools"
EXCLUDE_FOLDERS=".git Tools"
EXCLUDE_PATTERNS="examples matlab/scripts tests test unit_test *_test *_tests test_* apps/test_* UnitTests"
# A regular expression for the exclude patterns.
EXCLUDE_PATTERNS_RE="($(echo $EXCLUDE_PATTERNS | sed -e 's/\*/[^\/]*/g;s/ /|/g'))"
Expand Down
3 changes: 0 additions & 3 deletions src/drivers/device/vdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ void VDev::showDevices()

pthread_mutex_unlock(&devmutex);

#ifndef __PX4_UNIT_TESTS
PX4_INFO("DF Devices:");
const char *dev_path;
unsigned int index = 0;
Expand All @@ -583,8 +582,6 @@ void VDev::showDevices()
PX4_INFO(" %s", dev_path);
}
} while (i == 0);

#endif
}

void VDev::showTopics()
Expand Down
1 change: 1 addition & 0 deletions src/firmware/posix/sitl_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(tests
mc_pos_control
mixer
param
parameters
perf
rc
servo
Expand Down
10 changes: 1 addition & 9 deletions src/modules/systemlib/param/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
static const char *param_default_file = PX4_ROOTFSDIR"/eeprom/parameters";
static char *param_user_file = NULL;


#if 0
# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0)
#else
Expand All @@ -111,15 +110,8 @@ static bool autosave_disabled = false;
/**
* Array of static parameter info.
*/
#ifdef _UNIT_TEST
extern struct param_info_s param_array[];
extern struct param_info_s *param_info_base;
extern struct param_info_s *param_info_limit;
#define param_info_count (param_info_limit - param_info_base)
#else
static const struct param_info_s *param_info_base = (const struct param_info_s *) &px4_parameters;
#define param_info_count px4_parameters.param_count
#endif /* _UNIT_TEST */
#define param_info_count px4_parameters.param_count

/**
* Storage for modified parameters.
Expand Down
7 changes: 0 additions & 7 deletions src/modules/systemlib/param/param_shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,8 @@ static bool autosave_disabled = false;
/**
* Array of static parameter info.
*/
#ifdef _UNIT_TEST
extern struct param_info_s param_array[];
extern struct param_info_s *param_info_base;
extern struct param_info_s *param_info_limit;
#define param_info_count (param_info_limit - param_info_base)
#else
static struct param_info_s *param_info_base = (struct param_info_s *) &px4_parameters;
#define param_info_count px4_parameters.param_count
#endif /* _UNIT_TEST */

/**
* Storage for modified parameters.
Expand Down
4 changes: 1 addition & 3 deletions src/platforms/px4_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,5 @@
#include <board_config.h>

#elif defined (__PX4_POSIX)
# if !defined(__PX4_UNIT_TESTS)
# include <board_config.h>
# endif
# include <board_config.h>
#endif
5 changes: 3 additions & 2 deletions src/systemcmds/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
set(srcs
test_adc.c
test_autodeclination.cpp
test_dataman.c
test_hysteresis.cpp
test_bson.c
test_conv.cpp
test_dataman.c
test_file.c
test_file2.c
test_float.cpp
test_gpio.c
test_hott_telemetry.c
test_hrt.c
test_hysteresis.cpp
test_int.cpp
test_jig_voltages.c
test_led.c
Expand All @@ -52,6 +52,7 @@ set(srcs
test_mixer.cpp
test_mount.c
test_param.c
test_parameters.cpp
test_perf.c
test_ppm_loopback.c
test_rc.c
Expand Down
24 changes: 24 additions & 0 deletions src/systemcmds/tests/params.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_1, 2);

/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_2, 4);

/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_RC_X, 8);

/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_RC2_X, 16);

/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_PARAMS, 12345678);
5 changes: 0 additions & 5 deletions src/systemcmds/tests/test_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
#define PARAM_MAGIC1 12345678
#define PARAM_MAGIC2 0xa5a5a5a5

/**
* @group Testing
*/
PARAM_DEFINE_INT32(TEST_PARAMS, 12345678);

int
test_param(int argc, char *argv[])
{
Expand Down
172 changes: 172 additions & 0 deletions src/systemcmds/tests/test_parameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#include <unit_test/unit_test.h>

class ParameterTest : public UnitTest
{
public:
virtual bool run_tests();

ParameterTest()
{
p0 = param_find("TEST_RC_X");
p1 = param_find("TEST_RC2_X");
p2 = param_find("TEST_1");
p3 = param_find("TEST_2");
}

private:

param_t p0{PARAM_INVALID};
param_t p1{PARAM_INVALID};
param_t p2{PARAM_INVALID};
param_t p3{PARAM_INVALID};

bool _assert_parameter_int_value(param_t param, int32_t expected);
bool _set_all_int_parameters_to(int32_t value);

bool SimpleFind();
bool ResetAll();
bool ResetAllExcludesOne();
bool ResetAllExcludesTwo();
bool ResetAllExcludesBoundaryCheck();
bool ResetAllExcludesWildcard();
};

bool ParameterTest::_assert_parameter_int_value(param_t param, int32_t expected)
{
int32_t value;
int result = param_get(param, &value);
ut_compare("param_get did not return parameter", 0, result);
ut_compare("value for param doesn't match default value", expected, value);

return true;
}

bool ParameterTest::_set_all_int_parameters_to(int32_t value)
{
param_set(p0, &value);
param_set(p1, &value);
param_set(p2, &value);
param_set(p3, &value);

bool ret = false;

ret = ret || _assert_parameter_int_value(p0, value);
ret = ret || _assert_parameter_int_value(p1, value);
ret = ret || _assert_parameter_int_value(p2, value);
ret = ret || _assert_parameter_int_value(p3, value);

return ret;
}

bool ParameterTest::SimpleFind()
{
param_t param = param_find("TEST_2");

ut_assert_true(PARAM_INVALID != param);

int32_t value;
int result = param_get(param, &value);

ut_compare("param_get did not return parameter", 0, result);
ut_compare("value of returned parameter does not match", 4, value);

return true;
}

bool ParameterTest::ResetAll()
{
_set_all_int_parameters_to(50);

param_reset_all();

bool ret = false;

ret = ret || _assert_parameter_int_value(p0, 8);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);

return ret;
}

bool ParameterTest::ResetAllExcludesOne()
{
_set_all_int_parameters_to(50);

const char *excludes[] = {"TEST_RC_X"};
param_reset_excludes(excludes, 1);

bool ret = false;

ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);

return ret;
}

bool ParameterTest::ResetAllExcludesTwo()
{
_set_all_int_parameters_to(50);

const char *excludes[] = {"TEST_RC_X", "TEST_1"};
param_reset_excludes(excludes, 2);

bool ret = false;

ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 50);
ret = ret || _assert_parameter_int_value(p3, 4);

return ret;
}

bool ParameterTest::ResetAllExcludesBoundaryCheck()
{
_set_all_int_parameters_to(50);

const char *excludes[] = {"TEST_RC_X", "TEST_1"};
param_reset_excludes(excludes, 1);

bool ret = false;

ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 16);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);

return ret;
}

bool ParameterTest::ResetAllExcludesWildcard()
{
_set_all_int_parameters_to(50);

const char *excludes[] = {"TEST_RC*"};
param_reset_excludes(excludes, 1);

bool ret = false;

ret = ret || _assert_parameter_int_value(p0, 50);
ret = ret || _assert_parameter_int_value(p1, 50);
ret = ret || _assert_parameter_int_value(p2, 2);
ret = ret || _assert_parameter_int_value(p3, 4);

return ret;
}

bool ParameterTest::run_tests()
{
ut_run_test(SimpleFind);
ut_run_test(ResetAll);
ut_run_test(ResetAllExcludesOne);
ut_run_test(ResetAllExcludesTwo);
ut_run_test(ResetAllExcludesBoundaryCheck);
ut_run_test(ResetAllExcludesWildcard);

return (_tests_failed == 0);
}

ut_declare_test_c(test_parameters, ParameterTest)
1 change: 1 addition & 0 deletions src/systemcmds/tests/tests_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const struct {
{"matrix", test_matrix, 0},
{"mount", test_mount, OPT_NOJIGTEST | OPT_NOALLTEST},
{"param", test_param, 0},
{"parameters", test_parameters, 0},
{"perf", test_perf, OPT_NOJIGTEST},
{"ppm", test_ppm, OPT_NOJIGTEST | OPT_NOALLTEST},
{"ppm_loopback", test_ppm_loopback, OPT_NOALLTEST},
Expand Down
1 change: 1 addition & 0 deletions src/systemcmds/tests/tests_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern int test_uart_break(int argc, char *argv[]);
extern int test_uart_console(int argc, char *argv[]);
extern int test_uart_loopback(int argc, char *argv[]);
extern int test_uart_send(int argc, char *argv[]);
extern int test_parameters(int argc, char *argv[]);

/* external */
extern int commander_tests_main(int argc, char *argv[]);
Expand Down
Loading

0 comments on commit 4937449

Please sign in to comment.