void dynamic_safety_test_runnert::run_test(individualt &ind,
    const counterexamplet &ce, const std::function<void(bool)> on_complete)
{
  const auto source_code_provider=
      [this]()
      {
        std::string code(this->source_code_provider());
        substitute(code, "unsigned int __CPROVER_cegis_deserialise_index=__CPROVER_cegis_first_prog_offset", "unsigned int __CPROVER_cegis_deserialise_index=0");
        substitute(code, "unsigned int __CPROVER_cegis_ce_index=0u", "unsigned int __CPROVER_cegis_ce_index=__CPROVER_cegis_deserialise_index");
        return code;
      };
  prepare_fitness_tester_library(handle, fitness_tester, source_code_provider,
      shared_library());
  assert(ind.x0.empty());
  std::deque<unsigned int> args;
  // TODO: Implement for multiple loops (change constraint, instrumentation)
  assert(ind.programs.size() == 1u);
  serialise(args, ind, max_prog_sz);
  serialise(args, ce.x0);
  // TODO: Implement for multiple loops (change constraint, instrumentation)
  assert(ce.x.size() == 1u);
  serialise(args, ce.x.front());

  const int argc=args.size();
  std::vector<unsigned int> argv;
  argv.resize(argc);
  for (int i=0; i < argc; ++i)
    argv[i]=args[i];

  on_complete(EXIT_SUCCESS == fitness_tester(argv.data()));
}
Esempio n. 2
0
	void ObjectService::saveObject(const Object* pObj,std::string file) const
	{
		std::string name = pObj->ID();
		if(file.empty())
		{
			Serialise serialise(name);
			serialise.out(pObj);
		}
		else
		{
			Serialise serialise(file);
			serialise.out(pObj);
		}
	}
Esempio n. 3
0
void 
Serialiser::serialise(const OrderedTask& data)
{
  m_node.set_attribute(_T("type"), task_factory_type(data.get_factory_type()));
  serialise(data.get_ordered_task_behaviour());
  data.tp_CAccept(*this);
}
Esempio n. 4
0
QString Kleo::DN::prettyDN() const {
  if ( !d )
    return QString::null;
  if ( d->reorderedAttributes.empty() )
    d->reorderedAttributes = reorder_dn( d->attributes );
  return serialise( d->reorderedAttributes );
}
Esempio n. 5
0
void libmaus2::util::ConcatRequest::serialise(std::string const & filename) const
{
	libmaus2::aio::OutputStreamInstance ostr(filename);
	serialise(ostr);
	ostr.flush();
	assert ( ostr );
}
Esempio n. 6
0
void JsonStream::deleteCurrentChild()
{
    if(mChild)
    {
        if(serialise())
        {
            if(mDataType == TYPE_ARRAY)
            {
                // don't add empty value
                if(mChild->getJsonValue().GetType() != json::NULLVal)
                    mArray.push_back(mChild->getJsonValue());
            }
            else if(mDataType == TYPE_OBJECT)
            {
                mObject[mChildKey] = mChild->getJsonValue();
            }
            else
            {
                mErrorLog += "JsonStream::deleteCurrentChild() Error: cannot add child because own type is wrong\n";
            }
        }
        else
        {
            // don't have to do anything for deserialisation
        }
        delete mChild;
        mChild = NULL;
    }
}
Esempio n. 7
0
// make a binay data object (not a real object, just binary data)
StreamBase& JsonStream::operator<<(std::vector<uint8_t>& data)
{
    if(serialise())
    {
        if((mDataType == TYPE_UNDEFINED)||(mDataType == TYPE_RAW))
        {
            mDataType = TYPE_RAW;
            mRawString = std::string(data.begin(), data.end());
        }
        else
        {
            mErrorLog += "Error: trying to set raw data while the type of this object is already another type\n";
            mIsOk = false;
        }
    }
    else
    {
        if((mDataType == TYPE_UNDEFINED)||(mDataType == TYPE_RAW))
        {
            mDataType = TYPE_RAW;
            data = std::vector<uint8_t>(mRawString.begin(), mRawString.end());
        }
        else
        {
            mErrorLog += "Error: trying to read raw data while the type of this object is already another type\n";
            mIsOk = false;
        }
    }
    return *this;
}
Esempio n. 8
0
void genserialise_element(compile_t* c, reach_type_t* t, bool embed,
  LLVMValueRef ctx, LLVMValueRef ptr, LLVMValueRef offset)
{
  if(embed || (t->underlying == TK_TUPLETYPE))
  {
    // Embedded field or tuple, serialise in place. Don't load from ptr, as
    // it is already a pointer to the object.
    serialise(c, t, ctx, ptr, offset);
  } else if(t->primitive != NULL) {
    // Machine word, write the bits to the buffer.
    LLVMValueRef value = LLVMBuildLoad(c->builder, ptr, "");
    LLVMValueRef loc = LLVMBuildBitCast(c->builder, offset,
      LLVMPointerType(t->primitive, 0), "");
    LLVMBuildStore(c->builder, value, loc);
  } else {
    // Lookup the pointer and get the offset, write that.
    LLVMValueRef value = LLVMBuildLoad(c->builder, ptr, "");

    LLVMValueRef args[2];
    args[0] = ctx;
    args[1] = LLVMBuildBitCast(c->builder, value, c->void_ptr, "");
    LLVMValueRef object_offset = gencall_runtime(c, "pony_serialise_offset",
      args, 2, "");

    LLVMValueRef loc = LLVMBuildBitCast(c->builder, offset,
      LLVMPointerType(c->intptr, 0), "");
    LLVMBuildStore(c->builder, object_offset, loc);
  }
}
Esempio n. 9
0
static void make_serialise(compile_t* c, reach_type_t* t)
{
  // Use the trace function as the serialise_trace function.
  t->serialise_trace_fn = t->trace_fn;

  // Generate the serialise function.
  t->serialise_fn = codegen_addfun(c, genname_serialise(t->name),
    c->serialise_type);

  codegen_startfun(c, t->serialise_fn, NULL, NULL);
  LLVMSetFunctionCallConv(t->serialise_fn, LLVMCCallConv);
  LLVMSetLinkage(t->serialise_fn, LLVMExternalLinkage);

  LLVMValueRef ctx = LLVMGetParam(t->serialise_fn, 0);
  LLVMValueRef arg = LLVMGetParam(t->serialise_fn, 1);
  LLVMValueRef addr = LLVMGetParam(t->serialise_fn, 2);
  LLVMValueRef offset = LLVMGetParam(t->serialise_fn, 3);

  LLVMValueRef object = LLVMBuildBitCast(c->builder, arg, t->structure_ptr,
    "");
  LLVMValueRef offset_addr = LLVMBuildInBoundsGEP(c->builder, addr, &offset, 1,
    "");

  serialise(c, t, ctx, object, offset_addr);

  LLVMBuildRetVoid(c->builder);
  codegen_finishfun(c);
}
Esempio n. 10
0
	Object* ObjectService::createObject(std::string name,bool bLoadPredefined/* = false*/)
	{
		ObjectMap::iterator it = mObjects.find(name);
		if(it == mObjects.end())
		{
			Object* pObj;
			if(bLoadPredefined)
			{
				Deserialise serialise(name);
				serialise.in(pObj);
			}
			else
			{
				pObj = new Object(name);
			}

			mObjects.insert(std::make_pair(name,pObj));
			
			return pObj;
		}
		else
		{
			return it->second;
		}
	}
Esempio n. 11
0
void dynamic_danger_test_runnert::run_test(individualt &ind,
    const counterexamplet &ce, const std::function<void(bool)> on_complete)
{
  prepare_fitness_tester_library(handle, fitness_tester, source_code_provider,
      shared_library());
  std::deque<unsigned int> args;
  serialise(args, ce);
  serialise(args, ind, max_prog_sz);

  const int argc=args.size();
  std::vector<unsigned int> argv;
  argv.resize(argc);
  for (int i=0; i < argc; ++i)
    argv[i]=args[i];

  on_complete(EXIT_SUCCESS == fitness_tester(argv.data()));
}
Esempio n. 12
0
std::string DatFile::serialise(std::map<std::string, std::string> &rec)
{
	char header[] = {0x00, 0x00, 0xFF, 0xFE, 0x03, 0x90, 0xDE,
		 			0x10, 0x00, 0x04, 0x64, 0x49, 0x00, 0x05,
					0x00, 0x80};
	std::string output;
	// f*****g stl map auto sorts by key and not the order i create it
	// so simply using an iterator to loop through and do this won't
	// work because they have to be written out in this order.
	output.assign(header, header+sizeof(header));
	output.append(serialise("TIT2",std::string(rec["TIT2"])));
	output.append(serialise("TPE1",std::string(rec["TPE1"])));
	output.append(serialise("TALB",std::string(rec["TALB"])));
	output.append(serialise("TCON",std::string(rec["TCON"])));
	output.append(serialise("TSOP",std::string(rec["TSOP"])));
	return output;
}
Esempio n. 13
0
void DatFile::writeRecord(std::map<std::string, std::string> &rec)
{
	if(recordExists(rec))
	{
		std::string data = serialise(rec);
		file.write (data.c_str(), data.size());
	}

}
CompressedBitset::CompressedBitset(const set<tile_t> &s) {
  auto_ptr<tree_entry> root = build_crit_bit_tree(s);
  bytes = serialise(root);
  // printf("serialised as %ld bytes, array would be %ld bytes: ", data.size(), s.size() * sizeof(tile_t));
  // for (vector<unsigned char>::iterator itr = data.begin(); itr != data.end(); ++itr) {
  //   printf("%02x ", int(*itr));
  // }
  // printf("\n");
}
Esempio n. 15
0
void 
Serialiser::serialise(const OrderedTask &task)
{
  m_node.set_attribute(_T("type"), task_factory_type(task.get_factory_type()));
  serialise(task.get_ordered_task_behaviour());
  mode_optional_start = false;
  task.AcceptTaskPointVisitor(*this);
  mode_optional_start = true;
  task.AcceptStartPointVisitor(*this);
}
Esempio n. 16
0
static void check_serialise_deserialise(const Block &block)
{
	std::stringstream ss;

	// Write the test data to the memory stream
	serialise(ss, block);

	// Read it back, make sure input and output data are equal
	check_equal(block, deserialise(ss));
}
Esempio n. 17
0
/*{{{  void ccsp_wake_thread (sched_t scheduler)*/
void ccsp_wake_thread (sched_t *scheduler, int sync_bit)
{
	unsigned int data = 0;
	
	att_safe_clear_bit (&sleeping_threads, scheduler->index);
	weak_write_barrier ();
	att_safe_set_bit (&(scheduler->sync), sync_bit);
	serialise ();
	write (scheduler->signal_in, &data, 1);
}
			void serialise(std::string const & filename)
			{
				std::ofstream ostr(filename.c_str(),std::ios::binary);
				assert ( ostr.is_open() );
				assert ( ostr );
				serialise(ostr);
				ostr.flush();
				assert ( ostr );
				ostr.close();
			}
Esempio n. 19
0
bool
DataNodeXML::save(const TCHAR* path)
{
  /// @todo make xml writing portable (unicode etc)
  TextWriter writer(path);
  if (writer.error())
    return false;

  serialise(writer);
  return true;
}
Esempio n. 20
0
inline bool send(zmq::socket_t & socket, tile_protocol const& tile)
{
   std::string buf;
   if (serialise(tile, buf))
   {
      zmq::message_t msg(buf.size()); 
      std::memcpy(msg.data(),buf.data(),buf.size());
      return socket.send(msg);
   }
   return false;
}
Esempio n. 21
0
/*{{{  void ccsp_safe_pause (sched_t *sched)*/
void ccsp_safe_pause (sched_t *sched)
{
	unsigned int buffer, sync;

	#ifdef DEBUG_RTS
	fprintf(stderr, "USERPROC: ccsp_safe_pause() entered\n");
	#endif
	
	while (!(sync = att_safe_swap (&(sched->sync), 0))) {
		serialise ();
		read (sched->signal_out, &buffer, 1);
		serialise ();
	}

	/* restore detected flags */
	att_safe_or (&(sched->sync), sync);

	#ifdef DEBUG_RTS
	fprintf(stderr, "USERPROC: ccsp_safe_pause about to exit (return 0)\n");
	#endif
}
void resolution_service::receive(const boost::system::error_code& error, std::size_t) {
	if(error) return;
	std::cout << "Receiving UDP data" << std::endl;
	dvsp_packet in(m_recv);
	auto inbound_addr = m_remote_ep.address();
	auto out = m_proto.process_packet(in, inbound_addr);
	auto out_shr = std::shared_ptr<char>(out->serialise());
	m_socket.async_send_to(
		boost::asio::buffer(out_shr.get(), out->size()),
		m_remote_ep,
		[this](const berror&, std::size_t) { 
	});
	start_recv();
}
Esempio n. 23
0
	data::IData *Inventory::serialise()
	{
		data::Table *output = new data::Table();
		output->at("spacesX", mSpacesX);
		output->at("spacesY", mSpacesY);

		data::Table *spots = new data::Table();
		for (auto iter = mSpots.begin(); iter != mSpots.end(); ++iter)
		{
			spots->push(iter->serialise());
		}

		output->at("spots", spots);
		return output;
	}
Esempio n. 24
0
// usefull if the new object member should be an array or object
// the reference should be at least valid until another method of this class gets called
StreamBase& JsonStream::getStreamToMember(std::string name)
{
    setType(TYPE_OBJECT);
    deleteCurrentChild();
    mChildKey = name;
    mChild = new JsonStream();
    if(!serialise())
    {
        if(checkDeserialisation() && checkObjectMember(name))
        {
            mChild->mValue = mObject[name];
        }
    }
    return *mChild;
}
Esempio n. 25
0
	data::IData *StatModifiers::serialise()
	{
		data::Table *output = new data::Table();
		for (auto iter = mModifiers.begin(); iter != mModifiers.end(); ++iter)
		{
			data::Table *modifiers = new data::Table();
			for (auto modIter = iter->second.begin(); modIter != iter->second.end(); ++modIter)
			{
				modifiers->push(modIter->serialise());
			}
			output->at(Stat::getStatName(iter->first), modifiers);
		}

		return output;
	}
Esempio n. 26
0
/*{{{  void ccsp_safe_pause_timeout (sched_t *sched)*/
void ccsp_safe_pause_timeout (sched_t *sched)
{
	unsigned int sync;
	Time now;

	#ifdef DEBUG_RTS
	fprintf(stderr, "USERPROC: ccsp_safe_pause_timeout() entered\n");
	#endif

	if (sched->tq_fptr == NULL) {
		return;
	} else if (Time_PastTimeout (sched)) {
		return;
	}

	now = Time_GetTime(sched);
	if (Time_AFTER (sched->tq_fptr->time, now)) {
		unsigned int usecs = Time_MINUS (sched->tq_fptr->time, now);

		if (usecs < min_sleep) {
			while (!(sync = att_safe_swap (&(sched->sync), 0))) {
				int i = 10;
				
				while (i--) {
					idle_cpu ();
				}

				if (Time_PastTimeout (sched)) {
					break;
				}

				serialise ();
			}

			if (sync) {
				/* restore detected flags */
				att_safe_or (&(sched->sync), sync);
			}
		} else {
			ccsp_set_next_alarm (sched, usecs);
			ccsp_safe_pause (sched);
		}
	}

	#ifdef DEBUG_RTS
	fprintf(stderr, "USERPROC: ccsp_safe_pause_timeout() about to exit (return 0)\n");
	#endif
}
Esempio n. 27
0
StreamBase& JsonStream::getStreamToMember()
{
    setType(TYPE_ARRAY);
    deleteCurrentChild();
    mChild = new JsonStream();
    if(!serialise())
    {
        if(checkDeserialisation() && arrayBoundsOk())
        {
            mChild->mValue = mArray[mArrayNextRead];
            mChild->mSerialise = false;
            mArrayNextRead++;
        }
    }
    return *mChild;
}
Esempio n. 28
0
StreamBase& JsonStream::operator<<(KeyValueReference<std::string> keyValue)
{
    if(serialise())
    {
        setType(TYPE_OBJECT);
        mObject[keyValue.key] = keyValue.value;
    }
    else
    {
        if(checkDeserialisation() && checkObjectMember(keyValue.key))
        {
            valueToString(mObject[keyValue.key], keyValue.value);
        }
    }
    return *this;
}
Esempio n. 29
0
TEST(binnf, python_communication)
{
	// Open the python loopback as a subprocess
	Process proc("python", {Resources::PYNN_BINNF_LOOPBACK.open()});

	// Generate a test data block
	const Block block_in_1 = generate_test_matrix_block();
	const Block block_in_2 = generate_test_log_block();

	// Send the data block to python
	serialise(proc.child_stdin(), block_in_1);
	serialise(proc.child_stdin(), block_in_2);
	serialise(proc.child_stdin(), block_in_2);
	serialise(proc.child_stdin(), block_in_1);
	serialise(proc.child_stdin(), block_in_2);
	serialise(proc.child_stdin(), block_in_2);
	serialise(proc.child_stdin(), block_in_1);
	serialise(proc.child_stdin(), block_in_1);
	proc.close_child_stdin();

	// Read it back, expect the deserialisation to be successful
	try {
		check_equal(block_in_1, deserialise(proc.child_stdout()));
		check_equal(block_in_2, deserialise(proc.child_stdout()));
		check_equal(block_in_2, deserialise(proc.child_stdout()));
		check_equal(block_in_1, deserialise(proc.child_stdout()));
		check_equal(block_in_2, deserialise(proc.child_stdout()));
		check_equal(block_in_2, deserialise(proc.child_stdout()));
		check_equal(block_in_1, deserialise(proc.child_stdout()));
		check_equal(block_in_1, deserialise(proc.child_stdout()));
	}
	catch (BinnfDecodeException &e) {
		// Most likely there is an error message
		char buf[4096];
		while (proc.child_stderr().good()) {
			proc.child_stderr().read(buf, 4096);
			std::cout.write(buf, proc.child_stderr().gcount());
		}
		EXPECT_TRUE(false);
	}

	// Make sure the Python code does not crash
	EXPECT_EQ(0, proc.wait());
}
Esempio n. 30
0
StreamBase& JsonStream::operator<<(ValueReference<double> value)
{
    if(serialise())
    {
        setType(TYPE_ARRAY);
        mArray.push_back(value.value);
    }
    else
    {
        if(checkDeserialisation() && arrayBoundsOk())
        {
            valueToDouble(mArray[mArrayNextRead], value.value);
            mArrayNextRead++;
        }
    }
    return *this;
}