コード例 #1
0
ファイル: intTests.cpp プロジェクト: gerardvisser/projects
static void testBsr (void) {
  ___BTPUSH;
  printTest ("int_bsr");

  assert (int_bsr (0x00) == 0);
  assert (int_bsr (0x01) == 1);
  assert (int_bsr (0x02) == 2);
  assert (int_bsr (0x03) == 2);
  assert (int_bsr (0x04) == 3);
  assert (int_bsr (0x05) == 3);
  assert (int_bsr (0x06) == 3);
  assert (int_bsr (0x07) == 3);
  assert (int_bsr (0x08) == 4);
  assert (int_bsr (0x09) == 4);
  assert (int_bsr (0x0A) == 4);
  assert (int_bsr (0x0B) == 4);
  assert (int_bsr (0x0C) == 4);
  assert (int_bsr (0x0D) == 4);
  assert (int_bsr (0x0E) == 4);
  assert (int_bsr (0x0F) == 4);
  assert (int_bsr (0x10) == 5);
  assert (int_bsr (0x20) == 6);
  assert (int_bsr (0xC3) == 8);
  assert (int_bsr (0xCD20) == 16);
  assert (int_bsr (0xE80000) == 24);
  assert (int_bsr (0x40003001) == 31);
  assert (int_bsr (0x80000000) == 32);
  assert (int_bsr (-2) == 32);
  assert (int_bsr (-1) == 32);

  printOk ();
  ___BTPOP;
}
コード例 #2
0
ファイル: Logger.cpp プロジェクト: DX-MON/crunch
void echoOk()
{
	if (isTTY)
		testPrintf(CURS_UP SET_COL BRACKET "[" SUCCESS "  OK  " BRACKET "]" NEWLINE, COL(getColumns()));
	else
		printOk();
	++passes;
}
コード例 #3
0
ファイル: bcc-eval.c プロジェクト: allenh1/cs252-lab6
int main(int argc, char ** argv)
{
  struct sigaction chld;
  chld.sa_handler = sigchld_handlr;
  sigemptyset(&chld.sa_mask);
  chld.sa_flags = SA_RESTART | SA_NOCLDSTOP;

  if (sigaction(SIGCHLD, &chld, NULL) == -1) {
    perror("sigchild");
    _exit(-1);
  }
  
  const unsigned short port = 8888;
  
  struct sockaddr_in serverIP;

  // Clear server socket
  memset(&serverIP, 0, sizeof(serverIP));
  serverIP.sin_family = AF_INET;             // internet mode
  serverIP.sin_addr.s_addr = INADDR_ANY;     // accept from any host
  serverIP.sin_port = htons((u_short) port); // accept on port 8888

  int masterSocket = socket(PF_INET, SOCK_STREAM, 0);
  if (masterSocket < 0) {
    perror("socket");
    _exit(1);
  }

  int error = bind(masterSocket, (struct sockaddr*) &serverIP, sizeof(serverIP));

  if (error) {
    perror("bind");
    _exit(2);
  }

  error = listen(masterSocket, _queue_length);
  if (error) {
    perror("listen");
    _exit(3);
  }

  for (; true;) {
    struct sockaddr_in client_ip; int pid = -1;
    ssize_t alen = sizeof(client_ip);
    int slave = accept(masterSocket, (struct sockaddr*) &client_ip,
		       (socklen_t*) &alen);
    if (slave < 0) {
      perror("accept");
      _exit(4);
    }
    struct winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
  
    printOk("client connection received");
    process_request(slave);
  } return 0;
}
コード例 #4
0
void checkFunnelObstacleReadWrite()
{
  std::string inputFileName = "bla.dat";
  FunnelObstacle fo(16.0f, 20.0f, 40.0f, 128, 128);
  fo.write(inputFileName);

  FunnelObstacle fIn(16.0f, 20.0f, 40.0f, 128, 128, inputFileName);
  assertTrue(fIn == fo);
  printOk();
}
コード例 #5
0
ファイル: intTests.cpp プロジェクト: gerardvisser/projects
static void testBsf (void) {
  ___BTPUSH;
  printTest ("int_bsf");

  assert (int_bsf (0x00) == 0);
  assert (int_bsf (0x01) == 0);
  assert (int_bsf (0x02) == 1);
  assert (int_bsf (0x03) == 0);
  assert (int_bsf (0x04) == 2);
  assert (int_bsf (0x05) == 0);
  assert (int_bsf (0x06) == 1);
  assert (int_bsf (0x07) == 0);
  assert (int_bsf (0x08) == 3);
  assert (int_bsf (0x09) == 0);
  assert (int_bsf (0x0A) == 1);
  assert (int_bsf (0x0B) == 0);
  assert (int_bsf (0x0C) == 2);
  assert (int_bsf (0x0D) == 0);
  assert (int_bsf (0x0E) == 1);
  assert (int_bsf (0x0F) == 0);
  assert (int_bsf (0x10) == 4);
  assert (int_bsf (0x80000000) == 31);
  assert (int_bsf (0x90000000) == 28);
  assert (int_bsf (0xA0000000) == 29);
  assert (int_bsf (0xB0000000) == 28);
  assert (int_bsf (0xC0000000) == 30);
  assert (int_bsf (0xD0000000) == 28);
  assert (int_bsf (0xD8740000) == 18);
  assert (int_bsf (0xD8740002) == 1);
  assert (int_bsf (0xE0000000) == 29);
  assert (int_bsf (0xF0000000) == 28);
  assert (int_bsf (-8) == 3);
  assert (int_bsf (-6) == 1);
  assert (int_bsf (-4) == 2);
  assert (int_bsf (-2) == 1);
  assert (int_bsf (-1) == 0);

  printOk ();
  ___BTPOP;
}
コード例 #6
0
ファイル: Logger.cpp プロジェクト: DX-MON/crunch
void echoOk()
{
	if (isTTY)
	{
		CONSOLE_SCREEN_BUFFER_INFO cursor;
		GetConsoleScreenBufferInfo(console, &cursor);
		cursor.dwCursorPosition.Y--;
		cursor.dwCursorPosition.X = COL(getColumns());
		SetConsoleCursorPosition(console, cursor.dwCursorPosition);
		SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
		testPrintf("[");
		SetConsoleTextAttribute(console, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
		testPrintf("  OK  ");
		SetConsoleTextAttribute(console, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
		testPrintf("]");
		SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
		testPrintf("\n");
	}
	else
		printOk();
	passes++;
}
コード例 #7
0
ファイル: bcc-eval.c プロジェクト: allenh1/cs252-lab6
/**
 * @brief Process bcc request.
 *
 * This function evalutes a bcc program and serves,
 * as a response, the output of the bcc program.
 *
 * @param fd The file descriptor of the requesting client.
 */
void process_request(int fd)
{
  const unsigned short max_request = 1024;
  char * _get_request = (char*) calloc(max_request + 1, sizeof(char));
  ssize_t request_len = 0;
  int n;

  unsigned char next_char = '\0';
  unsigned char last_char = '\0';

  int pid = -1;
  
  for (int n = 0; request_len < max_request && (n = read(fd, &next_char,
							 sizeof(next_char)) > 0);) {
    if (strstr(_get_request, "done!")) {
      _get_request[request_len++] = '\n';
      break;
    }
    if (next_char == '\r') continue; // Hacky, yes.
    else {
      if (request_len) last_char = _get_request[request_len-1];
      _get_request[request_len++] = next_char;
    }
  }
  char * copy = _get_request;
  pid = fork();

  if (pid == 0) {
    int fdpipe[2]; int pid2;
    if (pipe(fdpipe) < 0) {
      printErr("failed to construct pipe");
      _exit(8);
    } else if ((pid2 = fork()) < 0) {
      printErr("failed to fork process");
      _exit(9);
    } else if (pid2 == 0) {
      dup2(fdpipe[0], 0);
      dup2(2, fd);// write errors to host
      close(2);
      dup2(1, fd);// write other  to host
      close(1);
      close(fdpipe[0]); close(1);
      close(fdpipe[1]);
      if (execlp("bcc", "bcc", "out.s", NULL)) {
	printErr("bcc failed -- is it installed?");
      } 
    } else {
      close(fdpipe[0]);
      write(fdpipe[1], _get_request, request_len);
      close(fdpipe[1]);
      
      waitpid(pid2, NULL, 0);
      char * buff = (char*) calloc(1024, sizeof(char));
      sprintf(buff, "process [%d] (bcc) has exited.", pid2);
      printOk(buff); free(buff);
      _exit(0);
    }
  } else if (pid > 0) {
    struct winsize w;
    ioctl(1,TIOCGWINSZ, &w);
    waitpid(pid, NULL, 0);
    char * buff = (char*) calloc(1024, sizeof(char));
    sprintf(buff, "process [%d] has exited.", pid);
    printOk(buff); free(buff);
  } free(copy);

  /** generate out.txt **/
  if (write(fd, "\n", 1) < 0) {
    printErr("Client disconnected unexpectedly.");
    return;
  }

  int fdpipe[2];
  if (pipe(fdpipe) < 0) {
    printErr("Failed to construct pipe.");
    close(fd); return;
  } else if ((pid = fork()) < 0) {
    printErr("Failed to fork process");
    close(fd); return;
  } else if (pid == 0) {
    close(fdpipe[0]);

    dup2(fdpipe[1], 1); // stdout to pipe
    dup2(fdpipe[1], 2); // stderr to pipe

    close(fdpipe[1]);

    execlp("./out", "./out", NULL);
    _exit(0);
  } else {
    char buff[2048]; memset(buff, 0, 2048);
    close(fdpipe[1]);

    for(;read(fdpipe[0], buff, sizeof(buff)););
    waitpid(pid, NULL, 0);
    char buff2[64]; memset(buff2, 0, 64);
    sprintf(buff2, "process [%d] has exited", pid);
    printOk(buff2);
    /** Send output to client **/
    D fprintf(stderr, "bufflen: %zd\n", strlen(buff));
    for (char * b = buff; *b && write(fd, b++, 1); b - buff != strlen(buff));
    printOk("closing client connection.");
  } 
}