• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <unistd.h>
18 #include "test.h"
19 
get_brk()20 void *get_brk()
21 {
22     return sbrk(0);
23 }
24 
25 /**
26  * @tc.name      : brk_0100
27  * @tc.desc      : Verify Change the location of program breakpoints
28  * @tc.level     : Level 0
29  */
brk_0100(void)30 void brk_0100(void)
31 {
32     errno = 0;
33     void *initial_break = get_brk();
34     void *new_break = (void *)((uintptr_t)(initial_break) + 1);
35 
36     int result = brk(new_break);
37     if (result == -1) {
38         if (errno != ENOMEM) {
39             t_error("%s errno should be ENOMEM\n", __func__);
40         }
41     } else {
42         if (result != 0) {
43             t_error("%s brk failed\n", __func__);
44         }
45         if (get_brk() < new_break) {
46             t_error("%s brk invalid\n", __func__);
47         }
48     }
49 }
50 
main(int argc,char * argv[])51 int main(int argc, char *argv[])
52 {
53     brk_0100();
54     return t_status;
55 }