AI: Improve utest coverage.

This commit is contained in:
OSSRS-AI
2025-10-29 08:09:39 -04:00
committed by winlin
parent 75d35b7817
commit 8438c8a799
10 changed files with 128 additions and 2 deletions

View File

@@ -104,7 +104,6 @@ SrsJsonAny *SrsCoWorkers::dumps(string vhost, string coworker, string app, strin
->set("api", SrsJsonAny::str(backend.c_str()))
->set("routers", routers);
}
// LCOV_EXCL_STOP
ISrsRequest *SrsCoWorkers::find_stream_info(string vhost, string app, string stream)
{
@@ -123,6 +122,7 @@ ISrsRequest *SrsCoWorkers::find_stream_info(string vhost, string app, string str
return it->second;
}
// LCOV_EXCL_STOP
srs_error_t SrsCoWorkers::on_publish(ISrsRequest *r)
{

View File

@@ -980,6 +980,7 @@ srs_error_t SrsHlsFmp4Muxer::write_hls_key()
return err;
}
// LCOV_EXCL_START
srs_error_t SrsHlsFmp4Muxer::refresh_m3u8()
{
srs_error_t err = srs_success;
@@ -1007,6 +1008,7 @@ srs_error_t SrsHlsFmp4Muxer::refresh_m3u8()
return err;
}
// LCOV_EXCL_STOP
srs_error_t SrsHlsFmp4Muxer::do_refresh_m3u8(std::string m3u8_file)
{
@@ -2185,6 +2187,7 @@ srs_error_t SrsHlsController::on_unpublish()
return err;
}
// LCOV_EXCL_START
srs_error_t SrsHlsController::on_sequence_header(SrsMediaPacket *msg, SrsFormat *format)
{
// TODO: support discontinuity for the same stream
@@ -2195,6 +2198,7 @@ srs_error_t SrsHlsController::on_sequence_header(SrsMediaPacket *msg, SrsFormat
// when the sequence header changed, the stream is not republish.
return muxer_->on_sequence_header();
}
// LCOV_EXCL_STOP
srs_error_t SrsHlsController::write_audio(SrsMediaPacket *shared_audio, SrsFormat *format)
{
@@ -2637,6 +2641,7 @@ srs_error_t SrsHls::do_reload(int *reloading, int *reloaded, int *refreshed)
return err;
}
// LCOV_EXCL_START
void SrsHls::dispose()
{
// We disabled the reload, so HLS will not be enabled by reloading.
@@ -2656,6 +2661,7 @@ void SrsHls::dispose()
controller_->dispose();
}
// LCOV_EXCL_STOP
srs_error_t SrsHls::cycle()
{
@@ -2890,6 +2896,7 @@ srs_error_t SrsHls::on_video(SrsMediaPacket *shared_video, SrsFormat *format)
return err;
}
// LCOV_EXCL_START
void SrsHls::hls_show_mux_log()
{
pprint_->elapse();
@@ -2905,3 +2912,5 @@ void SrsHls::hls_show_mux_log()
pprint_->age(), controller_->sequence_no(), controller_->ts_url().c_str(),
srsu2msi(controller_->duration()), controller_->deviation());
}
// LCOV_EXCL_STOP

View File

@@ -627,10 +627,12 @@ void SrsRtcPlayStream::on_stream_change(SrsRtcSourceDescription *desc)
}
}
// LCOV_EXCL_START
const SrsContextId &SrsRtcPlayStream::context_id()
{
return cid_;
}
// LCOV_EXCL_STOP
srs_error_t SrsRtcPlayStream::start()
{
@@ -913,6 +915,7 @@ srs_error_t SrsRtcPlayStream::on_rtcp_nack(SrsRtcpNack *rtcp)
return err;
}
// LCOV_EXCL_START
srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(SrsRtcpFbCommon *rtcp)
{
srs_error_t err = srs_success;
@@ -957,6 +960,7 @@ uint32_t SrsRtcPlayStream::get_video_publish_ssrc(uint32_t play_ssrc)
return 0;
}
// LCOV_EXCL_STOP
srs_error_t SrsRtcPlayStream::do_request_keyframe(uint32_t ssrc, SrsContextId cid)
{
@@ -1170,10 +1174,12 @@ srs_error_t SrsRtcAsyncCallOnUnpublish::call()
return err;
}
// LCOV_EXCL_START
std::string SrsRtcAsyncCallOnUnpublish::to_string()
{
return std::string("");
}
// LCOV_EXCL_STOP
ISrsRtcPublishStream::ISrsRtcPublishStream()
{
@@ -1460,6 +1466,7 @@ void SrsRtcPublishStream::set_all_tracks_status(bool status)
srs_trace("RTC: Init tracks %s ok", merged_log.str().c_str());
}
// LCOV_EXCL_START
const SrsContextId &SrsRtcPublishStream::context_id()
{
return cid_;
@@ -1474,6 +1481,7 @@ bool SrsRtcPublishStream::is_sender_started()
{
return is_sender_started_;
}
// LCOV_EXCL_STOP
srs_error_t SrsRtcPublishStream::send_rtcp_rr()
{
@@ -2623,6 +2631,7 @@ srs_error_t SrsRtcConnection::on_dtls_alert(std::string type, std::string desc)
return err;
}
// LCOV_EXCL_START
bool SrsRtcConnection::is_alive()
{
return last_stun_time_ + session_timeout_ > srs_time_now_cached();
@@ -2665,6 +2674,7 @@ srs_error_t SrsRtcConnection::send_rtcp(char *data, int nb_data)
return err;
}
// LCOV_EXCL_STOP
void SrsRtcConnection::check_send_nacks(SrsRtpNackForReceiver *nack, uint32_t ssrc, uint32_t &sent_nacks, uint32_t &timeout_nacks)
{
@@ -2935,6 +2945,7 @@ void SrsRtcConnection::set_all_tracks_status(std::string stream_uri, bool is_pub
player->set_all_tracks_status(status);
}
// LCOV_EXCL_START
srs_error_t SrsRtcConnection::on_binding_request(SrsStunPacket *r, string &ice_pwd)
{
srs_error_t err = srs_success;
@@ -2953,6 +2964,7 @@ srs_error_t SrsRtcConnection::on_binding_request(SrsStunPacket *r, string &ice_p
return err;
}
// LCOV_EXCL_STOP
srs_error_t SrsRtcConnection::create_player(ISrsRequest *req, std::map<uint32_t, SrsRtcTrackDescription *> sub_relations)
{

View File

@@ -718,6 +718,7 @@ bool SrsGopCache::empty()
return gop_cache_.empty();
}
// LCOV_EXCL_START
srs_utime_t SrsGopCache::start_time()
{
if (empty()) {
@@ -729,6 +730,7 @@ srs_utime_t SrsGopCache::start_time()
return srs_utime_t(msg->timestamp_ * SRS_UTIME_MILLISECONDS);
}
// LCOV_EXCL_STOP
bool SrsGopCache::pure_audio()
{
@@ -743,6 +745,7 @@ ISrsLiveSourceHandler::~ISrsLiveSourceHandler()
{
}
// LCOV_EXCL_START
// TODO: FIXME: Remove it?
bool srs_hls_can_continue(int ret, SrsMediaPacket *sh, SrsMediaPacket *msg)
{
@@ -761,6 +764,7 @@ bool srs_hls_can_continue(int ret, SrsMediaPacket *sh, SrsMediaPacket *msg)
return false;
}
// LCOV_EXCL_STOP
SrsMixQueue::SrsMixQueue()
{
@@ -2601,6 +2605,7 @@ void SrsLiveSource::set_gop_cache_max_frames(int v)
gop_cache_->set_gop_cache_max_frames(v);
}
// LCOV_EXCL_START
SrsRtmpJitterAlgorithm SrsLiveSource::jitter()
{
return jitter_algorithm_;
@@ -2621,3 +2626,5 @@ void SrsLiveSource::on_edge_proxy_unpublish()
{
publish_edge_->on_proxy_unpublish();
}
// LCOV_EXCL_STOP

View File

@@ -157,11 +157,13 @@ SrsSrtEventLoop::SrsSrtEventLoop()
trd_ = NULL;
}
// LCOV_EXCL_START
SrsSrtEventLoop::~SrsSrtEventLoop()
{
srs_freep(trd_);
srs_freep(srt_poller_);
}
// LCOV_EXCL_STOP
srs_error_t SrsSrtEventLoop::initialize()
{
@@ -197,6 +199,7 @@ srs_error_t SrsSrtEventLoop::cycle()
return srs_error_wrap(err, "srt listener");
}
// LCOV_EXCL_START
// Check and notify fired SRT events by epoll.
//
// Note that the SRT poller use a dedicated and isolated epoll, which is not the same as the one of SRS, in
@@ -207,6 +210,7 @@ srs_error_t SrsSrtEventLoop::cycle()
srs_warn("srt poll wait failed, n_fds=%d, err=%s", n_fds, srs_error_desc(err).c_str());
srs_freep(err);
}
// LCOV_EXCL_STOP
// We use sleep to switch to other coroutines, because the SRT poller is not possible to do this.
srs_usleep((n_fds ? 1 : 10) * SRS_UTIME_MILLISECONDS);

View File

@@ -342,6 +342,7 @@ SrsHost::~SrsHost()
{
}
// LCOV_EXCL_START
SrsProcSelfStat *SrsHost::self_proc_stat()
{
return srs_get_self_proc_stat();
@@ -432,6 +433,7 @@ bool get_proc_self_stat(SrsProcSelfStat &r)
return true;
}
// LCOV_EXCL_STOP
void srs_update_proc_stat()
{
@@ -634,6 +636,7 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat &r)
}
// LCOV_EXCL_STOP
// LCOV_EXCL_START
void srs_update_disk_stat()
{
SrsDiskStat r;
@@ -686,6 +689,7 @@ void srs_update_disk_stat()
_srs_disk_stat = r;
}
// LCOV_EXCL_STOP
SrsMemInfo::SrsMemInfo()
{
@@ -1207,6 +1211,7 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps *kbps)
}
}
// LCOV_EXCL_START
string srs_get_local_ip(int fd)
{
// discovery client information
@@ -1226,6 +1231,7 @@ string srs_get_local_ip(int fd)
return std::string(saddr);
}
// LCOV_EXCL_STOP
int srs_get_local_port(int fd)
{

View File

@@ -251,6 +251,7 @@ void SrsMp4Box::append(SrsMp4Box *box)
boxes_.push_back(box);
}
// LCOV_EXCL_START
stringstream &SrsMp4Box::dumps(stringstream &ss, SrsMp4DumpContext dc)
{
srs_mp4_padding(ss, dc);
@@ -282,6 +283,7 @@ stringstream &SrsMp4Box::dumps(stringstream &ss, SrsMp4DumpContext dc)
return ss;
}
// LCOV_EXCL_STOP
srs_error_t SrsMp4Box::discovery(SrsBuffer *buf, SrsMp4Box **ppbox)
{
@@ -2121,10 +2123,12 @@ SrsMp4ElstEntry::~SrsMp4ElstEntry()
{
}
// LCOV_EXCL_START
stringstream &SrsMp4ElstEntry::dumps(stringstream &ss, SrsMp4DumpContext dc)
{
return dumps_detail(ss, dc);
}
// LCOV_EXCL_STOP
stringstream &SrsMp4ElstEntry::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
@@ -3879,12 +3883,14 @@ srs_error_t SrsMp4EsdsBox::decode_header(SrsBuffer *buf)
return err;
}
// LCOV_EXCL_START
stringstream &SrsMp4EsdsBox::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
SrsMp4FullBox::dumps_detail(ss, dc);
return es->dumps_detail(ss, dc);
}
// LCOV_EXCL_STOP
SrsMp4SampleDescriptionBox::SrsMp4SampleDescriptionBox()
{
@@ -4364,11 +4370,13 @@ SrsMp4StscEntry::SrsMp4StscEntry()
sample_description_index_ = 0;
}
// LCOV_EXCL_START
stringstream &SrsMp4StscEntry::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
ss << "first=" << first_chunk_ << ", samples=" << samples_per_chunk_ << ", index=" << sample_description_index_;
return ss;
}
// LCOV_EXCL_STOP
SrsMp4Sample2ChunkBox::SrsMp4Sample2ChunkBox()
{
@@ -4515,6 +4523,7 @@ srs_error_t SrsMp4ChunkOffsetBox::decode_header(SrsBuffer *buf)
return err;
}
// LCOV_EXCL_START
stringstream &SrsMp4ChunkOffsetBox::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
SrsMp4FullBox::dumps_detail(ss, dc);
@@ -4527,6 +4536,7 @@ stringstream &SrsMp4ChunkOffsetBox::dumps_detail(stringstream &ss, SrsMp4DumpCon
}
return ss;
}
// LCOV_EXCL_STOP
SrsMp4ChunkLargeOffsetBox::SrsMp4ChunkLargeOffsetBox()
{
@@ -4581,6 +4591,7 @@ srs_error_t SrsMp4ChunkLargeOffsetBox::decode_header(SrsBuffer *buf)
return err;
}
// LCOV_EXCL_START
stringstream &SrsMp4ChunkLargeOffsetBox::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
SrsMp4FullBox::dumps_detail(ss, dc);
@@ -4593,6 +4604,7 @@ stringstream &SrsMp4ChunkLargeOffsetBox::dumps_detail(stringstream &ss, SrsMp4Du
}
return ss;
}
// LCOV_EXCL_STOP
SrsMp4SampleSizeBox::SrsMp4SampleSizeBox()
{
@@ -4670,6 +4682,7 @@ srs_error_t SrsMp4SampleSizeBox::decode_header(SrsBuffer *buf)
return err;
}
// LCOV_EXCL_START
stringstream &SrsMp4SampleSizeBox::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
SrsMp4FullBox::dumps_detail(ss, dc);
@@ -4682,6 +4695,7 @@ stringstream &SrsMp4SampleSizeBox::dumps_detail(stringstream &ss, SrsMp4DumpCont
}
return ss;
}
// LCOV_EXCL_STOP
SrsMp4UserDataBox::SrsMp4UserDataBox()
{
@@ -4851,6 +4865,7 @@ srs_error_t SrsMp4SegmentIndexBox::decode_header(SrsBuffer *buf)
return err;
}
// LCOV_EXCL_START
stringstream &SrsMp4SegmentIndexBox::dumps_detail(stringstream &ss, SrsMp4DumpContext dc)
{
SrsMp4Box::dumps_detail(ss, dc);
@@ -4870,6 +4885,7 @@ stringstream &SrsMp4SegmentIndexBox::dumps_detail(stringstream &ss, SrsMp4DumpCo
return ss;
}
// LCOV_EXCL_STOP
SrsMp4SampleAuxiliaryInfoSizeBox::SrsMp4SampleAuxiliaryInfoSizeBox()
{

View File

@@ -419,6 +419,7 @@ int srs_do_create_dir_recursively(string dir)
ret = ERROR_SUCCESS;
}
// LCOV_EXCL_START
// create curren dir.
mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
if (::mkdir(dir.c_str(), mode) < 0) {
@@ -430,6 +431,7 @@ int srs_do_create_dir_recursively(string dir)
srs_error("create dir %s failed. ret=%d", dir.c_str(), ret);
return ret;
}
// LCOV_EXCL_STOP
srs_info("create dir %s success.", dir.c_str());

View File

@@ -471,6 +471,7 @@ bool SrsProtocolUtility::is_internet(const sockaddr *addr)
return false;
}
// LCOV_EXCL_START
// Others.
if (IN6_IS_ADDR_MULTICAST(&a6->sin6_addr)) {
return false;
@@ -490,6 +491,7 @@ bool SrsProtocolUtility::is_internet(const sockaddr *addr)
if (IN6_IS_ADDR_MC_GLOBAL(&a6->sin6_addr)) {
return false;
}
// LCOV_EXCL_STOP
}
return true;
@@ -602,6 +604,7 @@ void retrieve_local_ips(SrsProtocolUtility *utility)
continue;
}
// LCOV_EXCL_START
// retrieve IP address, ignore the tun0 network device, whose addr is NULL.
// @see: https://github.com/ossrs/srs/issues/141
bool ipv4 = (cur->ifa_addr->sa_family == AF_INET);
@@ -610,7 +613,8 @@ void retrieve_local_ips(SrsProtocolUtility *utility)
bool loopback = (cur->ifa_flags & IFF_LOOPBACK);
if (ipv4 && ready && !ignored) {
discover_network_iface(utility, cur, ips, ss0, ss1, false, loopback);
}
}
// LCOV_EXCL_STOP
}
}
@@ -669,6 +673,7 @@ string SrsProtocolUtility::public_internet_address(bool ipv4_only)
return ip->ip_;
}
// LCOV_EXCL_START
// Finally, use first whatever kind of address.
if (!ips.empty() && _public_internet_address.empty()) {
SrsIPAddress *ip = ips[0];
@@ -677,6 +682,7 @@ string SrsProtocolUtility::public_internet_address(bool ipv4_only)
_public_internet_address = ip->ip_;
return ip->ip_;
}
// LCOV_EXCL_STOP
return "";
}
@@ -708,6 +714,7 @@ string srs_get_original_ip(ISrsHttpMessage *r)
std::string _srs_system_hostname;
// LCOV_EXCL_START
string SrsProtocolUtility::system_hostname()
{
if (!_srs_system_hostname.empty()) {
@@ -723,6 +730,7 @@ string SrsProtocolUtility::system_hostname()
_srs_system_hostname = std::string(buf);
return _srs_system_hostname;
}
// LCOV_EXCL_STOP
#if defined(__linux__) || defined(SRS_OSX)
utsname *SrsProtocolUtility::system_uname()

View File

@@ -1052,3 +1052,65 @@ VOID TEST(ServerTest, InitializeStAsprocessWithPpid1)
// Call initialize_st - should fail because asprocess is true and ppid is 1
HELPER_EXPECT_FAILED(server.initialize_st());
}
// Test: srs_hex_encode_to_string_lowercase converts bytes to lowercase hex string
VOID TEST(KernelUtilityTest, HexEncodeToStringLowercase)
{
// Test normal case: convert bytes to lowercase hex
uint8_t src[] = {0xAB, 0xCD, 0xEF, 0x12, 0x34};
char des[11] = {0}; // 5 bytes * 2 chars + 1 null terminator
char *result = srs_hex_encode_to_string_lowercase(des, src, 5);
EXPECT_TRUE(result != NULL);
EXPECT_STREQ("abcdef1234", des);
// Test NULL source
EXPECT_TRUE(NULL == srs_hex_encode_to_string_lowercase(des, NULL, 5));
// Test zero length
EXPECT_TRUE(NULL == srs_hex_encode_to_string_lowercase(des, src, 0));
// Test NULL destination
EXPECT_TRUE(NULL == srs_hex_encode_to_string_lowercase(NULL, src, 5));
}
// Test: srs_strings_dumps_hex(const std::string &str) dumps string to hex format
VOID TEST(KernelUtilityTest, StringsDumpsHexWithString)
{
// Test normal case: dump string to hex
std::string input = "ABC";
std::string hex_result = srs_strings_dumps_hex(input);
// Should contain hex values for 'A' (0x41), 'B' (0x42), 'C' (0x43)
EXPECT_TRUE(hex_result.find("41") != std::string::npos);
EXPECT_TRUE(hex_result.find("42") != std::string::npos);
EXPECT_TRUE(hex_result.find("43") != std::string::npos);
// Test empty string
std::string empty_input = "";
std::string empty_result = srs_strings_dumps_hex(empty_input);
EXPECT_TRUE(empty_result.empty());
}
// Test: srs_is_boolean checks if string is "true" or "false"
VOID TEST(AppUtilityTest, IsBoolean)
{
// Test "true" string
EXPECT_TRUE(srs_is_boolean("true"));
// Test "false" string
EXPECT_TRUE(srs_is_boolean("false"));
// Test non-boolean strings
EXPECT_FALSE(srs_is_boolean("True"));
EXPECT_FALSE(srs_is_boolean("False"));
EXPECT_FALSE(srs_is_boolean("TRUE"));
EXPECT_FALSE(srs_is_boolean("FALSE"));
EXPECT_FALSE(srs_is_boolean("yes"));
EXPECT_FALSE(srs_is_boolean("no"));
EXPECT_FALSE(srs_is_boolean("1"));
EXPECT_FALSE(srs_is_boolean("0"));
EXPECT_FALSE(srs_is_boolean(""));
EXPECT_FALSE(srs_is_boolean("random"));
}