Exemplo n.º 1
0
DataVector DataTransformation::transform(const DataVector &input) const
{
    checkInput(input);
    DataVector output = transform_(input);
    checkOutput(output);
    return output;
}
Exemplo n.º 2
0
// Main.
int main() {
  char buffer[MAX_CHARS];               // Buffer to hold user input.
  int commandStatus = 0;
  struct Command *userCmd;
  int i = 0;
  int foreStatus;
  int backStatus;

  signal(SIGINT, kill_handler);

  do {
    if(killDelivered > 0) {
      printf("terminated by signal %d\n", killDelivered);
      killDelivered = 0;
    }

    userCmd = getCommand(&backStatus);               // Get the user's entered command.

    if(checkInput(userCmd) == 0) {
      continue;                           // Input file was bad, reprompt.
    }

    if(checkOutput(userCmd) == 0) {
      continue;                           // Output file was bad, reprompt.
    }

    commandStatus = executeCommand(userCmd, commandStatus, &backStatus, &foreStatus); // Returns 1 if users entered 'exit', 0 otherwise.



  } while(strcmp("exit", userCmd->cmd) != 0);

};
Exemplo n.º 3
0
void Parcel::putShort(short value) {
    checkOutput();
    try {
        mDataOutputStream->writeShort(value);
    } catch (const IOException& e) {
        throw RemoteException(e);
    }
}
Exemplo n.º 4
0
void Parcel::putChar(char value) {
    checkOutput();
    try {
        mDataOutputStream->writeChar(value);
    } catch (const IOException& e) {
        throw RemoteException(e);
    }
}
Exemplo n.º 5
0
void Parcel::putByte(uint8_t value) {
    checkOutput();
    try {
        mDataOutputStream->writeByte(value);
    } catch (const IOException& e) {
        throw RemoteException(e);
    }
}
Exemplo n.º 6
0
void Parcel::putBoolean(bool value) {
    checkOutput();
    try {
        mDataOutputStream->writeBoolean(value);
    } catch (const IOException& e) {
        throw RemoteException(e);
    }
}
Exemplo n.º 7
0
void Parcel::putString(const sp<String>& value) {
    checkOutput();
    try {
        mDataOutputStream->writeUTF(value);
    } catch (const IOException& e) {
        throw RemoteException(e);
    }
}
Exemplo n.º 8
0
void Parcel::putDouble(double value) {
    checkOutput();
    try {
        mDataOutputStream->writeDouble(value);
    } catch (const IOException& e) {
        throw RemoteException(e);
    }
}
int testOutput(struct node *node)
{
	struct v4l2_output descr;
	int cur_output = MAGIC;
	int output;
	int ret = doioctl(node, VIDIOC_G_OUTPUT, &cur_output);
	int o = 0;

	if (ret == EINVAL) {
		descr.index = 0;
		ret = doioctl(node, VIDIOC_ENUMOUTPUT, &descr);
		if (ret != EINVAL)
			return fail("G_OUTPUT not supported, but ENUMOUTPUT is\n");
		output = 0;
		ret = doioctl(node, VIDIOC_S_OUTPUT, &output);
		if (ret != EINVAL)
			return fail("G_OUTPUT not supported, but S_OUTPUT is\n");
		return -ENOSYS;
	}
	if (ret)
		return ret;
	if (cur_output == MAGIC)
		return fail("VIDIOC_G_OUTPUT didn't fill in the output\n");
	for (;;) {
		memset(&descr, 0xff, sizeof(descr));
		descr.index = o;
		ret = doioctl(node, VIDIOC_ENUMOUTPUT, &descr);
		if (ret)
			break;
		output = o;
		if (doioctl(node, VIDIOC_S_OUTPUT, &output))
			return fail("could not set output to %d\n", o);
		if (output != o)
			return fail("output set to %d, but becomes %d?!\n", o, output);
		if (checkOutput(node, descr, o))
			return fail("invalid attributes for output %d\n", o);
		node->outputs++;
		o++;
	}
	output = o;
	if (doioctl(node, VIDIOC_S_OUTPUT, &output) != EINVAL)
		return fail("could set output to invalid output %d\n", o);
	if (doioctl(node, VIDIOC_S_OUTPUT, &cur_output))
		return fail("couldn't set output to the original output %d\n", cur_output);
	if (node->outputs && !node->has_outputs)
		return fail("outputs found, but no output capabilities set\n");
	if (!node->outputs && node->has_outputs)
		return fail("no outputs found, but output capabilities set\n");
	return 0;
}
Exemplo n.º 10
0
int main(int argc, char **argv) {
  Parameters par;
  HHblits::ProcessAllArguments(argc, argv, par);
  checkOutput(par);

  std::vector<HHblitsDatabase*> databases;
  HHblits::prepareDatabases(par, databases);
#ifdef OPENMP
  omp_set_num_threads(par.threads);
#endif
  HHblits hhblits(par, databases);

  FILE* inf;
  if(strcmp(par.infile, "stdin") == 0) {
	  inf = stdin;
  }
  else {
	  inf = fopen(par.infile, "r");
  }

  if(!inf) {
	  HH_LOG(ERROR) << "Input file (" << par.infile << ") could not be opened!" << std::endl;
	  exit(1);
  }

  hhblits.run(inf, par.infile);
  fclose(inf);

  if(Log::reporting_level() >= INFO) {
    hhblits.printHitList();
  }

  hhblits.writeHHRFile(par.outfile);
  hhblits.writeAlisFile(par.alisbasename);
  hhblits.writeScoresFile(par.scorefile);
  hhblits.writeM8(par.m8file);
  hhblits.writePairwiseAlisFile(par.pairwisealisfile, par.outformat);
  hhblits.writeAlitabFile(par.alitabfile);
  hhblits.writePsiFile(par.psifile);
  hhblits.writeHMMFile(par.hhmfile);
  hhblits.writeA3MFile(par.alnfile);
  hhblits.writeMatricesFile(par.matrices_output_file);

  for(size_t i = 0; i < databases.size(); i++) {
    delete databases[i];
  }
  databases.clear();
}
Exemplo n.º 11
0
bool SubscriptionManager::checkSubscription()
{
	m_Edition = Unknown;
	persistDirectory();
	CoreInterface coreInterface;
	QString output;
	try
	{
		output = coreInterface.checkSubscription();
	}
	catch (std::exception& e)
	{
		m_ErrorMessage = e.what();
		checkError(m_ErrorMessage);
		return false;
	}

	checkOutput(output);

	return true;
}
Exemplo n.º 12
0
void semCheckTypes(AST_NODE *node) {
    static int returnType = DTYPE_UNDEF;
    int i;

    if(!node) return;

    if(node->type == AST_FUNDEC)
        returnType = node->datatype;

    for(i = 0; i < node->size; i++)
        semCheckTypes(node->children[i]);

    switch (node->type) {
    case AST_VAR:
    case AST_LIT:
        node->datatype = node->symbol->datatype;
        break;

    case AST_NOT:
        if(node->children[0]->datatype != DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_BOOL, node->lineNumber, NULL);
        node->datatype = DTYPE_BOOL;
        break;

    case AST_AND:
    case AST_OR:
        if(node->children[0]->datatype != DTYPE_BOOL ||
                node->children[1]->datatype != DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_BOOL, node->lineNumber, NULL);
        node->datatype = DTYPE_BOOL;
        break;

    case AST_EQ:
    case AST_NE:
        if((node->children[0]->datatype == DTYPE_BOOL &&
                node->children[1]->datatype != DTYPE_BOOL) || 
                (node->children[0]->datatype != DTYPE_BOOL &&
                node->children[1]->datatype == DTYPE_BOOL))
            semError(SEM_TYPE_INCOMPATIBLE_OPS, node->lineNumber, NULL);
        node->datatype = DTYPE_BOOL;
        break;

    case AST_LE:
    case AST_GE:
    case AST_LESS:
    case AST_GREATER:
        if(node->children[0]->datatype == DTYPE_BOOL ||
                node->children[1]->datatype == DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_NUMBER, node->lineNumber, NULL);

        node->datatype = DTYPE_BOOL;
        break;

    case AST_ADD:
    case AST_SUB:
    case AST_MUL:
        node->datatype = checkArithmetic(node->children[0]->datatype,
                                         node->children[1]->datatype,
                                         node->lineNumber);
        break;

    case AST_DIV:
        if(node->children[0]->datatype == DTYPE_BOOL ||
                node->children[1]->datatype == DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_NUMBER, node->lineNumber, NULL);
        node->datatype = DTYPE_REAL;
        break;

    case AST_PAR:
        node->datatype = node->children[0]->datatype;
        break;	

	case AST_FUNCALL:
	    node->datatype = node->symbol->declaration->datatype;
	    checkParameters(node);
	    break;
	
	case AST_ARRACCESS:
	    node->datatype = node->symbol->datatype;
	    if(node->children[0]->datatype != DTYPE_INT && 
			    node->children[0]->datatype != DTYPE_CHAR) 
                semError(SEM_TYPE_INDEX, node->lineNumber, node->symbol->text);
	    break;
	
	case AST_ATTR:
	    if(numAndBool(node->symbol->datatype, node->children[0]->datatype)) 
		semError(SEM_TYPE_ATTR_TYPE, node->lineNumber, NULL);
	    break;

	case AST_ATTRARR:
	    if(numAndBool(node->symbol->datatype, node->children[1]->datatype)) 
		semError(SEM_TYPE_ATTR_TYPE, node->lineNumber, NULL);

	    if(node->children[0]->datatype != DTYPE_INT && 
			    node->children[0]->datatype != DTYPE_CHAR) 
                semError(SEM_TYPE_INDEX, node->lineNumber, node->symbol->text);
	    break;
	
	case AST_IF:
	case AST_IFTE:
	case AST_WHILE:
	    if(node->children[0]->datatype != DTYPE_BOOL)
		semError(SEM_TYPE_EXPECTED_BOOL, node->lineNumber, NULL);
	    break;

	case AST_INPUT:
	    checkInput(node->children[0]);
	    break;

	case AST_OUTPUT:
	    checkOutput(node->children[0]);
	    break;

	case AST_RETURN:
        if(numAndBool(node->children[0]->datatype, returnType))
		    semError(SEM_TYPE_INCOMPATIBLE_RETURN, node->lineNumber, NULL);
	    break;
    }
}
Exemplo n.º 13
0
void Parcel::putBytes(const sp<ByteArray>& buffer, size_t offset, size_t size) {
    checkOutput();
    mOutputStream->write(buffer, offset, size);
}
Exemplo n.º 14
0
void Parcel::putBytes(const sp<ByteArray>& buffer) {
    checkOutput();
    mOutputStream->write(buffer);
}
Exemplo n.º 15
0
void doVMTests(json_spirit::mValue& v, bool _fillin)
{
	processCommandLineOptions();

	for (auto& i: v.get_obj())
	{
		cnote << i.first;
		mObject& o = i.second.get_obj();

		BOOST_REQUIRE(o.count("env") > 0);
		BOOST_REQUIRE(o.count("pre") > 0);
		BOOST_REQUIRE(o.count("exec") > 0);

		FakeExtVM fev;
		fev.importEnv(o["env"].get_obj());
		fev.importState(o["pre"].get_obj());

		if (_fillin)
			o["pre"] = mValue(fev.exportState());

		fev.importExec(o["exec"].get_obj());
		if (fev.code.empty())
		{
			fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
			fev.code = fev.thisTxCode;
		}

		bytes output;
		u256 gas;
		bool vmExceptionOccured = false;
		auto startTime = std::chrono::high_resolution_clock::now();
		try
		{
			auto vm = eth::VMFactory::create(fev.gas);
			output = vm->go(fev, fev.simpleTrace()).toBytes();
			gas = vm->gas();
		}
		catch (VMException const& _e)
		{
			cnote << "Safe VM Exception";
			vmExceptionOccured = true;
		}
		catch (Exception const& _e)
		{
			cnote << "VM did throw an exception: " << diagnostic_information(_e);
			BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
		}
		catch (std::exception const& _e)
		{
			cnote << "VM did throw an exception: " << _e.what();
			BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
		}

		auto endTime = std::chrono::high_resolution_clock::now();
		auto argc = boost::unit_test::framework::master_test_suite().argc;
		auto argv = boost::unit_test::framework::master_test_suite().argv;
		for (auto i = 0; i < argc; ++i)
		{	       
			if (std::string(argv[i]) == "--show-times")
			{
				auto testDuration = endTime - startTime;
				cnote << "Execution time: "
				      << std::chrono::duration_cast<std::chrono::milliseconds>(testDuration).count()
				      << " ms";
				break;
			}
		}

		// delete null entries in storage for the sake of comparison

		for (auto  &a: fev.addresses)
		{
			vector<u256> keystoDelete;
			for (auto &s: get<2>(a.second))
			{
				if (s.second == 0)
					keystoDelete.push_back(s.first);
			}
			for (auto const key: keystoDelete )
			{
				get<2>(a.second).erase(key);
			}
		}


		if (_fillin)
		{
			o["env"] = mValue(fev.exportEnv());
			o["exec"] = mValue(fev.exportExec());
			if (!vmExceptionOccured)
			{
				o["post"] = mValue(fev.exportState());
				o["callcreates"] = fev.exportCallCreates();
				o["out"] = "0x" + toHex(output);
				fev.push(o, "gas", gas);
				o["logs"] = exportLog(fev.sub.logs);
			}
		}
		else
		{
			if (o.count("post") > 0)	// No exceptions expected
			{
				BOOST_CHECK(!vmExceptionOccured);

				BOOST_REQUIRE(o.count("post") > 0);
				BOOST_REQUIRE(o.count("callcreates") > 0);
				BOOST_REQUIRE(o.count("out") > 0);
				BOOST_REQUIRE(o.count("gas") > 0);
				BOOST_REQUIRE(o.count("logs") > 0);

				dev::test::FakeExtVM test;
				test.importState(o["post"].get_obj());
				test.importCallCreates(o["callcreates"].get_array());
				test.sub.logs = importLog(o["logs"].get_array());

				checkOutput(output, o);

				BOOST_CHECK_EQUAL(toInt(o["gas"]), gas);

				auto& expectedAddrs = test.addresses;
				auto& resultAddrs = fev.addresses;
				for (auto&& expectedPair : expectedAddrs)
				{
					auto& expectedAddr = expectedPair.first;
					auto resultAddrIt = resultAddrs.find(expectedAddr);
					if (resultAddrIt == resultAddrs.end())
						BOOST_ERROR("Missing expected address " << expectedAddr);
					else
					{
						auto& expectedState = expectedPair.second;
						auto& resultState = resultAddrIt->second;
						BOOST_CHECK_MESSAGE(std::get<0>(expectedState) == std::get<0>(resultState), expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState));
						BOOST_CHECK_MESSAGE(std::get<1>(expectedState) == std::get<1>(resultState), expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState));
						BOOST_CHECK_MESSAGE(std::get<3>(expectedState) == std::get<3>(resultState), expectedAddr << ": incorrect code");

						checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr);
					}
				}

				checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses);
				BOOST_CHECK(test.callcreates == fev.callcreates);

				checkLog(fev.sub.logs, test.sub.logs);
			}
			else	// Exception expected
				BOOST_CHECK(vmExceptionOccured);
		}
	}
}