Skip to content

Commit 7589063

Browse files
committed
Enable default configure test.
1 parent ef048b0 commit 7589063

File tree

4 files changed

+175
-1
lines changed

4 files changed

+175
-1
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
- name: Checkout repository
7171
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
7272
# Build for Ubuntu20
73+
- name: Build on Ubuntu20, default
74+
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-default .
7375
- name: Build on Ubuntu20, baseline
7476
run: DOCKER_BUILDKIT=1 docker build -f trunk/Dockerfile.builds --target ubuntu20-baseline .
7577
- name: Build on Ubuntu20, with all features

trunk/Dockerfile.builds

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ FROM ossrs/srs:ubuntu20-cache AS ubuntu20-baseline
4242
COPY . /srs
4343
RUN cd /srs/trunk && ./configure --sanitizer=on --srt=off --gb28181=off && make
4444

45+
FROM ossrs/srs:ubuntu20-cache AS ubuntu20-default
46+
COPY . /srs
47+
# Remove the ST from cache, which build with sanitizer, but we are not by default.
48+
RUN cd /usr/local/srs-cache/srs/trunk && rm -rf objs/Platform-*/3rdparty/st && du -sh objs/Platform-*/3rdparty/*
49+
RUN cd /srs/trunk && ./configure && make
50+
4551
FROM ossrs/srs:ubuntu20-cache AS ubuntu20-all
4652
COPY . /srs
4753
RUN cd /srs/trunk && ./configure --sanitizer=on --srt=on --gb28181=on --apm=on --h265=on && make

trunk/src/kernel/srs_kernel_utility.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ srs_error_t SrsPath::unlink(std::string path)
567567
"/usr",
568568
"/var",
569569
};
570-
for (int i = 0; i < sizeof(forbidden) / sizeof(forbidden[0]); i++) {
570+
for (int i = 0; i < (int)(sizeof(forbidden) / sizeof(string)); i++) {
571571
if (path == forbidden[i]) {
572572
return srs_error_new(ERROR_SYSTEM_FILE_UNLINK, "unlink forbidden %s", path.c_str());
573573
}

trunk/src/utest/srs_utest_ai24.cpp

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
#include <srs_kernel_error.hpp>
1010
#include <srs_kernel_rtc_rtcp.hpp>
1111
#include <srs_protocol_sdp.hpp>
12+
#include <srs_kernel_packet.hpp>
13+
#include <srs_kernel_codec.hpp>
14+
15+
#ifdef SRS_FFMPEG_FIT
16+
#include <srs_app_rtc_codec.hpp>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
#include <libavutil/log.h>
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
#endif
1226

1327
using namespace std;
1428

@@ -303,3 +317,155 @@ VOID TEST(RtcAVSyncTest, ZeroTimeElapsedBetweenSRs)
303317
// Rate should remain unchanged (SDP rate)
304318
EXPECT_DOUBLE_EQ(rate_before, track.get_rate());
305319
}
320+
321+
// Test: SrsParsedPacket::copy() method
322+
VOID TEST(ParsedPacketTest, CopyParsedPacket)
323+
{
324+
srs_error_t err;
325+
326+
// Create a parsed packet with sample data
327+
SrsParsedPacket packet;
328+
SrsVideoCodecConfig codec;
329+
HELPER_EXPECT_SUCCESS(packet.initialize(&codec));
330+
331+
// Set packet properties
332+
packet.dts_ = 1000;
333+
packet.cts_ = 100;
334+
335+
// Add sample data
336+
char sample_data1[] = {0x01, 0x02, 0x03};
337+
char sample_data2[] = {0x04, 0x05, 0x06, 0x07};
338+
HELPER_EXPECT_SUCCESS(packet.add_sample(sample_data1, sizeof(sample_data1)));
339+
HELPER_EXPECT_SUCCESS(packet.add_sample(sample_data2, sizeof(sample_data2)));
340+
341+
// Copy the packet
342+
SrsParsedPacket *copied = packet.copy();
343+
ASSERT_TRUE(copied != NULL);
344+
345+
// Verify all fields are copied correctly
346+
EXPECT_EQ(packet.dts_, copied->dts_);
347+
EXPECT_EQ(packet.cts_, copied->cts_);
348+
EXPECT_EQ(packet.codec_, copied->codec_);
349+
EXPECT_EQ(packet.nb_samples_, copied->nb_samples_);
350+
351+
// Verify samples are copied (shared pointers)
352+
for (int i = 0; i < packet.nb_samples_; i++) {
353+
EXPECT_EQ(packet.samples_[i].bytes_, copied->samples_[i].bytes_);
354+
EXPECT_EQ(packet.samples_[i].size_, copied->samples_[i].size_);
355+
}
356+
357+
srs_freep(copied);
358+
}
359+
360+
// Test: SrsParsedVideoPacket::copy() method
361+
VOID TEST(ParsedPacketTest, CopyParsedVideoPacket)
362+
{
363+
srs_error_t err;
364+
365+
// Create a parsed video packet with sample data
366+
SrsParsedVideoPacket packet;
367+
SrsVideoCodecConfig codec;
368+
HELPER_EXPECT_SUCCESS(packet.initialize(&codec));
369+
370+
// Set packet properties
371+
packet.dts_ = 2000;
372+
packet.cts_ = 200;
373+
packet.frame_type_ = SrsVideoAvcFrameTypeKeyFrame;
374+
packet.avc_packet_type_ = SrsVideoAvcFrameTraitNALU;
375+
packet.has_idr_ = true;
376+
packet.has_aud_ = false;
377+
packet.has_sps_pps_ = true;
378+
packet.first_nalu_type_ = SrsAvcNaluTypeIDR;
379+
380+
// Add sample data
381+
uint8_t sample_data[] = {0x65, 0x88, 0x84, 0x00};
382+
HELPER_EXPECT_SUCCESS(packet.add_sample((char*)sample_data, sizeof(sample_data)));
383+
384+
// Copy the packet
385+
SrsParsedVideoPacket *copied = packet.copy();
386+
ASSERT_TRUE(copied != NULL);
387+
388+
// Verify base class fields are copied
389+
EXPECT_EQ(packet.dts_, copied->dts_);
390+
EXPECT_EQ(packet.cts_, copied->cts_);
391+
EXPECT_EQ(packet.codec_, copied->codec_);
392+
EXPECT_EQ(packet.nb_samples_, copied->nb_samples_);
393+
394+
// Verify video-specific fields are copied
395+
EXPECT_EQ(packet.frame_type_, copied->frame_type_);
396+
EXPECT_EQ(packet.avc_packet_type_, copied->avc_packet_type_);
397+
EXPECT_EQ(packet.has_idr_, copied->has_idr_);
398+
EXPECT_EQ(packet.has_aud_, copied->has_aud_);
399+
EXPECT_EQ(packet.has_sps_pps_, copied->has_sps_pps_);
400+
EXPECT_EQ(packet.first_nalu_type_, copied->first_nalu_type_);
401+
402+
// Verify samples are copied (shared pointers)
403+
for (int i = 0; i < packet.nb_samples_; i++) {
404+
EXPECT_EQ(packet.samples_[i].bytes_, copied->samples_[i].bytes_);
405+
EXPECT_EQ(packet.samples_[i].size_, copied->samples_[i].size_);
406+
}
407+
408+
srs_freep(copied);
409+
}
410+
411+
#ifdef SRS_FFMPEG_FIT
412+
// Helper function to call ffmpeg_log_callback with formatted string
413+
static void call_ffmpeg_log(int level, const char *fmt, ...)
414+
{
415+
va_list vl;
416+
va_start(vl, fmt);
417+
SrsFFmpegLogHelper::ffmpeg_log_callback(NULL, level, fmt, vl);
418+
va_end(vl);
419+
}
420+
421+
// Test: SrsFFmpegLogHelper::ffmpeg_log_callback() method
422+
VOID TEST(FFmpegLogHelperTest, LogCallback)
423+
{
424+
// Save original disabled state
425+
bool original_disabled = SrsFFmpegLogHelper::disabled_;
426+
427+
// Test 1: Callback should work when not disabled
428+
SrsFFmpegLogHelper::disabled_ = false;
429+
430+
// AV_LOG_WARNING level
431+
call_ffmpeg_log(AV_LOG_WARNING, "Test warning message\n");
432+
433+
// AV_LOG_INFO level
434+
call_ffmpeg_log(AV_LOG_INFO, "Test info message\n");
435+
436+
// AV_LOG_VERBOSE/DEBUG/TRACE levels
437+
call_ffmpeg_log(AV_LOG_VERBOSE, "Test verbose message\n");
438+
call_ffmpeg_log(AV_LOG_DEBUG, "Test debug message\n");
439+
call_ffmpeg_log(AV_LOG_TRACE, "Test trace message\n");
440+
441+
// Test message without newline (should not strip last character)
442+
call_ffmpeg_log(AV_LOG_INFO, "Test message without newline");
443+
444+
// Test message with newline (should strip newline)
445+
call_ffmpeg_log(AV_LOG_INFO, "Test message with newline\n");
446+
447+
// Test 2: Callback should return early when disabled
448+
SrsFFmpegLogHelper::disabled_ = true;
449+
450+
// These calls should return immediately without processing
451+
call_ffmpeg_log(AV_LOG_ERROR, "This should not be logged\n");
452+
call_ffmpeg_log(AV_LOG_WARNING, "This should not be logged\n");
453+
call_ffmpeg_log(AV_LOG_INFO, "This should not be logged\n");
454+
455+
// Test 3: Test edge cases
456+
SrsFFmpegLogHelper::disabled_ = false;
457+
458+
// Empty message
459+
call_ffmpeg_log(AV_LOG_INFO, "");
460+
461+
// Very long message (should be truncated to buffer size)
462+
std::string long_msg(5000, 'x');
463+
call_ffmpeg_log(AV_LOG_INFO, "%s", long_msg.c_str());
464+
465+
// Restore original disabled state
466+
SrsFFmpegLogHelper::disabled_ = original_disabled;
467+
468+
// If we reach here without crashing, the test passes
469+
EXPECT_TRUE(true);
470+
}
471+
#endif

0 commit comments

Comments
 (0)