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