• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4  * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
5  * Author: Saji Kumar.V.R <saji.kumar@wipro.com>
6  */
7 
8 #include "setdomainname.h"
9 
10 #define ERRNO_DESC(x) .exp_errno = x, .errno_desc = #x
11 
12 #define MAX_NAME_LENGTH _UTSNAME_DOMAIN_LENGTH - 1
13 
14 struct test_case {
15 	char *desc;
16 	char *name;
17 	int len;
18 	int exp_errno;
19 	char *errno_desc;
20 } tcases[] = {
21 	{ "len == -1", TST_VALID_DOMAIN_NAME, -1, ERRNO_DESC(EINVAL) },
22 	{ "len > allowed maximum", TST_VALID_DOMAIN_NAME, MAX_NAME_LENGTH + 1, ERRNO_DESC(EINVAL) },
23 	{ "name == NULL", NULL, MAX_NAME_LENGTH, ERRNO_DESC(EFAULT) }
24 };
25 
verify_setdomainname(unsigned int nr)26 void verify_setdomainname(unsigned int nr)
27 {
28 	struct test_case *tcase = &tcases[nr];
29 
30 	TEST(do_setdomainname(tcase->name, (size_t) tcase->len));
31 
32 	tst_res(TINFO, "testing %s", tcase->desc);
33 	if (TST_RET != -1) {
34 		tst_res(TFAIL, "unexpected exit code: %ld", TST_RET);
35 		return;
36 	}
37 
38 	if (TST_ERR != tcase->exp_errno) {
39 		tst_res(TFAIL | TTERRNO, "unexpected errno: %d, expected: %d",
40 			TST_ERR, tcase->exp_errno);
41 		return;
42 	}
43 
44 	tst_res(TPASS | TTERRNO, "expected failure");
45 }
46 
47 static struct tst_test test = {
48 	.tcnt = ARRAY_SIZE(tcases),
49 	.needs_root = 1,
50 	.setup = setup,
51 	.cleanup = cleanup,
52 	.test = verify_setdomainname,
53 	.test_variants = TEST_VARIANTS,
54 };
55