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