1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 6f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 7f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 8f08c3bdfSopenharmony_ci * (at your option) any later version. 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 11f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 12f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 16f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 17f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18f08c3bdfSopenharmony_ci */ 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci/* 21f08c3bdfSopenharmony_ci * Test Name : sysinfo02 22f08c3bdfSopenharmony_ci * 23f08c3bdfSopenharmony_ci * Test description 24f08c3bdfSopenharmony_ci * Verify that sysinfo() returns the correct error for an invalid address structure. 25f08c3bdfSopenharmony_ci * 26f08c3bdfSopenharmony_ci * Expected Result : 27f08c3bdfSopenharmony_ci * sysinfo() returns value 0 on success and the sysinfo structure should 28f08c3bdfSopenharmony_ci * be filled with the system information. 29f08c3bdfSopenharmony_ci * 30f08c3bdfSopenharmony_ci * Algorithm: 31f08c3bdfSopenharmony_ci * Setup : 32f08c3bdfSopenharmony_ci * Setup for signal handling. 33f08c3bdfSopenharmony_ci * Create temporary directory. 34f08c3bdfSopenharmony_ci * Pause for SIGUSR1 if option specified. 35f08c3bdfSopenharmony_ci * Test: 36f08c3bdfSopenharmony_ci * Loop if the proper option is given. 37f08c3bdfSopenharmony_ci * Execute the system call. 38f08c3bdfSopenharmony_ci * Pass an invalid address to the structure. 39f08c3bdfSopenharmony_ci * Check return code, if system call failed (return=-1) 40f08c3bdfSopenharmony_ci * Test case passed, Issue functionality pass message 41f08c3bdfSopenharmony_ci * Otherwise, 42f08c3bdfSopenharmony_ci * Issue Functionality-Fail message. 43f08c3bdfSopenharmony_ci * Cleanup: 44f08c3bdfSopenharmony_ci * Print errno log and/or timing stats if options given 45f08c3bdfSopenharmony_ci * Delete the temporary directory created. 46f08c3bdfSopenharmony_ci * 47f08c3bdfSopenharmony_ci * USAGE: <for command-line> 48f08c3bdfSopenharmony_ci * sysinfo02 [-c n] [-i n] [-I x] [-P x] [-t] 49f08c3bdfSopenharmony_ci * where, -c n : Run n copies concurrently. 50f08c3bdfSopenharmony_ci * -i n : Execute test n times. 51f08c3bdfSopenharmony_ci * -I x : Execute test for x seconds. 52f08c3bdfSopenharmony_ci * -P x : Pause for x seconds between iterations. 53f08c3bdfSopenharmony_ci * -t : Turn on syscall timing. 54f08c3bdfSopenharmony_ci * History 55f08c3bdfSopenharmony_ci * 07/2001 John George 56f08c3bdfSopenharmony_ci * -Ported 57f08c3bdfSopenharmony_ci * 58f08c3bdfSopenharmony_ci * Restrictions: 59f08c3bdfSopenharmony_ci * None 60f08c3bdfSopenharmony_ci * 61f08c3bdfSopenharmony_ci */ 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_ci#include <stdio.h> 64f08c3bdfSopenharmony_ci#include <errno.h> 65f08c3bdfSopenharmony_ci#include <sys/types.h> 66f08c3bdfSopenharmony_ci#include <sys/stat.h> 67f08c3bdfSopenharmony_ci#include <sys/signal.h> 68f08c3bdfSopenharmony_ci#include <sys/sysinfo.h> 69f08c3bdfSopenharmony_ci#include <stdint.h> 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci#include "test.h" 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_ci#define INVALID_ADDRESS ((uintptr_t)-1) 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_civoid setup(); 76f08c3bdfSopenharmony_civoid cleanup(); 77f08c3bdfSopenharmony_ci 78f08c3bdfSopenharmony_cichar *TCID = "sysinfo02"; 79f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ci#if !defined(UCLINUX) 82f08c3bdfSopenharmony_ci 83f08c3bdfSopenharmony_ciint main(int ac, char **av) 84f08c3bdfSopenharmony_ci{ 85f08c3bdfSopenharmony_ci struct sysinfo *sysinfo_buf; 86f08c3bdfSopenharmony_ci int lc; 87f08c3bdfSopenharmony_ci 88f08c3bdfSopenharmony_ci sysinfo_buf = (void *)INVALID_ADDRESS; 89f08c3bdfSopenharmony_ci 90f08c3bdfSopenharmony_ci tst_parse_opts(ac, av, NULL, NULL); 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ci setup(); /* Global setup */ 93f08c3bdfSopenharmony_ci 94f08c3bdfSopenharmony_ci /* The following loop checks looping state if -i option given */ 95f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 96f08c3bdfSopenharmony_ci 97f08c3bdfSopenharmony_ci /* reset tst_count in case we are looping */ 98f08c3bdfSopenharmony_ci tst_count = 0; 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci TEST(sysinfo(sysinfo_buf)); 101f08c3bdfSopenharmony_ci /* check return code */ 102f08c3bdfSopenharmony_ci if (TEST_RETURN != 0 && TEST_ERRNO == EFAULT) { 103f08c3bdfSopenharmony_ci /* Test succeeded as it was supposed to return -1 */ 104f08c3bdfSopenharmony_ci tst_resm(TPASS, 105f08c3bdfSopenharmony_ci "Test to check the error code %d PASSED", 106f08c3bdfSopenharmony_ci TEST_ERRNO); 107f08c3bdfSopenharmony_ci } else { 108f08c3bdfSopenharmony_ci /* Test Failed */ 109f08c3bdfSopenharmony_ci tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1 " 110f08c3bdfSopenharmony_ci "returned %d/n", TEST_ERRNO); 111f08c3bdfSopenharmony_ci } 112f08c3bdfSopenharmony_ci } 113f08c3bdfSopenharmony_ci cleanup(); 114f08c3bdfSopenharmony_ci tst_exit(); 115f08c3bdfSopenharmony_ci 116f08c3bdfSopenharmony_ci} 117f08c3bdfSopenharmony_ci 118f08c3bdfSopenharmony_ci#else 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ciint main(void) 121f08c3bdfSopenharmony_ci{ 122f08c3bdfSopenharmony_ci tst_resm(TINFO, "test is not available on uClinux"); 123f08c3bdfSopenharmony_ci tst_exit(); 124f08c3bdfSopenharmony_ci} 125f08c3bdfSopenharmony_ci 126f08c3bdfSopenharmony_ci#endif /* if !defined(UCLINUX) */ 127f08c3bdfSopenharmony_ci 128f08c3bdfSopenharmony_ci/* 129f08c3bdfSopenharmony_ci * setup() 130f08c3bdfSopenharmony_ci * performs one time setup 131f08c3bdfSopenharmony_ci * 132f08c3bdfSopenharmony_ci */ 133f08c3bdfSopenharmony_civoid setup(void) 134f08c3bdfSopenharmony_ci{ 135f08c3bdfSopenharmony_ci 136f08c3bdfSopenharmony_ci tst_sig(FORK, DEF_HANDLER, cleanup); 137f08c3bdfSopenharmony_ci 138f08c3bdfSopenharmony_ci umask(0); 139f08c3bdfSopenharmony_ci 140f08c3bdfSopenharmony_ci TEST_PAUSE; 141f08c3bdfSopenharmony_ci} 142f08c3bdfSopenharmony_ci 143f08c3bdfSopenharmony_ci/* 144f08c3bdfSopenharmony_ci * cleanup() 145f08c3bdfSopenharmony_ci * 146f08c3bdfSopenharmony_ci */ 147f08c3bdfSopenharmony_civoid cleanup(void) 148f08c3bdfSopenharmony_ci{ 149f08c3bdfSopenharmony_ci} 150