Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/kern/execve/execve_test.sh
39488 views
1
2
bad_interp_len_head()
3
{
4
atf_set "descr" "Bad interpreter length"
5
}
6
bad_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
12
empty_head()
13
{
14
atf_set "descr" "Empty file"
15
}
16
empty_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
22
good_aout_head()
23
{
24
atf_set "descr" "Good a.out"
25
}
26
good_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
32
good_script_head()
33
{
34
atf_set "descr" "Good script"
35
}
36
good_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
42
non_exist_head()
43
{
44
atf_set "descr" "Non-existent file"
45
}
46
non_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
52
non_exist_shell_head()
53
{
54
atf_set "descr" "Non-existent shell"
55
}
56
non_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
62
script_arg_head()
63
{
64
atf_set "descr" "-x in the shebang"
65
}
66
script_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
72
script_arg_nospace_head()
73
{
74
atf_set "descr" '-x in the shebang; no space between #! and /bin/sh'
75
}
76
script_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
82
sparse_aout_head()
83
{
84
atf_set "descr" 'Sparse file'
85
}
86
sparse_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
92
trunc_aout_head()
93
{
94
atf_set "descr" 'Truncated file'
95
}
96
trunc_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
102
empty_args_head()
103
{
104
atf_set "descr" "Empty argv behavior"
105
}
106
empty_args_body()
107
{
108
atf_check -o inline:"1\n" \
109
-x "cd $(atf_get_srcdir) && ./execve_helper execve_argc_helper"
110
111
# Historically we allowed argc == 0, while execve(2) claimed we didn't.
112
# execve() should kick back an EINVAL now. We verified the helper was
113
# there/working in the check just above.
114
atf_check -s exit:1 \
115
-e match:".+Invalid argument$" \
116
-x "cd $(atf_get_srcdir) && ./execve_helper -n execve_argc_helper"
117
}
118
119
atf_init_test_cases()
120
{
121
atf_add_test_case bad_interp_len
122
atf_add_test_case empty
123
atf_add_test_case good_aout
124
atf_add_test_case good_script
125
atf_add_test_case non_exist
126
atf_add_test_case non_exist_shell
127
atf_add_test_case script_arg
128
atf_add_test_case script_arg_nospace
129
atf_add_test_case sparse_aout
130
atf_add_test_case trunc_aout
131
atf_add_test_case empty_args
132
133
}
134
135