Home | History | Annotate | only in /src/tests/lib/libutil
History log of /src/tests/lib/libutil
RevisionDateAuthorComments
 1.5 02-May-2025  rillig tests/strpct: demonstrate rounding errors
 1.4 30-Mar-2011  jruoho branches: 1.4.56;
Add some naive tests for the efun(3) family of debug functions.
 1.3 22-Mar-2011  jmmv Add some tests for pidfile(3).

I want to touch this module to attempt a feature addition but I need some
tests beforehand!
 1.2 20-Dec-2010  njoly Add testcase from PR/44255, that exercize parsedate(3) with sample
strings taken from the manpage.
 1.1 16-Jul-2010  jmmv Convert the libposix, libprop, librt, libskey and libutil tests to ATF.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.
 1.4.56.1 02-Aug-2025  perseant Sync with HEAD
 1.3 04-Nov-2012  christos add missing includes
 1.2 30-Mar-2011  jruoho branches: 1.2.4; 1.2.10;
Add missing __RCSID(3), again.
 1.1 30-Mar-2011  jruoho Add some naive tests for the efun(3) family of debug functions.
 1.2.10.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.4.1 16-Jan-2013  yamt sync with (a bit old) head
 1.33 02-May-2022  christos explicitly set TZ=UTC so that we don't depend on the testing rig for it.
 1.32 23-Apr-2022  christos 1. add check for December in MM/DD/YYYY
2. unsetenv("TZ") since tests assume UTC (all relative tests and one date test
fail otherwise)
 1.31 19-Oct-2020  kre Adapt for change to parsedate() which now follows POSIX and altered the
dividing line between 21st and 20th century conversions from 69/70 to
68/69. Adapt the tests for this to conform.
 1.30 22-Mar-2017  kre Fix typo in a comment.
 1.29 22-Mar-2017  kre Add tests for "12 noon", "12 midnight".
 1.28 22-Mar-2017  kre Since PR lib/52101 is now fixed, the tests for its bug should no longer fail.
 1.27 21-Mar-2017  kre Fix a typo - it doesn't matter now, as the test fails anyway, but
it will matter when parsedate is fixed and the test is supposed to
succeed.
 1.26 21-Mar-2017  kre PR lib/52101

Add 6 extra tests for the 12am/12pm bug - all currently expected to fail.
(That is, 6 subtests of the "times" test will fail, all new ones)>

While here, when parsedate() fails (returns -1) avoid converting that
failure value (-1) to a struct tm (1969-12-31T23:59:59 UTC) and then
comparing the values with those expected by the test, and complaining
about all of those (where ANY was not permitted) that don't match...
 1.25 22-Jun-2016  kre branches: 1.25.2; 1.25.4;

Remove tests of "dawn" and "sunset" in preparation for removing
them from parsedate() itself sometime soon.
 1.24 05-May-2016  kre Make the 9 months ago test, when reverting from late November to the
end of Feburary just a little less bogus (stupid cut & paste error).
 1.23 04-May-2016  gson Reduce the step size, exposing another bug.
 1.22 03-May-2016  kre PR bin/50574 - make the tests conform to what parsedate() actually
does, so they should no longer fail. This needs parsedate.y 1.28
in order to work properly.

OK christos@
 1.21 03-May-2016  kre Whitespace. No changes. OK christos@
 1.20 01-May-2016  gson In the "relative" test case, run the tests multiple times relative to
various dates over a span of a few decades, instead of just once
relative to the current date. This makes the test fail consistently
instead of sometimes failing and sometimes not depending on when
it is run. Makes PR lib/50574 consistently reproducible.
 1.19 31-Dec-2015  dholland Fix REL_CHECK error output; it had "expected" and "obtained" swapped.
While here, improve the general legibility of the printout. Not
actually relevant to PR 50574, but anyone looking at that should be
aware of this change.
 1.18 31-Dec-2015  dholland When evaluated on a Sunday, "next Sunday" means 7 days in the future,
not 14. When evaluated on a Monday, it apparently means 13 days in the
future. There's not exactly a spec for parsedate.y, so conform to the
implementation.

PR 50574.

XXX: to me at least this is an odd notion of "next Sunday", but whatever...
 1.17 31-Dec-2015  dholland Fix the "Tuesday midnight" test to match what parsedate.y does; in
particular it doesn't add a week if evaluating that on Wednesday.

Whether that's right is an open question, but there's not exactly a
spec for parsedate.y and there's no point having the test fail one
day in seven.

PR 50574.
 1.16 08-Dec-2015  christos Kill one more REL_DEBUG, from kre
 1.15 07-Dec-2015  christos there is no REL_DEBUG
 1.14 07-Dec-2015  christos new tests from kre
 1.13 08-Oct-2014  apb 2013-07-09 was in British Summer TIme, so use tzoff=-60, not 0.
 1.12 08-Oct-2014  apb When tests fail, print all args, notjust the date string.
 1.11 08-Oct-2014  apb Add tests for PR lib/47916. Some of these fail.
 1.10 07-Oct-2014  apb Adapt to a recent change in parsedate().
"9/10/69" still refers to 2069, and "9/10/70" still refers to 1970,
but "69-09-10" and "70-09-10" now refer to the years 69 and 70.
 1.9 07-Oct-2014  apb Add comments for some non-obvious cases.
Also add a test with year=70, which is documented to be treated as 1970.
 1.8 07-Oct-2014  apb Add local parsecheck() function and use it for several tests.

Instead of just checking that parsedate(3) does not return an error,
also pass the result through localtime_r(3) or gmtime_r(3) and check the
year/month/day/hour/minute/second fields in the resulting struct tm.
 1.7 19-Jan-2013  apb branches: 1.7.8;
Test parsedate("@-2",...) (should return -2 and not set errno);
and parsedate("@junk",...) (should return -1 and set errno).
We were already testing "@-1".
 1.6 19-Jan-2013  apb * Test that parsedate("@0", ...) returns (time_t)0 regardless of timezone.
* Test that parsedate("@-1", NULL, NULL) returns (time_t)-1
without setting errno.
 1.5 18-Mar-2012  jruoho branches: 1.5.2;
To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
 1.4 17-Mar-2012  christos mention the PR# in the description like everyone else.
 1.3 17-Dec-2011  apb branches: 1.3.2;
Add some tests for dates several centures into the past and future.
These currently fail, but I'll fix that soon.
 1.2 21-Dec-2010  christos branches: 1.2.6;
We don't expect tests to fail anymore.
 1.1 20-Dec-2010  njoly Add testcase from PR/44255, that exercize parsedate(3) with sample
strings taken from the manpage.
 1.2.6.2 23-Jan-2013  yamt sync with head
 1.2.6.1 17-Apr-2012  yamt sync with head
 1.3.2.1 17-Apr-2015  msaitoh Pull up following revision(s) (requested by nonaka in ticket #1291):
tests/lib/libutil/t_parsedate.c: revision 1.4-1.13
lib/libutil/parsedate.y: revision 1.14-1.20
lib/libutil/parsedate.3: revision 1.11-1.14
Distinguish between a non-error result of (time_t)-1 and an error result.
Modernise the test code inside #ifdef TEST.
add rcsid
fix timezone bugs in rev.1.11 and rev.1.13. PR/47916.
Some years don't need the "maybe add 1900 or 2000" adjustment
that was designed for handling two-digit abbreviated years.
For example, "1/2/70" still refers to the year 1970, as before,
but "70-01-02" now refers to the year 70.
* Add a new yyHaveFullYear member to struct dateinfo, to record whether
or not the year needs to be adjusted.
* Code that parses years sets yyHaveFullYear=1 if they know that the
year should not be adjusted (as is the case for ISO 8601 dates), or if
they perform their own adjustment (as is the case for CVS timestamps).
* Move the year adjustment code into a new function, AdjustYear,
instead of inline in Convert().
* Make Convert() assume the year doesn't need to be adjusted,
and make Convert's callers first call AdjustYear() if appropriate.
A time like HH:MM:SS.sss says nothing about whether DST is on or off.
Add a new non-terminal "time_numericzone" for a time with
a numeric timezone. Move some productions from "time" to "time_numericzone".
Increment yyHaveZone when encountering one of these.
Previously, input of the form "HH:MM:SS +ZZZZ" would not have set the
yyhaveZone flag.
Improved handling of local times.
* A magic value USE_LOCAL_TIME (defined as 99999) may be passed as the
Timezone to Convert(), instructing it to use mktime() to work
in the local time zone, instead of using mktime_z to work in UTC
(and then adding the specified timezone offset).
* Some old code is removed now that there's no need to find the local
timezone offset.
* Allow either one or both of the now and zone arguments to
parsedate() to be NULL, treating them independently. Previously,
if either one was NULL, the other was ignored.
* If the zone argument is specified, then the current date is calculated
in the specified zone, not in local time.
Also add some disabled debug code.
This should fix PR lib/47916.
Fix capitalization and typo, from Bug Hunting.
Document that errno may be used to distinguish between a
non-error result of -1 and an error.
Document that years in ISO 8601 dates are taken literally.
"69-09-10" is in the year 69, not 2069.
The tzoff argument is in minutes (behind/west of UTC), not seconds.
While here, also say that time = NULL and tzoff = NULL are independent.
The code doesn't yet implement that, but it will soon.
mention the PR# in the description like everyone else.
To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
* Test that parsedate("@0", ...) returns (time_t)0 regardless of timezone.
* Test that parsedate("@-1", NULL, NULL) returns (time_t)-1
without setting errno.
Test parsedate("@-2",...) (should return -2 and not set errno);
and parsedate("@junk",...) (should return -1 and set errno).
We were already testing "@-1".
Add local parsecheck() function and use it for several tests.
Instead of just checking that parsedate(3) does not return an error,
also pass the result through localtime_r(3) or gmtime_r(3) and check the
year/month/day/hour/minute/second fields in the resulting struct tm.
Add comments for some non-obvious cases.
Also add a test with year=70, which is documented to be treated as 1970.
Adapt to a recent change in parsedate().
"9/10/69" still refers to 2069, and "9/10/70" still refers to 1970,
but "69-09-10" and "70-09-10" now refer to the years 69 and 70.
Add tests for PR lib/47916. Some of these fail.
When tests fail, print all args, notjust the date string.
2013-07-09 was in British Summer TIme, so use tzoff=-60, not 0.
 1.5.2.1 25-Feb-2013  tls resync with head
 1.7.8.6 11-Oct-2014  snj Pull up following revision(s) (requested by apb in ticket #135):
tests/lib/libutil/t_parsedate.c: revision 1.13
2013-07-09 was in British Summer TIme, so use tzoff=-60, not 0.
 1.7.8.5 11-Oct-2014  snj Pull up following revision(s) (requested by apb in ticket #135.10):
tests/lib/libutil/t_parsedate.c: revision 1.12
When tests fail, print all args, notjust the date string.
 1.7.8.4 11-Oct-2014  snj Pull up following revision(s) (requested by apb in ticket #135):
tests/lib/libutil/t_parsedate.c: revision 1.11
Add tests for PR lib/47916. Some of these fail.
 1.7.8.3 11-Oct-2014  snj Pull up following revision(s) (requested by apb in ticket #135):
tests/lib/libutil/t_parsedate.c: revision 1.10
Adapt to a recent change in parsedate().
"9/10/69" still refers to 2069, and "9/10/70" still refers to 1970,
but "69-09-10" and "70-09-10" now refer to the years 69 and 70.
 1.7.8.2 11-Oct-2014  snj Pull up following revision(s) (requested by apb in ticket #135):
tests/lib/libutil/t_parsedate.c: revision 1.9
Add comments for some non-obvious cases.
Also add a test with year=70, which is documented to be treated as 1970.
 1.7.8.1 11-Oct-2014  snj Pull up following revision(s) (requested by apb in ticket #135):
tests/lib/libutil/t_parsedate.c: revision 1.8
Add local parsecheck() function and use it for several tests.
Instead of just checking that parsedate(3) does not return an error,
also pass the result through localtime_r(3) or gmtime_r(3) and check the
year/month/day/hour/minute/second fields in the resulting struct tm.
 1.25.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.25.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.3 29-Mar-2011  jmmv Extend pidfile(3) to support creating pid files in arbitrary locations.

If the argument provided to pidfile(3) contains a '/', then the value is
considered to be an absolute/relative path and the pid file is created
in the given location.

Otherwise, pidfile(3) behaves as before and treats the provided value as
a basename to construct a pid file in /var/run/<basename>.pid. This means
that to create a pid file named "foo.pid" in the current directory, one
must specify "./foo.pid".
 1.2 23-Mar-2011  jmmv Clean up some late-night braindeadness:

- Make the pidfile name generation functions return their value as a return
value, not an output pointer. And homogenize these into a single function.
- Free allocated memory. Not truly necessary because the test cases die
immediately anyway, but nice to do.
- Remove the pidfile__ prefix from test case names. (This was in advance of
some changes I want to propose to pidfile(3), but it turns out my approach
was flawed. Preemptive smartness is evil!)
 1.1 22-Mar-2011  jmmv Add some tests for pidfile(3).

I want to touch this module to attempt a feature addition but I need some
tests beforehand!
 1.39 09-Oct-2025  rillig libutil/snprintb: allow 'f' to be combined with ':'

But only if the numeric value can be clearly distinguished from the
description. This style is used by sh3/dmacreg.h.
 1.38 24-Aug-2025  rillig tests/snprintb: clean up comments
 1.37 31-Dec-2024  rillig tests/snprintb: clean up test for mixing 'Ff=:' conversions
 1.36 08-Apr-2024  rillig branches: 1.36.2;
snprintb.3: provide examples for hexadecimal character escapes

Suggested by uwe@, in reaction to the previous commit, which preferred
octal in the examples. Hexadecimal escapes are more familiar to most
programmers, and the chance of mistaking \x14 for decimal 14 is less
than the chance of mistaking octal \014 for decimal 14.
 1.35 07-Apr-2024  rillig snprintb: reject empty bit descriptions and wrongly placed defaults
 1.34 07-Apr-2024  rillig snprintb: reject combinations of 'f' with ':' as well as 'F' with '='

These combinations would lead to garbled output.
 1.33 07-Apr-2024  rillig snprintb: reject empty descriptions

In cases where the snprintb output is garbled, it is not trustworthy, so
make sure the mistakes in the bitfmt are fixed early.
 1.32 01-Apr-2024  rillig tests/snprintb_m: test null-terminated output in error case

While here, clean up the buffer handling for the visualized array
content in case of a failed test.
 1.31 25-Mar-2024  rillig snprintb: mark the end of the buffer if the buffer is too small

This avoids confusion in case the buffer ends with an incomplete number.
 1.30 04-Mar-2024  rillig snprintb: error out on unknown new-style formatting directive
 1.29 24-Feb-2024  rillig tests/snprintb: clean up tests

Always write the value to be formatted in hexadecimal, to make it easily
distinguishable from the buffer size and maximum line length.

Use consistent wording in the comments of the test cases. Be stricter
about mistakes in a format.

Fix some wrong numbers in the snprintb_m tests for limited line length.
 1.28 24-Feb-2024  rillig snprintb: allow non-ASCII descriptions on all platforms

Previously, these descriptions were only allowed on platforms where
plain 'char' is unsigned. On platforms where plain 'char' is signed,
they invoked undefined behavior or terminated the output early.
 1.27 22-Feb-2024  rillig snprintb: always null-terminate output

Always null-terminate the output in the buffer, even in error cases. The
wording in the manual page has been promising this since 2008. For
snprintb_m, ensure that the output is terminated with two null
characters, to gracefully handle situations in which the caller does not
check whether snprintb returned an error.

If the buffer size is zero, allow the buffer to be a null pointer,
analogous to snprintf.

Fix an out-of-bounds memory read if the bitfmt ends with a '*' directive
(since today).

In the tests, merge the helper functions for snprintb, snprintb_m, as
they were similar enough.

Fix a few 'line_max exceeded' tests, ensuring that they output a '#'
marker, and that the 'complete' tests don't.
 1.26 22-Feb-2024  rillig snprintb: error out on out-of-bounds bit shifts

Previously, these invoked undefined behavior, now they lead to an early
return. An example of out-of-bounds bit number is in SCZ_PCICTRL_BITS.
Bit fields that extend beyond the msb are still allowed.

Allow 'f' and 'F' to have fields that are 64 bits wide. This only makes
sense when the field starts at bit 0.

Remove the unused 'val_len', it was only needed before snprintb.c 1.20.
 1.25 20-Feb-2024  rillig tests/snprintb: test '=' and '*' directives that can never match
 1.24 20-Feb-2024  rillig snprintb_m: limit length of generated strings

The manual page promises that the 'max' argument limits the length of
the generated strings, so don't generate any strings that are longer
than that limit. Mark incomplete strings with a trailing '#' to make
them easily recognizable.
 1.23 20-Feb-2024  rillig tests/snprintb: fix out-of-bounds memory read (since 2024-02-16)

Before t_snprintb.c 1.20, the buffer size was required to be greater
than zero. Allowing the buffer size to be zero led to buf[-1] being
checked. On amd64, that byte happened to be 0, on i386 it didn't.

Fixes PR lib/57951.
 1.22 19-Feb-2024  rillig snprintb: fix how named bit-fields are split into multiple lines
 1.21 19-Feb-2024  rillig tests/snprintb: add more tests, especially for snprintb_m
 1.20 16-Feb-2024  rillig snprintb: eliminate two local variables, allow zero-size buffer

Like snprintf, the buffer size may be zero. Unlike snprintf, the buffer
must not be NULL.
 1.19 16-Feb-2024  rillig snprintb: fix integer overflow when writing past a small buffer

Previously, snprintb returned -1 in this case, assuming that the
snprintf used in FMTSTR validates against an overly large buffer size.
 1.18 16-Feb-2024  rillig tests/snprintb: fix test for 8-bit field value

The previous version tested the behavior on a platform with signed
'char' before the portability fix.
 1.17 16-Feb-2024  rillig snprintb: fix '=' and ':' for 8-bit values on platforms with signed char

Previously, '=' and ':' worked only on platforms where plain 'char' is
unsigned. On platforms where plain 'char' is signed, only 7-bit values
worked.
 1.16 16-Feb-2024  rillig tests/snprintb: clean up existing tests, add more tests

Due to the check that any bytes beyond the expected output must be
unmodified, there's no need anymore to explicitly write the "ZZZ" at the
end of the expected output. While here, remove the redundant trailing
"\0".

Add more tests to cover possible situations where an out-of-bounds write
may have occurred. In some cases, the line length specified in
snprintb_m is exceeded.
 1.15 15-Feb-2024  rillig snprintb: fix string termination (since today)

In the previous commit, I had accidentally only run the tests for
snprintb_m but not those for snprintb, thereby missing a newly
introduced bug that would not null-terminate the resulting strings.

Add more tests to cover similar situations in which the buffer is too
small to contain the complete output.
 1.14 15-Feb-2024  rillig snprintb: fix out-of-bounds write
 1.13 14-Feb-2024  rillig tests/libutil/snprintb_m: add tests for small line length
 1.12 27-Jan-2024  rillig tests/libutil/snprintb: remove redundant integer constant suffixes

I added these because lint told me so. Lint was wrong though, as it had
not implemented the C99 rules for integer constants.
 1.11 27-Jan-2024  rillig tests/libutil/snprintb: fix test for 32-bit platforms
 1.10 27-Jan-2024  rillig tests/libutil/snprintb: add more tests

Test all number bases (octal, decimal, hexadecimal), in both old-style
and new-style formats, as well as small buffer sizes.

Document working edge cases such as empty descriptions or descriptions
containing spaces, as well as situations that invoke undefined behavior.

Add comments to the individual test cases, as reading the actual format
strings takes more time.
 1.9 25-Jan-2024  rillig tests/libutil/snprintb: clean up and extend tests

In case of a failure, print the details of the test case, including file
and line number of the actual test data. Do not write the format strings
directly to the output, as they contain non-printable bytes and embedded
null bytes.

After a failed test case, continue with the others.

Lay out the format strings according to their structure, to make them
more readable. Remove redundant "\0" at the end of the new-style format
strings.

Fix an off-by-one error in the test data: 0xf is FIFTEEN, not SIXTEEN.

Add a test for performing a restricted subset of rot13 in the format
string, to explore the limits of snprintb formatting.

What's still missing are tests for edge cases and error cases.
 1.8 08-Dec-2019  christos Adjust tests for 0 hex values printing 0 instead of 0x0
 1.7 06-Dec-2019  christos Fix broken tests in big endian machines. Internally field values are
stored as uint64_t/uintmax_t so printing them with %d on big endian
ends up being 0.
 1.6 29-Apr-2019  kre snprintb(3) says that, in the new(?) Torek format, all fields specs end with \0
The F spec is one of those, it should be terminated with \0 just like all
the others (irrelevant that it has no extra data to delimit).

Fix <sys/mman.h> to define the snprintb() format string correctly (include
the missing \0's). Fix the copy of that definition included into
snprintb(3) to match the updated mman.h version (ride the date bump
from the day before yesterday .. this is the same change, just corrected).

Undo the previous snprintb.c change ("off by one" fix) which was an
attempt to make the broken mman.h usage work (and did, but not the way
it should be done). Also, after using the new * format (instead of only
when something has already matched) skip the associated data so we don't
attempt to interpret it as more field specifiers. This func needs lots of TLC!

Fix the ATF tests for snprintb() to not assume that F format is really
exactly like f format, and has data after the field specifier. It doesn't.
Add several more tests (including testing the '*' field operator
recently added).
 1.5 14-Oct-2017  ryo branches: 1.5.4;
add test case for new format 'f' and 'F'
 1.4 06-Jun-2014  shm PR/48517 testcase provided by Felix Deichmann
 1.3 08-Aug-2013  pgoyette branches: 1.3.2;
Arghhh! Typo.
 1.2 08-Aug-2013  pgoyette Add a new test case for snprintb_m(3) to catch previous boundary bug.
 1.1 16-Jul-2010  jmmv branches: 1.1.6; 1.1.12;
Convert the libposix, libprop, librt, libskey and libutil tests to ATF.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.
 1.1.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.2.1 10-Aug-2014  tls Rebase.
 1.5.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5.4.1 10-Jun-2019  christos Sync with HEAD
 1.36.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 14-Sep-2025  christos Add a generic test
 1.4 07-Nov-2022  msaitoh Sync with if_dl.h rev. 1.31's change.
 1.3 27-Oct-2022  msaitoh Revert for if_dl.h's change.
 1.2 24-Oct-2022  msaitoh Sync with if_dl.h rev. 1.29's change.
 1.1 16-Jul-2010  jmmv Convert the libposix, libprop, librt, libskey and libutil tests to ATF.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.
 1.2 03-May-2025  rillig branches: 1.2.4;
strpct: fix rounding errors and loss of accuracy
 1.1 02-May-2025  rillig tests/strpct: demonstrate rounding errors
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 03-May-2025  perseant file t_strpct.c was added on branch perseant-exfatfs on 2025-08-02 05:58:09 +0000

RSS XML Feed