blob: 3be6296f70211d6bdbbb73f293e6272c26e5b508 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
19 * TEST IDENTIFIER : getdomainname01
20 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Basic test for getdomainname(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
vapierd13d74b2006-02-11 07:24:00 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
vapierd13d74b2006-02-11 07:24:00 +000029 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000030 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
vapierd13d74b2006-02-11 07:24:00 +000032 *
33 * DESCRIPTION
34 * This is a Phase I test for the getdomainname(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
subrata_modak56207ce2009-03-23 13:35:39 +000037 * Setup:
38 * Setup signal handling.
vapierd13d74b2006-02-11 07:24:00 +000039 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
subrata_modak56207ce2009-03-23 13:35:39 +000041 * Test:
vapierd13d74b2006-02-11 07:24:00 +000042 * Loop if the proper options are given.
subrata_modak56207ce2009-03-23 13:35:39 +000043 * Execute system call
vapierd13d74b2006-02-11 07:24:00 +000044 * Check return code, if system call failed (return=-1)
45 * Log the errno and Issue a FAIL message.
46 * Otherwise, Issue a PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +000047 *
subrata_modak56207ce2009-03-23 13:35:39 +000048 * Cleanup:
49 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000050 *
vapierd13d74b2006-02-11 07:24:00 +000051 * USAGE: <for command-line>
52 * getdomainname01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
53 * where, -c n : Run n copies concurrently.
54 * -e : Turn on errno logging.
55 * -h : Show help screen
56 * -f : Turn off functional testing
57 * -i n : Execute test n times.
58 * -I x : Execute test for x seconds.
59 * -p : Pause for SIGUSR1 before starting
60 * -P x : Pause for x seconds between iterations.
61 * -t : Turn on syscall timing.
62 *
63 ****************************************************************/
64
65#include <errno.h>
66#include <linux/utsname.h>
67#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000068
69#define MAX_NAME_LEN __NEW_UTS_LEN
70
71static void setup();
72static void cleanup();
73
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020074char *TCID = "getdomainname01";
75int TST_TOTAL = 1;
vapierd13d74b2006-02-11 07:24:00 +000076
77static char domain_name[MAX_NAME_LEN];
78
subrata_modak56207ce2009-03-23 13:35:39 +000079int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000080{
81
Cyril Hrubis89af32a2012-10-24 16:39:11 +020082 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020083 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000084
Garrett Coopera9e49f12010-12-16 10:54:03 -080085 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080086 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000087
vapierd13d74b2006-02-11 07:24:00 +000088 setup();
89
vapierd13d74b2006-02-11 07:24:00 +000090 for (lc = 0; TEST_LOOPING(lc); lc++) {
91
Caspar Zhangd59a6592013-03-07 14:59:12 +080092 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000093
subrata_modak4bb656a2009-02-26 12:02:09 +000094 /*
vapierd13d74b2006-02-11 07:24:00 +000095 * Call getdomainname(2)
96 */
97 TEST(getdomainname(domain_name, sizeof(domain_name)));
subrata_modakbdbaec52009-02-26 12:14:51 +000098
vapierd13d74b2006-02-11 07:24:00 +000099 /* check return code */
100 if (TEST_RETURN == -1) {
101 tst_resm(TFAIL, "getdomainname() Failed, errno = %d :"
subrata_modak56207ce2009-03-23 13:35:39 +0000102 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
vapierd13d74b2006-02-11 07:24:00 +0000103 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +0000104 tst_resm(TPASS, "getdomainname() returned %ld ",
vapierd13d74b2006-02-11 07:24:00 +0000105 TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000106 }
vapierd13d74b2006-02-11 07:24:00 +0000107
Garrett Cooper2c282152010-12-16 00:55:50 -0800108 }
vapierd13d74b2006-02-11 07:24:00 +0000109
110 /* cleanup and exit */
111 cleanup();
112
Garrett Coopera9e49f12010-12-16 10:54:03 -0800113 tst_exit();
114
Garrett Cooper2c282152010-12-16 00:55:50 -0800115}
vapierd13d74b2006-02-11 07:24:00 +0000116
117/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400118void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000119{
subrata_modakbdbaec52009-02-26 12:14:51 +0000120
vapierd13d74b2006-02-11 07:24:00 +0000121 tst_sig(NOFORK, DEF_HANDLER, cleanup);
122
vapierd13d74b2006-02-11 07:24:00 +0000123 TEST_PAUSE;
124
Garrett Cooper2c282152010-12-16 00:55:50 -0800125}
vapierd13d74b2006-02-11 07:24:00 +0000126
subrata_modak4bb656a2009-02-26 12:02:09 +0000127/*
vapierd13d74b2006-02-11 07:24:00 +0000128 *cleanup() - performs all ONE TIME cleanup for this test at
129 * completion or premature exit.
130 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400131void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000132{
133
Chris Dearmanec6edca2012-10-17 19:54:01 -0700134}