Skip to content

Commit

Permalink
Add INFTIM and arc4andom feature test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristaps committed Oct 15, 2017
1 parent 6a33209 commit f8c513d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 34 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ COMPATS = compat_err.c \
compat_strlcat.c \
compat_strlcpy.c \
compat_strtonum.c
TESTS = test-PATH_MAX.c \
test-__progname.c \
TESTS = test-__progname.c \
test-arc4random.c \
test-capsicum.c \
test-err.c \
test-explicit_bzero.c \
test-getprogname.c \
test-INFTIM.c \
test-md5.c \
test-memmem.c \
test-memrchr.c \
test-memset_s.c \
test-PATH_MAX.c \
test-pledge.c \
test-program_invocation_short_name.c \
test-reallocarray.c \
Expand Down
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ done
# You WANT to change this.
#----------------------------------------------------------------------

HAVE_ARC4RANDOM=
HAVE_CAPSICUM=
HAVE_ERR=
HAVE_EXPLICIT_BZERO=
HAVE_GETPROGNAME=
HAVE_INFTIM=
HAVE_MD5=
HAVE_MEMMEM=
HAVE_MEMRCHR=
Expand Down Expand Up @@ -238,10 +240,12 @@ runtest() {
# You WANT to change this.
#----------------------------------------------------------------------

runtest arc4random ARC4RANDOM || true
runtest capsicum CAPSICUM || true
runtest err ERR || true
runtest explicit_bzero EXPLICIT_BZERO || true
runtest getprogname GETPROGNAME || true
runtest INFTIM INFTIM || true
runtest md5 MD5 || true
runtest memmem MEMMEM || true
runtest memrchr MEMRCHR || true
Expand Down Expand Up @@ -300,10 +304,12 @@ __HEREDOC__
&& echo "#define PATH_MAX 4096"

cat << __HEREDOC__
#define HAVE_ARC4RANDOM ${HAVE_ARC4RANDOM}
#define HAVE_CAPSICUM ${HAVE_CAPSICUM}
#define HAVE_ERR ${HAVE_ERR}
#define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
#define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
#define HAVE_INFTIM ${HAVE_INFTIM}
#define HAVE_MD5 ${HAVE_MD5}
#define HAVE_MEMMEM ${HAVE_MEMMEM}
#define HAVE_MEMRCHR ${HAVE_MEMRCHR}
Expand Down
13 changes: 13 additions & 0 deletions test-INFTIM.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Linux doesn't (always?) have this.
*/

#include <poll.h>
#include <stdio.h>

int
main(void)
{
printf("INFTIM is defined to be %ld\n", (long)INFTIM);
return 0;
}
7 changes: 7 additions & 0 deletions test-arc4random.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdlib.h>

int
main(void)
{
return (arc4random() + 1) ? 0 : 1;
}
88 changes: 56 additions & 32 deletions tests.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
#if TEST_PATH_MAX
/*
* POSIX allows PATH_MAX to not be defined, see
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
* the GNU Hurd is an example of a system not having it.
*
* Arguably, it would be better to test sysconf(_SC_PATH_MAX),
* but since the individual *.c files include "config.h" before
* <limits.h>, overriding an excessive value of PATH_MAX from
* "config.h" is impossible anyway, so for now, the simplest
* fix is to provide a value only on systems not having any.
* So far, we encountered no system defining PATH_MAX to an
* impractically large value, even though POSIX explicitly
* allows that.
*
* The real fix would be to replace all static buffers of size
* PATH_MAX by dynamically allocated buffers. But that is
* somewhat intrusive because it touches several files and
* because it requires changing struct mlink in mandocdb.c.
* So i'm postponing that for now.
*/

#include <limits.h>
#include <stdio.h>

int
main(void)
{
printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
return 0;
}
#endif /* TEST_PATH_MAX */
#if TEST___PROGNAME
int
main(void)
Expand All @@ -39,6 +7,15 @@ main(void)
return !__progname;
}
#endif /* TEST___PROGNAME */
#if TEST_ARC4RANDOM
#include <stdlib.h>

int
main(void)
{
return (arc4random() + 1) ? 0 : 1;
}
#endif /* TEST_ARC4RANDOM */
#if TEST_CAPSICUM
#include <sys/capability.h>

Expand Down Expand Up @@ -102,6 +79,21 @@ main(void)
return progname == NULL;
}
#endif /* TEST_GETPROGNAME */
#if TEST_INFTIM
/*
* Linux doesn't (always?) have this.
*/

#include <poll.h>
#include <stdio.h>

int
main(void)
{
printf("INFTIM is defined to be %ld\n", (long)INFTIM);
return 0;
}
#endif /* TEST_INFTIM */
#if TEST_MD5
#include <sys/types.h>
#include <md5.h>
Expand Down Expand Up @@ -153,6 +145,38 @@ int main(void)
return 0;
}
#endif /* TEST_MEMSET_S */
#if TEST_PATH_MAX
/*
* POSIX allows PATH_MAX to not be defined, see
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
* the GNU Hurd is an example of a system not having it.
*
* Arguably, it would be better to test sysconf(_SC_PATH_MAX),
* but since the individual *.c files include "config.h" before
* <limits.h>, overriding an excessive value of PATH_MAX from
* "config.h" is impossible anyway, so for now, the simplest
* fix is to provide a value only on systems not having any.
* So far, we encountered no system defining PATH_MAX to an
* impractically large value, even though POSIX explicitly
* allows that.
*
* The real fix would be to replace all static buffers of size
* PATH_MAX by dynamically allocated buffers. But that is
* somewhat intrusive because it touches several files and
* because it requires changing struct mlink in mandocdb.c.
* So i'm postponing that for now.
*/

#include <limits.h>
#include <stdio.h>

int
main(void)
{
printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
return 0;
}
#endif /* TEST_PATH_MAX */
#if TEST_PLEDGE
#include <unistd.h>

Expand Down

0 comments on commit f8c513d

Please sign in to comment.