Ejemplo n.º 1
0
Archivo: qbrt.cpp Proyecto: zhaobr/qbrt
void execute_lcontext(OpContext &ctx, const lcontext_instruction &i)
{
	const char *name = fetch_string(ctx.resource(), i.hashtag);
	qbrt_value *dst(ctx.dstvalue(i.reg));
	Failure *fail;
	if (!dst) {
		fail = FAIL_REGISTER404(ctx.module_name()
				, ctx.function_name(), ctx.pc());
		fail->debug << "invalid register: " << i.reg;
		ctx.fail_frame(fail);
		return;
	}

	qbrt_value *src = ctx.get_context(name);
	if (src) {
		qbrt_value::ref(*dst, *src);
	} else {
		fail = NEW_FAILURE("unknown_context", ctx.module_name()
				, ctx.function_name(), ctx.pc());
		fail->debug << "cannot find context variable: " << name;
		qbrt_value::fail(*dst, fail);
		cerr << fail->debug_msg() << endl;
	}

	ctx.pc() += lcontext_instruction::SIZE;
}
Ejemplo n.º 2
0
void FailureCheck::UpdateFaultState()
{
    if(!listLock)
    {
        listLock = true;
        failureList.Begin();
        Failure * tmp = failureList.Next();
        int i = 0;

        while (tmp != NULL)
        {
            if(tmp->IsOccurred())
            {
               fault |= (1 << i);
            }
            if(tmp->IsLocked())
            {
                faultLock |= (1 << i);
            }
            ++i;
            tmp = failureList.Next();
        }
        listLock = false;
    }
}
Ejemplo n.º 3
0
	void AddFailure (const Failure & failure)
	{
		char writeBuffer[1024];
		sprintf( writeBuffer, "%d,%s,%s", failure.LineNumber(), failure.Filename(), failure.Condition() );
		DWORD dwWrite;
		if( WriteFile( m_WritePipe, writeBuffer, 1024, &dwWrite, NULL ) == false || dwWrite != 1024 )
			exit(-1);
	}
Ejemplo n.º 4
0
Failure * CallNode::fail(const char *type, const char *c_file, int c_lineno)
{
	Failure *f = new_failure(type, c_file, c_lineno);
	f->trace_in_and_out();
	if (result) {
		qbrt_value::fail(*result, f);
	}
	cfstate = CFS_FAILED;
	return f;
}
Ejemplo n.º 5
0
Archivo: qbrt.cpp Proyecto: zhaobr/qbrt
void execute_ctuple(OpContext &ctx, const ctuple_instruction &i)
{
	qbrt_value *dst(ctx.dstvalue(i.dst));
	if (!dst) {
		Failure *f = FAIL_REGISTER404(ctx.module_name()
				, ctx.function_name(), ctx.pc());
		f->debug << "invalid register: " << i.dst;
		ctx.fail_frame(f);
		cerr << f->debug_msg() << endl;
		return;
	}

	qbrt_value::tuple(*dst, new Tuple(i.size));
	ctx.pc() += ctuple_instruction::SIZE;
}
Ejemplo n.º 6
0
void TestOutput::print(const Failure& failure)
{
    print("\n");
    print(failure.getFileName().asCharString());
    print(":");
    print(failure.getLineNumber());
    print(":");
    print(" error: ");
    print("Failure in ");
    print(failure.getTestName().asCharString());
    print("\n");
    print("\t");
    print(failure.getMessage().asCharString());
    print("\n\n");
}
Ejemplo n.º 7
0
void FailureCheck::ResetFaulture()
{
    if(!listLock)
    {
        listLock = true;
        failureList.Begin();
        Failure * tmp = failureList.Next();
        while (tmp != NULL)
        {
            tmp->Reset();
            tmp = failureList.Next();
        }
        fault = 0;
        listLock = false;
    }
}
Ejemplo n.º 8
0
Archivo: qbrt.cpp Proyecto: zhaobr/qbrt
void execute_stracc(OpContext &ctx, const stracc_instruction &i)
{
	RETURN_FAILURE(ctx, i.dst);
	RETURN_FAILURE(ctx, i.src);

	Failure *f;
	qbrt_value &dst(*ctx.dstvalue(i.dst));
	const qbrt_value &src(*ctx.srcvalue(i.src));

	int op_pc(ctx.pc());
	ctx.pc() += stracc_instruction::SIZE;

	if (dst.type->id != VT_STRING) {
		f = FAIL_TYPE(ctx.module_name(), ctx.function_name(), op_pc);
		f->debug << "stracc destination is not a string";
		qbrt_value::i(f->exit_code, 1);
		ctx.fail_frame(f);
		return;
	}

	ostringstream out;
	switch (src.type->id) {
		case VT_STRING:
			*dst.data.str += *src.data.str;
			break;
		case VT_INT:
			out << src.data.i;
			*dst.data.str += out.str();
			break;
		case VT_VOID:
			f = FAIL_TYPE(ctx.module_name(), ctx.function_name()
					, op_pc);
			f->debug << "cannot append void to string";
			cerr << f->debug_msg() << endl;
			qbrt_value::fail(dst, f);
			break;
		default:
			f = FAIL_TYPE(ctx.module_name(), ctx.function_name()
					, op_pc);
			f->debug << "stracc source type is not supported: "
				<< (int) src.type->id;
			cerr << f->debug_msg() << endl;
			qbrt_value::fail(dst, f);
			break;
	}
}
Ejemplo n.º 9
0
void CallNode::trace_in(Failure &f, const char *c_file, int c_lineno) const
{
	f.trace_in(module()->name, function_name(), pc(), c_file, c_lineno);
}
Ejemplo n.º 10
0
void TestResult::addFailure (const Failure& failure) 
{
    failure.print();		
	failureCount++;
}
Ejemplo n.º 11
0
Archivo: qbrt.cpp Proyecto: zhaobr/qbrt
void qbrtcall(Worker &w, qbrt_value &res, function_value *f)
{
	if (!f) {
		cerr << "function is null\n";
		w.current->cfstate = CFS_FAILED;
		return;
	}

	// check that none of the function args are bad first
	WorkerCContext failctx(w, *f);
	for (uint16_t i(0); i<f->argc; ++i) {
		qbrt_value *val(failctx.dstvalue(PRIMARY_REG(i)));
		if (val->type->id == VT_FAILURE) {
			FunctionCall &failed_call(w.current->function_call());
			Failure *fail = val->data.failure;
			fail->trace_down(failed_call.mod->name
					, failed_call.name(), w.current->pc
					, __FILE__, __LINE__);
			qbrt_value::fail(*failed_call.result, fail);
			w.current->cfstate = CFS_FAILED;
			return;
		}
	}

	override_function(w, *f);

	if (f->abstract()) {
		// can't execute the function if it's abstract
		ostringstream types;
		load_function_value_types(types, *f);
		cerr << "cannot execute abstract function: "
			<< f->name() << "; " << types.str() << endl;
		w.current->cfstate = CFS_FAILED;
		return;
	}

	WorkerCContext ctx(w, *f);
	if (f->func->cfunc()) {
		c_function cf = f->func->cfunc();
		cf(ctx, res);
		return;
	}

	const QbrtFunction *qfunc;
	qfunc = dynamic_cast< const QbrtFunction * >(f->func);
	const ResourceTable &resource(f->func->mod->resource);
	// check arguments
	for (uint16_t i(0); i < f->argc; ++i) {
		const qbrt_value *val(ctx.srcvalue(PRIMARY_REG(i)));
		if (!val) {
			cerr << "wtf null value?\n";
		}
		const Type *valtype = val->type;
		const ParamResource &param(qfunc->header->params[i]);
		const char *name = fetch_string(resource, param.name_idx);
		const TypeSpecResource &type(
			resource.obj< TypeSpecResource >(param.type_idx));
		const ModSym &type_ms(fetch_modsym(resource, type.name_idx));
		const char *type_mod =
			fetch_string(resource, type_ms.mod_name);
		// */anything means it's a type variable. it's fine so proceed
		if (type_mod[0] == '*' && type_mod[1] == '\0') {
			continue;
		}
		const char *type_name =
			fetch_string(resource, type_ms.sym_name);
		if (valtype->module != type_mod || valtype->name != type_name) {
			cerr << "Type Mismatch: parameter " << name << '/' << i
				<< " expected to be " << type_mod << '/'
				<< type_name << ", instead received "
				<< valtype->module << '/' << valtype->name
				<< " " << w.current->function_call().name()
				<< ':' << w.current->pc << endl;
			exit(1);
		}
	}

	FunctionCall *call = new FunctionCall(*w.current, res, *qfunc, *f);
	w.current = call;
}
Ejemplo n.º 12
0
    virtual void AddFailure (const Failure & failure)
    {
		lastCondition = failure.Condition();
    }