Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
    Bool addexit;
    char *label, *cmd;
    int i, xr, yr, bitm;
    unsigned int wr, hr;


    addexit = True;

    if (argc < 2)
        usage(argv[0]);
    i = 1;
    for (; argv[i]; i++) {
        if (argv[i][0] != '-')
            break;
        if (argv[i][1] == '-') {
            i++;
            break;
        }

        switch (argv[i][1]) {
        case 'g':
            if (i >= argc - 1)
                break;
            bitm = XParseGeometry(argv[i+1], &xr, &yr, &wr, &hr);
            if (bitm & XValue)
                wx = xr;
            if (bitm & YValue)
                wy = yr;
            if (bitm & WidthValue)
                ww = (int)wr;
            if (bitm & HeightValue)
                wh = (int)hr;
            if (bitm & XNegative && wx == 0)
                wx = -1;
            if (bitm & YNegative && wy == 0)
                wy = -1;
            i++;
            break;
        case 'h':
            switch ((i >= argc - 1)? 0 : argv[i][2]) {
            case 's':
                heightscaling = atof(argv[i+1]);
                i++;
                break;
            default:
                usage(argv[0]);
            }
            break;
        case 'o':
            horizontal = True;
            break;
        case 's':
            oneshot = 0;
            break;
        case 'w':
            switch ((i >= argc - 1)? 0 : argv[i][2]) {
            case 's':
                widthscaling = atof(argv[i+1]);
                i++;
                break;
            default:
                usage(argv[0]);
            }
            break;
        case 'x':
            addexit = False;
            break;
        default:
            usage(argv[0]);
        }
    }

    for (; argv[i]; i++) {
        label = argv[i];
        if (!argv[i+1])
            break;
        i++;
        cmd = argv[i];

        entries = realloc(entries, sizeof(entries[0])*(++nentries));
        entries[nentries-1] = malloc(sizeof(*entries[0]));
        memset(entries[nentries-1], 0, sizeof(*entries[0]));

        entries[nentries-1]->label = strdup(label);
        if (entries[nentries-1]->label == NULL)
            die("strdup returned NULL\n");
        entries[nentries-1]->cmd = strdup(cmd);
        if (entries[nentries-1]->cmd == NULL)
            die("strdup returned NULL\n");
    }
    if (nentries < 1)
        usage(argv[0]);

    if (addexit) {
        entries = realloc(entries, sizeof(entries[0])*(++nentries));
        entries[nentries-1] = malloc(sizeof(*entries[0]));
        memset(entries[nentries-1], 0, sizeof(*entries[0]));
        entries[nentries-1]->label = strdup("cancel");
        entries[nentries-1]->cmd = "exit";
        entries[nentries-1]->forceexit = True;
    }

    if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
        fprintf(stderr, "warning: no locale support\n");
    if(!(dpy = XOpenDisplay(0)))
        die("thingmenu: cannot open display\n");

    setup();
    run();
    cleanup();
    XCloseDisplay(dpy);

    for (i = 0; i < nentries; i++)
        free(entries[i]);
    free(entries);

    return 0;
}
Exemplo n.º 2
0
/** Handle tab completion.
    * User interface uses a dual model, first tab completes upto the
    * longest common (case insensitiv) match, further tabbing cycles through all
    * possible completions. When doing a tab completion without something to complete
    * possibly offers a special guess first.
    */
void TabCompletion::tryComplete() {
    switch (typingStatus_) {
        case TypingStatus::Normal:
            typingStatus_ = TypingStatus::TabPressed;
            break;
        case TypingStatus::TabPressed:
            typingStatus_ = TypingStatus::TabbingCompletions;
            break;
        default:
            break;
    }


    QString newText;
    bool replaced = false;

    if (typingStatus_ == TypingStatus::MultipleSuggestions) {
        if (!suggestedCompletion_.isEmpty()) {
            suggestedIndex_++;
            if (suggestedIndex_ >= (int)suggestedCompletion_.count()) {
                suggestedIndex_ = 0;
            }
            newText = suggestedCompletion_[suggestedIndex_];
            replaced = true;
        }
    } else {
        QTextCursor cursor = textEdit_->textCursor();
        QString wholeText = textEdit_->toPlainText();

        int begin, end;
        setup(wholeText, cursor.position(), begin, end);
        replacementCursor_ = QTextCursor(textEdit_->document());
        moveCursorToOffset(replacementCursor_, begin);
        moveCursorToOffset(replacementCursor_, end, QTextCursor::KeepAnchor);

        if (toComplete_.isEmpty() && typingStatus_ == TypingStatus::TabbingCompletions) {
            typingStatus_ = TypingStatus::MultipleSuggestions;

            QString guess;
            suggestedCompletion_ = allChoices(guess);

            if ( !guess.isEmpty() ) {
                suggestedIndex_ = -1;
                newText = guess;
                replaced = true;
            } else if (!suggestedCompletion_.isEmpty()) {
                suggestedIndex_ = 0;
                newText = suggestedCompletion_.first();
                replaced = true;
            }
        } else {
            newText = suggestCompletion(&replaced);
        }
    }

    if (replaced) {
        textEdit_->setUpdatesEnabled(false);

        int start = qMin(replacementCursor_.anchor(), replacementCursor_.position());

        replacementCursor_.beginEditBlock();
        replacementCursor_.insertText(newText);
        replacementCursor_.endEditBlock();

        QTextCursor newPos(replacementCursor_);

        moveCursorToOffset(replacementCursor_, start, QTextCursor::KeepAnchor);


        newPos.clearSelection();

        textEdit_->setTextCursor(newPos);

        textEdit_->setUpdatesEnabled(true);
        textEdit_->viewport()->update();
    }
    highlight(typingStatus_ == TypingStatus::MultipleSuggestions);
}
Exemplo n.º 3
0
ofxGuiGroup::ofxGuiGroup(const ofParameterGroup & parameters, string filename, float x, float y){
	minimized = false;
	parent = NULL;
    setup(parameters, filename, x, y);
}
Exemplo n.º 4
0
int AXWindow::run(){
    if(setup){
        setup();
    }
    if(activeScene){
        activeScene->start();
    }
    SDL_Event event;
    bool inFocus = true;
    while(go == 1){
        AXWindow::frameCount++;
        AXWindow::deltaTime = SDL_GetPerformanceCounter() - AXWindow::previousDeltaTime;
        AXWindow::previousDeltaTime = SDL_GetPerformanceCounter();
        while(SDL_PollEvent(&event) != 0 ){
            //User requests quit
            if(event.type == SDL_QUIT){
                go = 0;
                break;
            }else if( event.type == SDL_KEYDOWN){
                const std::string& temp = AXInput::setKeyDown(event.key.keysym.scancode);
                if(activeScene){
                    activeScene->inputChange(temp, 1);
                }
            }else if(event.type == SDL_KEYUP){
                const std::string& temp = AXInput::setKeyUp(event.key.keysym.scancode);
                if(activeScene){
                    activeScene->inputChange(temp, 0);
                }
            }else if(event.type == SDL_MOUSEMOTION){
                AXInput::mouseX = event.motion.x;
                AXInput::mouseY = event.motion.y;
            }else if(event.type == SDL_MOUSEBUTTONDOWN){
                const std::string& temp = AXInput::mousePressed(event.button.button);
                if(activeScene){
                    activeScene->inputChange(temp, 1);
                }
            }else if(event.type == SDL_MOUSEBUTTONUP){
                const std::string& temp = AXInput::mouseReleased(event.button.button);
                if(activeScene){
                    activeScene->inputChange(temp, 0);
                }
            }else if(event.type == SDL_CONTROLLERBUTTONDOWN){
                const std::string& temp = AXInput::setKeyDown((SDL_GameControllerButton)event.cbutton.button+(AX_INPUT_CONTROLLER_OFFSET*(event.cdevice.which+1)));
                if(activeScene){
                    activeScene->inputChange(temp, 1);
                }

            }else if(event.type == SDL_CONTROLLERBUTTONUP){
                const std::string& temp = AXInput::setKeyUp((SDL_GameControllerButton)event.cbutton.button+(AX_INPUT_CONTROLLER_OFFSET*(event.cdevice.which+1)));
                if(activeScene){
                    activeScene->inputChange(temp, 0);
                }
            }else if(event.type == SDL_CONTROLLERDEVICEADDED){
                AXInput::controllers[event.cdevice.which] = SDL_GameControllerOpen(event.cdevice.which);
            }else if(event.type == SDL_CONTROLLERDEVICEREMOVED){
                SDL_GameControllerClose(AXInput::controllers[event.cdevice.which]);
                AXInput::controllers[event.cdevice.which] = 0;
            }else if(event.type == SDL_CONTROLLERAXISMOTION){
                AXInput::setAxisValue(AX_INPUT_CONTROLLER_AXIS_OFFSET+event.caxis.axis+AX_INPUT_CONTROLLER_OFFSET*(event.caxis.which+1), event.caxis.value);
            }else if(event.type == SDL_WINDOWEVENT){
                if(event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED){
                    inFocus = true;
                }else if(event.window.event == SDL_WINDOWEVENT_FOCUS_LOST){
                    inFocus = false;
                }
            }
        }
        if(inFocus){
            if(update){
                update();
            }
            if(activeScene) {
                activeScene->update();
            }
        }
        //Fill the surface wshite
        SDL_SetRenderDrawColor(AXWindow::renderer, backgroundColour.getR(), backgroundColour.getG(), backgroundColour.getB(), backgroundColour.getA());
        SDL_RenderClear(AXWindow::renderer);
        if(inFocus){
            SDL_SetRenderDrawColor(AXWindow::renderer, renderColour.getR(), renderColour.getG(), renderColour.getB(), renderColour.getA());
            if(draw){
                draw();
            }
            if(activeScene) {
                activeScene->draw();
            }
        }
        SDL_RenderPresent(AXWindow::renderer);
    }
    SDL_DestroyWindow(window);
    SDL_DestroyRenderer(renderer);
    //quit the SDLMix
    if(audioStatus){
        while(Mix_Init(0)){
            Mix_Quit();
        }
        Mix_CloseAudio();
    }
    //Quit SDL subsystems
    SDL_Quit();

    return 0;
}
Exemplo n.º 5
0
Arquivo: semctl07.c Projeto: 1587/ltp
int main(int argc, char *argv[])
{
	int status;
	struct semid_ds buf_ds;

	union semun arg;

	setup();

	arg.buf = &buf_ds;
	if ((status = semctl(semid, 0, IPC_STAT, arg)) == -1) {
		tst_resm(TFAIL, "semctl() failed errno = %d", errno);
		semctl(semid, 1, IPC_RMID, arg);

	}

	/*
	 * Check contents of semid_ds structure.
	 */

	if (arg.buf->sem_nsems != nsems) {
		tst_resm(TFAIL, "error: unexpected number of sems %lu",
			 arg.buf->sem_nsems);

	}
	if (arg.buf->sem_perm.uid != getuid()) {
		tst_resm(TFAIL, "error: unexpected uid %d",
			 arg.buf->sem_perm.uid);

	}
	if (arg.buf->sem_perm.gid != getgid()) {
		tst_resm(TFAIL, "error: unexpected gid %d",
			 arg.buf->sem_perm.gid);

	}
	if (arg.buf->sem_perm.cuid != getuid()) {
		tst_resm(TFAIL, "error: unexpected cuid %d",
			 arg.buf->sem_perm.cuid);

	}
	if (arg.buf->sem_perm.cgid != getgid()) {
		tst_resm(TFAIL, "error: unexpected cgid %d",
			 arg.buf->sem_perm.cgid);

	}
	if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
		tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);

	}
	arg.val = 1;
	if ((status = semctl(semid, 0, SETVAL, arg)) == -1) {
		tst_resm(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno);

	}
	if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
		tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);

	}
	if (status != arg.val) {
		tst_resm(TFAIL, "error: unexpected value %d", status);

	}
	if ((status = semctl(semid, 0, GETPID, arg)) == -1) {
		tst_resm(TFAIL, "semctl(GETPID) failed errno = %d", errno);

	}
	status = getpid();
	if (status == 0) {
		tst_resm(TFAIL, "error: unexpected pid %d", status);

	}
	if ((status = semctl(semid, 0, GETNCNT, arg)) == -1) {
		tst_resm(TFAIL, "semctl(GETNCNT) failed errno = %d", errno);

	}
	if (status != 0) {
		tst_resm(TFAIL, "error: unexpected semncnt %d", status);

	}
	if ((status = semctl(semid, 0, GETZCNT, arg)) == -1) {
		tst_resm(TFAIL, "semctl(GETZCNT) failed errno = %d", errno);

	}
	if (status != 0) {
		tst_resm(TFAIL, "error: unexpected semzcnt %d", status);

	}

	tst_resm(TPASS, "semctl07 ran successfully!");

	cleanup();
	tst_exit();
}
Exemplo n.º 6
0
  void BitVector_Test::Test_bitVectorPopulationCount()
  {
    {
      const u32 SIZE =  0;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(i);
        assert(bits.PopulationCount() == i + 1);
      }
    }
    {
      const u32 SIZE =  1;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(i);
        assert(bits.PopulationCount() == i + 1);
      }
    }
    {
      const u32 SIZE =  31;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(i);
        assert(bits.PopulationCount() == i + 1);
      }
    }
    {
      const u32 SIZE =  32;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(i);
        assert(bits.PopulationCount() == i + 1);
      }
    }
    {
      const u32 SIZE =  35;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(i);
        assert(bits.PopulationCount() == i + 1);
      }

    }
    {
      const u32 SIZE =  67;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(i);
        assert(bits.PopulationCount() == i + 1);
      }

      // all combinations of start and len..
      BitVector<SIZE> zbits;

      for (u32 start = 0; start < SIZE; ++start) 
      {
        for (u32 end = start; end < SIZE; ++end) 
        {
          u32 len = end - start + 1;
          assert(bits.PopulationCount(start, len) == len);
          assert(zbits.PopulationCount(start, len) == 0);
        }
      }

    }

    {
      const u32 SIZE =  258;
      BitVector<SIZE> bits;
      assert(bits.PopulationCount() == 0);
      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.SetBit(SIZE - i - 1);
        assert(bits.PopulationCount() == i + 1);
      }

      assert(bits.PopulationCount() == SIZE);

      for (u32 i = 0; i < SIZE; ++i) 
      {
        bits.ClearBit(i);
        assert(bits.PopulationCount() == SIZE - (i + 1));
      }
    }

    {
      BitVector<256>* bits = setup();
      assert(bits->PopulationCount() == 115);
      assert(bits->PopulationCount(64,96) == 51); 
      assert(bits->PopulationCount(5,250) == 113);
    }
  }
//-------------------------------------------
blobTracker::blobTracker() {
    setup(500);
}
Exemplo n.º 8
0
/* FIXME: this is only used by solver code since matrix solvers are started in
 *        post_start.
 */
void device_t::connect_post_start(detail::core_terminal_t &t1, detail::core_terminal_t &t2)
{
	if (!setup().connect(t1, t2))
		log().fatal(MF_ERROR_CONNECTING_1_TO_2(t1.name(), t2.name()));
}
Exemplo n.º 9
0
Menu::Menu(sf::RenderWindow* window){
    this->menuWindow = window;
    this->menuOptions = play;
    setup();
}
Exemplo n.º 10
0
void device_t::connect(detail::core_terminal_t &t1, detail::core_terminal_t &t2)
{
	setup().register_link_fqn(t1.name(), t2.name());
}
Exemplo n.º 11
0
void device_t::connect(const pstring &t1, const pstring &t2)
{
	setup().register_link_fqn(name() + "." + t1, name() + "." + t2);
}
Exemplo n.º 12
0
Arquivo: semctl06.c Projeto: Nudiv/ltp
int main(int argc, char **argv)
{
	register int i, pid;
	int count, child, status, nwait;

#ifdef UCLINUX
	const char *msg;
	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	argv0 = argv[0];
	maybe_run_child(&do_child, "dS", &id_uclinux, &maxsemstring);
#endif

	prog = argv[0];
	nwait = 0;
	setup();

	tid = -1;

	for (i = 0; i < NPROCS; i++)
		keyarray[i] = getipckey();

	if ((signal(SIGTERM, term)) == SIG_ERR) {
		tst_resm(TFAIL, "\tsignal failed. errno = %d", errno);

	}

	for (i = 0; i < NPROCS; i++) {
		if ((pid = FORK_OR_VFORK()) < 0) {
			tst_resm(TFAIL,
				 "\tFork failed (may be OK if under stress)");

		}
		if (pid == 0) {
			procstat = 1;
			dotest(keyarray[i]);
			exit(0);
		}
		pidarray[i] = pid;
		nwait++;
	}

	/*
	 * Wait for children to finish.
	 */

	count = 0;
	while ((child = wait(&status)) > 0) {
		if (status) {
			tst_resm(TFAIL, "%s[%d] Test failed.  exit=0x%x", prog,
				 child, status);
			local_flag = FAILED;
		}
		++count;
	}

	/*
	 * Should have collected all children.
	 */

	if (count != nwait) {
		tst_resm(TFAIL, "\tWrong # children waited on, count = %d",
			 count);
		local_flag = FAILED;
	}

	if (local_flag != FAILED)
		tst_resm(TPASS, "semctl06 ran successfully!");
	else
		tst_resm(TFAIL, "semctl06 failed");


	cleanup();
	tst_exit();
}
Exemplo n.º 13
0
Arquivo: mkdir02.c Projeto: GOEUM/ltp
int main(int ac, char **av)
{
	int lc;
	char *msg;
	struct stat buf, buf1;
	pid_t pid, pid1;
	struct passwd *ltpuser1;
	struct passwd *ltpuser2;
	int rval, status;

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

	/*
	 * perform global setup for test
	 */
	setup();

	/*
	 * check looping state if -i option given
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/* check the inherited group ID */

		/*
		 * first, fork the first child, set to ltpuser1's uid and gid,
		 * create a directory, with S_ISGID bit set
		 */

		ltpuser1 = my_getpwnam(user1name);
		sprintf(tstdir1, "tstdir1.%d", getpid());

		if ((pid = FORK_OR_VFORK()) < 0) {
			tst_brkm(TFAIL, cleanup, "fork() failed");

		}

		if (pid == 0) {	/* first child */
			rval = setregid(ltpuser1->pw_gid, ltpuser1->pw_gid);
			if (rval < 0) {
				perror("setregid");
				tst_resm(TFAIL, "setregid failed to "
					 "to set the real gid to %d and "
					 "effective gid to %d",
					 ltpuser1->pw_gid, ltpuser1->pw_gid);
				exit(1);

			}
			/* being ltupuser1 */
			rval = setreuid(ltpuser1->pw_uid, ltpuser1->pw_uid);
			if (rval < 0) {
				perror("setreuid");
				tst_resm(TFAIL, "setreuid failed to "
					 "to set the real uid to %d and "
					 "effective uid to %d",
					 ltpuser1->pw_uid, ltpuser1->pw_uid);
				exit(1);

			}

			/*
			 * create a direcoty with S_ISGID bit set
			 * and the group ID is ltpuser1
			 */
			if (mkdir(tstdir1, PERMS) != 0) {
				perror("mkdir");
				tst_resm(TFAIL, "mkdir() failed to create"
					 " a directory with Set "
					 " group ID turn on ");
				exit(1);

			}
			if (stat(tstdir1, &buf1) == -1) {
				perror("stat");
				tst_resm(TFAIL,
					 "failed to stat the new directory"
					 "in mkdir()");
				exit(1);

			}
			if (chmod(tstdir1, buf1.st_mode | S_ISGID) != 0) {
				perror("chmod");
				tst_resm(TFAIL, "failed to set S_ISGID bit");
				exit(1);

			}

			/* Successfully create the parent directory */
			exit(0);

		}
		wait(&status);
		if (WEXITSTATUS(status) != 0) {
			tst_brkm(TFAIL, cleanup,
				 "Test to attempt to make a directory"
				 " inherits group ID FAILED ");
		}
		/*
		 * fork the second child process, set to ltpuser2's uid and gid
		 * create a sub directory under the directory
		 * just created by child process 1
		 * check the group ID of the sub directory
		 * should inherit from parent directory
		 */

		ltpuser2 = my_getpwnam(user2name);
		sprintf(tstdir2, "%s/tstdir2.%d", tstdir1, getpid());
		if ((pid1 = FORK_OR_VFORK()) < 0) {
			perror("fork failed");
			tst_brkm(TFAIL, cleanup, "fork() failed");

		} else if (pid1 == 0) {	/* second child */

			/* being user ltpuser2 */
			rval = setregid(ltpuser2->pw_gid, ltpuser2->pw_gid);
			if (rval < 0) {
				tst_resm(TFAIL, "setregid failed to "
					 "to set the real gid to %d and "
					 "effective gid to %d",
					 ltpuser2->pw_gid, ltpuser2->pw_gid);
				perror("setregid");
				exit(1);

			}
			rval = setreuid(ltpuser2->pw_uid, ltpuser2->pw_uid);
			if (rval < 0) {
				tst_resm(TFAIL, "setreuid failed to "
					 "to set the real uid to %d and "
					 "effective uid to %d",
					 ltpuser2->pw_uid, ltpuser2->pw_uid);
				perror("setreuid");
				exit(1);

			}

			/*
			 * create a sub direcoty
			 * under the directory just created
			 * by ltpuser1
			 */
			if (mkdir(tstdir2, PERMS) != 0) {
				tst_resm(TFAIL, "mkdir() failed to create"
					 " a directory %s under %s ", tstdir2,
					 tstdir1);
				exit(1);

			}
			/*
			 * check the group ID
			 * should not be the same as the current processs's
			 * since parent directory is set with S_ISGID bit
			 */
			if (stat(tstdir2, &buf) == -1) {
				tst_resm(TFAIL,
					 "failed to stat the new directory"
					 "in mkdir()");
				exit(1);

			}
			if (stat(tstdir1, &buf1) == -1) {
				tst_resm(TFAIL,
					 "failed to stat the new directory"
					 "in mkdir()");
				exit(1);

			}
			if (buf.st_gid != buf1.st_gid) {
				tst_resm(TFAIL, "mkdir() FAILED to inherit "
					 " the group ID %d from parent "
					 " directory %d",
					 buf.st_gid, buf1.st_gid);
				exit(1);

			}

			/* check the S_ISGID  bit */
			if (!(buf.st_mode & S_ISGID)) {
				tst_resm(TFAIL, "mkdir() FAILED to inherit "
					 " the S_ISGID bit from parent "
					 " directory");
				exit(1);

			}
			/* PASS */
			exit(0);

		}

		waitpid(pid1, &status, 0);
		if (WEXITSTATUS(status) == 0) {
			tst_resm(TPASS, "Test to attempt to make a directory"
				 " inherits group ID SUCCEEDED ");
		} else {
			tst_resm(TFAIL, "Test to attempt to make a directory"
				 " inherits group ID FAILED");
			cleanup();
		}

	}

	/*
	 * cleanup and exit
	 */
	cleanup();

	tst_exit();
}
Exemplo n.º 14
0
int main(int ac, char **av)
{
	int lc;
	char *msg;

	int ind;
	int offset;

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

	}

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		offset = (lc % 100) * 4096;	/* max size is 100 blocks */

		for (ind = 0; Whence[ind] >= 0; ind++) {

			/*
			 *  Call lseek(2)
			 */
			TEST(lseek(Fd, (long)offset, Whence[ind]));

			/* check return code */
			if (TEST_RETURN == -1) {
				TEST_ERROR_LOG(TEST_ERRNO);
				tst_resm(TFAIL,
					 "lseek(%s, %d, 0) Failed, errno=%d : %s",
					 Fname, offset, TEST_ERRNO,
					 strerror(TEST_ERRNO));
			} else {

		/***************************************************************
	         * only perform functional verification if flag set (-f not given)
	         ***************************************************************/
				if (STD_FUNCTIONAL_TEST) {
					/* No Verification test, yet... */
					tst_resm(TPASS,
						 "lseek(%s, %d, %d) returned %ld",
						 Fname, offset, Whence[ind],
						 TEST_RETURN);
				} else
					Tst_count++;
			}
		}

	}

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();
	tst_exit();

}
Exemplo n.º 15
0
Arquivo: open10.c Projeto: 1587/ltp
int main(int ac, char *av[])
{
	int ret;
	struct stat buf;
	struct group *group;
	struct passwd *user1;
	char DIR_A[MSGSIZE], DIR_B[MSGSIZE];
	char setgid_A[MSGSIZE], nosetgid_A[MSGSIZE];
	char setgid_B[MSGSIZE], nosetgid_B[MSGSIZE], root_setgid_B[MSGSIZE];
	gid_t group1_gid, group2_gid, mygid;
	uid_t save_myuid, user1_uid;
	pid_t mypid;

	int lc;
	int fail_count = 0;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		save_myuid = getuid();
		mypid = getpid();
		sprintf(DIR_A, DIR_A_TEMP, mypid);
		sprintf(DIR_B, DIR_B_TEMP, mypid);
		sprintf(setgid_A, "%s/%s", DIR_A, SETGID);
		sprintf(nosetgid_A, "%s/%s", DIR_A, NOSETGID);
		sprintf(setgid_B, "%s/%s", DIR_B, SETGID);
		sprintf(nosetgid_B, "%s/%s", DIR_B, NOSETGID);
		sprintf(root_setgid_B, "%s/%s", DIR_B, ROOT_SETGID);

		/* Get the uid of user1 */
		user1 = getpwnam("nobody");
		if (user1 == NULL)
			tst_brkm(TBROK, cleanup, "nobody not in /etc/passwd");

		user1_uid = user1->pw_uid;

		/*
		 * Get the group IDs of group1 and group2.
		 */
		group = getgrnam("nobody");
		if (group == NULL) {
			group = getgrnam("nogroup");
			if (group == NULL) {
				tst_brkm(TBROK, cleanup,
					 "nobody/nogroup not in /etc/group");
			}
		}
		group1_gid = group->gr_gid;
		group = getgrnam("bin");
		if (group == NULL)
			tst_brkm(TBROK, cleanup, "bin not in /etc/group");

		group2_gid = group->gr_gid;

		/*
		 * Create a directory with group id the same as this process
		 * and with no setgid bit.
		 */
		if (mkdir(DIR_A, MODE_RWX) < 0) {
			tst_resm(TFAIL | TERRNO, "mkdir(%s) failed", DIR_A);
			local_flag = FAILED;
		}

		if (chown(DIR_A, user1_uid, group2_gid) < 0) {
			tst_resm(TFAIL | TERRNO, "chown(%s) failed", DIR_A);
			local_flag = FAILED;
		}

		if (stat(DIR_A, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed", DIR_A);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (buf.st_mode & S_ISGID) {
			tst_resm(TFAIL, "%s: Incorrect modes, setgid bit set",
				 DIR_A);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != group2_gid) {
			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
				 DIR_A, buf.st_gid, group2_gid);
			local_flag = FAILED;
		}

		/*
		 * Create a directory with group id different from that of
		 * this process and with the setgid bit set.
		 */
		if (mkdir(DIR_B, MODE_RWX) < 0) {
			tst_resm(TFAIL | TERRNO, "mkdir(%s) failed", DIR_B);
			local_flag = FAILED;
		}

		if (chown(DIR_B, user1_uid, group2_gid) < 0) {
			tst_resm(TFAIL | TERRNO, "chown(%s) failed", DIR_B);
			local_flag = FAILED;
		}

		if (chmod(DIR_B, MODE_SGID) < 0) {
			tst_resm(TFAIL | TERRNO, "chmod(%s) failed", DIR_B);
			local_flag = FAILED;
		}

		if (stat(DIR_B, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed", DIR_B);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (!(buf.st_mode & S_ISGID)) {
			tst_resm(TFAIL,
				 "%s: Incorrect modes, setgid bit not set",
				 DIR_B);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != group2_gid) {
			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
				 DIR_B, buf.st_gid, group2_gid);
			local_flag = FAILED;
		}

		if (local_flag == PASSED) {
			tst_resm(TPASS, "Test passed in block0.");
		} else {
			tst_resm(TFAIL, "Test failed in block0.");
			fail_count++;
		}

		local_flag = PASSED;

		/*
		 * Create two files in testdir.A, one with the setgid
		 * bit set in the creation modes and the other without.
		 * Both should inherit the group ID of the process and
		 * maintain the setgid bit as specified in the creation
		 * modes.
		 */
		if (setgid(group1_gid) < 0) {
			tst_resm(TINFO,
				 "Unable to set process group ID to group1");
		}

		if (setreuid(-1, user1_uid) < 0)
			tst_resm(TINFO, "Unable to set process uid to user1");

		mygid = getgid();

		/*
		 * Create the file with setgid not set
		 */
		ret = open(nosetgid_A, O_CREAT | O_EXCL | O_RDWR, MODE_RWX);
		if (ret < 0) {
			tst_resm(TFAIL | TERRNO, "open(%s) failed", nosetgid_A);
			local_flag = FAILED;
		}
		close(ret);

		if (stat(nosetgid_A, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed", nosetgid_A);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (buf.st_mode & S_ISGID) {
			tst_resm(TFAIL, "%s: Incorrect modes, setgid bit set",
				 nosetgid_A);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != mygid) {
			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
				 nosetgid_A, buf.st_gid, mygid);
			local_flag = FAILED;
		}

		/*
		 * Create the file with setgid set
		 */
		ret = open(setgid_A, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
		if (ret < 0) {
			tst_resm(TFAIL | TERRNO, "open(%s) failed", setgid_A);
			local_flag = FAILED;
		}
		close(ret);

		if (stat(setgid_A, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed", setgid_A);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (!(buf.st_mode & S_ISGID)) {
			tst_resm(TFAIL,
				 "%s: Incorrect modes, setgid bit not set",
				 setgid_A);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != mygid) {
			tst_resm(TFAIL, "%s: Incorrect group (%d and %d)",
				 setgid_A, buf.st_gid, mygid);
			local_flag = FAILED;
		}

		if (local_flag == PASSED) {
			tst_resm(TPASS, "Test passed in block1.");
		} else {
			tst_resm(TFAIL, "Test failed in block1.");
			fail_count++;
		}

		local_flag = PASSED;

		/*
		 * Create two files in testdir.B, one with the setgid
		 * bit set in the creation modes and the other without.
		 * Both should inherit the group ID of the parent
		 * directory, group2. Either file should have the segid
		 * bit set in the modes.
		 */
		/*
		 * Create the file with setgid not set
		 */
		ret = open(nosetgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_RWX);
		if (ret < 0) {
			tst_resm(TFAIL | TERRNO, "open(%s) failed", nosetgid_B);
			local_flag = FAILED;
		}
		close(ret);

		if (stat(nosetgid_B, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed", nosetgid_B);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (buf.st_mode & S_ISGID) {
			tst_resm(TFAIL,
				 "%s: Incorrect modes, setgid bit should be set",
				 nosetgid_B);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != group2_gid) {
			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
				 nosetgid_B, buf.st_gid, group2_gid);
			local_flag = FAILED;
		}

		/*
		 * Create the file with setgid set
		 */
		ret = open(setgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
		if (ret < 0) {
			tst_resm(TFAIL | TERRNO, "open(%s) failed", setgid_B);
			local_flag = FAILED;
		}
		close(ret);

		if (stat(setgid_B, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed", setgid_B);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != group2_gid) {
			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
				 setgid_B, buf.st_gid, group2_gid);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (!(buf.st_mode & S_ISGID)) {
			tst_resm(TFAIL,
				 "%s: Incorrect modes, setgid bit not set",
				 setgid_B);
			local_flag = FAILED;
		}

		if (local_flag == PASSED) {
			tst_resm(TPASS, "Test passed in block2.");
		} else {
			tst_resm(TFAIL, "Test failed in block2.");
			fail_count++;
		}

		local_flag = PASSED;

		/*
		 * Create a file in testdir.B, with the setgid bit set
		 * in the creation modes and do so as root. The file
		 * should inherit the group ID of the parent directory,
		 * group2 and should have the setgid bit set.
		 */

		/* Become root again */
		if (setreuid(-1, save_myuid) < 0) {
			tst_resm(TFAIL | TERRNO,
				 "Changing back to root failed");
			local_flag = FAILED;
		}

		/* Create the file with setgid set */
		ret = open(root_setgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
		if (ret < 0) {
			tst_resm(TFAIL | TERRNO, "open(%s) failed",
				 root_setgid_B);
			local_flag = FAILED;
		}
		close(ret);

		if (stat(root_setgid_B, &buf) < 0) {
			tst_resm(TFAIL | TERRNO, "stat(%s) failed",
				 root_setgid_B);
			local_flag = FAILED;
		}

		/* Verify modes */
		if (!(buf.st_mode & S_ISGID)) {
			tst_resm(TFAIL,
				 "%s: Incorrect modes, setgid bit not set",
				 root_setgid_B);
			local_flag = FAILED;
		}

		/* Verify group ID */
		if (buf.st_gid != group2_gid) {
			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
				 root_setgid_B, buf.st_gid, group2_gid);
			local_flag = FAILED;
		}

		if (local_flag == PASSED) {
			tst_resm(TPASS, "Test passed in block3.");
		} else {
			tst_resm(TFAIL, "Test failed in block3.");
			fail_count++;
		}

		/*
		 * Clean up any files created by test before call to anyfail.
		 * Remove the directories.
		 */
		if (unlink(setgid_A) < 0)
			tst_resm(TWARN | TERRNO, "unlink(%s) failed", setgid_A);
		if (unlink(nosetgid_A) < 0)
			tst_resm(TWARN | TERRNO, "unlink(%s) failed",
				 nosetgid_A);
		if (rmdir(DIR_A) < 0)
			tst_resm(TWARN | TERRNO, "rmdir(%s) failed", DIR_A);

		if (unlink(setgid_B) < 0)
			tst_resm(TWARN | TERRNO, "unlink(%s) failed", setgid_B);
		if (unlink(root_setgid_B) < 0)
			tst_resm(TWARN | TERRNO, "unlink(%s) failed",
				 root_setgid_B);
		if (unlink(nosetgid_B) < 0)
			tst_resm(TWARN | TERRNO, "unlink(%s) failed",
				 nosetgid_B);
		if (rmdir(DIR_B) < 0)
			tst_resm(TWARN | TERRNO, "rmdir(%s) failed", DIR_B);

		if (fail_count == 0) {
			tst_resm(TPASS, "Test passed.");
		} else {
			tst_resm(TFAIL,
				 "Test failed because of above failures.");
		}

	}

	cleanup();
	tst_exit();
}
Exemplo n.º 16
0
int
main(int ac, char **av)
{
    int lc;		/* loop counter */
    const char *msg;	/* message returned from parse_opts */
    long tret;
    
    /***************************************************************
     * parse standard options
     ***************************************************************/
    if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) {
	tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	tst_exit(0);
    }

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
    setup();

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
    for (lc=0; TEST_LOOPING(lc); lc++) {

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

		
	/* 
	 * TEST CASE:
	 * Increase by 8192 bytes
	 */
	Increment = 8192;

	/* Call sbrk(2) */
#if defined(sgi)
	tret=(long)sbrk(Increment);   /* Remove -64 IRIX compiler warning */
	TEST_ERRNO=errno;
#else
	TEST(sbrk(Increment));
	tret=TEST_RETURN;
#endif
	
	/* check return code */
	if ( tret == -1 ) {
	    TEST_ERROR_LOG(TEST_ERRNO);
	    tst_resm(TFAIL, "sbrk - Increase by 8192 bytes failed, errno=%d : %s",
		     TEST_ERRNO, strerror(TEST_ERRNO));
	} else {
	    /***************************************************************
	     * only perform functional verification if flag set (-f not given)
	     ***************************************************************/
	    if ( STD_FUNCTIONAL_TEST ) {
		/* No Verification test, yet... */
		tst_resm(TPASS, "sbrk - Increase by 8192 bytes returned %d", 
		    tret);
	    } 
	}
	
	
	/* 
	 * TEST CASE:
	 * Decrease to original size
	 */
	Increment=(Increment * -1);

	/* Call sbrk(2) */
#ifdef CRAY
	TEST(sbrk(Increment));
	tret=TEST_RETURN;
#else
	tret=(long)sbrk(Increment);
	TEST_ERRNO=errno;
#endif
	
	/* check return code */
	if ( tret == -1 ) {
	    TEST_ERROR_LOG(TEST_ERRNO);
	    tst_resm(TFAIL, "sbrk - Decrease to original size failed, errno=%d : %s",
		     TEST_ERRNO, strerror(TEST_ERRNO));
	} else {
	    /***************************************************************
	     * only perform functional verification if flag set (-f not given)
	     ***************************************************************/
	    if ( STD_FUNCTIONAL_TEST ) {
		/* No Verification test, yet... */
		tst_resm(TPASS, "sbrk - Decrease to original size returned %d", tret);
	    } 
	}
	

    }	/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
    cleanup();

    return 0;
}	/* End main */
Exemplo n.º 17
0
  void BitVector_Test::Test_bitVectorSetAndClearBits()
  {
    BitVector<256>* bits;
    bits = setup();

    assertUnchanged(0,7);
    bits->ClearBits(0,64);

    assertUnchanged(2,7);
    assert(bits->Read(0,32) == 0);
    assert(bits->Read(32,32) == 0);

    bits->SetBits(48,64);  // hits 1,2,3
    assert(bits->Read(0,32) == 0);
    assert(bits->Read(32,32) == 0x0000ffff);
    assert(bits->Read(64,32) == 0xffffffff);
    assert(bits->Read(96,32) == 0xffffdef0);

    bits = setup();
    bits->ClearBits(31,33);  // 0,1; unaligned start, aligned end

    assert(bits->Read(0,32) == 0x24681356);
    assert(bits->Read(32,32) == 0x0);
    assertUnchanged(2,7);

    bits = setup();
    bits->ClearBits(128,32+32+32+1);  // 4-7; aligned start, unaligned end

    assertUnchanged(0,3);
    assert(bits->Read(128,32) == 0x0);
    assert(bits->Read(160,32) == 0x0);
    assert(bits->Read(192,32) == 0x0);
    assert(bits->Read(224,32) == 0x7edbca09);

    bits = setup();
    bits->SetBits(128,32+32+32+32);  // 4-6; aligned start, aligned end

    assertUnchanged(0,3);
    assert(bits->Read(128,32) == 0xffffffff);
    assert(bits->Read(160,32) == 0xffffffff);
    assert(bits->Read(192,32) == 0xffffffff);
    assertUnchanged(7,7);

    bits = setup();
    bits->SetBits(100,48);        // 3-4; unaligned start, unaligned end, adjacent

    assertUnchanged(0,2);
    assert(bits->Read( 96,32) == 0x9fffffff);
    assert(bits->Read(128,32) == 0xfffffba9);
    assertUnchanged(5,7);

    bits = setup();
    bits->ClearBits(4,48); // 0-1; unaligned start&end, adjacent, first unit

    assert(bits->Read(  0,32) == 0x20000000);
    assert(bits->Read( 32,32) == 0x00000314);
    assertUnchanged(2,7);

    bits = setup();
    bits->ClearBits(192+16,32); // 6-7; unaligned start&end, adjacent, last unit

    assertUnchanged(0,5);
    assert(bits->Read(192,32) == 0x44330000);
    assert(bits->Read(224,32) == 0x0000ca09);

    bits = setup();
    bits->ClearBits(32+16,32*5); // 1-6; unaligned start&end, non-adjacent

    assertUnchanged(0,0);
    assert(bits->Read( 32,32) == 0x11120000);
    assert(bits->Read( 64,32) == 0x00000000);
    assert(bits->Read( 96,32) == 0x00000000);
    assert(bits->Read(128,32) == 0x00000000);
    assert(bits->Read(160,32) == 0x00000000);
    assert(bits->Read(192,32) == 0x00002211);
    assertUnchanged(7,7);

    bits = setup();
    bits->ClearBits(16,32*7); // 0-7; unaligned start&end, all units

    assert(bits->Read(  0,32) == 0x24680000);
    assert(bits->Read( 32,32) == 0x00000000);
    assert(bits->Read( 64,32) == 0x00000000);
    assert(bits->Read( 96,32) == 0x00000000);
    assert(bits->Read(128,32) == 0x00000000);
    assert(bits->Read(160,32) == 0x00000000);
    assert(bits->Read(192,32) == 0x00000000);
    assert(bits->Read(224,32) == 0x0000ca09);

    bits = setup();
    bits->ClearBits(0,32*8); // 0-7; all bits cleared

    for (u32 i = 0; i < 32*8; i += 32)
      assert(bits->Read(i,32) == 0x00000000);

    bits->SetBits(0,32*8); // 0-7; all bits set

    for (u32 i = 0; i < 32*8; i += 32)
      assert(bits->Read(i,32) == 0xffffffff);
  }
Exemplo n.º 18
0
int main(int ac, char **av) {
        pid_t pid1;
	int lc;                 /* loop counter */
        char *msg;              /* message TEST_RETURNurned from parse_opts */
	
        /* parse standard options */
        if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
             tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
             tst_exit();
           }

        setup();

        /* Check looping state if -i option given */
        for (lc = 0; TEST_LOOPING(lc); ++lc) {
                Tst_count = 0;
                for (testno = 0; testno < TST_TOTAL; ++testno) {

 /*
 *fork a child process;testing which one is a child or a parent;
 * */
		        TEST(pid1=fork());    //call to fork()
			if (TEST_RETURN == -1) {
				tst_resm(TFAIL|TTERRNO, "fork() failed.");
				cleanup();
				tst_exit();
			} else if (TEST_RETURN == 0) {
				TEST_RETURN = unshare(CLONE_FS);
				if (TEST_RETURN == 0)
					tst_resm(TPASS,
						"unshare with CLONE_FILES call "
						"succeeded");
				else if (TEST_RETURN == -1) {
					if (errno == ENOSYS)
						tst_resm(TCONF,
							"unshare is not "
							"implemented in kernel."
							);
					else
						tst_resm(TFAIL|TERRNO,
							"unshare failed.");
				}
				tst_exit();
			}else{
			}

			TEST(pid1=fork());    //call to fork()
			if (TEST_RETURN == -1) {
				tst_resm(TFAIL|TTERRNO, "fork() failed.");
	                        cleanup();
                        	tst_exit();
			} else if (TEST_RETURN == 0) {
				TEST_RETURN = unshare(CLONE_FS);
				if (TEST_RETURN == 0)
					tst_resm(TPASS,
						"unshare with CLONE_FS call "
						"succeeded");
				else if (TEST_RETURN == -1) {
					if (errno == ENOSYS)
						tst_resm(TCONF,
							"unshare is not "
							"implemented in kernel."
							);
					else
						tst_resm(TFAIL|TERRNO,
							"unshare failed 2.");
				}
				tst_exit();
                        }else{
			}

			TEST(pid1=fork());    //call to fork()
			if (TEST_RETURN == -1) {
				tst_resm(TFAIL|TTERRNO, "fork() failed.");
	                        cleanup();
                        	tst_exit();
			} else if (TEST_RETURN == 0) {
				TEST_RETURN = unshare(CLONE_NEWNS);
				if (TEST_RETURN == 0) {
					tst_resm(TPASS,
						"unshare call with CLONE_NEWNS "
						"succeeded");
				} else if (TEST_RETURN == -1) {
					if (errno == ENOSYS)
						tst_resm(TCONF,
							"unshare is not "
							"implemented in kernel."
							);
					else
						tst_resm(TFAIL|TERRNO,
							"unshare failed 2.");
				}
				tst_exit();
                        }else{
			}


                }

                }
	cleanup();
	tst_exit();
}
Exemplo n.º 19
0
  void BitVector_Test::Test_bitVectorAllocate()
  {
    BitVector<256>* bits = setup();

    assert(bits->Read(0, 32) == 0x24681357);
  }
Exemplo n.º 20
0
int test_setup() {
    setup();
}
Exemplo n.º 21
0
/* MotionManager::MotionManager: constructor */
MotionManager::MotionManager(PMDModel * pmd)
{
    initialize();
    setup(pmd);
}
Exemplo n.º 22
0
// Pawn attacks.
void test_position_targets_suite__040(void) {
	setup("Ke1,a3,b3,c3,d3,e3,f3,g3,h3", "Ke8,a6,b6,c6,d6,e6,f6,g6,h6");
    	Position *p = start();
	cl_check(pawn_attacks(p, White) == (bit[A4] | bit[B4] | bit[C4] | bit[D4] | bit[E4] | bit[F4] | bit[G4] | bit[H4]));
	cl_check(pawn_attacks(p, Black) == (bit[A5] | bit[B5] | bit[C5] | bit[D5] | bit[E5] | bit[F5] | bit[G5] | bit[H5]));
}
Exemplo n.º 23
0
AIMGRAPH::AIMGRAPH ()
{
  for (int i = 0; i < AIM_SIZE; ++i)
    p[i] = P_MAX / 2;
  father[ROOT] = ROOT;
  setup (BIND < AIM, int >()(10, ROOT, HIS_CLUSTER, HIS_MASS, HIS_POTENTIAL, PUBLICAREA, MY_CLUSTER, MY_MASS, MY_POTENTIAL, COMPLICATE, SIMPLIFY));
  setup (BIND < AIM, int >()(5, HIS_CLUSTER, GE, FENG, GAN, SHA));
  setup (BIND < AIM, int >()(3, SHA, POYAN, SUOYANWEI));
  setup (BIND < AIM, int >()(3, HIS_MASS, _ZHENGXING, CHIZI));
  setup (BIND < AIM, int >()(8, CHIZI, DA, JIA, GUN, JIEBUGUI, DAOPU, ZHENGZI, DAOTUOXUE));
  setup (BIND < AIM, int >()(6, HIS_POTENTIAL, QINGXIAO, BI, SHENGTUI, QINSHI, DARU));
  setup (BIND < AIM, int >()(2, PUBLICAREA, ZHANDACHANG));
  setup (BIND < AIM, int >()(5, MY_CLUSTER, _GE, TUWEI, SHENGGEN, ZUOHUO));
  setup (BIND < AIM, int >()(3, ZUOHUO, ZUOYAN, KUOYANWEI));
  setup (BIND < AIM, int >()(3, MY_MASS, ZHENGXING, JIUZI));
  setup (BIND < AIM, int >()(8, JIUZI, _DA, _JIA, _GUN, _JIEBUGUI, _DAOPU, _ZHENGZI, _DAOTUOXUE));
  setup (BIND < AIM, int >()(6, MY_POTENTIAL, KUOZHANG, CHAI, _SHENGTUI, _QINSHI, _DARU));
  setup (BIND < AIM, int >()(1, ZHIGAODIAN));
  setup (BIND < AIM, int >()(9, COMPLICATE, TENNUO, JIAO, YUWEI, SHIYINGSHOU, ZUOJIE, XUNJIE, CHANGSHENG, DUISHA));
  setup (BIND < AIM, int >()(5, SIMPLIFY, DINGXING, LIYONG, ZHENGXIAN, DAJIANG));
}
Exemplo n.º 24
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int advise;

	/* Check this system has fadvise64 system which is used
	   in posix_fadvise. */
	if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) {
		tst_resm(TWARN,
			 "This test can only run on kernels that implements ");
		tst_resm(TWARN, "fadvise64 which is used from posix_fadvise");
		exit(0);
	}

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

	/*
	 * perform global setup for test
	 */
	setup();

	/*
	 * check looping state if -i option given on the command line
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

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

			/* Don't use defiend advise as an argument. */
			if (is_defined_advise(advise)) {
				continue;
			}

			TEST(posix_fadvise(fd, 0, 0, advise));

			if (TEST_RETURN == 0) {
				tst_resm(TFAIL, "call succeeded unexpectedly");
				continue;
			}

			/* Man page says:
			   "On error, an error number is returned." */
			if (TEST_RETURN == expected_error) {
				tst_resm(TPASS,
					 "expected failure - "
					 "returned value = %ld, advise = %d : %s",
					 TEST_RETURN,
					 advise, strerror(TEST_RETURN));
			} else {
				tst_resm(TFAIL,
					 "unexpected return value - %ld : %s, advise %d - "
					 "expected %d",
					 TEST_RETURN,
					 strerror(TEST_RETURN),
					 advise, expected_error);
			}
		}
	}

	/*
	 * cleanup and exit
	 */
	cleanup();

	tst_exit();
}
Exemplo n.º 25
0
SHomography::SHomography(SAttachedPoint *a=0, SAttachedPoint *b=0, SAttachedPoint *c=0, SAttachedPoint *d=0)
{
	for (int i=0; i<4; i++) pts[i]=0;
	setup(a,b,c,d);
}
Exemplo n.º 26
0
GameSpyServer::GameSpyServer(const char *host, int port)
{
    setup(host, port);
}
Exemplo n.º 27
0
int main(int ac, char **av)
{
	int lc;
	char *msg;

	int i, red, wtstatus;
	int pipefd[2];		/* fds for pipe read/write */
	char rebuf[BUFSIZ];
	int Acnt = 0, Bcnt = 0;	/* count 'A' and 'B' */
	int fork_1, fork_2;	/* ret values in parent */

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

	setup();

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

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

		TEST(pipe(pipefd));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "pipe() call failed");
			continue;
		}

		if (!STD_FUNCTIONAL_TEST) {
			tst_resm(TWARN, "-f option should not be used");
			tst_resm(TPASS, "call succeeded");
			continue;
		}

		if ((fork_1 = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork() #1 failed");
		}

		if (fork_1 == 0) {	/* 1st child */
			if (close(pipefd[0]) != 0) {
				tst_resm(TWARN, "pipefd[0] close failed, "
					 "errno = %d", errno);
				exit(1);
			}

			for (i = 0; i < PIPEWRTCNT / 2; ++i) {
				if (write(pipefd[1], "A", 1) != 1) {
					tst_resm(TWARN, "write to pipe failed");
					exit(1);
				}
			}
			exit(0);
		}

		/* parent */

		if (waitpid(fork_1, &wtstatus, 0) == -1)
			tst_brkm(TBROK, cleanup, "waitpid failed");
		if (WIFEXITED(wtstatus) && WEXITSTATUS(wtstatus) != 0) {
			tst_brkm(TBROK, cleanup, "child exited abnormally");
		}

		if ((fork_2 = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork() #2 failed");
		 }

		if (fork_2 == 0) {	/* 2nd child */
			if (close(pipefd[0]) != 0) {
				perror("pipefd[0] close failed");
				exit(1);
			}

			for (i = 0; i < PIPEWRTCNT / 2; ++i) {
				if (write(pipefd[1], "B", 1) != 1) {
					perror("write to pipe failed");
					exit(1);
				}
			}
			exit(0);
		}

		/* parent */

		if (waitpid(fork_2, &wtstatus, 0) == -1)
			tst_brkm(TBROK, cleanup, "waitpid failed");
		if (WEXITSTATUS(wtstatus) != 0) {
			tst_brkm(TBROK, cleanup, "problem detected in child, "
				 "wait status %d, errno = %d", wtstatus, errno);
		}

		if (close(pipefd[1]) != 0) {
			tst_brkm(TBROK|TERRNO, cleanup,
			    "pipefd[1] close failed");
		}

		while ((red = safe_read(pipefd[0], rebuf, 100)) > 0) {
			for (i = 0; i < red; i++) {
				if (rebuf[i] == 'A') {
					Acnt++;
					continue;
				}
				if (rebuf[i] == 'B') {
					Bcnt++;
					continue;
				}
				tst_resm(TFAIL, "got bogus '%c' character",
					 rebuf[i]);
				break;
			}
		}

		if (red == -1) {
			tst_brkm(TBROK|TERRNO, cleanup,
			    "reading pipefd pipe failed");
		}

		if (Bcnt == Acnt && Bcnt == (PIPEWRTCNT / 2)) {
			tst_resm(TPASS, "functionality appears to be correct");
		} else {
			tst_resm(TFAIL, "functionality is not correct - Acnt "
				 "= %d, Bcnt = %d", Acnt, Bcnt);
		}

		/* clean up things in case we are looping */
		Acnt = Bcnt = 0;
	}
	cleanup();

	tst_exit();
}
Exemplo n.º 28
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	char file_content;	/* tempfile content */

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

	setup();

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

		Tst_count = 0;

		/*
		 * Call mmap to map the temporary file 'TEMPFILE'
		 * with no access.
		 */
		errno = 0;
		addr = mmap(0, page_sz, PROT_NONE,
			    MAP_FILE | MAP_SHARED, fildes, 0);
		TEST_ERRNO = errno;

		/* Check for the return value of mmap() */
		if (addr == MAP_FAILED) {
			tst_resm(TFAIL|TERRNO, "mmap() failed on %s", TEMPFILE);
			continue;
		}

		/*
		 * Perform functional verification if test
		 * executed without (-f) option.
		 */
		if (STD_FUNCTIONAL_TEST) {

			/*
			 * Try to access the mapped region.  This should
			 * generate a SIGSEGV which will be caught below.
			 *
			 * This is wrapped by the sigsetjmp() call that will
			 * take care of restoring the program's context in an
			 * elegant way in conjunction with the call to
			 * siglongjmp() in the signal handler.
			 */
			if (sigsetjmp(env, 1) == 0) {
				file_content = addr[0];
			}

			if (pass) {
				tst_resm(TPASS, "Got SIGSEGV as expected");
			} else {
				tst_resm(TFAIL, "Mapped memory region with NO "
					 "access is accessible");
			}
		} else {
			tst_resm(TPASS, "call succeeded");
		}

		/* Unmap mapped memory and reset pass in case we are looping */
		if (munmap((void *)addr, page_sz) != 0) {
			tst_brkm(TFAIL|TERRNO, cleanup, "munmap failed");
		}
		pass = 0;

	}
	cleanup();
	tst_exit();

}
Exemplo n.º 29
0
ofxGuiGroup * ofxGuiGroup::setup(string collectionName, string filename, float x, float y){
	parameters.setName(collectionName);
	return setup(parameters,filename,x,y);
}
Exemplo n.º 30
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	pid_t my_pid;		/* test process id */

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

	 /*NOTREACED*/}

	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

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

		tst_count = 0;

		/*
		 * Call sigprocmask() to block (SIGINT) signal
		 * so that, signal will not be delivered to
		 * the test process.
		 */
		TEST(sigprocmask(SIG_BLOCK, &sigset, 0));

		/* Get the process id of test process */
		my_pid = getpid();

		/* Send SIGINT signal to the process */
		kill(my_pid, SIGINT);

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "sigprocmask() Failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/*
			 * Perform functional verification if test
			 * executed without (-f) option.
			 */
			if (STD_FUNCTIONAL_TEST) {
				/*
				 * Check whether process received the signal.
				 * If yes! signal handler was executed and
				 * incremented 'sig_catch' variable.
				 */
				if (sig_catch) {
					tst_resm(TFAIL, "sigprocmask fails to "
						 "change process's signal mask");
				} else {
					/*
					 * Check whether specified signal
					 * 'SIGINT' is pending for the process.
					 */
					errno = 0;
					if (sigpending(&sigset2) == -1) {
						tst_brkm(TFAIL, cleanup,
							 "blocked signal not "
							 "in pending state, "
							 "error:%d", errno);
					}

					/*
					 * Check whether specified signal
					 * is the member of signal set.
					 */
					errno = 0;
					if (!sigismember(&sigset2, SIGINT)) {
						tst_brkm(TFAIL, cleanup,
							 "sigismember() failed, "
							 "error:%d", errno);
					}

					/*
					 * Invoke sigprocmask() again to
					 * unblock the specified signal.
					 * so that, signal is delivered and
					 * signal handler executed.
					 */
					errno = 0;
					if (sigprocmask(SIG_UNBLOCK,
							&sigset, 0) == -1) {
						tst_brkm(TFAIL, cleanup,
							 "sigprocmask() failed "
							 "to unblock signal, "
							 "error=%d", errno);
					}
					if (sig_catch) {
						tst_resm(TPASS, "Functionality "
							 "of sigprocmask() "
							 "Successful");
					} else {
						tst_resm(TFAIL, "Functionality "
							 "of sigprocmask() "
							 "Failed");
					}
					/* set sig_catch back to 0 */
					sig_catch = 0;
				}
			} else {
				tst_resm(TPASS, "Call succeeded");
			}
		}

		tst_count++;	/* incr TEST_LOOP counter */
	}

	cleanup();
	tst_exit();

}