예제 #1
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int i;
	struct test_case_t tc;

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
	}

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		/* setup test case paremeters */
		setup_tc(lc, &tc);

		/* loop through the test cases */
		for (i = 0; i < TST_TOTAL; i++) {
			/*
			 * make the call using the TEST() macro - attempt
			 * various invalid shared memory attaches
			 */
			errno = 0;
			addr = shmat(*(tc.shmid), base_addr + tc.offset, 0);
			TEST_ERRNO = errno;

			if (addr != (void *)-1) {
				tst_resm(TFAIL, "call succeeded unexpectedly");
				continue;
			}

			TEST_ERROR_LOG(TEST_ERRNO);

			if (TEST_ERRNO == tc.error) {
				tst_resm(TPASS, "expected failure - errno = "
					 "%d : %s", TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {
				tst_resm(TFAIL, "call failed with an "
					 "unexpected error - %d : %s",
					 TEST_ERRNO, strerror(TEST_ERRNO));

			}
		}
	}

	cleanup();

	 /*NOTREACHED*/ return 0;
}
예제 #2
0
파일: shmat02.c 프로젝트: AbhiramiP/ltp
int main(int ac, char **av)
{
	int lc;
	int i;
	struct test_case_t *tc;

	tc = NULL;

	tst_parse_opts(ac, av, NULL, NULL);

	tc = malloc(sizeof(struct test_case_t));
	if (tc == NULL)
		tst_brkm(TBROK | TERRNO, cleanup, "malloc failed");

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		for (i = 0; i < TST_TOTAL; i++) {

			setup_tc(i, tc);

			base_addr = probe_free_addr();
			errno = 0;
			addr = shmat(*(tc->shmid), base_addr + tc->offset, 0);

			if (addr != (void *)-1) {
				tst_resm(TFAIL, "call succeeded unexpectedly");
				continue;
			}

			if (errno == tc->error)
				tst_resm(TPASS | TERRNO,
					 "shmat failed as expected");
			else
				tst_resm(TFAIL,
					 "shmat failed unexpectedly; expected: "
					 "%d - %s", tc->error,
					 strerror(tc->error));
		}
	}

	cleanup();

	tst_exit();
}
예제 #3
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int i;
	struct test_case_t *tc;

	tc = NULL;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	if ((tc = malloc(sizeof(struct test_case_t))) == NULL)
		tst_brkm(TBROK|TERRNO, cleanup, "malloc failed");

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		Tst_count = 0;

		for (i = 0; i < TST_TOTAL; i++) {

			setup_tc(i, tc);

			errno = 0;
			addr = shmat(*(tc->shmid), base_addr + tc->offset, 0);

			if (addr != (void *)-1) {
				tst_resm(TFAIL, "call succeeded unexpectedly");
				continue;
			}

			if (errno == tc->error)
				tst_resm(TPASS|TERRNO,
				    "shmat failed as expected");
			else
				tst_resm(TFAIL,
				    "shmat failed unexpectedly; expected: "
				    "%d - %s", tc->error, strerror(tc->error));
		}
	}

	cleanup();

	tst_exit();
}
예제 #4
0
파일: shmat01.c 프로젝트: ystk/debian-ltp
/*
 * check_functionality - check various conditions to make sure they
 *			 are correct.
 */
void check_functionality(int i)
{
    void *orig_add;
    int *shared;
    int fail = 0;
    struct shmid_ds buf;
    struct test_case_t tc;

    shared = (int *)addr;

    /* stat the shared memory ID */
    if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
        tst_brkm(TBROK, cleanup, "couldn't stat shared memory");
    }

    /* check the number of attaches */
    if (buf.shm_nattch != 1) {
        tst_resm(TFAIL, "# of attaches is incorrect");
        return;
    }

    /* check the size of the segment */
    if (buf.shm_segsz != INT_SIZE) {
        tst_resm(TFAIL, "segment size is incorrect");
        return;
    }

    /* check for specific conditions depending on the type of attach */
    switch (i) {
    case 0:
        /*
         * Check the functionality of the first call by simply
         * "writing" a value to the shared memory space.
         * If this fails the program will get a SIGSEGV, dump
         * core and exit.
         */

        *shared = CASE0;
        break;
    case 1:
        /*
         * Check the functionality of the second call by writing
         * a value to the shared memory space and then checking
         * that the original address given was rounded down as
         * specified in the man page.
         */
        setup_tc(1, &tc);

        *shared = CASE1;
        orig_add = addr + ((unsigned long)tc.offset % SHMLBA);
        if (orig_add != base_addr + tc.offset) {
            tst_resm(TFAIL, "shared memory address is not "
                     "correct");
            fail = 1;
        }
        break;
    case 2:
        /*
         * This time the shared memory is read only.  Read the value
         * and check that it is equal to the value set in case #2,
         * because shared memory is persistent.
         */

        if (*shared != CASE1) {
            tst_resm(TFAIL, "shared memory value isn't correct");
            fail = 1;
        }
        break;
    }

    if (!fail) {
        tst_resm(TPASS, "conditions and functionality are correct");
    }
}
예제 #5
0
파일: shmat01.c 프로젝트: ystk/debian-ltp
int main(int ac, char **av)
{
    int lc;			/* loop counter */
    char *msg;		/* message returned from parse_opts */
    int i;
    struct test_case_t tc;
    void check_functionality(int);

    /* parse standard options */
    if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
        tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
    }

    setup();		/* global setup */

    /* The following loop checks looping state if -i option given */

    for (lc = 0; TEST_LOOPING(lc); lc++) {

        /* reset Tst_count in case we are looping */
        Tst_count = 0;

        /* setup test case paremeters */
        setup_tc(lc, &tc);

        /* loop through the test cases */
        for (i = 0; i < TST_TOTAL; i++) {

            /*
             * Use TEST macro to make the call
             */
            errno = 0;
            addr = shmat(*(tc.shmid), base_addr + tc.offset,
                         tc.flags);
            TEST_ERRNO = errno;

            if (addr == (void *)-1) {
                tst_brkm(TFAIL, cleanup, "%s call failed - "
                         "errno = %d : %s", TCID, TEST_ERRNO,
                         strerror(TEST_ERRNO));
            } else {
                if (STD_FUNCTIONAL_TEST) {
                    check_functionality(i);
                } else {
                    tst_resm(TPASS, "call succeeded");
                }
            }

            /*
             * clean up things in case we are looping - in
             * this case, detach the shared memory
             */
            if (shmdt((const void *)addr) == -1) {
                tst_brkm(TBROK, cleanup,
                         "Couldn't detach shared memory");
            }
        }
    }

    cleanup();

    /*NOTREACHED*/ return 0;
}