/[base]/head/bin/test/test.c
ViewVC logotype

Log of /head/bin/test/test.c

Parent Directory Parent Directory | Revision Log Revision Log


Links to HEAD: (view) (download) (annotate)
Sticky Revision:

Revision 298232 - (view) (download) (annotate) - [select for diffs]
Modified Tue Apr 19 00:38:07 2016 UTC (7 years, 7 months ago) by araujo
File length: 11398 byte(s)
Diff to previous 295082
Use NULL for pointers instead of 0.

MFC after:	2 weeks.


Revision 295082 - (view) (download) (annotate) - [select for diffs]
Modified Sat Jan 30 19:59:58 2016 UTC (7 years, 10 months ago) by jilles
File length: 11395 byte(s)
Diff to previous 259017
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.


Revision 259017 - (view) (download) (annotate) - [select for diffs]
Modified Thu Dec 5 22:53:32 2013 UTC (10 years ago) by jilles
File length: 10881 byte(s)
Diff to previous 258799
test: Avoid looking up again the type of a known binary operator.


Revision 258799 - (view) (download) (annotate) - [select for diffs]
Modified Sun Dec 1 17:00:57 2013 UTC (10 years ago) by jilles
File length: 10910 byte(s)
Diff to previous 251208
test: Simplify the code by unifying op_num and op_type.

The global variable t_wp_op is no longer needed.


Revision 251208 - (view) (download) (annotate) - [select for diffs]
Modified Fri May 31 22:54:20 2013 UTC (10 years, 6 months ago) by jilles
File length: 11107 byte(s)
Diff to previous 247274
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.


Revision 247274 - (view) (download) (annotate) - [select for diffs]
Modified Mon Feb 25 19:05:40 2013 UTC (10 years, 9 months ago) by peterj
File length: 14529 byte(s)
Diff to previous 227984
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


Revision 227984 - (view) (download) (annotate) - [select for diffs]
Modified Fri Nov 25 23:45:29 2011 UTC (12 years ago) by jilles
File length: 11107 byte(s)
Diff to previous 226961
test: Reduce code size of ops table.


Revision 226961 - (view) (download) (annotate) - [select for diffs]
Modified Mon Oct 31 08:59:17 2011 UTC (12 years, 1 month ago) by ed
File length: 11107 byte(s)
Diff to previous 219680
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.


Revision 219680 - (view) (download) (annotate) - [select for diffs]
Modified Tue Mar 15 22:22:11 2011 UTC (12 years, 8 months ago) by jilles
File length: 11072 byte(s)
Diff to previous 219084
bin: Prefer strrchr() to rindex().

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


Revision 219084 - (view) (download) (annotate) - [select for diffs]
Modified Sun Feb 27 12:28:06 2011 UTC (12 years, 9 months ago) by delphij
File length: 11071 byte(s)
Diff to previous 218724
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


Revision 218724 - (view) (download) (annotate) - [select for diffs]
Modified Tue Feb 15 22:17:47 2011 UTC (12 years, 9 months ago) by jilles
File length: 11048 byte(s)
Diff to previous 205793
test: Note that this is used both as a normal program and a shell builtin.

MFC after:	1 week


Revision 205793 - (view) (download) (annotate) - [select for diffs]
Modified Sun Mar 28 13:16:08 2010 UTC (13 years, 8 months ago) by ed
File length: 10921 byte(s)
Diff to previous 192862
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.


Revision 192862 - (view) (download) (annotate) - [select for diffs]
Modified Tue May 26 22:33:10 2009 UTC (14 years, 6 months ago) by jilles
File length: 10951 byte(s)
Diff to previous 139969
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)


Revision 139969 - (view) (download) (annotate) - [select for diffs]
Modified Mon Jan 10 08:39:26 2005 UTC (18 years, 10 months ago) by imp
File length: 9959 byte(s)
Diff to previous 102097
/*- or .\"- or #- to begin license clauses.


Revision 102097 - (view) (download) (annotate) - [select for diffs]
Modified Mon Aug 19 09:19:31 2002 UTC (21 years, 3 months ago) by maxim
File length: 9958 byte(s)
Diff to previous 101923
Forced commit to correct a PR number in the previous commit. It is bin/40177.

Pointed out by: obrien


Revision 101923 - (view) (download) (annotate) - [select for diffs]
Modified Thu Aug 15 14:53:20 2002 UTC (21 years, 3 months ago) by maxim
File length: 9958 byte(s)
Diff to previous 100774
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


Revision 100774 - (view) (download) (annotate) - [select for diffs]
Modified Sat Jul 27 22:53:44 2002 UTC (21 years, 4 months ago) by dwmalone
File length: 9949 byte(s)
Diff to previous 99436
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


Revision 99436 - (view) (download) (annotate) - [select for diffs]
Modified Fri Jul 5 10:27:34 2002 UTC (21 years, 5 months ago) by maxim
File length: 9859 byte(s)
Diff to previous 99110
Fix a memory leak.

PR:		bin/40177
MFC after:	1 week


Revision 99110 - (view) (download) (annotate) - [select for diffs]
Modified Sun Jun 30 05:15:05 2002 UTC (21 years, 5 months ago) by obrien
File length: 9845 byte(s)
Diff to previous 96376
Consistently use FBSDID


Revision 96376 - (view) (download) (annotate) - [select for diffs]
Modified Sat May 11 01:25:54 2002 UTC (21 years, 7 months ago) by alfred
File length: 9877 byte(s)
Diff to previous 96375
while i'm breaking stuff, use __dead2 instead of GCC specific __attribute__.


Revision 96375 - (view) (download) (annotate) - [select for diffs]
Modified Sat May 11 01:24:39 2002 UTC (21 years, 7 months ago) by alfred
File length: 9900 byte(s)
Diff to previous 96374
backout additional include of cdefs.h, it's not helping any.


Revision 96374 - (view) (download) (annotate) - [select for diffs]
Modified Sat May 11 00:54:33 2002 UTC (21 years, 7 months ago) by alfred
File length: 9923 byte(s)
Diff to previous 93345
include cdefs.h for __printf0like to silence warning.


Revision 93345 - (view) (download) (annotate) - [select for diffs]
Modified Thu Mar 28 16:30:42 2002 UTC (21 years, 8 months ago) by ache
File length: 9900 byte(s)
Diff to previous 91737
Use intmax_t as quad_t replacement, like in expr


Revision 91737 - (view) (download) (annotate) - [select for diffs]
Modified Wed Mar 6 11:20:13 2002 UTC (21 years, 9 months ago) by maxim
File length: 9880 byte(s)
Diff to previous 90157
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


Revision 90157 - (view) (download) (annotate) - [select for diffs]
Modified Mon Feb 4 01:11:48 2002 UTC (21 years, 10 months ago) by kris
File length: 9981 byte(s)
Diff to previous 90156
__printflike() should really be __printf0like() since verrx() can
accept a NULL format string.


Revision 90156 - (view) (download) (annotate) - [select for diffs]
Modified Mon Feb 4 01:07:07 2002 UTC (21 years, 10 months ago) by kris
File length: 9980 byte(s)
Diff to previous 90133
Add a __printflike() attribute to silence warning with FORMAT_AUDIT=1


Revision 90133 - (view) (download) (annotate) - [select for diffs]
Modified Sun Feb 3 10:01:49 2002 UTC (21 years, 10 months ago) by knu
File length: 9960 byte(s)
Diff to previous 90111
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


Revision 90111 - (view) (download) (annotate) - [select for diffs]
Modified Sat Feb 2 06:50:57 2002 UTC (21 years, 10 months ago) by imp
File length: 9655 byte(s)
Diff to previous 88471
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)
	{
	...


Revision 88471 - (view) (download) (annotate) - [select for diffs]
Modified Tue Dec 25 08:10:34 2001 UTC (21 years, 11 months ago) by ache
File length: 9964 byte(s)
Diff to previous 88084
strtoq -> strtoll (strtoq is deprecated)


Revision 88084 - (view) (download) (annotate) - [select for diffs]
Modified Mon Dec 17 23:14:14 2001 UTC (21 years, 11 months ago) by ache
File length: 9951 byte(s)
Diff to previous 87961
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.


Revision 87961 - (view) (download) (annotate) - [select for diffs]
Modified Fri Dec 14 23:20:54 2001 UTC (21 years, 11 months ago) by ache
File length: 9789 byte(s)
Diff to previous 86622
POSIX strto*() functions MAY return EINVAL, so don't assume that only one
errno from them allowed and it is always ERANGE


Revision 86622 - (view) (download) (annotate) - [select for diffs]
Modified Mon Nov 19 20:39:24 2001 UTC (22 years ago) by knu
File length: 9697 byte(s)
Diff to previous 86619
Fix style bugs I found, and add a comment.


Revision 86619 - (view) (download) (annotate) - [select for diffs]
Modified Mon Nov 19 20:15:10 2001 UTC (22 years ago) by knu
File length: 9668 byte(s)
Diff to previous 86618
Oops sorry, forgot to add a #include.


Revision 86618 - (view) (download) (annotate) - [select for diffs]
Modified Mon Nov 19 19:57:45 2001 UTC (22 years ago) by knu
File length: 9648 byte(s)
Diff to previous 86505
- Do not reference argv[1] if no argument is given.

Reported by:	brian

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


Revision 86505 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 17 19:10:11 2001 UTC (22 years ago) by knu
File length: 9280 byte(s)
Diff to previous 76883
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)


Revision 76883 - (view) (download) (annotate) - [select for diffs]
Modified Sun May 20 05:33:53 2001 UTC (22 years, 6 months ago) by kris
File length: 9213 byte(s)
Diff to previous 62925
Silence WARNS=2 and BDECFLAGS on alpha and i386

MFC After:	1 week


Revision 62925 - (view) (download) (annotate) - [select for diffs]
Modified Mon Jul 10 21:29:28 2000 UTC (23 years, 5 months ago) by se
File length: 9162 byte(s)
Diff to previous 55179
Add support for 64bit integer comparisons.


Revision 55179 - (view) (download) (annotate) - [select for diffs]
Modified Tue Dec 28 09:34:57 1999 UTC (23 years, 11 months ago) by sheldonh
File length: 8601 byte(s)
Diff to previous 50471
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


Revision 50471 - (view) (download) (annotate) - [select for diffs]
Modified Fri Aug 27 23:15:48 1999 UTC (24 years, 3 months ago) by peter
File length: 8528 byte(s)
Diff to previous 50302
$Id$ -> $FreeBSD$


Revision 50302 - (view) (download) (annotate) - [select for diffs]
Modified Tue Aug 24 06:10:14 1999 UTC (24 years, 3 months ago) by green
File length: 8568 byte(s)
Diff to previous 50189
Make the comments nice, short-but-sweet XXX format.

Submitted by:	sheldonh


Revision 50189 - (view) (download) (annotate) - [select for diffs]
Modified Sun Aug 22 22:32:41 1999 UTC (24 years, 3 months ago) by green
File length: 8754 byte(s)
Diff to previous 50087
Make a comment I added a bit nicer.


Revision 50087 - (view) (download) (annotate) - [select for diffs]
Modified Fri Aug 20 16:19:26 1999 UTC (24 years, 3 months ago) by green
File length: 8704 byte(s)
Diff to previous 49993
Finally: fix test -x as completely as possible.

Reviewed by: bde
Reworked by: bde


Revision 49993 - (view) (download) (annotate) - [select for diffs]
Modified Wed Aug 18 00:18:52 1999 UTC (24 years, 3 months ago) by green
File length: 8466 byte(s)
Diff to previous 49884
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


Revision 49884 - (view) (download) (annotate) - [select for diffs]
Modified Mon Aug 16 09:44:09 1999 UTC (24 years, 3 months ago) by sheldonh
File length: 8266 byte(s)
Diff to previous 49707
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


Revision 49707 - (view) (download) (annotate) - [select for diffs]
Modified Sat Aug 14 05:38:04 1999 UTC (24 years, 3 months ago) by chris
File length: 13651 byte(s)
Diff to previous 46684
Minor style fix - change 'if(!*v)' to 'if (!*v)'


Revision 46684 - (view) (download) (annotate) - [select for diffs]
Modified Sat May 8 10:22:15 1999 UTC (24 years, 7 months ago) by kris
File length: 13654 byte(s)
Diff to previous 38914
Various spelling/formatting changes.

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


Revision 38914 - (view) (download) (annotate) - [select for diffs]
Modified Mon Sep 7 16:59:05 1998 UTC (25 years, 3 months ago) by cracauer
File length: 13654 byte(s)
Diff to previous 36152
Add -S flag to test for sockets.
PR:		bin/7507
Reviewed by:	I tested the patch
Submitted by:	Stefan `Sec` Zehl sec@42.org


Revision 36152 - (view) (download) (annotate) - [select for diffs]
Modified Mon May 18 06:51:59 1998 UTC (25 years, 6 months ago) by charnier
File length: 13558 byte(s)
Diff to previous 31666
Correct use of .Nm. Add rcsid.


Revision 31666 - (view) (download) (annotate) - [select for diffs]
Modified Wed Dec 10 22:18:54 1997 UTC (26 years ago) by eivind
File length: 13571 byte(s)
Diff to previous 22988
Remove simultaneous include of <sys/param.h> and <sys/types.h>.
Reorder includes to be alphabetical some places since I already was in
here.


Revision 22988 - (view) (download) (annotate) - [select for diffs]
Modified Sat Feb 22 14:13:04 1997 UTC (26 years, 9 months ago) by peter
File length: 13548 byte(s)
Diff to previous 21673
Revert $FreeBSD$ to $Id$


Revision 21673 - (view) (download) (annotate) - [select for diffs]
Modified Tue Jan 14 07:20:47 1997 UTC (26 years, 10 months ago) by jkh
File length: 13553 byte(s)
Diff to previous 20903
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.


Revision 20903 - (view) (download) (annotate) - [select for diffs]
Modified Wed Dec 25 00:08:10 1996 UTC (26 years, 11 months ago) by steve
File length: 13594 byte(s)
Diff to previous 20424
Fix handling of -o and -a operators in the 3 argument case.

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


Revision 20424 - (view) (download) (annotate) - [select for diffs]
Modified Sat Dec 14 06:16:51 1996 UTC (26 years, 11 months ago) by steve
File length: 13556 byte(s)
Diff to previous 14539
-Wall cleaning.


Revision 14539 - (view) (download) (annotate) - [select for diffs]
Modified Mon Mar 11 11:01:03 1996 UTC (27 years, 9 months ago) by joerg
File length: 13543 byte(s)
Diff to previous 11855
err() --> errx() for non-errno related failures.


Revision 11855 - (view) (download) (annotate) - [select for diffs]
Modified Sat Oct 28 11:54:42 1995 UTC (28 years, 1 month ago) by ache
File length: 13544 byte(s)
Diff to previous 8855
Fix -h option:
sense symlink even it is unresolved


Revision 8855 - (view) (download) (annotate) - [select for diffs]
Modified Tue May 30 00:07:29 1995 UTC (28 years, 6 months ago) by rgrimes
File length: 13536 byte(s)
Diff to previous 7165
Remove trailing whitespace.

Reviewed by:	phk


Revision 7165 - (view) (download) (annotate) - [select for diffs]
Modified Sun Mar 19 13:29:28 1995 UTC (28 years, 8 months ago) by joerg
File length: 13539 byte(s)
Diff to previous 4171
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)


Revision 4171 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 5 20:48:06 1994 UTC (29 years, 1 month ago) by ache
File length: 13534 byte(s)
Diff to previous 4170
Fix group permissions check for group list size > 1
Pointed by Bruce


Revision 4170 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 5 20:24:49 1994 UTC (29 years, 1 month ago) by ache
File length: 13344 byte(s)
Diff to previous 4168
Fix root -w case according to manpage (-x & -r cases already accords)
Pointed by Bruce.


Revision 4168 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 5 17:31:23 1994 UTC (29 years, 1 month ago) by ache
File length: 13296 byte(s)
Diff to previous 4167
Cosmetique, missing tab/spaces after patch


Revision 4167 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 5 17:28:03 1994 UTC (29 years, 1 month ago) by ache
File length: 13303 byte(s)
Diff to previous 4166
More complex implementation of previos superuser fix
because rw and x bit treats differently infact


Revision 4166 - (view) (download) (annotate) - [select for diffs]
Modified Sat Nov 5 17:07:14 1994 UTC (29 years, 1 month ago) by ache
File length: 13169 byte(s)
Diff to previous 3044
test produce wrong results for superuser, i.e. tells
that file is unreadable when it is readable infact.


Revision 3044 - (view) (download) (annotate) - [select for diffs]
Modified Sat Sep 24 02:59:15 1994 UTC (29 years, 2 months ago) by dg
File length: 13101 byte(s)
Diff to previous 2675
Added $Id$


Revision 2675 - (view) (download) (annotate) - [select for diffs]
Modified Sun Sep 11 21:30:09 1994 UTC (29 years, 3 months ago) by csgr
File length: 13090 byte(s)
Diff to previous 2664
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


Revision 2664 - (view) (download) (annotate) - [select for diffs]
Modified Sun Sep 11 13:57:31 1994 UTC (29 years, 3 months ago) by csgr
File length: 13054 byte(s)
Diff to previous 1557
- 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.


Revision 1557 - (view) (download) (annotate) - [select for diffs]
Modified Thu May 26 06:18:55 1994 UTC (29 years, 6 months ago) by rgrimes
File length: 12967 byte(s)
Copied from: vendor/CSRG/dist/bin/test/test.c revision 1556
Diff to previous 1556
This commit was generated by cvs2svn to compensate for changes in r1556,
which included commits to RCS files with non-trunk default branches.


Revision 1556 - (view) (download) (annotate) - [select for diffs]
Added Thu May 26 06:18:55 1994 UTC (29 years, 6 months ago) by rgrimes
Original Path: vendor/CSRG/dist/bin/test/test.c
File length: 12967 byte(s)
BSD 4.4 Lite bin Sources


This form allows you to request diffs between any two revisions of this file. For each of the two "sides" of the diff, enter a numeric revision.

  Diffs between and
  Type of Diff should be a

  ViewVC Help
Powered by ViewVC 1.1.27