1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Cover more kernel time.

This commit is contained in:
winlin 2019-05-15 08:57:46 +08:00
parent f7994b85eb
commit 8b595c4cdf
3 changed files with 39 additions and 1 deletions

View file

@ -122,11 +122,14 @@ srs_utime_t srs_get_system_startup_time()
return _srs_system_time_startup_time; return _srs_system_time_startup_time;
} }
// For utest to mock it.
_srs_gettimeofday_t _srs_gettimeofday = ::gettimeofday;
srs_utime_t srs_update_system_time() srs_utime_t srs_update_system_time()
{ {
timeval now; timeval now;
if (gettimeofday(&now, NULL) < 0) { if (_srs_gettimeofday(&now, NULL) < 0) {
srs_warn("gettimeofday failed, ignore"); srs_warn("gettimeofday failed, ignore");
return -1; return -1;
} }

View file

@ -161,5 +161,9 @@ extern int srs_chunk_header_c0(int perfer_cid, uint32_t timestamp, int32_t paylo
// @return the size of header. 0 if cache not enough. // @return the size of header. 0 if cache not enough.
extern int srs_chunk_header_c3(int perfer_cid, uint32_t timestamp, char* cache, int nb_cache); extern int srs_chunk_header_c3(int perfer_cid, uint32_t timestamp, char* cache, int nb_cache);
// For utest to mock it.
#include <sys/time.h>
typedef int (*_srs_gettimeofday_t)(struct timeval* tv, struct timezone* tz);
#endif #endif

View file

@ -3597,6 +3597,37 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll)
} }
} }
extern _srs_gettimeofday_t _srs_gettimeofday;
int mock_gettimeofday(struct timeval* /*tp*/, struct timezone* /*tzp*/) {
return -1;
}
class MockTime
{
private:
_srs_gettimeofday_t ot;
public:
MockTime(_srs_gettimeofday_t t = NULL) {
ot = _srs_gettimeofday;
if (t) {
_srs_gettimeofday = t;
}
}
virtual ~MockTime() {
if (ot) {
_srs_gettimeofday = ot;
}
}
};
VOID TEST(KernelUtilityTest, CoverTimeSpecial)
{
if (true) {
MockTime _mt(mock_gettimeofday);
EXPECT_TRUE(-1 == srs_update_system_time());
}
}
extern int64_t _srs_system_time_startup_time; extern int64_t _srs_system_time_startup_time;
extern int64_t _srs_system_time_us_cache; extern int64_t _srs_system_time_us_cache;
extern int av_toupper(int c); extern int av_toupper(int c);