Beispiel #1
0
static struct ptunit_result enqueue_all_dequeue(struct evq_fixture *efix,
						enum pt_event_binding evb,
						size_t num)
{
	struct pt_event *in[evq_max], *out[evq_max];
	size_t idx;

	ptu_uint_le(num, evq_max - 2);

	for (idx = 0; idx < num; ++idx) {
		in[idx] = pt_evq_enqueue(&efix->evq, evb);
		ptu_ptr(in[idx]);
	}

	ptu_test(evq_pending, efix, evb);
	ptu_test(evq_others_empty, efix, evb);

	for (idx = 0; idx < num; ++idx) {
		out[idx] = pt_evq_dequeue(&efix->evq, evb);
		ptu_ptr_eq(out[idx], in[idx]);
	}

	ptu_test(evq_empty, efix, evb);

	return ptu_passed();
}
Beispiel #2
0
static struct ptunit_result sfix_fini(struct section_fixture *sfix)
{
	int thrd;

	ptu_test(ptunit_thrd_fini, &sfix->thrd);

	for (thrd = 0; thrd < sfix->thrd.nthreads; ++thrd)
		ptu_int_eq(sfix->thrd.result[thrd], 0);

	if (sfix->section) {
		pt_section_put(sfix->section);
		sfix->section = NULL;
	}

	if (sfix->file) {
		fclose(sfix->file);
		sfix->file = NULL;
	}

	if (sfix->name) {
		free(sfix->name);
		sfix->name = NULL;
	}

	return ptu_passed();
}
static struct ptunit_result no_payload(struct packet_fixture *pfix,
				       enum pt_packet_type type)
{
	pfix->packet[0].type = type;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result tsc(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_tsc;
	pfix->packet[0].payload.tsc.tsc = 0x42ull;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result cbr(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_cbr;
	pfix->packet[0].payload.cbr.ratio = 0x23;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result cyc(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_cyc;
	pfix->packet[0].payload.cyc.value = 0x23;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result mtc(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_mtc;
	pfix->packet[0].payload.mtc.ctc = 0x23;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result vmcs(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_vmcs;
	pfix->packet[0].payload.vmcs.base = 0xabcdef000ull;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result mnt(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_mnt;
	pfix->packet[0].payload.mnt.payload = 0x1234567890abcdefull;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result tma(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_tma;
	pfix->packet[0].payload.tma.ctc = 0x42;
	pfix->packet[0].payload.tma.fc = 0x123;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result pip(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_pip;
	pfix->packet[0].payload.pip.cr3 = 0x4200ull;
	pfix->packet[0].payload.pip.nr = 1;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result mode_tsx(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_mode;
	pfix->packet[0].payload.mode.leaf = pt_mol_tsx;
	pfix->packet[0].payload.mode.bits.tsx.intx = 1;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
static struct ptunit_result tnt_64(struct packet_fixture *pfix)
{
	pfix->packet[0].type = ppt_tnt_64;
	pfix->packet[0].payload.tnt.bit_size = 23;
	pfix->packet[0].payload.tnt.payload = 0xabcdeull;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
Beispiel #14
0
/* Check that a boring instruction is decoded correctly. */
static struct ptunit_result ptunit_ild_boring(uint8_t *insn, uint8_t size,
					      enum pt_exec_mode mode)
{
	struct pt_ild ild;

	ptunit_ild_init(&ild, insn, size, mode);
	ptu_test(ptunit_ild_decode, &ild, pti_boring, size);

	return ptu_passed();
}
Beispiel #15
0
/* Check that a boring instruction is decoded correctly. */
static struct ptunit_result ptunit_ild_boring(pti_uint8_t *insn,
					      pti_uint32_t size,
					      pti_machine_mode_enum_t mode)
{
	pti_ild_t ild;

	ptunit_ild_init(&ild, insn, size, mode);
	ptu_test(ptunit_ild_decode, &ild, pti_boring, size);

	return ptu_passed();
}
Beispiel #16
0
static struct ptunit_result clear(struct evq_fixture *efix,
				  enum pt_event_binding evb)
{
	int errcode;

	errcode = pt_evq_clear(&efix->evq, evb);
	ptu_int_eq(errcode, 0);

	ptu_test(evq_empty, efix, evb);

	return ptu_passed();
}
Beispiel #17
0
static struct ptunit_result find(struct evq_fixture *efix,
				 enum pt_event_binding evb,
				 enum pt_event_type evt,
				 size_t before, size_t after)
{
	struct pt_event *in, *out;

	ptu_test(evq_enqueue_other, efix, evb, evt, before);

	in = pt_evq_enqueue(&efix->evq, evb);
	ptu_ptr(in);

	in->type = evt;

	ptu_test(evq_enqueue_other, efix, evb, evt, after);

	out = pt_evq_find(&efix->evq, evb, evt);
	ptu_ptr_eq(out, in);

	return ptu_passed();
}
static struct ptunit_result fetch_mode_tsx(struct fetch_fixture *ffix)
{
	struct pt_packet packet;

	memset(&packet, 0, sizeof(packet));
	packet.type = ppt_mode;
	packet.payload.mode.leaf = pt_mol_tsx;

	ptu_test(fetch_packet, ffix, &packet, &pt_decode_mode);

	return ptu_passed();
}
Beispiel #19
0
/* Check that an interesting instruction is decoded and classified correctly. */
static struct ptunit_result ptunit_ild_classify(uint8_t *insn, uint8_t size,
						enum pt_exec_mode mode,
						pti_inst_enum_t iclass)
{
	struct pt_ild ild;

	ptunit_ild_init(&ild, insn, size, mode);
	ptu_test(ptunit_ild_decode, &ild, interesting, size);
	ptu_int_eq(ild.iclass, iclass);

	return ptu_passed();
}
static struct ptunit_result fetch_tnt_8(struct fetch_fixture *ffix)
{
	struct pt_packet packet;

	memset(&packet, 0, sizeof(packet));
	packet.type = ppt_tnt_8;
	packet.payload.tnt.bit_size = 1;

	ptu_test(fetch_packet, ffix, &packet, &pt_decode_tnt_8);

	return ptu_passed();
}
static struct ptunit_result fetch_type(struct fetch_fixture *ffix,
				       enum pt_packet_type type,
				       const struct pt_decoder_function *dfun)
{
	struct pt_packet packet;

	memset(&packet, 0, sizeof(packet));
	packet.type = type;

	ptu_test(fetch_packet, ffix, &packet, dfun);

	return ptu_passed();
}
Beispiel #22
0
/* Check that an interesting instruction is decoded and classified correctly. */
static struct ptunit_result ptunit_ild_classify(pti_uint8_t *insn,
						pti_uint32_t size,
						pti_machine_mode_enum_t mode,
						pti_inst_enum_t iclass)
{
	pti_ild_t ild;

	ptunit_ild_init(&ild, insn, size, mode);
	ptu_test(ptunit_ild_decode, &ild, pti_interesting, size);
	ptu_int_eq(ild.iclass, iclass);

	return ptu_passed();
}
static struct ptunit_result ip(struct packet_fixture *pfix,
			       enum pt_packet_type type,
			       enum pt_ip_compression ipc,
			       uint64_t ip)
{
	pfix->packet[0].type = type;
	pfix->packet[0].payload.ip.ipc = ipc;
	pfix->packet[0].payload.ip.ip = ip;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
Beispiel #24
0
static struct ptunit_result find_none_evt(struct evq_fixture *efix,
					  enum pt_event_binding evb,
					  enum pt_event_type evt,
					  size_t num)
{
	struct pt_event *ev;

	ptu_test(evq_enqueue_other, efix, evb, evt, num);

	ev = pt_evq_find(&efix->evq, evb, evt);
	ptu_null(ev);

	return ptu_passed();
}
Beispiel #25
0
static struct ptunit_result evq_others_empty(struct evq_fixture *efix,
					     enum pt_event_binding evb)
{
	int other;

	for (other = 0; other < evb_max; ++other) {
		enum pt_event_binding ob;

		ob = (enum pt_event_binding) other;
		if (ob != evb)
			ptu_test(evq_empty, efix, ob);
	}

	return ptu_passed();
}
Beispiel #26
0
static struct ptunit_result sfix_init(struct section_fixture *sfix)
{
	sfix->section = NULL;
	sfix->file = NULL;
	sfix->name = NULL;

	sfix->name = mktempname();
	ptu_ptr(sfix->name);

	sfix->file = fopen(sfix->name, "wb");
	ptu_ptr(sfix->file);

	ptu_test(ptunit_thrd_init, &sfix->thrd);

	return ptu_passed();
}
static struct ptunit_result mode_exec(struct packet_fixture *pfix,
				      enum pt_exec_mode mode)
{
	struct pt_packet_mode_exec packet;

	packet = pt_set_exec_mode(mode);

	pfix->packet[0].type = ppt_mode;
	pfix->packet[0].payload.mode.leaf = pt_mol_exec;
	pfix->packet[0].payload.mode.bits.exec.csl = packet.csl;
	pfix->packet[0].payload.mode.bits.exec.csd = packet.csd;

	ptu_test(pfix_test, pfix);

	return ptu_passed();
}
Beispiel #28
0
static struct ptunit_result stress(struct section_fixture *sfix)
{
	uint8_t bytes[] = { 0xcc, 0x2, 0x4, 0x6 };
	int errcode;

	sfix_write(sfix, bytes);

	sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull);
	ptu_ptr(sfix->section);

#if defined(FEATURE_THREADS)
	{
		int thrd;

		for (thrd = 0; thrd < num_threads; ++thrd)
			ptu_test(ptunit_thrd_create, &sfix->thrd, worker, sfix);
	}
#endif /* defined(FEATURE_THREADS) */

	errcode = worker(sfix);
	ptu_int_eq(errcode, 0);

	return ptu_passed();
}