mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-20 20:03:54 +08:00
Unit tests: Fixed unit test build
Unit tests now work. The linux build was failing saving params because it was using the changes for QuRT that fake out the filesystem. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -54,13 +54,24 @@
|
||||
#define CODER_CHECK(_c) do { if (_c->dead) { debug("coder dead"); return -1; }} while(0)
|
||||
#define CODER_KILL(_c, _reason) do { debug("killed: %s", _reason); _c->dead = true; return -1; } while(0)
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
#define BSON_READ px4_read
|
||||
#define BSON_WRITE px4_write
|
||||
#define BSON_FSYNC px4_fsync
|
||||
#else
|
||||
#define BSON_READ read
|
||||
#define BSON_WRITE write
|
||||
#define BSON_FSYNC fsync
|
||||
#endif
|
||||
|
||||
static int
|
||||
read_x(bson_decoder_t decoder, void *p, size_t s)
|
||||
{
|
||||
CODER_CHECK(decoder);
|
||||
|
||||
if (decoder->fd > -1)
|
||||
return (px4_read(decoder->fd, p, s) == (int)s) ? 0 : -1;
|
||||
if (decoder->fd > -1) {
|
||||
return (BSON_READ(decoder->fd, p, s) == (int)s) ? 0 : -1;
|
||||
}
|
||||
|
||||
if (decoder->buf != NULL) {
|
||||
/* staged operations to avoid integer overflow for corrupt data */
|
||||
@@ -302,7 +313,7 @@ write_x(bson_encoder_t encoder, const void *p, size_t s)
|
||||
CODER_CHECK(encoder);
|
||||
|
||||
if (encoder->fd > -1)
|
||||
return (px4_write(encoder->fd, p, s) == (int)s) ? 0 : -1;
|
||||
return (BSON_WRITE(encoder->fd, p, s) == (int)s) ? 0 : -1;
|
||||
|
||||
/* do we need to extend the buffer? */
|
||||
while ((encoder->bufpos + s) > encoder->bufsize) {
|
||||
@@ -409,7 +420,7 @@ bson_encoder_fini(bson_encoder_t encoder)
|
||||
}
|
||||
|
||||
/* sync file */
|
||||
px4_fsync(encoder->fd);
|
||||
BSON_FSYNC(encoder->fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,14 @@
|
||||
# define debug(fmt, args...) do { } while(0)
|
||||
#endif
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
#define PARAM_OPEN px4_open
|
||||
#define PARAM_CLOSE px4_close
|
||||
#else
|
||||
#define PARAM_OPEN open
|
||||
#define PARAM_CLOSE close
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Array of static parameter info.
|
||||
*/
|
||||
@@ -707,7 +715,7 @@ param_save_default(void)
|
||||
const char *filename = param_get_default_file();
|
||||
|
||||
/* write parameters to temp file */
|
||||
fd = px4_open(filename, O_WRONLY | O_CREAT, 0x777);
|
||||
fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, 0x777);
|
||||
|
||||
if (fd < 0) {
|
||||
warn("failed to open param file: %s", filename);
|
||||
@@ -720,7 +728,7 @@ param_save_default(void)
|
||||
warnx("failed to write parameters to file: %s", filename);
|
||||
}
|
||||
|
||||
px4_close(fd);
|
||||
PARAM_CLOSE(fd);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -732,7 +740,7 @@ int
|
||||
param_load_default(void)
|
||||
{
|
||||
warnx("param_load_default\n");
|
||||
int fd_load = px4_open(param_get_default_file(), O_RDONLY);
|
||||
int fd_load = PARAM_OPEN(param_get_default_file(), O_RDONLY);
|
||||
|
||||
if (fd_load < 0) {
|
||||
/* no parameter file is OK, otherwise this is an error */
|
||||
@@ -745,7 +753,7 @@ param_load_default(void)
|
||||
}
|
||||
|
||||
int result = param_load(fd_load);
|
||||
px4_close(fd_load);
|
||||
PARAM_CLOSE(fd_load);
|
||||
|
||||
if (result != 0) {
|
||||
warn("error reading parameters from '%s'", param_get_default_file());
|
||||
|
||||
@@ -33,6 +33,7 @@ add_definitions(-Dmain_t=int)
|
||||
add_definitions(-DERROR=-1)
|
||||
add_definitions(-DOK=0)
|
||||
add_definitions(-D_UNIT_TEST=)
|
||||
add_definitions(-D__PX4_POSIX)
|
||||
add_definitions(-D__PX4_LINUX)
|
||||
|
||||
# check
|
||||
|
||||
Reference in New Issue
Block a user