ac_bool test_interrupts(void) { ac_bool error = AC_FALSE; descriptor_ptr idtr; get_idt(&idtr); error |= AC_TEST(idtr.limit != 0); error |= AC_TEST(idtr.iig != 0); // Test we can set an interrupt handler and invoke it set_intr_handler(79, intr_79); print_idt_intr_gate("idt[79]:", get_idt_intr_gate(79)); idt_intr_gate *g = get_idt_intr_gate(79); error |= AC_TEST(GET_IDT_INTR_GATE_OFFSET(*g) == (ac_uptr)intr_79); intr_79_counter = 0; ac_printf("invoke intr(79)\n"); intr(79); ac_printf("done intr(79)\n"); error |= AC_TEST(intr_79_counter == 1); return error; }
ac_bool test_crs(void) { ac_bool error = AC_FALSE; union cr0_u cr0 = { .raw = get_cr0() }; // cr1 is reserved ac_uint cr2 = get_cr2(); union cr3_u cr3 = { .raw = get_cr3() }; union cr4_u cr4 = { .raw = get_cr4() }; ac_uint cr8 = get_cr8(); print_cr0("cr0", cr0.raw); ac_printf("cr2: 0x%p\n", cr2); print_cr3("cr3", cr3.raw); print_cr4("cr4", cr4.raw); ac_printf("cr8: 0x%p\n", cr8); set_cr0(cr0.raw); // cr2 is read only set_cr3(cr3.raw); set_cr4(cr4.raw); set_cr8(cr8); ac_uint cr0_1 = get_cr0(); ac_uint cr3_1 = get_cr3(); ac_uint cr4_1 = get_cr4(); ac_uint cr8_1 = get_cr8(); error |= AC_TEST(cr0.raw == cr0_1); error |= AC_TEST(cr3.raw == cr3_1); error |= AC_TEST(cr4.raw == cr4_1); error |= AC_TEST(cr8 == cr8_1); return error; }
static ac_bool ac1_process_msg(AcComp* ac, AcMsg* msg) { Ac1Comp* this = (Ac1Comp*)ac; ac_debug_printf("ac1_process_msg:+ msg->arg1=%lx, msg->arg2=%lx\n", msg->arg1, msg->arg2); ac_debug_printf("ac1_process_msg:+\n"); if (msg->op == AC_INIT_CMD) { ac_debug_printf("ac1_process_msg: AC_INIT_CMD\n"); this->ac_init_cmd_count += 1; this->error |= AC_TEST(this->ac_init_cmd_count == 1); this->error |= AC_TEST(this->ac_deinit_cmd_count == 0); } else if (msg->op == AC_DEINIT_CMD) { ac_debug_printf("ac1_process_msg: AC_DEINIT_CMD\n"); this->ac_deinit_cmd_count += 1; this->error |= AC_TEST(this->ac_init_cmd_count == 1); this->error |= AC_TEST(this->ac_deinit_cmd_count == 1); } else { ac_debug_printf("ac1_process_msg: OTHER msg->arg1=%lx, msg->arg2=%lx\n", msg->arg1, msg->arg2); this->msg_count += 1; this->error |= AC_TEST(msg->op == 1); } ac_debug_printf("ac1_process_msg: ret msg=%p\n", msg); AcMsgPool_ret_msg(msg); ac_debug_printf("ac1_process_msg:-error=%d\n", this->error); return AC_TRUE; }
/** * Test we can add and remove from Q. * * return !0 if an error. */ static ac_bool test_add_rmv_msg() { ac_bool error = AC_FALSE; ac_msg stub; ac_msg msg; ac_mpscfifo q; ac_msg* presult; stub.cmd = -1; ac_mpscfifo* pq = ac_init_mpscfifo(&q, &stub); presult = ac_rmv_msg(pq); error |= AC_TEST(presult == AC_NULL); msg.cmd = 1; ac_add_msg(pq, &msg); error |= AC_TEST(pq->phead == &msg); error |= AC_TEST(pq->ptail->pnext == &msg); presult = ac_rmv_msg(pq); error |= AC_TEST(presult != AC_NULL); error |= AC_TEST(presult != &msg); error |= AC_TEST(presult->cmd == 1); presult = ac_rmv_msg(pq); error |= AC_TEST(presult == AC_NULL); presult = ac_deinit_mpscfifo(&q); error |= AC_TEST(presult == &msg); return error; }
int main(void) { AcUint error = AC_FALSE; ac_thread_init(4); AcReceptor_init(256); AcCompMgr cm; AcStatus status = AcCompMgr_init(&cm, 3, 10, 0); error |= AC_TEST(status == AC_STATUS_OK); AcInetLink_init(&cm); if (!error) { error |= test_inet_link_impl(&cm); } AcInetLink_deinit(&cm); AcCompMgr_deinit(&cm); if (!error) { ac_printf("OK\n"); } return error; }
int main(void) { volatile0 = 0; ac_bool error = AC_FALSE; /* * Manually test these runtime errors, enable one at a time * and compile and run, each statement should fail. */ //ac_static_assert(1 == 0, "ac_static_assert(1 == 0), should always fail"); //ac_static_assert(volatile0 == 0, "ac_static_assert(volatile0 == 0), should always fail"); // Expect these asserts to fail, but since our ac_fail_impl // does not invoke "stop()" we can use AC_TEST to validate // that they failed (returned AC_TRUE) and PASS. ac_printf("Expect 5 failures vvvvvvvvvvvvvvvvvvvvvvv\n"); error |= AC_TEST(ac_fail("failing")); error |= AC_TEST(ac_assert(0 == 1)); error |= AC_TEST(ac_assert(volatile0 == 1)); error |= AC_TEST(ac_debug_assert(1 == 2)); error |= AC_TEST(ac_debug_assert(volatile0 == 2)); ac_printf("Expect 5 failures ^^^^^^^^^^^^^^^^^^^^^^^\n"); // These should never fail ac_static_assert(0 == 0, "ac_static_assert(0 == 0) should never fail"); error |= AC_TEST(!ac_assert(0 == 0)); error |= AC_TEST(!ac_assert(volatile0 == 0)); if (!error) { // Succeeded ac_printf("OK\n"); } return error; }
/** * Test dispatching a message * * return AC_TRUE if an error. */ /*static*/ ac_bool test_dispatching() { ac_bool error = AC_FALSE; AcStatus status; ac_debug_printf("test_dispatching:+\n"); // Get a dispatcher AcDispatcher* pd = AcDispatcher_get(1); error |= AC_TEST(pd != AC_NULL); Ac1Comp ac1 = { .comp = { .name=(ac_u8*)"ac1", .process_msg = &ac1_process_msg }, .msg_count = 0, .ac_init_cmd_count = 0, .ac_deinit_cmd_count = 0, .error = 0 }; // Add an acq AcDispatchableComp* dc1; dc1 = AcDispatcher_add_comp(pd, &ac1.comp); error |= AC_TEST(dc1 != AC_NULL); // Initialize a msg pool AcMsgPool mp; status = AcMsgPool_init(&mp, 2, 0); error |= AC_TEST(status == AC_STATUS_OK); // Get a msg and dispatch it AcMsg* msg1; msg1 = AcMsgPool_get_msg(&mp); error |= AC_TEST(msg1 != AC_NULL); msg1->op = 1; AcDispatcher_send_msg(dc1, msg1); ac_debug_printf("test_dispatching: dispatch now\n"); ac_bool processed_msgs = AcDispatcher_dispatch(pd); ac_debug_printf("test_dispatching: dispatch complete\n"); error |= AC_TEST(processed_msgs == AC_TRUE); // Get a second message and dispatch it AcMsg* msg2; msg2 = AcMsgPool_get_msg(&mp); error |= AC_TEST(msg2 != AC_NULL); msg2->op = 1; AcDispatcher_send_msg(dc1, msg2); ac_debug_printf("test_dispatching: rmv_ac\n"); error |= AC_TEST(AcDispatcher_rmv_comp(pd, &ac1.comp) == AC_STATUS_OK); error |= AC_TEST(ac1.error == 0); ac_debug_printf("test_dispatching:- error=%d\n", error); return error; }
/** * Test we can initialize and deinitialize AcMpscLinkList * * return !0 if an error. */ AcBool test_init_and_deinit_mpscfifo() { AcBool error = AC_FALSE; AcMpscLinkList list; ac_printf("test_init_and_deinit:+list=%p\n", &list); // Initialize ac_printf("test_init_deinit: invoke init list=%p\n", &list); error |= AC_TEST(AcMpscLinkList_init(&list) == AC_STATUS_OK); AcMpscLinkList_print("test_init_deinit: initialized list:", &list); error |= AC_TEST(list.head == &list.stub); error |= AC_TEST(list.tail == &list.stub); error |= AC_TEST(list.stub.next == AC_NULL); // Deinitialize AcMpscLinkList_print("test_init_deinit: invoke deinit list:", &list); AcMpscLinkList_deinit(&list); ac_printf("test_init_deinit: deinitialized list=%p\n", &list); error |= AC_TEST(list.head == AC_NULL); error |= AC_TEST(list.tail == AC_NULL); ac_printf("test_init_and_deinit:-error=%d\n", error); return error; }
int main(void) { ac_bool error = AC_FALSE; ac_u32 numcpus = ac_numcpus(); error |= AC_TEST(numcpus > 0); if (!error) { // Succeeded ac_printf("OK\n"); } return error; }
ac_bool test_apic() { ac_bool error = AC_FALSE; initialize_apic(); ac_u64 msr_apic_base = get_msr(MSR_IA32_APIC_BASE); error |= AC_TEST(msr_apic_base != 0); ac_printf("msr_apic_base=0x%llx\n",msr_apic_base); ac_printf(" bsp=%d\n", AC_GET_BITS(ac_u32, msr_apic_base, 8, 1)); ac_printf(" extd=%d\n", AC_GET_BITS(ac_u32, msr_apic_base, 10, 1)); ac_printf(" e=%d\n", AC_GET_BITS(ac_u32, msr_apic_base, 11, 1)); ac_u64 phy_addr = apic_get_physical_addr(); ac_printf(" phy_addr=0x%llx\n", phy_addr); error |= AC_TEST(phy_addr != 0); ac_u32 local_id = apic_get_id(); ac_printf(" local_id=0x%x\n", local_id); return error; }
/** * Test dispatcher get and return * * return AC_TRUE if an error. */ /*static*/ ac_bool test_dispatcher_get_ret() { ac_bool error = AC_FALSE; AcDispatcher* d = AcDispatcher_get(10); error |= AC_TEST(d != AC_NULL); if (d != AC_NULL) { AcDispatcher_ret(d); } // Return AC_NULL should be a NOP AcDispatcher_ret(AC_NULL); return error; }
/** * Test we can initialize and deinitialize ac_mpscfifo * * return !0 if an error. */ static ac_bool test_init_and_deinit_mpscfifo() { ac_bool error = AC_FALSE; ac_msg stub; ac_mpscfifo q; stub.cmd = -1; ac_mpscfifo* pq = ac_init_mpscfifo(&q, &stub); error |= AC_TEST(pq != AC_NULL); error |= AC_TEST(pq == &q); error |= AC_TEST(pq->phead == &stub); error |= AC_TEST(pq->ptail == &stub); error |= AC_TEST(pq->phead->pnext == AC_NULL); ac_msg *pStub = ac_deinit_mpscfifo(pq); error |= AC_TEST(pStub == &stub); error |= AC_TEST(pq->phead == AC_NULL); error |= AC_TEST(pq->ptail == AC_NULL); return error; }
/** * Test dispatching a message * * return AC_TRUE if an error. */ /*static*/ int test_dispatcher_add_rmv_acq() { ac_bool error = AC_FALSE; // Get a dispatcher AcDispatcher* pd = AcDispatcher_get(1); error |= AC_TEST(pd != AC_NULL); // Add a acq Ac1Comp ac1 = { .comp = { .name=(ac_u8*)"ac1", .process_msg = &ac1_process_msg }, }; AcDispatchableComp* dc1; ac1.msg_count = 0; ac1.ac_init_cmd_count = 0; ac1.ac_deinit_cmd_count = 0; ac1.error = 0; dc1 = AcDispatcher_add_comp(pd, &ac1.comp); error |= AC_TEST(dc1 != AC_NULL); // Test that adding a second acq fails because we // only are allowing 1 AcDispatchableComp* dc2 = AcDispatcher_add_comp(pd, &ac1.comp); error |= AC_TEST(dc2 == AC_NULL); // Test we can remove pac1 and then add it back error |= AC_TEST(AcDispatcher_rmv_comp(pd, &ac1.comp) == AC_STATUS_OK); ac1.msg_count = 0; ac1.ac_init_cmd_count = 0; ac1.ac_deinit_cmd_count = 0; ac1.error = 0; dc1 = AcDispatcher_add_comp(pd, &ac1.comp); error |= AC_TEST(dc1 != AC_NULL); // And finally remove so we leave with the pd empty error |= AC_TEST(AcDispatcher_rmv_comp(pd, &ac1.comp) == AC_STATUS_OK); // Return the dispatcher AcDispatcher_ret(pd); return error; }
int main(void) { ac_bool error = AC_FALSE; ac_u8 array0[] = {}; ac_u8 array1[] = {1}; ac_u8 array2[] = {1,1}; ac_u8 array3[] = {1,0,0xfe}; ac_u8 array4[] = {1,1,0xfe}; ac_u8 array5[] = {1,2,0xfe}; error |= AC_TEST(ac_check_sum_u8(array0, sizeof(array0)) == 0); error |= AC_TEST(ac_check_sum_u8(array1, sizeof(array1)) == 1); error |= AC_TEST(ac_check_sum_u8(array2, sizeof(array2)) == 2); error |= AC_TEST(ac_check_sum_u8(array3, sizeof(array3)) == 0xff); error |= AC_TEST(ac_check_sum_u8(array4, sizeof(array4)) == 0x00); error |= AC_TEST(ac_check_sum_u8(array5, sizeof(array5)) == 0x01); if (!error) { ac_printf("OK\n"); } return error; }
int main(void) { ac_bool error = AC_FALSE; // Must return AC_NULL although according to C99 standard a // malloc(0) may return either but undefined behavior happens // if the pointer is used. Therefore we'll defined it as always // returning AC_NULL error |= AC_TEST(ac_malloc(0) == AC_NULL); // Test conditions which attempt allocate too much memory error |= AC_TEST(ac_malloc(((ac_size_t)0) - 1) == AC_NULL); error |= AC_TEST(ac_malloc(((ac_size_t)0) - 2) == AC_NULL); error |= AC_TEST(ac_malloc(((ac_size_t)0) - 63) == AC_NULL); error |= AC_TEST(ac_malloc(((ac_size_t)0) - 64) == AC_NULL); error |= AC_TEST(ac_malloc(((ac_size_t)0) - 65) == AC_NULL); error |= AC_TEST(ac_malloc(((ac_size_t)0) - 66) == AC_NULL); // Test conditions which must succeed as we expect at // least being able to do a few small allocations void* p1 = ac_malloc(1); error |= AC_TEST(ac_malloc(1) != AC_NULL); ac_free(p1); void* p2 = ac_malloc(2); error |= AC_TEST(p2 != AC_NULL); ac_free(p2); void* p63 = ac_malloc(63); error |= AC_TEST(p63 != AC_NULL); ac_free(p63); void* p64 = ac_malloc(64); error |= AC_TEST(p64 != AC_NULL); ac_free(p64); void* p65 = ac_malloc(1); error |= AC_TEST(p65 != AC_NULL); ac_free(p65); if (!error) { // Succeeded ac_printf("OK\n"); } return error; }
ac_bool test_cpuid() { ac_u32 out_eax = 0; ac_u32 out_ebx = 0; ac_u32 out_ecx = 0; ac_u32 out_edx = 0; ac_bool error = AC_FALSE; char vendor_id[13]; ac_u32 max_leaf = cpuid_max_leaf(); get_cpuid(0, &out_eax, &out_ebx, &out_ecx, &out_edx); cpuid_get_vendor_id(vendor_id, sizeof(vendor_id)); static char* vendor_id_list[] = { "AMDisbetter!", "AuthenticAMD", "CentaurHauls", "CyrixInstead", "GenuineIntel", "TransmetaCPU", "GenuineTMx86", "Geode by NSC", "NexGenDriven", "RiseRiseRise", "SiS SiS SiS ", "UMC UMC UMC ", "VIA VIA VIA ", "Vortex86 SoC", "KVMKVMKVM", "Microsoft Hv", " lrpepyh vr", "VMwareVMware", "XenVMMXenVMM", }; // See if vendor_id is valid ac_int i; for (i = 0; i < AC_ARRAY_COUNT(vendor_id_list); i++) { if (ac_strncmp(vendor_id, vendor_id_list[i], sizeof(vendor_id)) == 0) { break; } } error |= AC_TEST_EM(i < AC_ARRAY_COUNT(vendor_id_list), "Invalid cpuid vendor"); ac_printf("Max leaf=%d vendor_id=%s\n", max_leaf, vendor_id); get_cpuid(0x80000000, &out_eax, &out_ebx, &out_ecx, &out_edx); ac_u32 max_extleaf = out_eax; error |= AC_TEST_EM(max_extleaf != 0, "max extended leaf was 0"); ac_printf("Max extended leaf=%x\n", max_extleaf); if (ac_strncmp(vendor_id, "GenuineIntel", sizeof(vendor_id)) == 0) { ac_u32 max_subleaf = 0; get_cpuid_subleaf(0x7, 0, &max_subleaf, &out_ebx, &out_ecx, &out_edx); ac_printf("Max subleaf=%x\n", max_subleaf); // Test that 0 is retured if max_subleaf is too large get_cpuid_subleaf(0x7, max_subleaf+1, &out_eax, &out_ebx, &out_ecx, &out_edx); error |= AC_TEST(out_eax == 0); //error |= AC_TEST(out_ebx == 0); Not true on my i7 ? error |= AC_TEST(out_ecx == 0); error |= AC_TEST(out_edx == 0); } // Get Processor Info and Feature Bits get_cpuid(1, &out_eax, &out_ebx, &out_ecx, &out_edx); ac_printf("Cpu info and feature bits eax=0x%x ebx=0x%x ecx=0x%x edx=0x%x\n", out_eax, out_ebx, out_ecx, out_edx); ac_printf("EAX:\n"); ac_printf(" Extended Family ID=%x\n", AC_GET_BITS(ac_u32, out_eax, 8, 20)); ac_printf(" Extended Model ID=%x\n", AC_GET_BITS(ac_u32, out_eax, 4, 16)); ac_printf(" Processor Type=%x\n", AC_GET_BITS(ac_u32, out_eax, 2, 12)); ac_printf(" Family ID=%x\n", AC_GET_BITS(ac_u32, out_eax, 4, 8)); ac_printf(" Model=%x\n", AC_GET_BITS(ac_u32, out_eax, 4, 4)); ac_printf(" Stepping ID=%x\n", AC_GET_BITS(ac_u32, out_eax, 4, 0)); ac_printf("EBX:\n"); ac_printf(" Brand Index=%x\n", AC_GET_BITS(ac_u32, out_ebx, 8, 0)); ac_printf(" CFLUSH instruction cache line size=%x\n", AC_GET_BITS(ac_u32, out_ebx, 8, 8)); ac_printf(" Local APIC ID=%x\n", AC_GET_BITS(ac_u32, out_ebx, 8, 24)); ac_printf("ECX:\n"); ac_printf(" SSE3=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 0)); ac_printf(" PCLMULQDQ=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 1)); ac_printf(" DTES64=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 2)); ac_printf(" MONITOR=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 3)); ac_printf(" DS-CPL=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 4)); ac_printf(" VMX=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 5)); ac_printf(" SMX=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 6)); ac_printf(" EIST=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 7)); ac_printf(" TM2=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 8)); ac_printf(" SSSE3=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 9)); ac_printf(" CNXT-ID=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 10)); ac_printf(" SDBG=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 11)); ac_printf(" FMA=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 12)); ac_printf(" CMPXCHG16B=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 13)); ac_printf(" xTPR Update Control=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 14)); ac_printf(" PDCM=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 15)); ac_printf(" RESERVED=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 16)); ac_printf(" PCID=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 17)); ac_printf(" DCA=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 18)); ac_printf(" SSE4_1=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 19)); ac_printf(" SSE4_2=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 20)); ac_printf(" x2APIC=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 21 )); ac_printf(" MOVBE=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 22)); ac_printf(" POPCNT=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 23)); ac_printf(" TSC-Deadline=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 24)); ac_printf(" AES=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 25)); ac_printf(" XSAVE=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 26)); ac_printf(" OXSAVE=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 27)); ac_printf(" AVX=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 28)); ac_printf(" F16C=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 29)); ac_printf(" RDRDN=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 30)); ac_printf(" UNUSED=%b\n", AC_GET_BITS(ac_u32, out_ecx, 1, 31)); ac_printf("EDX:\n"); ac_printf(" FPU=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 0)); ac_printf(" VME=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 1)); ac_printf(" DE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 2)); ac_printf(" PSE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 3)); ac_printf(" TSC=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 4)); ac_printf(" MSR=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 5)); ac_printf(" PAE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 6)); ac_printf(" MCE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 7)); ac_printf(" CX8=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 8)); ac_printf(" APIC=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 9)); ac_printf(" RESERVED_B10=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 10)); ac_printf(" SEP=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 11)); ac_printf(" MTRR=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 12)); ac_printf(" PGE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 13)); ac_printf(" MCA=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 14)); ac_printf(" CMOV=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 15)); ac_printf(" PAT=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 16)); ac_printf(" PSE-36=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 17)); ac_printf(" PSN=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 18)); ac_printf(" CFLUSH=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 19)); ac_printf(" RESERVED_B20=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 20)); ac_printf(" DS=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 21 )); ac_printf(" ACPI-Thermal Monitor and Clock Ctrl=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 22 )); ac_printf(" MMX=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 23)); ac_printf(" FXSR-FXSAVE/FXRSTOR=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 24)); ac_printf(" SSE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 25)); ac_printf(" SSE2=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 26)); ac_printf(" SS=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 27)); ac_printf(" HTT=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 28)); ac_printf(" TM=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 29)); ac_printf(" RESERVED_B30=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 30)); ac_printf(" PBE=%b\n", AC_GET_BITS(ac_u32, out_edx, 1, 31)); #if 0 ac_uint max_pab = cpuid_max_physical_address_bits(); ac_uint max_lab = cpuid_max_linear_address_bits(); error |= AC_TEST(max_lab >= max_pab); error |= AC_TEST(max_pab > 0); error |= AC_TEST(max_lab > 0); ac_printf(" max_pab=%u\n", max_pab); ac_printf(" max_lab=%u\n", max_lab); #endif return error; }
ac_uint test_receptor(void) { ac_printf("test_receptor:+\n"); ac_uint error = AC_FALSE; #if AC_PLATFORM == Posix || AC_PLATFORM == pc_x86_64 struct test_params params; ac_printf("test_receptor: call AcReceptor_get\n"); params.receptor = AcReceptor_get(); params.done_receptor = AcReceptor_get(); params.counter = 0; #ifdef NDEBUG params.loops = 1000000; #else params.loops = 10; ac_uint x = 0; #endif ac_thread_rslt_t rslt = ac_thread_create(0, t1, (void*)¶ms); error |= AC_TEST(rslt.status == 0); ac_u64 start = ac_tscrd(); ac_printf("test_receptor: loops=%ld\n", params.loops); for (ac_uint i = 0; i < params.loops; i++) { #ifdef NDEBUG // Wait for params.counter to change, i.e. t1 and incremented the counter // and is waiting for the signal while (__atomic_load_n(¶ms.counter, __ATOMIC_ACQUIRE) <= i) { } AcReceptor_signal_yield_if_waiting(params.receptor); #else // Wait for params.counter to change, i.e. t1 and incremented the counter // and is waiting for the signal while (__atomic_load_n(¶ms.counter, __ATOMIC_ACQUIRE) <= i) { if ((++x % 20000000) == 0) { ac_printf("test_receptor: waiting for counter i=%d x=%d\n", i, x); } //ac_printf("test_receptor: call ac_thread_yield\n"); //ac_thread_yield(); } ac_u64 wait_until = ac_tscrd() + (ac_tsc_freq() / 1); while (ac_tscrd() < wait_until) { if ((++x % 20000000) == 0) { ac_printf("test_receptor: wait until=%ld cur tsc=%ld i=%d x=%d\n", wait_until, ac_tscrd(), i, x); } //ac_thread_yield(); } //ac_printf("test_receptor: signal\n"); ac_u64 signal_start = ac_tscrd(); AcReceptor_signal_yield_if_waiting(params.receptor); ac_u64 ticks = ac_tscrd() - signal_start; ac_printf("test_receptor: signal time=%.9t\n", ticks); #endif } ac_debug_printf("test_receptor: wait on done_receptor x=%d\n", x); AcReceptor_wait(params.done_receptor); ac_debug_printf("test_receptor: continuing done_receptor\n"); ac_u64 stop = ac_tscrd(); ac_u64 ticks = stop - start; ac_printf("test_receptor: ticks=%ld %ld - %ld\n", ticks, stop, start); ac_u64 ticks_per_op = AC_U64_DIV_ROUND_UP(ticks, params.loops); ac_printf("test_receptor: ticks_per_op=%ld(%.9t)\n", ticks_per_op, ticks_per_op); ac_printf("test_receptor: time=%.9t\n", ticks); AcReceptor_ret(params.receptor); #endif ac_printf("test_receptor:-error=%d\n", error); return error; }
/** * Test we can add and remove msgs from a FIFO. * * return !0 if an error. */ AcBool test_add_rmv(void) { AcBool error = AC_FALSE; AcStatus status; AcMpscLinkList list; const ac_u32 data_size = 2; ac_printf("test_add_rmv:+list=%p\n", &list); // Initialize status = AcMpscLinkList_init(&list); AcMpscLinkList_print("test_add_rmv_ac_mem list:", &list); error |= AC_TEST(status == AC_STATUS_OK); // Create a message pool AcMsgPool pool; status = AcMsgPool_init(&pool, 2, data_size); // Add msg1 AcMsg* msg1 = AcMsgPool_get_msg(&pool); error |= AC_TEST(msg1 != AC_NULL); msg1->extra[0] = 1; msg1->extra[1] = 2; AcMpscLinkList_add(&list, msg1); AcMpscLinkList_print("test_add_rmv: after add msg1 list:", &list); error |= AC_TEST(list.head->msg == msg1); error |= AC_TEST(list.head->next == AC_NULL); error |= AC_TEST(list.tail->next->msg == msg1); // Add msg2 AcMsg* msg2 = AcMsgPool_get_msg(&pool); error |= AC_TEST(msg2 != AC_NULL); msg2->extra[0] = 3; msg2->extra[1] = 4; AcMpscLinkList_add(&list, msg2); AcMpscLinkList_print("test_add_rmv: after add msg2 list:", &list); error |= AC_TEST(list.head->msg == msg2); error |= AC_TEST(list.head->next == AC_NULL); error |= AC_TEST(list.tail->next->msg == msg1); // Remove msg1 AcMsg* msg = AcMpscLinkList_rmv(&list); error |= AC_TEST(msg == msg1); error |= AC_TEST(msg1->extra[0] == 1); error |= AC_TEST(msg1->extra[1] == 2); AcMpscLinkList_print("test_add_rmv: after rmv msg1 list:", &list); // Remove msg2 msg = AcMpscLinkList_rmv(&list); error |= AC_TEST(msg == msg2); error |= AC_TEST(msg2->extra[0] == 3); error |= AC_TEST(msg2->extra[1] == 4); AcMpscLinkList_print("test_add_rmv: after rmv msg1 list:", &list); // Remove from empty which should be null msg = AcMpscLinkList_rmv(&list); error |= AC_TEST(msg == AC_NULL); // Deinitialize AcMpscLinkList_deinit(&list); AcMsgPool_deinit(&pool); ac_printf("test_add_rmv:-error=%d\n", error); return error; }
int main(void) { ac_bool error = AC_FALSE; #if defined(Posix) ac_printf("test_ac_timer: no tests for Posix\n"); #elif defined(VersatilePB) ac_u32 result; //ac_printf("test_ac_timer: initial routes=0x%x enable=0x%x\n", // ac_interrupts_rd_int_routes(), ac_interrupts_rd_int_enable()); // Set to route to irq then fiq ac_interrupts_int_route_to_irq(PIC_ALL); error |= AC_TEST(ac_interrupts_rd_int_routes() == 0); ac_interrupts_int_route_to_fiq(PIC_ALL); error |= AC_TEST(ac_interrupts_rd_int_routes() == 0xFFFFFFFF); // Set interrupts disable then enabled ac_interrupts_int_disable(PIC_ALL); error |= AC_TEST(ac_interrupts_rd_int_enable() == 0); ac_interrupts_int_enable(PIC_ALL); error |= AC_TEST(ac_interrupts_rd_int_enable() == 0xFFFFFFFF); // Back to route to irq and no interrupts ac_interrupts_int_route_to_irq(PIC_ALL); error |= AC_TEST(ac_interrupts_rd_int_routes() == 0); ac_interrupts_int_disable(PIC_ALL); error |= AC_TEST(ac_interrupts_rd_int_enable() == 0); // Expect 4 timers ac_u32 count = ac_timer_get_count(); error |= AC_TEST(count == 4); ac_printf("test_ac_timer: count=%u\n", count); /* Loop through all of the timers printing the registers */ for (ac_u32 i = 0; i < count; i++) { ac_u32 value = ac_timer_rd_value(i); ac_u32 load = ac_timer_rd_load(i); ac_u32 control = ac_timer_rd_control(i); ac_u32 ris = ac_timer_rd_ris(i); ac_u32 mis = ac_timer_rd_mis(i); ac_u32 bgload = ac_timer_rd_bgload(i); ac_printf("test_ac_timer: value=%u\n", value); ac_printf("test_ac_timer: load=0x%x\n", load); ac_printf("test_ac_timer: control=0x%x\n", control); ac_printf("test_ac_timer: ris=0x%x\n", ris); ac_printf("test_ac_timer: mis=0x%x\n", mis); ac_printf("test_ac_timer: bgload=0x%x\n", bgload); } ac_u32 cur_value = 0; ac_timer_free_running(3); for (ac_u32 i = 0; i < 10; i++) { cur_value = ac_timer_rd_free_running(3); ac_printf("test_ac_timer: new free_running_value=%u\n", cur_value); } irq_param one_shot_param = { .timer = 2, .source = AC_FALSE, }; cur_value = 1; one_shot_counter = cur_value; ac_u32 prev_value = cur_value; ac_u32 terminal_value = cur_value + 1; ac_printf("test_ac_timer: one_shot_counter is %u\n", cur_value); result = ac_exception_irq_register(&one_shot_handler, &one_shot_iacs, (ac_uptr)&one_shot_param); error |= AC_TEST(result == 0); ac_timer_one_shot(one_shot_param.timer, 1000); for (ac_u32 i = 0; i < 10000 && cur_value != terminal_value; i++) { ac_u32 timer_value = ac_timer_rd_value(0); ac_u32 timer_ris = ac_timer_rd_ris(0); ac_u32 timer_mis = ac_timer_rd_mis(0); ac_u32 timer_control = ac_timer_rd_control(0); ac_printf("test_ac_timer: new value=%u timer_ris=0x%x" " timer_mis=0x%x timer_control=0x%x\n", timer_value, timer_ris, timer_mis, timer_control); ac_u32 irq_status = ac_interrupts_rd_irq_status(); ac_u32 fiq_status = ac_interrupts_rd_fiq_status(); ac_u32 ris_status = ac_interrupts_rd_ris_status(); ac_u32 int_routes = ac_interrupts_rd_int_routes(); ac_u32 int_enable = ac_interrupts_rd_int_enable(); ac_printf("test_ac_timer: irq_status=0x%x fiq_status=0x%x" " ris_status=0x%x\n", irq_status, fiq_status, ris_status); ac_printf("test_ac_timer: int_routes=0x%x int_enable=0x%x\n", int_routes, int_enable); cur_value = __atomic_load_n(&one_shot_counter, __ATOMIC_ACQUIRE); if (cur_value != prev_value) { prev_value = cur_value; ac_printf("test_ac_timer: one_shot_counter changed to %u\n", cur_value); } } error |= AC_TEST(one_shot_counter == terminal_value); irq_param periodic_param = { .timer = 3, .source = AC_FALSE, }; result = ac_exception_irq_register(&periodic_handler, &periodic_iacs, (ac_uptr)&periodic_param); error |= AC_TEST(result == 0); ac_timer_periodic(periodic_param.timer, 1000000); cur_value = 1; periodic_counter = cur_value; prev_value = cur_value; terminal_value = cur_value + 3; ac_printf("test_ac_timer: periodic_counter is %u\n", cur_value); for (ac_u64 i = 0; i < 1000000000 && cur_value != terminal_value; i++) { cur_value = __atomic_load_n(&periodic_counter, __ATOMIC_ACQUIRE); if (cur_value != prev_value) { prev_value = cur_value; ac_printf("test_ac_timer: periodic_counter changed to %u\n", cur_value); } } error |= AC_TEST(cur_value == terminal_value); #else ac_printf("test_ac_timer: Unknown Platform\n"); #endif if (!error) { // Succeeded ac_printf("OK\n"); } return error; }