void test_instruction_rr_3(void) { Instruction* i = new_instruction_rr(op("and", AND), 0, 4); TEST_ASSERT_EQUAL_INT(I_TYPE_RR, i->type); TEST_ASSERT_EQUAL_INT_MESSAGE(0, i->rD, "Incorrect rD value"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, i->rS, "Incorrect rS value"); free(i); }
void test_instruction_mem_4(void) { Instruction* i = new_instruction_mem(op("ld", LD), 0, 3, true); TEST_ASSERT_EQUAL_INT(I_TYPE_MEM, i->type); TEST_ASSERT_EQUAL_INT_MESSAGE(0, i->rD, "Incorrect rD value"); TEST_ASSERT_EQUAL_INT_MESSAGE(3, i->rS, "Incorrect rS value"); TEST_ASSERT_EQUAL_INT_MESSAGE(M_BYTE, i->flags, "Incorrect flags for MEM instruction"); free(i); }
void test_instruction_jmpi_3(void) { Instruction* i = new_instruction_jmpi(op("jmp", JMP), addr_from_immediate(23), EQ); TEST_ASSERT_EQUAL_INT(I_TYPE_JMPI, i->type); TEST_ASSERT_EQUAL_INT_MESSAGE(23, i->address->immediate, "Incorrect Immediate"); TEST_ASSERT_EQUAL_INT_MESSAGE(EQ, i->cc, "Incorrect Condition code"); TEST_ASSERT_EQUAL_INT_MESSAGE(JMPI, i->op_type, "Incorrect opcode"); free(i); }
void test_instruction_ri_3(void) { Instruction* i = new_instruction_ri(op("add", ADD), 5, addr_from_immediate(345)); TEST_ASSERT_EQUAL_INT(I_TYPE_RIMM, i->type); TEST_ASSERT_EQUAL_INT_MESSAGE(ADDI, i->op_type, "Incorrect opcode"); TEST_ASSERT_EQUAL_INT_MESSAGE(5, i->rD, "Incorrect rD value"); TEST_ASSERT_EQUAL_INT_MESSAGE(345, i->address->immediate, "Incorrect immediate"); free(i); }
void test_instruction_memi_5(void) { Instruction* i = new_instruction_memi( op("st", ST), 3, 4, addr_from_immediate(2567), false, true); TEST_ASSERT_EQUAL_INT(I_TYPE_MEMI, i->type); TEST_ASSERT_EQUAL_INT_MESSAGE(3, i->rD, "Incorrect rD value"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, i->rS, "Incorrect rS value"); TEST_ASSERT_EQUAL_INT_MESSAGE(M_DISP, i->flags, "Incorrect MEM flags"); TEST_ASSERT_EQUAL_INT_MESSAGE(2567, i->address->immediate, "Incorrect Immediate"); TEST_ASSERT_EQUAL_INT_MESSAGE(STI, i->op_type, "Incorrect opcode"); free(i); }
static void parse_hex4_should_parse_all_combinations(void) { unsigned int number = 0; unsigned char digits_lower[5]; unsigned char digits_upper[5]; /* test all combinations */ for (number = 0; number <= 0xFFFF; number++) { TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_lower, "%.4x", number), "sprintf failed."); TEST_ASSERT_EQUAL_INT_MESSAGE(4, sprintf((char*)digits_upper, "%.4X", number), "sprintf failed."); TEST_ASSERT_EQUAL_INT_MESSAGE(number, parse_hex4(digits_lower), "Failed to parse lowercase digits."); TEST_ASSERT_EQUAL_INT_MESSAGE(number, parse_hex4(digits_upper), "Failed to parse uppercase digits."); } }
void test_shift_selector(void) { Instruction* i = new_instruction_ri(op("shl", SHL), 4, addr_from_immediate(5)); TEST_ASSERT_EQUAL_INT_MESSAGE(5 << 3 | 4, build_shift_selector(i), "Incorrect selector for shli"); free(i); }
void test_jmp_selector(void) { Instruction* i = new_instruction_jmpi(op("jmp", JMP), addr_from_immediate(34), OS); TEST_ASSERT_EQUAL_INT_MESSAGE(OS << 3, build_jmp_selector(i), "Incorrect selector for jmp"); free(i); }
void test_mem_selector(void) { Instruction* i = new_instruction_memi( op("st", ST), 3, 2, addr_from_immediate(456), false, true); TEST_ASSERT_EQUAL_INT_MESSAGE(1 << 6 | 2 << 3 | 3, build_mem_selector(i), "Incorrect selector for memi"); free(i); }
void tearDown() { // Make sure parameters have been transmitted correctly if (expectedSend) { TEST_ASSERT_EQUAL_INT_MESSAGE(sizeof(parameterData) + 1, mock_driver.sendBuffer.size, "Parameter send buffer has wrong size"); TEST_ASSERT_EQUAL_UINT8_MESSAGE(operation, mock_driver.sendBuffer.data[0], "Operation byte not correctly set"); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(parameterData, mock_driver.sendBuffer.data + 1, sizeof(parameterData), "Parameter data is not correct"); } // Check returned values TEST_ASSERT_EQUAL_INT_MESSAGE(expectedStatus.status, status.status, "Unexpected rpc client result status"); TEST_ASSERT_EQUAL_INT_MESSAGE(expectedStatus.server_status, status.server_status, "Unexpected rpc client server status"); TEST_ASSERT_EQUAL_INT_MESSAGE(expectedStatus.handler_status, status.handler_status, "Unexpected rpc handler status"); TEST_ASSERT_EQUAL_MESSAGE(expectedSend || expectedReceive, mock_driver.waitedForCompletion, "Should (not) have waited for completion"); TEST_ASSERT_EQUAL_MESSAGE(expectedSend, mock_driver.sent, "rpc call should (not) have sent something"); TEST_ASSERT_EQUAL_MESSAGE(expectedReceive, mock_driver.received, "rpc call should (not) have received something"); }
void test_labels(void) { init_hash_table(); Instruction* i = new_instruction_label("test", 1); TEST_ASSERT_EQUAL_STRING("test", i->opcode); TEST_ASSERT(i->type = I_TYPE_LABEL); set_label_address("test", 34); Address* a = addr_from_label(strdup("test")); resolve_address(a); TEST_ASSERT_EQUAL_INT_MESSAGE(34, a->immediate, "Incorrect label address"); free(a); free(i); }
void test_instruction_length(void) { Instruction* rr = new_instruction_rr(op("add", ADD), 3, 2); Instruction* ri = new_instruction_ri(op("xor", XOR), 0, addr_from_immediate(234)); Instruction* memi = new_instruction_memi( op("ld", LD), 3, 4, addr_from_immediate(1234), false, false); Instruction* shift = new_instruction_ri(op("shl", SHL), 3, addr_from_immediate(2)); Instruction* mov_special = new_instruction_ri(op("mov", MOV), 3, addr_from_immediate(24)); Instruction* mov_general = new_instruction_ri(op("mov", MOV), 5, addr_from_immediate(1456)); Instruction* jmpi = new_instruction_jmpi(op("jmp", JMP), addr_from_immediate(34), AL); TEST_ASSERT_EQUAL_INT_MESSAGE(2, instruction_length(rr), "Incorrect RR instruction length"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(ri), "Incorrect RI instruction length"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(memi), "Incorrect MemI instruction length"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(shift), "Incorrect Shift instruction length"); TEST_ASSERT_EQUAL_INT_MESSAGE(2, instruction_length(mov_special), "Incorrect Special movi instruction length"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(mov_general), "Incorrect General movi instruction length"); TEST_ASSERT_EQUAL_INT_MESSAGE(4, instruction_length(jmpi), "Incorrect JmpI instruction length"); free(rr); free(ri); free(memi); free(shift); free(mov_special); free(mov_general); free(jmpi); }
void test_instruction_r_2(void) { Instruction* i = new_instruction_r(op("not", NOT), 3); TEST_ASSERT_EQUAL_INT(I_TYPE_R, i->type); TEST_ASSERT_EQUAL_INT_MESSAGE(3, i->rD, "Incorrect RD value"); free(i); }