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 read_offset(struct section_fixture *sfix) { uint8_t bytes[] = { 0xcc, 0x2, 0x4, 0x6 }; uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; sfix_write(sfix, bytes); sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); ptu_ptr(sfix->section); status = pt_section_map(sfix->section); ptu_int_eq(status, 0); status = pt_section_read(sfix->section, buffer, 2, 0x1ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], bytes[2]); ptu_uint_eq(buffer[1], bytes[3]); ptu_uint_eq(buffer[2], 0xcc); status = pt_section_unmap(sfix->section); ptu_int_eq(status, 0); return ptu_passed(); }
static struct ptunit_result overflow(struct evq_fixture *efix, enum pt_event_binding evb, size_t num) { struct pt_event *in[evq_max], *out[evq_max], *ev; size_t idx; ptu_uint_le(num, evq_max - 2); for (idx = 0; idx < (evq_max - 2); ++idx) { in[idx] = pt_evq_enqueue(&efix->evq, evb); ptu_ptr(in[idx]); } for (idx = 0; idx < num; ++idx) { ev = pt_evq_enqueue(&efix->evq, evb); ptu_null(ev); } for (idx = 0; idx < num; ++idx) { out[idx] = pt_evq_dequeue(&efix->evq, evb); ptu_ptr_eq(out[idx], in[idx]); } return ptu_passed(); }
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(); }
static struct ptunit_result ptu_pkt_eq(const struct pt_packet *enc, const struct pt_packet *dec) { const uint8_t *renc, *rdec; size_t byte; ptu_ptr(enc); ptu_ptr(dec); renc = (const uint8_t *) enc; rdec = (const uint8_t *) dec; for (byte = 0; byte < sizeof(*enc); ++byte) ptu_uint_eq(renc[byte], rdec[byte]); return ptu_passed(); }
static struct ptunit_result get_config(struct test_fixture *tfix) { const struct pt_config *config; config = pt_pkt_get_config(&tfix->decoder); ptu_ptr(config); return ptu_passed(); }
static struct ptunit_result standalone(struct evq_fixture *efix) { struct pt_event *ev; ev = pt_evq_standalone(&efix->evq); ptu_ptr(ev); ptu_uint_eq(ev->ip_suppressed, 0ul); ptu_uint_eq(ev->status_update, 0ul); return ptu_passed(); }
static struct ptunit_result efix_init_pending(struct evq_fixture *efix) { struct pt_event *ev; int evb; pt_evq_init(&efix->evq); for (evb = 0; evb < evb_max; ++evb) { ev = pt_evq_enqueue(&efix->evq, (enum pt_event_binding) evb); ptu_ptr(ev); } return ptu_passed(); }
static struct ptunit_result unmap_nomap(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); errcode = pt_section_unmap(sfix->section); ptu_int_eq(errcode, -pte_nomap); return ptu_passed(); }
static struct ptunit_result read_nomap(struct section_fixture *sfix) { uint8_t bytes[] = { 0xcc, 0x2, 0x4, 0x6 }, buffer[] = { 0xcc }; int status; sfix_write(sfix, bytes); sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); ptu_ptr(sfix->section); status = pt_section_read(sfix->section, buffer, 1, 0x0ull); ptu_int_eq(status, -pte_nomap); ptu_uint_eq(buffer[0], 0xcc); return ptu_passed(); }
static struct ptunit_result enqueue_one_dequeue(struct evq_fixture *efix, enum pt_event_binding evb, size_t num) { size_t idx; for (idx = 0; idx < num; ++idx) { struct pt_event *in, *out; in = pt_evq_enqueue(&efix->evq, evb); ptu_ptr(in); out = pt_evq_dequeue(&efix->evq, evb); ptu_ptr_eq(out, in); } return ptu_passed(); }
static struct ptunit_result create(struct section_fixture *sfix) { const char *name; uint8_t bytes[] = { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }; uint64_t size; sfix_write(sfix, bytes); sfix->section = pt_mk_section(sfix->name, 0x1ull, 0x3ull); ptu_ptr(sfix->section); name = pt_section_filename(sfix->section); ptu_str_eq(name, sfix->name); size = pt_section_size(sfix->section); ptu_uint_eq(size, 0x3ull); return ptu_passed(); }
static struct ptunit_result map_overflow(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); sfix->section->mcount = UINT16_MAX; errcode = pt_section_map(sfix->section); ptu_int_eq(errcode, -pte_internal); sfix->section->mcount = 0; return ptu_passed(); }
static struct ptunit_result evq_enqueue_other(struct evq_fixture *efix, enum pt_event_binding evb, enum pt_event_type evt, size_t num) { enum pt_event_type ot; struct pt_event *ev; size_t other; for (other = 0; other < num; ++other) { ot = (enum pt_event_type) other; if (ot != evt) { ev = pt_evq_enqueue(&efix->evq, evb); ptu_ptr(ev); ev->type = ot; } } return ptu_passed(); }
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 find_none_evb(struct evq_fixture *efix, enum pt_event_binding evb, enum pt_event_type evt) { struct pt_event *ev; size_t other; for (other = 0; other < evb_max; ++other) { enum pt_event_binding ob; ob = (enum pt_event_binding) other; if (ob != evb) { ev = pt_evq_enqueue(&efix->evq, ob); ptu_ptr(ev); ev->type = evt; } } ev = pt_evq_find(&efix->evq, evb, evt); ptu_null(ev); return ptu_passed(); }
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(); }