1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <errno.h>
17 #include <signal.h>
18 #include <stdlib.h>
19 
20 #include "test.h"
21 
22 /**
23  * @tc.name      : system_0100
24  * @tc.desc      : execute a shell command
25  * @tc.level     : Level 0
26  */
system_0100(void)27 void system_0100(void)
28 {
29     sighandler_t handler = signal(SIGCHLD, SIG_DFL);
30 
31     int result = system("cd /");
32     if (result != 0) {
33         t_error("%s failed: result = %d\n", __func__, result);
34     }
35 
36     signal(SIGCHLD, handler);
37 }
38 
39 /**
40  * @tc.name      : system_0200
41  * @tc.desc      : execute a shell command with NULL
42  * @tc.level     : Level 2
43  */
system_0200(void)44 void system_0200(void)
45 {
46     int result = system(NULL);
47     if (result == 0) {
48         t_error("%s failed: result = %d\n", __func__, result);
49     }
50 }
51 
main(int argc, char *argv[])52 int main(int argc, char *argv[])
53 {
54     system_0100();
55     system_0200();
56 
57     return t_status;
58 }
59