[LTP] [PATCH 3/3] rtc02: loosen the compare precision with few seconds

Li Wang liwang@redhat.com
Sun May 8 04:22:21 CEST 2022


On Thu, May 5, 2022 at 10:03 PM Cyril Hrubis <chrubis@suse.cz> wrote:


> > +      * To handle the normal and special situations:
> > +      * 1#
> > +      *       set_tm:  2022-04-28 13:00:50
> > +      *       read_tm: 2022-04-28 13:00:50
> > +      * 2#
> > +      *       set_tm:  2022-04-28 13:00:50
> > +      *       read_tm: 2022-04-28 13:00:51
> > +      * 3#
> > +      *       set_tm:  2022-04-28 13:00:59
> > +      *       read_tm: 2022-04-28 13:01:00
> > +      * 4#
> > +      *       set_tm:  2022-04-28 13:59:59
> > +      *       read_tm: 2022-04-28 14:00:00
> > +      *
> > +      * Note: as we have avoided testing around the zero
> > +      * clock, so it's impossible to hit situation 5#
> > +      *       set_tm:  2022-04-28 23:59:59
> > +      *       read_tm: 2022-04-29 00:00:00
> > +      */
> > +
> > +     /* 1~3 */
> > +     if (set_tm->tm_hour == read_tm->tm_hour) {
> > +             if (set_tm->tm_min == read_tm->tm_min - 1)
> > +                     delta += 60;
> > +             else if (set_tm->tm_min != read_tm->tm_min)
> > +                     return 1;
> > +     }
> > +
> > +     /* 4 */
> > +     if ((set_tm->tm_hour == read_tm->tm_hour - 1) &&
> > +                     (set_tm->tm_min == read_tm->tm_min + 59))
> > +             delta += 60;
> > +     else if ((set_tm->tm_hour != read_tm->tm_hour))
> > +             return 1;
> > +
> > +     if (delta < 0 || delta > 3)
> > +             return 1;
> > +
> > +     return !((set_tm->tm_mday == read_tm->tm_mday)
> >               && (set_tm->tm_mon == read_tm->tm_mon)
> >               && (set_tm->tm_year == read_tm->tm_year));
>
> Wouldn't it be easier to convert both dates into a 64bit timestamp and
> compare the timestamps?
>

Yeah, this is a good thought. And we don't even need to convert all dates
because we have avoided the zero clock setting. IOW, just take the
hours/min/sec to be compared should be enough.
Update process:
  patch1/3: drop this one until we find a good way to detect hardware
support.
  patch2/3: pushed.
  patch3/3: will send a V2.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220508/e9179788/attachment.htm>


More information about the ltp mailing list