Skip to content

Commit

Permalink
test: enable asan on travis
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Jan 21, 2020
1 parent 54a86fd commit e35bbeb
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ before_script:
script:
- mkdir build
- cd build
- cmake -DCODE_COVERAGE=ON -DTRAVIS=ON -DCMAKE_BUILD_TYPE=Debug ../
- cmake -DCODE_COVERAGE=ON -DTRAVIS=ON -DUSEASAN=ON -DCMAKE_BUILD_TYPE=Debug ../
- cmake --build . --config Debug -- -j8

after_success:
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(CicadaMedia)

#set(USEASAN ON)
#set(USETSAN ON)
#set(USEUBSAN ON)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# set(USEMSAN ON)
endif ()
add_subdirectory(cmdline)


Expand Down
7 changes: 0 additions & 7 deletions cmdline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ project(cicadaPlayer)

set(CMAKE_CXX_STANDARD 11)

#set(USEASAN ON)
#set(USETSAN ON)
#set(USEUBSAN ON)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# set(USEMSAN ON)
endif ()

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
else ()
set(CMAKE_CXX_FLAGS "-fprofile-instr-generate -fcoverage-mapping")
Expand Down
4 changes: 4 additions & 0 deletions framework/cacheModule/CacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>
#include <utils/mediaTypeInternal.h>
#include <vector>
#include <utils/mediaFrame.h>

CacheManager::CacheManager()
{
Expand Down Expand Up @@ -98,6 +99,9 @@ void CacheManager::sendMediaFrame(const unique_ptr<IAFPacket> &frame, StreamType

if (metaRet == 0) {
streamMetas.push_back(audioMeta);
} else {
releaseMeta(audioMeta);
free(audioMeta);
}
}
mCacheModule.setStreamMeta(streamMetas);
Expand Down
1 change: 1 addition & 0 deletions framework/cacheModule/CacheModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ void CacheModule::clearStreamMetas()
if (!mStreamMetas.empty()) {
for (auto &item : mStreamMetas) {
releaseMeta(item);
free(item);
}

mStreamMetas.clear();
Expand Down
10 changes: 10 additions & 0 deletions framework/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ if (!HAVE_COVERAGE_CONFIG)
include(../code_coverage.cmake)
endif ()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(TARGET_PLATFORM macOSX)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(TARGET_PLATFORM Linux)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(TARGET_PLATFORM windows)
endif ()

include(../${TARGET_PLATFORM}.cmake)

include(GoogleTest.cmake)
add_subdirectory(dataSource)
add_subdirectory(render)
Expand Down
2 changes: 2 additions & 0 deletions framework/tests/dataSource/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if (APPLE)
include(../Apple.cmake)
endif ()

include(../../${TARGET_PLATFORM}.cmake)

cmake_policy(SET CMP0079 NEW)
add_executable(dataSourceTest "")

Expand Down
1 change: 1 addition & 0 deletions framework/tests/dataSource/dataSourceUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ TEST(protocol, file)
char *obuffer = static_cast<char *>(malloc(strlen(buffer) + 1));
source->Read(obuffer, strlen(buffer) + 1);
ASSERT_EQ(memcmp(buffer, obuffer, strlen(buffer) + 1), 0);
free(obuffer);
}

TEST(dns, https)
Expand Down
1 change: 1 addition & 0 deletions framework/tests/decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (APPLE)
include(../Apple.cmake)
endif ()

include(../../${TARGET_PLATFORM}.cmake)
target_sources(decoderUnitTest
PRIVATE
decoderUnitTest.cpp
Expand Down
2 changes: 2 additions & 0 deletions framework/tests/demuxer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (APPLE)
include(../Apple.cmake)
endif ()

include(../../${TARGET_PLATFORM}.cmake)

target_sources(demuxerUnitTest
PRIVATE
demuxerUnitTest.cpp
Expand Down
2 changes: 2 additions & 0 deletions framework/tests/render/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (APPLE)
include(../Apple.cmake)
endif ()

include(../../${TARGET_PLATFORM}.cmake)

target_sources(renderTest
PRIVATE

Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/tests/apiTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endif ()
if (APPLE)
include(../../../framework/tests/Apple.cmake)
endif ()
include(../../../framework/${TARGET_PLATFORM}.cmake)

add_executable(mediaPlayerApiTest "")

Expand Down
3 changes: 3 additions & 0 deletions mediaPlayer/tests/apiTest/mediaPlayerApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utils/timer.h>
#include "tests/player_command.h"
#include <vector>
#include <utils/mediaFrame.h>

using namespace std;

Expand Down Expand Up @@ -204,6 +205,8 @@ static void getApiOnPrepared(void *arg)

Stream_meta meta{};
apiPlayer->GetCurrentStreamMeta(&meta, ST_TYPE_VIDEO);
releaseMeta(&meta);

}

TEST(coverag, getApi)
Expand Down
2 changes: 2 additions & 0 deletions mediaPlayer/tests/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (APPLE)
include(../../../framework/tests/Apple.cmake)
endif ()

include(../../../framework/${TARGET_PLATFORM}.cmake)

add_executable(mediaPlayerCacheTest "")

target_sources(mediaPlayerCacheTest
Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/tests/formatTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (APPLE)
include(../../../framework/tests/Apple.cmake)
endif ()

include(../../../framework/${TARGET_PLATFORM}.cmake)
add_executable(mediaPlayerFormatTest "")

target_sources(mediaPlayerFormatTest
Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/tests/player_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int command_loop(Cicada::MediaPlayer *player, void *arg)
return -1;
return 0;
}
std::unique_lock <std::mutex>lock(pCase->mMutex);
player_command &cmd = pCase->mCommands.front();
if (cmd.timestamp < af_getsteady_ms()) {
switch (cmd.mID) {
Expand Down
2 changes: 2 additions & 0 deletions mediaPlayer/tests/player_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <MediaPlayer.h>
#include <vector>
#include <mutex>

class player_command {
public:
Expand Down Expand Up @@ -44,6 +45,7 @@ class commandsCase {
}

std::vector<player_command> &mCommands;
std::mutex mMutex;
bool mExitOnEmpty{true};
};

Expand Down
2 changes: 2 additions & 0 deletions mediaPlayer/tests/seekTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (APPLE)
include(../../../framework/tests/Apple.cmake)
endif ()

include(../../../framework/${TARGET_PLATFORM}.cmake)

add_executable(mediaPlayerSeekTest "")

target_sources(mediaPlayerSeekTest
Expand Down
2 changes: 2 additions & 0 deletions mediaPlayer/tests/switch_stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (APPLE)
include(../../../framework/tests/Apple.cmake)
endif ()

include(../../../framework/${TARGET_PLATFORM}.cmake)

add_executable(mediaPlayerSwitchStreamTest "")

target_sources(mediaPlayerSwitchStreamTest
Expand Down
12 changes: 10 additions & 2 deletions mediaPlayer/tests/switch_stream/mediaPlayerSwitchStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void createTestCase_switchVideo(commandsCase &testCase)
testCase.mCommands.push_back(cmd);
cmd.mID = player_command::selectStream;
int64_t start_time = af_getsteady_ms();
std::unique_lock <std::mutex>lock(testCase.mMutex);
for (int i = 0; i < count; i++) {
cmd.timestamp = i * posDelta + start_time;
cmd.arg0 = i;
Expand Down Expand Up @@ -79,6 +80,7 @@ static void createTestCase_switchSubtitle(commandsCase &testCase)
cmd.timestamp += 3 * posDelta;
cmd.mID = player_command::setLoop;
cmd.arg0 = 0;
std::unique_lock <std::mutex>lock(testCase.mMutex);
testCase.mCommands.push_back(cmd);
}

Expand All @@ -89,7 +91,10 @@ static void onPrepared_video(void *userData)
player_command cmd;
cmd.mID = player_command::start;
cmd.timestamp = af_getsteady_ms();
testCase->mCommands.push_back(cmd);
{
std::unique_lock<std::mutex> lock(testCase->mMutex);
testCase->mCommands.push_back(cmd);
}
createTestCase_switchVideo(*testCase);
testCase->mExitOnEmpty = true;
}
Expand All @@ -102,7 +107,10 @@ static void onPrepared_subtitle(void *userData)
player_command cmd;
cmd.mID = player_command::start;
cmd.timestamp = af_getsteady_ms();
testCase->mCommands.push_back(cmd);
{
std::unique_lock <std::mutex>lock(testCase->mMutex);
testCase->mCommands.push_back(cmd);
}
createTestCase_switchSubtitle(*testCase);
testCase->mExitOnEmpty = true;
}
Expand Down

0 comments on commit e35bbeb

Please sign in to comment.