Skip to content

Commit

Permalink
system_tests: try to avoid segfaults
Browse files Browse the repository at this point in the history
This is an attempt to avoid spurious segfaults happening in some of the
CI tests for some of the system tests. Presumably they happen on the
quick destruction of the objects right after construction.

Signed-off-by: Julian Oes <[email protected]>
  • Loading branch information
julianoes committed Nov 2, 2023
1 parent d1ec125 commit f92e3d1
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/system_tests/action_arm_disarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "plugins/action/action.h"
#include "plugins/action_server/action_server.h"
#include <gtest/gtest.h>
#include <thread>

using namespace mavsdk;

Expand Down Expand Up @@ -48,4 +49,6 @@ TEST(SystemTest, ActionArmDisarm)

// And disarm again
EXPECT_EQ(action.disarm(), Action::Result::Success);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/camera_take_photo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "log.h"
#include <future>
#include <mutex>
#include <thread>
#include <gtest/gtest.h>

using namespace mavsdk;
Expand Down Expand Up @@ -69,4 +70,6 @@ TEST(SystemTest, CameraTakePhoto)
ASSERT_EQ(
received_captured_info_fut.wait_for(std::chrono::seconds(10)), std::future_status::ready);
received_captured_info_fut.get();

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/component_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vector>
#include <atomic>
#include <future>
#include <thread>

#include "mavsdk.h"
#include "log.h"
Expand Down Expand Up @@ -67,4 +68,6 @@ TEST(SystemTest, DISABLED_ComponentInformationConnect)

// Use another parameter to trigger the second callback.
param_client.set_param_float("ANG_RATE_ACC_MAX", 6.0f);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/ftp_compare_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <chrono>
#include <future>
#include <fstream>
#include <thread>
#include "plugins/ftp/ftp.h"
#include "plugins/ftp_server/ftp_server.h"
#include "fs_helpers.h"
Expand Down Expand Up @@ -73,4 +74,6 @@ TEST(SystemTest, FtpCompareFiles)
(temp_dir_provided / temp_file).string(), temp_file_different.string());
EXPECT_EQ(result.first, Ftp::Result::Success);
EXPECT_EQ(result.second, false);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/ftp_create_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <filesystem>
#include <gtest/gtest.h>
#include <chrono>
#include <thread>

using namespace mavsdk;

Expand Down Expand Up @@ -57,4 +58,6 @@ TEST(SystemTest, FtpCreateDir)
EXPECT_EQ(ftp.create_directory(temp_dir.string()), Ftp::Result::Success);

EXPECT_TRUE(file_exists(temp_dir_provided / temp_dir));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
11 changes: 11 additions & 0 deletions src/system_tests/ftp_download_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <chrono>
#include <future>
#include <fstream>
#include <thread>
#include "plugins/ftp/ftp.h"
#include "plugins/ftp_server/ftp_server.h"
#include "fs_helpers.h"
Expand Down Expand Up @@ -92,6 +93,8 @@ TEST(SystemTest, FtpDownloadFile)
EXPECT_TRUE(
are_files_identical(temp_dir_provided / temp_file, temp_dir_downloaded / temp_file));
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadBigFile)
Expand Down Expand Up @@ -147,6 +150,8 @@ TEST(SystemTest, FtpDownloadBigFile)

EXPECT_TRUE(
are_files_identical(temp_dir_provided / temp_file, temp_dir_downloaded / temp_file));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadBigFileLossy)
Expand Down Expand Up @@ -213,6 +218,8 @@ TEST(SystemTest, FtpDownloadBigFileLossy)
// drop_some callback which accesses the local counter variable.
mavsdk_groundstation.intercept_incoming_messages_async(nullptr);
mavsdk_groundstation.intercept_outgoing_messages_async(nullptr);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadStopAndTryAgain)
Expand Down Expand Up @@ -302,6 +309,8 @@ TEST(SystemTest, FtpDownloadStopAndTryAgain)
ASSERT_EQ(future_status, std::future_status::ready);
EXPECT_EQ(fut.get(), Ftp::Result::Success);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadFileOutsideOfRoot)
Expand Down Expand Up @@ -352,4 +361,6 @@ TEST(SystemTest, FtpDownloadFileOutsideOfRoot)
ASSERT_EQ(future_status, std::future_status::ready);
EXPECT_EQ(fut.get(), Ftp::Result::ProtocolError);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
11 changes: 11 additions & 0 deletions src/system_tests/ftp_download_file_burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <chrono>
#include <future>
#include <fstream>
#include <thread>
#include "plugins/ftp/ftp.h"
#include "plugins/ftp_server/ftp_server.h"
#include "fs_helpers.h"
Expand Down Expand Up @@ -92,6 +93,8 @@ TEST(SystemTest, FtpDownloadBurstFile)
EXPECT_TRUE(
are_files_identical(temp_dir_provided / temp_file, temp_dir_downloaded / temp_file));
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadBurstBigFile)
Expand Down Expand Up @@ -147,6 +150,8 @@ TEST(SystemTest, FtpDownloadBurstBigFile)

EXPECT_TRUE(
are_files_identical(temp_dir_provided / temp_file, temp_dir_downloaded / temp_file));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadBurstBigFileLossy)
Expand Down Expand Up @@ -213,6 +218,8 @@ TEST(SystemTest, FtpDownloadBurstBigFileLossy)
// drop_some callback which accesses the local counter variable.
mavsdk_groundstation.intercept_incoming_messages_async(nullptr);
mavsdk_groundstation.intercept_outgoing_messages_async(nullptr);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadBurstStopAndTryAgain)
Expand Down Expand Up @@ -302,6 +309,8 @@ TEST(SystemTest, FtpDownloadBurstStopAndTryAgain)
ASSERT_EQ(future_status, std::future_status::ready);
EXPECT_EQ(fut.get(), Ftp::Result::Success);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpDownloadBurstFileOutsideOfRoot)
Expand Down Expand Up @@ -352,4 +361,6 @@ TEST(SystemTest, FtpDownloadBurstFileOutsideOfRoot)
ASSERT_EQ(future_status, std::future_status::ready);
EXPECT_EQ(fut.get(), Ftp::Result::ProtocolError);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/ftp_list_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <filesystem>
#include <gtest/gtest.h>
#include <chrono>
#include <thread>

using namespace mavsdk;

Expand Down Expand Up @@ -73,4 +74,6 @@ TEST(SystemTest, FtpListDir)
EXPECT_EQ(ret.first, Ftp::Result::Success);

EXPECT_EQ(ret.second, truth_list);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
5 changes: 5 additions & 0 deletions src/system_tests/ftp_remove_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <filesystem>
#include <gtest/gtest.h>
#include <chrono>
#include <thread>

using namespace mavsdk;

Expand Down Expand Up @@ -58,6 +59,8 @@ TEST(SystemTest, FtpRemoveDir)
EXPECT_EQ(ftp.remove_directory(temp_dir.string()), Ftp::Result::Success);

EXPECT_FALSE(file_exists(temp_dir_provided / temp_dir));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpRemoveDirNotEmpty)
Expand Down Expand Up @@ -97,4 +100,6 @@ TEST(SystemTest, FtpRemoveDirNotEmpty)
EXPECT_EQ(ftp.remove_directory(temp_dir.string()), Ftp::Result::ProtocolError);

EXPECT_TRUE(file_exists(temp_dir_provided / temp_dir));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
7 changes: 7 additions & 0 deletions src/system_tests/ftp_remove_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <chrono>
#include <future>
#include <fstream>
#include <thread>
#include "plugins/ftp/ftp.h"
#include "plugins/ftp_server/ftp_server.h"
#include "fs_helpers.h"
Expand Down Expand Up @@ -58,6 +59,8 @@ TEST(SystemTest, FtpRemoveFile)
EXPECT_EQ(ftp.remove_file(temp_file.string()), Ftp::Result::Success);

EXPECT_FALSE(file_exists(temp_dir_provided / temp_file));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpRemoveFileThatDoesNotExist)
Expand Down Expand Up @@ -95,6 +98,8 @@ TEST(SystemTest, FtpRemoveFileThatDoesNotExist)
EXPECT_EQ(ftp.remove_file(temp_file.string()), Ftp::Result::FileDoesNotExist);

EXPECT_FALSE(file_exists(temp_dir_provided / temp_file));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpRemoveFileOutsideOfRoot)
Expand Down Expand Up @@ -130,4 +135,6 @@ TEST(SystemTest, FtpRemoveFileOutsideOfRoot)
ftp_server.set_root_dir(temp_dir_provided.string());

EXPECT_EQ(ftp.remove_file((fs::path("..") / temp_file).string()), Ftp::Result::ProtocolError);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/ftp_rename_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <chrono>
#include <future>
#include <fstream>
#include <thread>
#include "plugins/ftp/ftp.h"
#include "plugins/ftp_server/ftp_server.h"
#include "fs_helpers.h"
Expand Down Expand Up @@ -61,4 +62,6 @@ TEST(SystemTest, FtpRenameFile)
EXPECT_EQ(ftp.rename(temp_file.string(), temp_file_renamed.string()), Ftp::Result::Success);

EXPECT_TRUE(file_exists(temp_dir_provided / temp_file_renamed));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
11 changes: 11 additions & 0 deletions src/system_tests/ftp_upload_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <chrono>
#include <future>
#include <fstream>
#include <thread>
#include "plugins/ftp/ftp.h"
#include "plugins/ftp_server/ftp_server.h"
#include "fs_helpers.h"
Expand Down Expand Up @@ -94,6 +95,8 @@ TEST(SystemTest, FtpUploadFile)
EXPECT_TRUE(
are_files_identical(temp_dir_to_upload / temp_file, temp_dir_provided / temp_file));
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpUploadBigFile)
Expand Down Expand Up @@ -150,6 +153,8 @@ TEST(SystemTest, FtpUploadBigFile)
EXPECT_TRUE(
are_files_identical(temp_dir_to_upload / temp_file, temp_dir_provided / temp_file));
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpUploadBigFileLossy)
Expand Down Expand Up @@ -215,6 +220,8 @@ TEST(SystemTest, FtpUploadBigFileLossy)

mavsdk_groundstation.intercept_incoming_messages_async(nullptr);
mavsdk_groundstation.intercept_outgoing_messages_async(nullptr);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpUploadStopAndTryAgain)
Expand Down Expand Up @@ -302,6 +309,8 @@ TEST(SystemTest, FtpUploadStopAndTryAgain)
ASSERT_EQ(future_status, std::future_status::ready);
EXPECT_EQ(fut.get(), Ftp::Result::Success);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, FtpUploadFileOutsideOfRoot)
Expand Down Expand Up @@ -354,4 +363,6 @@ TEST(SystemTest, FtpUploadFileOutsideOfRoot)
ASSERT_EQ(future_status, std::future_status::ready);
EXPECT_EQ(fut.get(), Ftp::Result::ProtocolError);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/mission_raw_upload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "plugins/mission_raw_server/mission_raw_server.h"
#include <string>
#include <fstream>
#include <thread>
#include <gtest/gtest.h>

using namespace mavsdk;
Expand Down Expand Up @@ -42,4 +43,6 @@ TEST(SystemTest, MissionRawUpload)

EXPECT_EQ(
mission_raw.upload_mission(result_pair.second.mission_items), MissionRaw::Result::Success);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
5 changes: 5 additions & 0 deletions src/system_tests/param_custom_set_and_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "mavsdk.h"
#include "plugins/param/param.h"
#include "plugins/param_server/param_server.h"
#include <thread>
#include <gtest/gtest.h>

using namespace mavsdk;
Expand Down Expand Up @@ -79,6 +80,8 @@ TEST(SystemTest, ParamCustomSetAndGet)
auto server_result_pair = param_server.retrieve_param_custom(param_name);
EXPECT_EQ(server_result_pair.first, ParamServer::Result::Success);
EXPECT_EQ(server_result_pair.second, data_shorter);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, ParamCustomSetAndGetLossy)
Expand Down Expand Up @@ -146,4 +149,6 @@ TEST(SystemTest, ParamCustomSetAndGetLossy)
// drop_some callback which accesses the local counter variable.
mavsdk_groundstation.intercept_incoming_messages_async(nullptr);
mavsdk_groundstation.intercept_incoming_messages_async(nullptr);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
5 changes: 5 additions & 0 deletions src/system_tests/param_get_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>
#include <thread>
#include <map>
#include <thread>

using namespace mavsdk;

Expand Down Expand Up @@ -115,6 +116,8 @@ TEST(SystemTest, ParamGetAll)
assert_equal<float, Param::FloatParam>(test_float_params, all_params.float_params);
assert_equal<std::string, Param::CustomParam>(test_string_params, all_params.custom_params);
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, ParamGetAllLossy)
Expand Down Expand Up @@ -187,4 +190,6 @@ TEST(SystemTest, ParamGetAllLossy)
// drop_some callback which accesses the local counter variable.
mavsdk_groundstation.intercept_incoming_messages_async(nullptr);
mavsdk_groundstation.intercept_outgoing_messages_async(nullptr);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
3 changes: 3 additions & 0 deletions src/system_tests/param_set_and_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "plugins/param/param.h"
#include "plugins/param_server/param_server.h"
#include <chrono>
#include <thread>
#include <gtest/gtest.h>

using namespace mavsdk;
Expand Down Expand Up @@ -94,6 +95,8 @@ TEST(SystemTest, ParamSetAndGet)
auto server_result_all_params = param_server.retrieve_all_params();
EXPECT_EQ(server_result_all_params.int_params.size(), 1);
EXPECT_EQ(server_result_all_params.float_params.size(), 1);

std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

TEST(SystemTest, ParamSetAndGetLossy)
Expand Down
Loading

0 comments on commit f92e3d1

Please sign in to comment.