Ejemplo n.º 1
0
// 17/04/2003, flight Barcelona-Manchester
// 03/05/2003 Manchester changed
void Inference::Data::destroy ()
{ 
  TRACER ("Inference::Data::destroy");

  ASS (this);
  ASS (_counter == 0);

  switch (rule()) 
    {
    case FORALL_AND_MINISCOPE:
    case SWAP:
      delete static_cast<Type1*>(this);
      return;

    case FORALL_OR_MINISCOPE:
      delete static_cast<ForallOrMiniscope*>(this);
      return;

    case DUMMY_QUANTIFIER_REMOVAL:
      delete static_cast<DummyQuantifierRemoval*>(this);
      return;

    case FLATTEN:
      delete static_cast<Flatten*>(this);
      return;

    default:
      ASS (false);
    }
} // Inference::Data::destroy ()
Ejemplo n.º 2
0
inline
void Inference::Data::deref () 
{ 
  ASS (this);
  ASS (_counter > 0);
  _counter--;

  if (_counter == 0) {
    destroy ();
  }
} // Inference::Data::deref ()
Ejemplo n.º 3
0
/*  ...
 */
void CBaSwOsciTest::Errors() {
   IBaSwOsci *p = IBaSwOsciCreate(0, RESPATH, true);
   ASS(!p);
   TBaSwOsciHdl h = BaSwOsciCreate("BaSwOsciTest", 0, eBaBool_false);
   ASS(h);
   ASS(BaSwOsciDestroy(h));

   std::cout << remove("BaSwOsciTest.csv") << ":";
   std::cout << errno << std::endl;

   ASS(!IBaSwOsciDestroy(0));
}
Ejemplo n.º 4
0
Inference::Type1::Type1 (Rule r, const Formula& premise, const Position& p)
  :
  DFormula (r, premise),
  _position (p)
{
  ASS (r == FORALL_AND_MINISCOPE || r == SWAP);
} // Inference::Type1::Type1
Ejemplo n.º 5
0
inline
void Inference::Data::ref () 
{ 
  ASS (this);

  _counter++;
} // Inference::Data::ref ()
Ejemplo n.º 6
0
// comparison of two atoms, needed to normalize
// 28/08/2002 Torrevieja
Compare Atom::compare ( Atom a ) const 
{ 
  // equality is less than nonequality
  if ( isEquality() ) {
    if ( ! a.isEquality() )
      return LESS;
  }
  else if ( a.isEquality() ) {
      return GREATER;
  }
  // now either both are equality or both are not equality

  switch ( functor()->compare(a.functor()) ) {
    case LESS:
      return LESS;

    case EQUAL:
      return args().compare(a.args());

    case GREATER:
      return GREATER;

    #if DEBUG_PREPRO
    default:
      ASS(false);
    #endif
  }
}  // Atom::compare
Ejemplo n.º 7
0
inline 
Inference::Data::~Data ()
{
  TRACER( "Inference::Data::~Data" );

  ASS (_counter == 0);
} // Inference::Data::~Data ()
Ejemplo n.º 8
0
inline
Inference::Rule Inference::Data::rule () const 
{ 
  ASS (this);

  return _rule; 
} // Inference::Data::rule ()
Ejemplo n.º 9
0
// 03/05/2003 Manchester
Inference::Inference (Rule r, 
		      const Formula& premise, 
		      const Position& p)
  :
  _data (new Type1 (r, premise, p))
{
  ASS (r == FORALL_AND_MINISCOPE || r == SWAP);
} // Inference::Inference
Ejemplo n.º 10
0
void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) {
  uint32_t Offset = sizeof(uint32_t); /* SectionLength */

  SW.printNumber("SectionLength", Length);

  const char *VendorName = reinterpret_cast<const char*>(Data + Offset);
  size_t VendorNameLength = std::strlen(VendorName);
  SW.printString("Vendor", StringRef(VendorName, VendorNameLength));
  Offset = Offset + VendorNameLength + 1;

  if (StringRef(VendorName, VendorNameLength).lower() != "aeabi")
    return;

  while (Offset < Length) {
    /// Tag_File | Tag_Section | Tag_Symbol   uleb128:byte-size
    uint8_t Tag = Data[Offset];
    SW.printEnum("Tag", Tag, makeArrayRef(TagNames));
    Offset = Offset + sizeof(Tag);

    uint32_t Size =
      *reinterpret_cast<const support::ulittle32_t*>(Data + Offset);
    SW.printNumber("Size", Size);
    Offset = Offset + sizeof(Size);

    if (Size > Length) {
      errs() << "subsection length greater than section length\n";
      return;
    }

    StringRef ScopeName, IndexName;
    SmallVector<uint8_t, 8> Indicies;
    switch (Tag) {
    case ARMBuildAttrs::File:
      ScopeName = "FileAttributes";
      break;
    case ARMBuildAttrs::Section:
      ScopeName = "SectionAttributes";
      IndexName = "Sections";
      ParseIndexList(Data, Offset, Indicies);
      break;
    case ARMBuildAttrs::Symbol:
      ScopeName = "SymbolAttributes";
      IndexName = "Symbols";
      ParseIndexList(Data, Offset, Indicies);
      break;
    default:
      errs() << "unrecognised tag: 0x" << utohexstr(Tag) << '\n';
      return;
    }

    DictScope ASS(SW, ScopeName);

    if (!Indicies.empty())
      SW.printList(IndexName, Indicies);

    ParseAttributeList(Data, Offset, Length);
  }
}
Ejemplo n.º 11
0
/*  Test the time stamp functions
 */
void CBaCoreTest::TimeStamps() {
   TBaCoreTimeStamp tStamp;

   // Test the time stamp structure
   BaCoreGetTStamp(&tStamp);
   ASS(tStamp.micros < 1000000);
   ASS(tStamp.millis < 1000);

   // 11/04/2016
   ASS_MSG(std::to_string(tStamp.tt) + " > 1460366790", tStamp.tt > 1460366790);

   // Assert it returns a pointer
   ASS(BaCoreTStampToStr(&tStamp, sBuf));

   // Test the mallocated function
   const char * tss = BaCoreTStampToStr(&tStamp, 0);
   ASS(tss);
   std::cout << tss << std::endl;
   free((void*)tss);

   std::cout << BaCoreTStampToStr(&tStamp, sBuf) << std::endl;

   // Bad timestamp
   tStamp.millis = 1234;
   ASS(!BaCoreTStampToStr(&tStamp, sBuf));


   // Monotonic timestamp
   TBaCoreMonTStampUs ts = BaCoreGetMonTStamp();
   ASS(ts > 0);
   BaCoreUSleep(1);
   ASS(BaCoreGetMonTStamp() > ts);

}
Ejemplo n.º 12
0
// 03/05/2003 Manchester
Inference::Inference (Rule r, 
		      const Formula& premise,
		      const Position& p,
		      int subformulaIndex)
  :
  _data (new Flatten (r, premise, p, subformulaIndex))
{
  ASS (r == FLATTEN);
} // Inference::Inference
Ejemplo n.º 13
0
// 03/05/2003 Manchester
Inference::Inference (Rule r, 
		      const Formula& premise, 
		      const Position& p,
		      const VarList& removedVars)
  :
  _data (new DummyQuantifierRemoval (r, premise, p, removedVars))
{
  ASS (r == DUMMY_QUANTIFIER_REMOVAL);
} // Inference::Inference
Ejemplo n.º 14
0
// 03/05/2003 Manchester
Inference::DummyQuantifierRemoval::DummyQuantifierRemoval (Rule r, 
							   const Formula& premise,
							   const Position& p, 
							   const VarList& removedVars)
  : 
  DFormula (r, premise),
  _removedVars (removedVars)
{
  ASS (r == DUMMY_QUANTIFIER_REMOVAL);
} // Inference::DummyQuantifierRemoval::DummyQuantifierRemoval
Ejemplo n.º 15
0
// 03/05/2003 Manchester
Inference::Flatten::Flatten (Rule r, 
			     const Formula& premise,
			     const Position& p,
			     int subformulaIndex)
  :
  DFormula (r, premise),
  _position (p),
  _subformulaIndex (subformulaIndex)
{
  ASS (r == FLATTEN);
} // Flatten::Flatten
Ejemplo n.º 16
0
// comparison of two literals, needed to normalize
// 26/06/2002 Manchester
bool Literal::isless (Literal l) const  
{
  switch ( compare(l) ) {
  case LESS:
    return true;

  case EQUAL:
  case GREATER:
    return false;
  }

  ASS(false);
} // Literal::isless
Ejemplo n.º 17
0
// 03/05/2003 Manchester
Inference::Inference (Rule r, 
		      const Formula& premise,
		      const Position& p,
		      const IntList& toppledVarPositions,
		      const IntList& toppledSubformulaPositions,
		      int toppledSubformulaIndex)
  :
  _data (new ForallOrMiniscope (r, premise, p, 
				toppledVarPositions,
				toppledSubformulaPositions,
				toppledSubformulaIndex))
{
  ASS (r == FORALL_OR_MINISCOPE);
} // Inference::Inference
Ejemplo n.º 18
0
Inference::ForallOrMiniscope::ForallOrMiniscope (Rule r,
						 const Formula& premise,
						 const Position& p,
						 IntList toppledVarPositions,
						 IntList toppledSubformulaPositions,
						 int toppledSubformulaIndex)
  :
  DFormula (r, premise),
  _position (p),
  _toppledVarPositions (toppledVarPositions),
  _toppledSubformulaPositions (toppledSubformulaPositions)
{
  ASS (r == FORALL_OR_MINISCOPE);
} // Inference::ForallOrMiniscope::ForallOrMiniscope
Ejemplo n.º 19
0
/*  ...
 */
void CBaComTest::I2cError() {
   TBaBool err = eBaBool_false;
   BaComI2CRead8(&err);
   ASS(err);
   err = eBaBool_false;
   BaComI2CReadReg8(0, &err);
   ASS(err);
   err = eBaBool_false;
   BaComI2CReadReg16(0, &err);
   ASS(err);
   err = eBaBool_false;

   ASS(!BaComI2CWrite8(0));
   ASS(!BaComI2CWriteReg8(0, 0));
   ASS(!BaComI2CWriteReg16(0, 0));

   ASS(BaComI2CSelectDev(ADDRADS1115));
   BaComI2CRead8(&err);
   ASS(!err);
   ASS(BaComI2CExit());
}
Ejemplo n.º 20
0
/*  ...
 */
void CBaComTest::I2c() {
   TBaBool err = 0;
   uint16_t readReg = 0;
   uint16_t confReg = 0;

   ASS(BaComI2CInit());
   ASS(BaComI2CSelectDev(ADDRADS1115));

   // Test functions
   uint64_t funcs = BaComI2CFuncs();
   ASS(funcs & I2C_FUNC_SMBUS_WRITE_I2C_BLOCK);
   ASS(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK  );
   ASS(funcs & I2C_FUNC_SMBUS_WRITE_BLOCK_DATA);
   ASS(!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA));
   ASS(funcs & I2C_FUNC_SMBUS_PROC_CALL      );
   ASS(funcs & I2C_FUNC_SMBUS_WRITE_WORD_DATA);
   ASS(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA );
   ASS(funcs & I2C_FUNC_SMBUS_WRITE_BYTE_DATA);
   ASS(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA );
   ASS(funcs & I2C_FUNC_SMBUS_WRITE_BYTE     );
   ASS(funcs & I2C_FUNC_SMBUS_READ_BYTE      );
   ASS(funcs & I2C_FUNC_SMBUS_QUICK          );
   ASS(!(funcs & I2C_FUNC_SMBUS_BLOCK_PROC_CALL));
   // ...
   ASS(!(funcs & I2C_FUNC_SMBUS_BLOCK_PROC_CALL));
   ASS(!(funcs & I2C_FUNC_NOSTART));
   ASS(funcs & I2C_FUNC_SMBUS_PEC          );
   ASS(!(funcs & I2C_FUNC_PROTOCOL_MANGLING));
   ASS(!(funcs & I2C_FUNC_10BIT_ADDR));
   ASS(funcs & I2C_FUNC_I2C          );

   // ADS1115: http://www.ti.com/lit/ds/symlink/ads1113.pdf
   // Configuration register
   //                Byte 0    Byte 1
   //               7654 3210 5432 1098
   // 0x83C0:       1000 0011 1100 0000: 33728
   //  5 Data rate -^^^| |||| |||| ||||
   //  4 Comp Mode ----+ |||| |||| ||||
   //  3 Comp Pol -------+||| |||| ||||
   //  2 Comp Lat --------+|| |||| ||||
   //  0 Comp Q -----------++ |||| ||||
   // 15 Op Status -----------+||| ||||
   // 14 Mux ------------------+++ ||||
   //  9 Gain ---------------------+++|
   //  8 Op mode ---------------------+

   // Continuous Mode
   confReg = 0b1000001111000000;
   ASS(BaComI2CWriteReg16(CONFREG, confReg));
   readReg = BaComI2CReadReg16(CONFREG, &err);
   ASS_EQ(readReg, (uint16_t)0x8340);
   ASS(!err);
   printf("0x%04X, e:%i\n", readReg, err);

   // Voltage read
   BaCoreMSleep(5);
   readReg = bswap_16(BaComI2CReadReg16(CONVREG, &err));
   // Same as original register, but without status flag
   ASS(!err);
   printf("%f V\n", 6.144*readReg/32767.0);
   BaCoreMSleep(5);
   // Byte order must be swapped to get the right int
   readReg = bswap_16(BaComI2CReadReg16(CONVREG, &err));
   printf("%f V\n", 6.144*readReg/32767.0);
   ASS(!err);

   // One Shot Mode
   confReg = 0b1000001111000001;
   ASS(BaComI2CWriteReg16(CONFREG, confReg));
   readReg = BaComI2CReadReg16(CONFREG, &err);
   ASS(!err);
   printf("0x%04X, e:%i\n", readReg, err);

   // voltage read
   BaCoreMSleep(5);
   // Byte order must be swapped to get the right int
   readReg = bswap_16(BaComI2CReadReg16(CONVREG, &err));
   ASS(!err);
   printf("%f V, 0x%04x\n", 6.144*readReg/32767.0, readReg);
   ASS_EQ(uint8_t(readReg >> 8), BaComI2CRead8(&err));
   ASS(!err);
   ASS_EQ(uint8_t(readReg >> 8), BaComI2CReadReg8(CONVREG, &err));
   ASS(!err);

   ASS(BaComI2CExit());
}
Ejemplo n.º 21
0
/*  ...
 */
void CBaComTest::Bus1W() {
   TBaBool error1 = eBaBool_false;
   TBaBool error2 = eBaBool_false;
   TBaCoreMonTStampUs ts = 0;
   const char *pAsyncVal = 0;
   const char* out = 0;
   float temp = 0;
   ASS(BaCom1WInit());
   ASS(BaCom1WExit());

   // Uninitialized
   ASS(!BaCom1WRdAsync("28-0215c2c4bcff", &ts));
   ASS(!BaCom1WGetValue("28-0215c2c4bcff", rdDvr, 0));
   ASS_D_EQ(-300.0, BaCom1WGetTemp("28-0215c2c4bcff", 0), 0.001);


   ASS(BaCom1WInit());

   // Threads not ready
   ASS(!BaCom1WRdAsync("28-0215c2c4bcff", &ts));
   ASS(!BaCom1WRdAsync("28-0315c2c4bcff", 0));
   ASS(!BaCom1WRdAsync("28-0415c2c4bcff", &ts));

   // After sleeping threads are ready
   BaCoreMSleep(900);

// Meant for RPI
#ifdef __arm__
   pAsyncVal = BaCom1WRdAsync("28-0215c2c4bcff", &ts);
   temp      = BaCom1WGetTemp("28-0215c2c4bcff", &error1);
   temp      = BaCom1WGetTemp(0, &error1);
   temp      = BaCom1WGetTemp("28-xxx", &error2);
   ASS(!BaCom1WGetValue("28-xxx", rdDvr, 0));
   ASS(!BaCom1WGetValue("28-xxx", 0, 0));
   out = (const char*) BaCom1WGetValue("28-0215c2c4bcff", rdDvr, &error1);

// Meant for PC (Lin, Win)
#else
   // Test async reading
   // Only overwrite if no error
   pAsyncVal = BaCom1WRdAsync("28-0215c2c4bcff", &ts);
   pAsyncVal = pAsyncVal ? BaCom1WRdAsync("28-0315c2c4bcff", &ts) : 0;
   pAsyncVal = pAsyncVal ? BaCom1WRdAsync("28-0415c2c4bcff", &ts) : 0;

   // Test sync reading
   // No error
   temp = BaCom1WGetTemp("28-0215c2c4bcff", &error1);
   std::cout << temp << ": "<< (error1 ? "T" : "F") << std::endl;
   temp = BaCom1WGetTemp(0, &error1);
   std::cout << temp << ": "<< (error1 ? "T" : "F") << std::endl;
   out = (const char*) BaCom1WGetValue(0, rdDvr,  &error1);
   std::cout << out << ": "<< (error1 ? "T" : "F") << std::endl;
   free((void*)out);

   // Error
   temp = BaCom1WGetTemp("28-xxx", &error2);
   std::cout << temp << ": "<< (error2 ? "T" : "F") << std::endl;
#endif

   ASS(BaCom1WExit());

   // Test at the end so all functions are always called
   if (TEST1W) {
      ASS(pAsyncVal);
      ASS(!error1);
      ASS(error2);
   }
}
Ejemplo n.º 22
0
int
do_process(void)
{
	struct kevent ke;
	int kq, status;
	pid_t pid, pid2;
	int didfork, didchild;
	int i;
	struct timespec ts;

	/*
	 * Timeout in case something doesn't work.
	 */
	ts.tv_sec = 10;
	ts.tv_nsec = 0;

	ASS((kq = kqueue()) >= 0, warn("kqueue"));

	/*
	 * Install a signal handler so that we can use pause() to synchronize
	 * with the child with the parent.
	 */
	signal(SIGUSR1, usr1handler);

	switch ((pid = fork())) {
	case -1:
		err(1, "fork");
	case 0:
		_exit(process_child());
	}

	sleep(2);	/* wait for child to settle down. */

	EV_SET(&ke, pid, EVFILT_PROC, EV_ADD|EV_ENABLE|EV_CLEAR,
	    NOTE_EXIT|NOTE_FORK|NOTE_EXEC|NOTE_TRACK, 0, NULL);
	ASS(kevent(kq, &ke, 1, NULL, 0, NULL) == 0,
	    warn("can't register events on kqueue"));

	kill(pid, SIGUSR1);	/* sync 1 */

	didfork = didchild = 0;

	pid2 = -1;
	for (i = 0; i < 2; i++) {
		ASS(kevent(kq, NULL, 0, &ke, 1, &ts) == 1,
		    warnx("didn't receive event"));
		ASSX(ke.filter == EVFILT_PROC);
		switch (ke.fflags) {
		case NOTE_CHILD:
			didchild = 1;
			ASSX((pid_t)ke.data == pid);
			pid2 = ke.ident;
			fprintf(stderr, "child %d\n", pid2);
			break;
		case NOTE_FORK:
			didfork = 1;
			ASSX(ke.ident == pid);
			fprintf(stderr, "fork\n");
			break;
		case NOTE_TRACKERR:
			errx(1, "child tracking failed due to resource shortage");
		default:
			errx(1, "kevent returned weird event 0x%x pid %d",
			    ke.fflags, (pid_t)ke.ident);
		}
	}

	if (pid2 == -1)
		return (1);

	/* Both children now sleeping. */

	ASSX(didchild == didfork == 1);
	
	kill(pid2, SIGUSR1);	/* sync 2.1 */
	kill(pid, SIGUSR1);	/* sync 2 */

	if (wait(&status) < 0)
		err(1, "wait");

	if (!WIFEXITED(status))
		errx(1, "child didn't exit?");

	close(kq);
	return (WEXITSTATUS(status) != 0);
}
Ejemplo n.º 23
0
/*  ...
 */
void CBaSwOsciTest::ConcreteNiceWeather() {
   CBaSwOsci *p = CBaSwOsci::Create("BaSwOsciTest", RESPATH, true);
   ASS(p);
   double d = 3.14e-5;
   uint64_t llu = 999999999999;
   uint16_t usi = 300;
   int8_t c = 56;

   ASS(p->Register(&d, eBaSwOsci_double, "d", "double"));
   ASS(p->Register(&llu, eBaSwOsci_uint64, "llu", "unsigned ll"));
   ASS(p->Register(&usi, eBaSwOsci_uint16, "usi", "unsigned s"));
   ASS(p->Register(&c, eBaSwOsci_int8, "c", "signed char"));

   ASS(p->Sample());
   // Let the thread flush it
   BaCoreSleep(1);

   // Re-sample
   d *= 2;
   llu *= 2;
   usi *= 2;
   c *= 2;
   ASS(p->Sample());
   ASS(CBaSwOsci::Destroy(p, 300));

   // Test the header
   std::ifstream iS(RESPATH "BaSwOsciTest.csv");

   ASS(iS.good());
   std::string s;
   std::getline(iS, s, ','); // Header
   ASS(s == "Time");
   std::getline(iS, s, ',');
   ASS(s == " Timestamp");
   std::getline(iS, s, ',');
   ASS(s == " d");
   std::getline(iS, s, ',');
   ASS(s == " llu");
   std::getline(iS, s, ',');
   ASS(s == " usi");
   std::getline(iS, s);
   ASS(s == " c");

   // Test the first line
   std::getline(iS, s, ',');
   std::getline(iS, s, ',');
   std::getline(iS, s, ',');
#ifdef __WIN32
   ASS(s == " 3.14e-005");
#else
   ASS(s == " 3.14e-05");
#endif
   std::getline(iS, s, ',');
   ASS(s == " 999999999999");
   std::getline(iS, s, ',');
   ASS(s == " 300");
   std::getline(iS, s);
   ASS(s == " 56");

   // Test the second line
   std::getline(iS, s, ',');
   std::getline(iS, s, ',');
   std::getline(iS, s, ',');
#ifdef __WIN32
   ASS(s == " 6.28e-005");
#else
   ASS(s == " 6.28e-05");
#endif
   std::getline(iS, s, ',');
   ASS(s == " 1999999999998");
   std::getline(iS, s, ',');
   ASS(s == " 600");
   std::getline(iS, s);
   ASS(s == " 112");

}