xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/chdir/chdir04.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * Testcase to test whether chdir(2) sets errno correctly.
10*49cdfc7eSAndroid Build Coastguard Worker  */
11*49cdfc7eSAndroid Build Coastguard Worker 
12*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker static char long_dir[] = "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
16*49cdfc7eSAndroid Build Coastguard Worker static char noexist_dir[] = "noexistdir";
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
19*49cdfc7eSAndroid Build Coastguard Worker 	char *dir;
20*49cdfc7eSAndroid Build Coastguard Worker 	int exp_errno;
21*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
22*49cdfc7eSAndroid Build Coastguard Worker 	{long_dir, ENAMETOOLONG},
23*49cdfc7eSAndroid Build Coastguard Worker 	{noexist_dir, ENOENT},
24*49cdfc7eSAndroid Build Coastguard Worker 	{0, EFAULT}, // bad_addr
25*49cdfc7eSAndroid Build Coastguard Worker };
26*49cdfc7eSAndroid Build Coastguard Worker 
verify_chdir(unsigned int i)27*49cdfc7eSAndroid Build Coastguard Worker static void verify_chdir(unsigned int i)
28*49cdfc7eSAndroid Build Coastguard Worker {
29*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL(chdir(tcases[i].dir), tcases[i].exp_errno, "chdir()");
30*49cdfc7eSAndroid Build Coastguard Worker }
31*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)32*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
33*49cdfc7eSAndroid Build Coastguard Worker {
34*49cdfc7eSAndroid Build Coastguard Worker 	tcases[2].dir = tst_get_bad_addr(NULL);
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 	.needs_tmpdir = 1,
39*49cdfc7eSAndroid Build Coastguard Worker 	.test = verify_chdir,
40*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
41*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
42*49cdfc7eSAndroid Build Coastguard Worker };
43