Titan Logger timestamp problem after 2038
Submitted by G??bor Szalai
Link to original bug (#563289)
Description
Using the Titan for test with setting the system time after 2038 Jan 12, produces a faulty time stamp in the log file:
Instead of 2038/Mar/26 07:23:23.111835 TTCN-3 Parallel Test Component started on gtcloud0740.
The following time stamp is printed into the log file: 1902/Mar/26 07:23:23.111835 TTCN-3 Parallel Test Component started on gtcloud0740.
There are at least two fault in the time stamp handling of the Logger
- Storing the event time stamp: void LoggerPluginManager::fill_common_fields(API::TitanLogEvent& event, const TTCN_Logger::Severity& severity) { ... struct timeval tv; if (gettimeofday(&tv, NULL) < 0) TTCN_Logger::fatal_error("The gettimeofday() system call failed."); event.timestamp__() = API::TimestampType(tv.tv_sec, tv.tv_usec);
The tv.tv_sec contains the correct value (64 bit signed), but interpreted as int (32 bit signed) and overflows, negative value
Correct way: event.timestamp__().seconds().set_long_long_val(tv.tv_sec); event.timestamp__().microSeconds()=tv.tv_usec;
2nd bug: Reading the timestamp: LegacyLogger.cc: char *event_to_str(const TitanLoggerApi::TitanLogEvent& event, boolean without_header) { char *ret_val = NULL; if (!without_header) { struct timeval timestamp = { (time_t)event.timestamp__().seconds(), (suseconds_t)event.timestamp__().microSeconds() };
The field seconds contains value which can't be represented in int -> Dynamic test case error: Invalid conversion of a large integer value
Correct code: struct timeval timestamp = { (time_t)event.timestamp__().seconds().get_long_long_val(), (suseconds_t)event.timestamp__().microSeconds() };
Version: 6.6.1