static struct ptunit_result read(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, 0x0ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], bytes[1]); ptu_uint_eq(buffer[1], bytes[2]); ptu_uint_eq(buffer[2], 0xcc); status = pt_section_unmap(sfix->section); ptu_int_eq(status, 0); return ptu_passed(); }
static struct ptunit_result init(struct section_fixture *sfix) { ptu_ptr_eq(sfix->msec.section, &sfix->section); ptu_uint_eq(sfix->msec.vaddr, sfix->vaddr); ptu_uint_eq(sfix->msec.asid.size, sfix->asid.size); ptu_uint_eq(sfix->msec.asid.cr3, sfix->asid.cr3); return ptu_passed(); }
static struct ptunit_result remove_bad_asid(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[0], 0x1001ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); status = pt_image_remove(&ifix->image, &ifix->section[0], &ifix->asid[1], 0x1000ull); ptu_int_eq(status, -pte_bad_image); ptu_int_eq(ifix->status[0].deleted, 0); ptu_int_eq(ifix->status[1].deleted, 0); status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[0], 0x1003ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x03); ptu_uint_eq(buffer[1], 0x04); ptu_uint_eq(buffer[2], 0xcc); status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[1], 0x2005ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x05); ptu_uint_eq(buffer[1], 0x06); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result remove_by_asid(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[0], 0x1001ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); status = pt_image_remove_by_asid(&ifix->image, &ifix->asid[0]); ptu_int_eq(status, 1); ptu_int_ne(ifix->status[0].deleted, 0); ptu_int_eq(ifix->status[1].deleted, 0); status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &ifix->asid[0], 0x1003ull); ptu_int_eq(status, -pte_nomap); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[1], 0x2003ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x03); ptu_uint_eq(buffer[1], 0x04); ptu_uint_eq(buffer[2], 0xcc); 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 read_null_asid(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_read(&ifix->image, buffer, 2, NULL, 0x2003ull); ptu_int_eq(status, -pte_internal); ptu_uint_eq(buffer[0], 0xcc); ptu_uint_eq(buffer[1], 0xcc); return ptu_passed(); }
static struct ptunit_result read_nomem(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc }; int status; status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &ifix->asid[1], 0x1010ull); ptu_int_eq(status, -pte_nomap); ptu_uint_eq(buffer[0], 0xcc); ptu_uint_eq(buffer[1], 0xcc); return ptu_passed(); }
static struct ptunit_result from_user_default(void) { struct pt_asid asid; int errcode; errcode = pt_asid_from_user(&asid, NULL); ptu_int_eq(errcode, 0); ptu_uint_eq(asid.size, sizeof(asid)); ptu_uint_eq(asid.cr3, pt_asid_no_cr3); ptu_uint_eq(asid.vmcs, pt_asid_no_vmcs); return ptu_passed(); }
static struct ptunit_result init(void) { struct pt_tnt_cache tnt_cache; memset(&tnt_cache, 0xcd, sizeof(tnt_cache)); pt_tnt_cache_init(&tnt_cache); ptu_uint_eq(tnt_cache.tnt, 0ull); ptu_uint_eq(tnt_cache.index, 0ull); return ptu_passed(); }
static struct ptunit_result read_truncated(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc }; int status; status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &ifix->asid[0], 0x100full); ptu_int_eq(status, 1); ptu_uint_eq(buffer[0], 0x0f); ptu_uint_eq(buffer[1], 0xcc); return ptu_passed(); }
static struct ptunit_result read_truncated(struct section_fixture *sfix) { uint8_t buffer[] = { 0xcc, 0xcc }; int status; status = pt_msec_read(&sfix->msec, buffer, 2, &sfix->asid, sfix->vaddr + sfix->section.size - 1); ptu_int_eq(status, 1); ptu_uint_eq(buffer[0], sfix->mapping.content[sfix->mapping.size - 1]); ptu_uint_eq(buffer[1], 0xcc); return ptu_passed(); }
static struct ptunit_result read(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[1], 0x2003ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x03); ptu_uint_eq(buffer[1], 0x04); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result read_offset(struct section_fixture *sfix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_msec_read(&sfix->msec, buffer, 2, &sfix->asid, sfix->vaddr + 3); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], sfix->mapping.content[3]); ptu_uint_eq(buffer[1], sfix->mapping.content[4]); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result update_tnt_null_packet(void) { struct pt_tnt_cache tnt_cache; int errcode; tnt_cache.tnt = 42ull; tnt_cache.index = 12ull; errcode = pt_tnt_cache_update_tnt(&tnt_cache, NULL, NULL); ptu_int_eq(errcode, -pte_invalid); ptu_uint_eq(tnt_cache.tnt, 42ull); ptu_uint_eq(tnt_cache.index, 12ull); return ptu_passed(); }
static struct ptunit_result from_user_small(void) { struct pt_asid asid, user; int errcode; user.size = sizeof(user.size); errcode = pt_asid_from_user(&asid, &user); ptu_int_eq(errcode, 0); ptu_uint_eq(asid.size, sizeof(asid)); ptu_uint_eq(asid.cr3, pt_asid_no_cr3); ptu_uint_eq(asid.vmcs, pt_asid_no_vmcs); return ptu_passed(); }
static struct ptunit_result read_empty(struct image_fixture *ifix) { struct pt_asid asid; uint8_t buffer[] = { 0xcc, 0xcc }; int status; pt_asid_init(&asid); status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &asid, 0x1000ull); ptu_int_eq(status, -pte_nomap); ptu_uint_eq(buffer[0], 0xcc); ptu_uint_eq(buffer[1], 0xcc); return ptu_passed(); }
static struct ptunit_result read_default_asid(struct section_fixture *sfix) { struct pt_asid asid; uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; pt_asid_init(&asid); status = pt_msec_read(&sfix->msec, buffer, 2, &asid, sfix->vaddr); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], sfix->mapping.content[0]); ptu_uint_eq(buffer[1], sfix->mapping.content[1]); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result update_tnt_not_empty(void) { struct pt_tnt_cache tnt_cache; struct pt_packet_tnt packet; int errcode; tnt_cache.tnt = 42ull; tnt_cache.index = 12ull; errcode = pt_tnt_cache_update_tnt(&tnt_cache, &packet, NULL); ptu_int_eq(errcode, -pte_bad_context); ptu_uint_eq(tnt_cache.tnt, 42ull); ptu_uint_eq(tnt_cache.index, 12ull); return ptu_passed(); }
static struct ptunit_result asid(void) { struct pt_mapped_section msec; struct pt_asid asid; const struct pt_asid *pasid; pt_asid_init(&asid); asid.cr3 = 0xa00; pt_msec_init(&msec, NULL, &asid, 0ull); pasid = pt_msec_asid(&msec); ptu_uint_eq(pasid->size, asid.size); ptu_uint_eq(pasid->cr3, asid.cr3); return ptu_passed(); }
static struct ptunit_result from_user_big(void) { struct pt_asid asid, user; int errcode; user.size = sizeof(user) + 4; user.cr3 = 0x4200ull; user.vmcs = 0x23000ull; errcode = pt_asid_from_user(&asid, &user); ptu_int_eq(errcode, 0); ptu_uint_eq(asid.size, sizeof(asid)); ptu_uint_eq(asid.cr3, 0x4200ull); ptu_uint_eq(asid.vmcs, 0x23000ull); return ptu_passed(); }
static struct ptunit_result end_null(void) { uint64_t end; end = pt_msec_end(NULL); ptu_uint_eq(end, 0ull); return ptu_passed(); }
static struct ptunit_result begin(struct section_fixture *sfix) { uint64_t begin; begin = pt_msec_begin(&sfix->msec); ptu_uint_eq(begin, sfix->vaddr); return ptu_passed(); }
static struct ptunit_result end(struct section_fixture *sfix) { uint64_t end; end = pt_msec_end(&sfix->msec); ptu_uint_eq(end, sfix->vaddr + sfix->section.size); return ptu_passed(); }
static struct ptunit_result begin_null(void) { uint64_t begin; begin = pt_msec_begin(NULL); ptu_uint_eq(begin, 0ull); return ptu_passed(); }
static struct ptunit_result update_tnt(void) { struct pt_tnt_cache tnt_cache; struct pt_packet_tnt packet; int errcode; pt_tnt_cache_init(&tnt_cache); packet.bit_size = 4ull; packet.payload = 8ull; errcode = pt_tnt_cache_update_tnt(&tnt_cache, &packet, NULL); ptu_int_eq(errcode, 0); ptu_uint_eq(tnt_cache.tnt, 8ull); ptu_uint_eq(tnt_cache.index, 1ull << 3); return ptu_passed(); }
static struct ptunit_result size_null(void) { uint64_t size; size = pt_section_size(NULL); ptu_uint_eq(size, 0ull); return ptu_passed(); }
static struct ptunit_result read_callback(struct image_fixture *ifix) { uint8_t memory[] = { 0xdd, 0x01, 0x02, 0xdd }; uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_set_callback(&ifix->image, image_readmem_callback, memory); ptu_int_eq(status, 0); status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[0], 0x3001ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result get_offset_init(struct test_fixture *tfix) { uint64_t offset; int errcode; errcode = pt_enc_get_offset(&tfix->encoder, &offset); ptu_int_eq(errcode, 0); ptu_uint_eq(offset, 0ull); return ptu_passed(); }
static struct ptunit_result remove_all_by_filename(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; ifix->section[0].filename = "same-name"; ifix->section[1].filename = "same-name"; status = pt_image_add(&ifix->image, &ifix->section[0], &ifix->asid[0], 0x1000ull); ptu_int_eq(status, 0); status = pt_image_add(&ifix->image, &ifix->section[1], &ifix->asid[0], 0x2000ull); ptu_int_eq(status, 0); status = pt_image_read(&ifix->image, buffer, 2, &ifix->asid[0], 0x1001ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); status = pt_image_remove_by_filename(&ifix->image, "same-name", &ifix->asid[0]); ptu_int_eq(status, 2); ptu_int_ne(ifix->status[0].deleted, 0); ptu_int_ne(ifix->status[1].deleted, 0); status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &ifix->asid[0], 0x1003ull); ptu_int_eq(status, -pte_nomap); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); status = pt_image_read(&ifix->image, buffer, sizeof(buffer), &ifix->asid[0], 0x2003ull); ptu_int_eq(status, -pte_nomap); ptu_uint_eq(buffer[0], 0x01); ptu_uint_eq(buffer[1], 0x02); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }
static struct ptunit_result copy_duplicate(struct image_fixture *ifix) { uint8_t buffer[] = { 0xcc, 0xcc, 0xcc }; int status; status = pt_image_add(&ifix->copy, &ifix->section[1], &ifix->asid[1], 0x2000ull); ptu_int_eq(status, 0); status = pt_image_copy(&ifix->copy, &ifix->image); ptu_int_eq(status, 1); status = pt_image_read(&ifix->copy, buffer, 2, &ifix->asid[1], 0x2003ull); ptu_int_eq(status, 2); ptu_uint_eq(buffer[0], 0x03); ptu_uint_eq(buffer[1], 0x04); ptu_uint_eq(buffer[2], 0xcc); return ptu_passed(); }