pts: A POSIX test suite shall use only POSIX tools.
[dragonfly.git] / test / contrib / posixtestsuite-1.5.2 / locate-test
1 #! /usr/bin/env bash
2 # Copyright (c) 2002, Intel Corporation. All rights reserved.
3 # Created by:  inaky.perez-gonzalez REMOVE-THIS AT intel DOT com
4 # This file is licensed under the GPL license.  For the full content
5 # of this license, see the COPYING file at the top level of this
6 # source tree.
7
8 # Added FreeBSD compatibility changes by Craig Rodrigues
9
10 usage()
11 {
12     cat <<EOF
13 Usage: $(basename $0) [OPTIONs] DIRECTORY
14
15 Lists the tests (source/binary) available from the DIRECTORY directory
16 and down.
17
18   --buildable     List only tests that require building
19   --execs         List only tests that are executable
20                   If you just want to build a test, but not run it,
21                   do not include a main function into the .c file or
22                   name it something including the "-buildonly" string.
23   --fmake         Find functional makefiles.
24   --smake         Find stress makefiles.
25   --frun          Find functional run.sh files.
26   --srun          Find stress run.sh files.
27   --help          Show this help and exit
28
29 Filenames need to follow some standarized format for them to be picked
30 up by this tool. This might change in the future. So far, the ones
31 picked up are:
32
33 NUMBER-NUMBER.c     [requires compilation]
34 NUMBER-NUMBER.sh    [does not require compilation]
35 NUMBER-buildonly.c  [requires compilation]
36 NAME.sh             [does not require compilation]
37
38 Note that the [requires compilation] tags will mean that the actual
39 test name for TEST.c after compiling will be TEST. Currently it does
40 not support TESTs compiled from many different sources.
41
42 EOF
43 }
44
45 buildable="";
46 execs=""
47 print_execs=0
48
49 # Go through the cmd line options
50 while true
51 do
52   case "$1" in
53       "--buildable")
54           buildable="( -name [0-9]*-*.c ! -name [0-9]*-[0-9]*.sh )";
55           shift;
56           ;;
57       "--execs")
58           print_execs=1;
59           execs="( ( -name [0-9]*-[0-9]*.c -o -name [0-9]*-[0-9]*.sh ) -a ! -name *-buildonly* )";
60           shift;
61           ;;
62       "--fmake")
63           find functional/ -maxdepth 2 -mindepth 2 -type f -name "Makefile" -exec dirname '{}' ';'
64           exit 0;
65           ;;
66       "--frun")
67           find functional/ -maxdepth 2 -mindepth 2 -type f -name "run.sh" -exec dirname '{}' ';'
68           exit 0;
69           ;;
70       "--smake")
71           find stress/ -maxdepth 2 -mindepth 2 -type f -name "Makefile" -exec dirname '{}' ';'
72           exit 0;
73           ;;
74       "--srun")
75           find stress/ -maxdepth 2 -mindepth 2 -type f -name "run.sh" -exec dirname '{}' ';'
76           exit 0;
77           ;;
78       "--help")
79           usage;
80           exit 0;
81           ;;
82       --*)
83           echo "Unknown option $1" 1>&2;
84           usage 1>&2;
85           exit 1;
86           ;;
87       *)
88           break 2;
89           ;;
90   esac
91 done
92
93 # Need the DIRECTORY arg ...
94 if [ -z "$1" ]
95 then
96     echo "Error: no root directory specified" 1>&2
97     usage 1>&2;
98     exit 1;
99 fi
100
101 # Simple version right now, just locate all:
102 WHERE="$1"
103
104 # Force something .c or .sh
105 # Avoid .o, backups
106 # IF --execs, force it has no "-buildonly"
107 # If --buildable, remove the .sh files
108 find "$WHERE" -type f \
109     \( \
110        \( -name "[0-9]*-*.c" -o -name "[0-9]*-[0-9]*.sh" \) \
111        ! -name \*.o ! -name \*~ \
112     \) \
113     $buildable $execs \
114     | if [ $print_execs -eq 1 ]
115         then
116             sed -e 's/\.c$/.test/' -e 's/\.sh$/.test/'
117         else
118             cat
119         fi