xref: /freebsd/tests/sys/kern/execve/execve_test.sh (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1
2bad_interp_len_head()
3{
4	atf_set "descr" "Bad interpreter length"
5}
6bad_interp_len_body()
7{
8	atf_check -s exit:1 -e 'match:No such file or directory' -o empty \
9	    -x "cd $(atf_get_srcdir) && ./execve_helper bad_interp_len"
10}
11
12empty_head()
13{
14	atf_set "descr" "Empty file"
15}
16empty_body()
17{
18	atf_check -s exit:1 -e 'match:Exec format error' -o empty \
19	    -x "cd $(atf_get_srcdir) && ./execve_helper empty"
20}
21
22good_aout_head()
23{
24	atf_set "descr" "Good a.out"
25}
26good_aout_body()
27{
28	atf_check -s exit:0 -e empty -o 'match:succeeded' \
29	    -x "cd $(atf_get_srcdir) && ./execve_helper ./good_aout"
30}
31
32good_script_head()
33{
34	atf_set "descr" "Good script"
35}
36good_script_body()
37{
38	atf_check -s exit:0 -e empty -o 'match:succeeded' \
39	    -x "cd $(atf_get_srcdir) && ./execve_helper good_script"
40}
41
42non_exist_head()
43{
44	atf_set "descr" "Non-existent file"
45}
46non_exist_body()
47{
48	atf_check -s exit:1 -e 'match:No such file or directory' -o empty \
49	    -x "cd $(atf_get_srcdir) && ./execve_helper non_exist"
50}
51
52non_exist_shell_head()
53{
54	atf_set "descr" "Non-existent shell"
55}
56non_exist_shell_body()
57{
58	atf_check -s exit:1 -e 'match:No such file or directory' -o empty \
59	    -x "cd $(atf_get_srcdir) && ./execve_helper non_exist_shell"
60}
61
62script_arg_head()
63{
64	atf_set "descr" "-x in the shebang"
65}
66script_arg_body()
67{
68	atf_check -s exit:0 -e 'match:\+ echo succeeded' -o 'match:succeeded' \
69	    -x "cd $(atf_get_srcdir) && ./execve_helper script_arg"
70}
71
72script_arg_nospace_head()
73{
74	atf_set "descr" '-x in the shebang; no space between #! and /bin/sh'
75}
76script_arg_nospace_body()
77{
78	atf_check -s exit:0 -e 'match:\+ echo succeeded' -o 'match:succeeded' \
79	    -x "cd $(atf_get_srcdir) && ./execve_helper script_arg_nospace"
80}
81
82sparse_aout_head()
83{
84	atf_set "descr" 'Sparse file'
85}
86sparse_aout_body()
87{
88	atf_check -s exit:1 -e 'match:Exec format error' -o empty \
89	    -x "cd $(atf_get_srcdir) && ./execve_helper sparse_aout"
90}
91
92trunc_aout_head()
93{
94	atf_set "descr" 'Truncated file'
95}
96trunc_aout_body()
97{
98	atf_check -s exit:1 -e 'match:Exec format error' -o empty \
99	    -x "cd $(atf_get_srcdir) && ./execve_helper trunc_aout"
100}
101
102atf_init_test_cases()
103{
104	atf_add_test_case bad_interp_len
105	atf_add_test_case empty
106	atf_add_test_case good_aout
107	atf_add_test_case good_script
108	atf_add_test_case non_exist
109	atf_add_test_case non_exist_shell
110	atf_add_test_case script_arg
111	atf_add_test_case script_arg_nospace
112	atf_add_test_case sparse_aout
113	atf_add_test_case trunc_aout
114
115}
116