/*-
* Copyright (c) 2024-2025 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Fired exactly one interval early. Treat this too as clock
* wound backwards.
*/
[7] = {{.it_value = {3,0}, .it_interval = {1,0}},
{2,0}, {3,0}, 0,
NULL},
/*
* Fired less than one interval early -- callouts and real-time
* clock might not be perfectly synced, counted as zero
* overruns. Advance by one interval from the scheduled time.
*/
[8] = {{.it_value = {3,0}, .it_interval = {1,0}},
{2,1}, {3,0}, 0,
NULL},
[9] = {{.it_value = {3,0}, .it_interval = {1,0}},
{2,500000000}, {3,0}, 0,
NULL},
[10] = {{.it_value = {3,0}, .it_interval = {1,0}},
{2,999999999}, {3,0}, 0,
NULL},
/*
* Fired exactly on time. Advance by one interval.
*/
[11] = {{.it_value = {3,0}, .it_interval = {1,0}},
{3,0}, {4,0}, 0, NULL},
/*
* Fired late by less than one interval -- callouts and
* real-time clock might not be prefectly synced, counted as
* zero overruns. Advance by one interval from the scheduled
* time (even if it's very close to a full interval).
*/
[12] = {{.it_value = {3,0}, .it_interval = {1,0}},
{3,1}, {4,0}, 0, NULL},
[14] = {{.it_value = {3,0}, .it_interval = {1,0}},
{3,500000000}, {4,0}, 0, NULL},
[15] = {{.it_value = {3,0}, .it_interval = {1,0}},
{3,999999999}, {4,0}, 0, NULL},
/*
* Fired late by exactly one interval -- treat it as overrun.
*/
[16] = {{.it_value = {3,0}, .it_interval = {1,0}},
{4,0}, {5,0}, 1,
NULL},
/*
* Fired late by more than one interval but less than two --
* overrun.
*/
[17] = {{.it_value = {3,0}, .it_interval = {1,0}},
{4,1}, {5,0}, 1,
NULL},
[18] = {{.it_value = {3,0}, .it_interval = {1,0}},
{4,500000000}, {5,0}, 1,
NULL},
[19] = {{.it_value = {3,0}, .it_interval = {1,0}},
{4,999999999}, {5,0}, 1,
NULL},
/*
* Fired late by exactly two intervals -- two overruns.
*/
[20] = {{.it_value = {3,0}, .it_interval = {1,0}},
{5,0}, {6,0}, 2,
NULL},
/*
* Fired late by more intervals plus slop, up to 32.
*
* XXX Define DELAYTIMER_MAX so we can write it in terms of
* that.
*/
[21] = {{.it_value = {3,0}, .it_interval = {1,0}},
{13,123456789}, {14,0}, 10,
NULL},
[22] = {{.it_value = {3,0}, .it_interval = {1,0}},
{34,999999999}, {35,0}, 31,
NULL},
/*
* Overflows -- we should (XXX but currently don't) reject
* intervals of at least 2^64 nanoseconds up front, since this
* is more time than it is reasonable to wait (more than 584
* years).
*/
/*
* Overflow nanosecond arithmetic. The magic interval number
* here is ceiling(INT64_MAX/2) nanoseconds. The interval
* start value will be rounded to an integral number of ticks,
* so rather than write exactly `4611686018,427387905', just
* round up the `now' value to the next second. This forces an
* overrun _and_ triggers int64_t arithmetic overflow.
*/
[47] = {{.it_value = {0,1},
.it_interval = {4611686018,427387904}},
/* XXX needless overflow */
{4611686019,0}, {0,0}, 1,
NULL},