xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/sbrk/sbrk01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  *  AUTHOR : William Roske, CO-PILOT : Dave Fenner
5  * Copyright (c) 2023 SUSE LLC Avinesh Kumar <[email protected]>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Verify that sbrk() successfully increments or decrements the program's
12  * data break.
13  */
14 
15 #include "tst_test.h"
16 
17 static struct tcase {
18 	long increment;
19 } tcases[] = {
20 	{0},
21 	{8192},
22 	{-8192}
23 };
24 
run(unsigned int i)25 static void run(unsigned int i)
26 {
27 	struct tcase *tc = &tcases[i];
28 
29 	TESTPTR(sbrk(tc->increment));
30 
31 	if (TST_RET_PTR == (void *) -1)
32 		tst_res(TFAIL | TTERRNO, "sbrk(%ld) failed", tc->increment);
33 	else
34 		tst_res(TPASS, "sbrk(%ld) returned %p", tc->increment, TST_RET_PTR);
35 }
36 
37 static struct tst_test test = {
38 	.test = run,
39 	.tcnt = ARRAY_SIZE(tcases)
40 };
41