virtual void SetUp() {
   fdin = SC_openPort(port_address); 
   if (fdin==-1) exit(EXIT_FAILURE);
   const ::testing::TestInfo* const test_info =
         ::testing::UnitTest::GetInstance()->current_test_info();
   char test_description[CS1_MAX_FRAME_SIZE] = {0};
   Shakespeare::log(Shakespeare::NOTICE, PROCESS, ">>>>>>>>>>>>>>>>>>>>>> NEW TEST <<<<<<<<<<<<<<<<<<<<<<");
   sprintf(test_description,"We are in test %s of test case %s.",
                   test_info->name(), test_info->test_case_name());
   Shakespeare::log(Shakespeare::NOTICE, PROCESS, test_description);
 }
示例#2
0
bool initialize(){

   fprintf(stderr, "Initializing %s\n", __FILE__);
   
   if(0 == (he100_fd = SC_openPort(port_address))){
      fprintf(stderr, "SC_openPort returned 0 (%s:%d)\n",__FILE__,__LINE__);
      return false;
   }

   fprintf(stderr, "Initialization successful!\n");

   return true;
}
示例#3
0
TEST(SerialTestGroup, UTestSerial_ConfigureInterface)
{
    struct termios settings;

    settings.c_iflag &= ~(
          IGNBRK // disable: ignore BREAK condition on input
        | BRKINT // convert break to null byte
        | ICRNL  // no CR to NL translation
        | INLCR  // no NL to CR translation
        | PARMRK // don't mark parity errors or breaks
        | INPCK  // no input parity check
        | ISTRIP // don't strip high bit off
    //    | IXON   // no XON/XOFF software flow control
    );
    settings.c_iflag |= (
          IXON
        | IXOFF
        | IGNPAR // ignore bytes with parity errors
        | ICRNL  // map CR to NL (otherwise CR input on other computer will not terminate input)
    //    | INLCR  // map NL to CR (otherwise CR input on other computer will not terminate input)
    );

    // Output flags
    settings.c_oflag = 0; // disable output processing, raw output

    // Line processing flags
    settings.c_lflag = 0; // disable line processing

    // settings.c_lflag = ICANON; // enable canonical input
    //cfmakeraw(&settings); // raw mode Input is not assembled into lines and special characters are not processed.

    settings.c_lflag = ECHONL;

    // Control flags
    settings.c_cflag &= ~( // disable stuff
          PARENB  // no parity bit
        | CSIZE   // mask the character size bits
        | CSTOPB  // stop bits: 1 stop bit
        | CRTSCTS // disable hardware flow control
        //| ~PARODD; // even parity
    );
    settings.c_cflag |= ( // enable stuff
          B9600    // set BAUD to 9600
        | CS8      // byte size: 8 data bits
        | CREAD   // enable receiver
        //| PARENB  // enable parity bit
        //| PARODD  // odd parity
        //| CLOCAL  // set local mode
    );

    settings.c_ispeed = B9600;
    settings.c_ospeed = B9600;

    // ONLY for non-canonical read control behaviour
    settings.c_cc[VMIN]  = 1;     // min bytes to return read
    settings.c_cc[VTIME] = 30;    // read timeout in 1/10 seconds

    // set up our mock serial device
    int pdm; // the master pseudo tty to write to
    int pds; // the slave pseudo tty to read from

    // set up master
    pdm = SC_openPort("/dev/ptmx"/*, O_RDWR | O_NOCTTY*/);
    CHECK(pdm != -1);

    // assign slave
    grantpt(pdm);
    unlockpt(pdm);
    pds = SC_openPort(ptsname(pdm), settings); // TESTING OVERLOADED CALL HERE

    CHECK(pds != -1);

    CHECK( SC_configureInterface(pdm,settings) == 0 ); // TESTING OVERLOADED CALL HERE
    
    // flush and close the pseudo serial devices
    fsync(pdm);
    fsync(pds);

    // close both pseudo terminal connections
    int pdmc = SC_closePort(pdm);
    int pdsc = SC_closePort(pds);

    // check that the return status was successful when closing
    CHECK_EQUAL(0,pdmc);
    CHECK_EQUAL(0,pdsc);
}