History log of /freebsd-current/bin/test/test.c
Revision Date Author Comments
# e043f372 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 1cc908de 22-Dec-2020 Xin LI <delphij@FreeBSD.org>

Remove unused includes.


# 172c3b0b 18-Apr-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use NULL for pointers instead of 0.

MFC after: 2 weeks.


# f1602fa5 30-Jan-2016 Jilles Tjoelker <jilles@FreeBSD.org>

test: Optimize operator lookup.

The linear search using strcmp() shows up in pmcstat for several percent.

Split the operators into lengths and whether they start with '-' and compare
bytes using == instead of strcmp().

A simple test

sh -c 'i=0; w=$(printf %0100d 7); while [ "$i" -lt 1000000 ]; do
v=$(printf %sx%s "$w" "$w"); i=$((i+1)); done'

is over 4% faster on an amd64 bhyve VM.


# c80ad859 05-Dec-2013 Jilles Tjoelker <jilles@FreeBSD.org>

test: Avoid looking up again the type of a known binary operator.


# 577ad9b2 01-Dec-2013 Jilles Tjoelker <jilles@FreeBSD.org>

test: Simplify the code by unifying op_num and op_type.

The global variable t_wp_op is no longer needed.


# f19825af 31-May-2013 Jilles Tjoelker <jilles@FreeBSD.org>

test: Remove -ntXY and -otXY primaries.

This reverts commit r247274.

As maintainer of sh, I disapprove of this feature addition.

It is too specific and can be done without easily using find(1) or stat(1).
I will add some hints to the test(1) man page shortly.

In general, FreeBSD sh is not the place to invent new shell language
features. This is how it has been maintained and adding features randomly
does not work with that.

The new syntax (e.g. [ FILE1 -ntca FILE2 ]) looks cryptic to me.


# 293beebc 25-Feb-2013 Peter Jeremy <peterj@FreeBSD.org>

Enhance test(1) by adding provision to compare any combination of the
access, birth, change and modify times of two files, instead of only
being able to compare modify times. The builtin test in sh(1) will
automagically acquire the same expansion.

Approved by: grog
MFC after: 2 weeks


# ba22f6c6 25-Nov-2011 Jilles Tjoelker <jilles@FreeBSD.org>

test: Reduce code size of ops table.


# f9d4afb4 31-Oct-2011 Ed Schouten <ed@FreeBSD.org>

Put some static keywords in the source code.

For these simple utilities, it doesn't harm to make all global variables
static. In fact, this allows the compiler to perform better forms of
optimisation and analysis.


# 0cf90cd1 15-Mar-2011 Jilles Tjoelker <jilles@FreeBSD.org>

bin: Prefer strrchr() to rindex().

This removes the last index/rindex usage from /bin.


# eaea8924 26-Feb-2011 Xin LI <delphij@FreeBSD.org>

Accept == as an alias of = which is a popular GNU extension.

This is intentionally undocumented for now since it's not part
of any standard.

MFC after: 1 month


# 2fd7d6aa 15-Feb-2011 Jilles Tjoelker <jilles@FreeBSD.org>

test: Note that this is used both as a normal program and a shell builtin.

MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 99742a23 28-Mar-2010 Ed Schouten <ed@FreeBSD.org>

Change all our own code to use st_*tim instead of st_*timespec.

Also remove some local patches to diff(1) which are now unneeded.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 00e8c94f 26-May-2009 Jilles Tjoelker <jilles@FreeBSD.org>

Fix various cases with 3 or 4 parameters in test(1) to be POSIX compliant.
More precisely, this gives precedence to an interpretation not using the
'(', ')', '-a' and '-o' in their special meaning, if possible. For example,
it is now safe to write [ "$a" = "$b" ] and assume it compares the two
strings.

The man page already says that test(1) works this way, so does not need to
be changed.

Interpretation of input with more parameters tries a bit harder to find a
valid parse in some cases.

Add various additional test cases to TEST.sh.

PR: standards/133369
Approved by: ed (mentor)


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 9ddb49cb 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

/*- or .\"- or #- to begin license clauses.


# 6c62b047 15-Aug-2002 Maxim Konovalov <maxim@FreeBSD.org>

o Backout rev. 1.40 and rev. 1.49.
o Add argv[] boudary check.

PR: bin/40117
Reviewed by: silence on -audit
MFC after: 2 months


# 6576952c 27-Jul-2002 David Malone <dwmalone@FreeBSD.org>

Make test check the tv_nsec part of a struct stat when comparing
the mtimes of a file. (This is probably only useful if you have
vfs.timestamp_precision set to something nonzero).

PR: 39163
Submitted by: Hal Burch <hburch@lumeta.com>
MFC after: 2 weeks


# 27f3fb1a 05-Jul-2002 Maxim Konovalov <maxim@FreeBSD.org>

Fix a memory leak.

PR: bin/40177
MFC after: 1 week


# 2749b141 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use FBSDID


# 033be9ae 10-May-2002 Alfred Perlstein <alfred@FreeBSD.org>

while i'm breaking stuff, use __dead2 instead of GCC specific __attribute__.


# 46d56055 10-May-2002 Alfred Perlstein <alfred@FreeBSD.org>

backout additional include of cdefs.h, it's not helping any.


# dfe7e2f8 10-May-2002 Alfred Perlstein <alfred@FreeBSD.org>

include cdefs.h for __printf0like to silence warning.


# 82ea3997 28-Mar-2002 Andrey A. Chernov <ache@FreeBSD.org>

Use intmax_t as quad_t replacement, like in expr


# 89a3a364 06-Mar-2002 Maxim Konovalov <maxim@FreeBSD.org>

Log:
Remove eaccess(2) absence workaround. Add eaccess(2) checks for FILRD,
FILWR, FILEX and FILEXIST cases.

We cannot MFC this because there is no eaccess(2) in -stable yet.

PR: bin/35076
Reviewed by: ru
Approved by: ru


# f4c14283 03-Feb-2002 Kris Kennaway <kris@FreeBSD.org>

__printflike() should really be __printf0like() since verrx() can
accept a NULL format string.


# 7cbc81e6 03-Feb-2002 Kris Kennaway <kris@FreeBSD.org>

Add a __printflike() attribute to silence warning with FORMAT_AUDIT=1


# 5c08c7d3 03-Feb-2002 Akinori MUSHA <knu@FreeBSD.org>

Work around a buffer overflow problem on argv that has been exposed
after making test(1) a sh(1) builtin; sh(1) coredumps when you run
something like this:

sh -c 'test ! `true 1`'

The cause is that the test(1) code totally depends on the presence of
two extra cells at the end of argv that are filled with NULL's. The
reason why the bug hasn't been exposed would be because the C startup
code kindly prepares argv with some extra zeroed cells for a program.

I know this is not the best fix, but since there are argv++'s without
boundary checks everywhere, I'd rather patch it up like this
(preparing a copy of argv with extra NULL's) for the moment.

MFC after: 3 days


# 5134c3f7 01-Feb-2002 Warner Losh <imp@FreeBSD.org>

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.
o Change
int
foo() {
...
to
int
foo(void)
{
...


# 4cc31e55 25-Dec-2001 Andrey A. Chernov <ache@FreeBSD.org>

strtoq -> strtoll (strtoq is deprecated)


# 3d09cebf 17-Dec-2001 Andrey A. Chernov <ache@FreeBSD.org>

1) Localize (LC_CTYPE)
2) Catch "" to 0 conversion for OSes that not catch it in strto*()
(f.e. -stable). It is needed because POSIX agrees with both variants.


# 9ea42c8e 14-Dec-2001 Andrey A. Chernov <ache@FreeBSD.org>

POSIX strto*() functions MAY return EINVAL, so don't assume that only one
errno from them allowed and it is always ERANGE


# bd90b9c7 19-Nov-2001 Akinori MUSHA <knu@FreeBSD.org>

Fix style bugs I found, and add a comment.


# 25e04004 19-Nov-2001 Akinori MUSHA <knu@FreeBSD.org>

Oops sorry, forgot to add a #include.


# d919a882 19-Nov-2001 Akinori MUSHA <knu@FreeBSD.org>

- Do not reference argv[1] if no argument is given.

Reported by: brian

- Call error() instead of errx() if compiled as sh(1) builtin.


# d90c5c4a 17-Nov-2001 Akinori MUSHA <knu@FreeBSD.org>

Make test(1) a builtin command of our sh(1) for efficiency. The
binary size increase is 3,784 bytes (about 0.6%).

I don't drop the printf builtin while I'm here because some /etc/rc.*
scripts seem to use it before mounting /usr where printf(1) resides.

Reviewed by: arch (sheldonh)
Inspired by: NetBSD, ksh
Clued by: ume (on how the printf builtin is used)


# 6dca6515 19-May-2001 Kris Kennaway <kris@FreeBSD.org>

Silence WARNS=2 and BDECFLAGS on alpha and i386

MFC After: 1 week


# de96f240 10-Jul-2000 Stefan Eßer <se@FreeBSD.org>

Add support for 64bit integer comparisons.


# 9abf3043 28-Dec-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Take into account the fact that "[" may be called with a path,
for example "/bin/[".

Reported by: Vlad Skvortsov <vss@ulstu.ru>
Reported by: Peter Jeremy <peter.jeremy@alcatel.com.au>
Message-Id: 99Dec27.111307est.40321@border.alcanet.com.au


# 2a456239 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 2a6d85a9 24-Aug-1999 Brian Feldman <green@FreeBSD.org>

Make the comments nice, short-but-sweet XXX format.

Submitted by: sheldonh


# 03376631 22-Aug-1999 Brian Feldman <green@FreeBSD.org>

Make a comment I added a bit nicer.


# d2fed466 20-Aug-1999 Brian Feldman <green@FreeBSD.org>

Finally: fix test -x as completely as possible.

Reviewed by: bde
Reworked by: bde


# eb5e5558 17-Aug-1999 Brian Feldman <green@FreeBSD.org>

The new test(1) did not use access() correctly. I don't know why, since
supposedly it's ksh-derived, and it's not broken in pdksh. I've added
a test for test running as root: if testing for -x, the file must be
mode & 0111 to get "success", rather than just existant.

Reviewed by: chris


# 717a08b6 16-Aug-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Replace our test(1) with NetBSD's pdksh-derived version. The code is
significantly easier to read and extend and offers a few new tests.
A few style changes taken from style(9) and OpenBSD, as well as
whitespace cleanups.

This change was discussed on freebsd-committers and freebsd-hackers
and met with approval from at least des, eivind and brian.

PR: 13091
Obtained from: NetBSD


# bf627182 13-Aug-1999 Chris Costello <chris@FreeBSD.org>

Minor style fix - change 'if(!*v)' to 'if (!*v)'


# 46be34b9 08-May-1999 Kris Kennaway <kris@FreeBSD.org>

Various spelling/formatting changes.

Submitted by: Philippe Charnier <charnier@xp11.frmug.org>


# 23f8fb3d 07-Sep-1998 Martin Cracauer <cracauer@FreeBSD.org>

Add -S flag to test for sockets.
PR: bin/7507
Reviewed by: I tested the patch
Submitted by: Stefan `Sec` Zehl sec@42.org


# 9ba8bd65 18-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm. Add rcsid.


# 007d3350 10-Dec-1997 Eivind Eklund <eivind@FreeBSD.org>

Remove simultaneous include of <sys/param.h> and <sys/types.h>.
Reorder includes to be alphabetical some places since I already was in
here.


# b97fa2ef 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 9d633f68 24-Dec-1996 Steve Price <steve@FreeBSD.org>

Fix handling of -o and -a operators in the 3 argument case.

Submitted by: Tom Rush <tarush@mindspring.com>


# 4507dafd 13-Dec-1996 Steve Price <steve@FreeBSD.org>

-Wall cleaning.


# 9074ba2e 11-Mar-1996 Joerg Wunsch <joerg@FreeBSD.org>

err() --> errx() for non-errno related failures.


# 25c3d351 28-Oct-1995 Andrey A. Chernov <ache@FreeBSD.org>

Fix -h option:
sense symlink even it is unresolved


# 2162b2d2 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.

Reviewed by: phk


# 0fd510b7 19-Mar-1995 Joerg Wunsch <joerg@FreeBSD.org>

You will find enclosed some changes to make gcc -Wall more happy in
/usr/src/bin. Note that some patches are still needed in that directory.

I (Joerg) finished most of Philippe's cleanup. /bin/sh will still
need *allot* of work, however.

Submitted by: charnier@lirmm.fr (Philippe Charnier)


# 5b515dcb 05-Nov-1994 Andrey A. Chernov <ache@FreeBSD.org>

Fix group permissions check for group list size > 1
Pointed by Bruce


# 20662469 05-Nov-1994 Andrey A. Chernov <ache@FreeBSD.org>

Fix root -w case according to manpage (-x & -r cases already accords)
Pointed by Bruce.


# 01bb3d8e 05-Nov-1994 Andrey A. Chernov <ache@FreeBSD.org>

Cosmetique, missing tab/spaces after patch


# ea8bd6e3 05-Nov-1994 Andrey A. Chernov <ache@FreeBSD.org>

More complex implementation of previos superuser fix
because rw and x bit treats differently infact


# 3b0beab6 05-Nov-1994 Andrey A. Chernov <ache@FreeBSD.org>

test produce wrong results for superuser, i.e. tells
that file is unreadable when it is readable infact.


# 89730b29 23-Sep-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# 282d7272 11-Sep-1994 Geoff Rehmet <csgr@FreeBSD.org>

Make get_int() think that "" (null) has the integer value 0.
(Which is the same behaviour as in 1.x)
The install blows up without this.
Reviewed by: rgrimes


# 5fafa206 11-Sep-1994 Geoff Rehmet <csgr@FreeBSD.org>

- handle signs on integers properly,
- make sure error messages for bad integers are moderately sensible
- handle test ! "abc" -o "abc" (This should evaluate to true)
(and similar cases) ie:
and/or operator test added to POSIX special case processing.
- more test cases added.

Based on: Work done on 1.x's test(1) by Andrew Moore and Adam David.


# 4b88c807 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite bin Sources