void test_spiffs_rename(const char* filename_prefix) { char name_dst[64]; char name_src[64]; snprintf(name_dst, sizeof(name_dst), "%s_dst.txt", filename_prefix); snprintf(name_src, sizeof(name_src), "%s_src.txt", filename_prefix); unlink(name_dst); unlink(name_src); FILE* f = fopen(name_src, "w+"); TEST_ASSERT_NOT_NULL(f); const char* str = "0123456789"; for (int i = 0; i < 400; ++i) { TEST_ASSERT_NOT_EQUAL(EOF, fputs(str, f)); } TEST_ASSERT_EQUAL(0, fclose(f)); TEST_ASSERT_EQUAL(0, rename(name_src, name_dst)); TEST_ASSERT_NULL(fopen(name_src, "r")); FILE* fdst = fopen(name_dst, "r"); TEST_ASSERT_NOT_NULL(fdst); TEST_ASSERT_EQUAL(0, fseek(fdst, 0, SEEK_END)); TEST_ASSERT_EQUAL(4000, ftell(fdst)); TEST_ASSERT_EQUAL(0, fclose(fdst)); }
TEST(ErrorCheck, CompareChecksum_Data_ProcessMultiBytesSize_GoodMatch) { uint8_t buffer[2]; buffer[0] = 1; buffer[1] = 2; TEST_ASSERT_NOT_EQUAL(0, CompareChecksum(buffer, 2, 3)); }
void test_cftNew_should_create_cft_for_symbols_from_file(){ Stream *in = NULL; CFT *cftPtr; int tableSize; CEXCEPTION_T error; Try{ // Please check cftData.txt, inside has a lengthy string in = openStream("cftData.txt","r"); cftPtr = cftNew(in, &tableSize); }Catch(error){ TEST_ASSERT_NOT_EQUAL(ERR_FILE_NOT_EXIST,error); } dumpCFT(cftPtr,0); dumpCFT(cftPtr,1); dumpCFT(cftPtr,2); TEST_ASSERT_EQUAL(3,tableSize); TEST_ASSERT_EQUAL('a', cftPtr[0].symbol); TEST_ASSERT_EQUAL(40, cftPtr[0].cum_Freq); TEST_ASSERT_EQUAL(40, cftPtr[0].occurNo); TEST_ASSERT_EQUAL('b', cftPtr[1].symbol); TEST_ASSERT_EQUAL(41, cftPtr[1].cum_Freq); TEST_ASSERT_EQUAL(1, cftPtr[1].occurNo); TEST_ASSERT_EQUAL('c', cftPtr[2].symbol); TEST_ASSERT_EQUAL(50, cftPtr[2].cum_Freq); TEST_ASSERT_EQUAL(9, cftPtr[2].occurNo); if(in != NULL){ closeStream(in); } }
static inline bool s_check_get_thread_id(lagopus_thread_t *thd_ptr, lagopus_result_t require_ret) { bool result = false; lagopus_result_t ret; pthread_t tid; int i; for (i = 0; i < GET_TID_RETRY; i++) { ret = lagopus_thread_get_pthread_id(thd_ptr, &tid); if (ret == require_ret) { break; } } if (ret == require_ret) { if (ret == LAGOPUS_RESULT_OK) { TEST_ASSERT_NOT_EQUAL(tid, LAGOPUS_INVALID_THREAD); } result = true; } else { if (require_ret == LAGOPUS_RESULT_OK && ret == LAGOPUS_RESULT_ALREADY_HALTED) { lagopus_msg_warning( "test requires LAGOPUS_RESULT_OK, but result is LAGOPUS_ALREADY_HALTED. " "Modify value of WAIT_NSEC and MAIN_SLEEP_USEC of thread_test.c, please try again.\n"); result = true; } else { lagopus_perror(ret); TEST_FAIL_MESSAGE("get_thread_id failed"); result = false; } } return result; }
void test_idle_cancel_before(void) { lagopus_result_t r = LAGOPUS_RESULT_ANY_FAILURES; lagopus_callout_task_t t = NULL; size_t n_exec; callout_arg_t arg = NULL; arg = s_alloc_arg(10, 500LL * 1000LL * 1000LL); TEST_ASSERT_NOT_EQUAL(arg, NULL); r = lagopus_callout_create_task(&t, 0, __func__, callout_task, (void *)arg, s_freeup_arg); TEST_ASSERT_EQUAL(r, LAGOPUS_RESULT_OK); r = lagopus_callout_submit_task(&t, -1LL, 1000LL * 1000LL * 1000LL); TEST_ASSERT_EQUAL(r, LAGOPUS_RESULT_OK); lagopus_callout_cancel_task(&t); n_exec = s_wait_freeup_arg(arg); if (n_exec == 1) { /* * idle tasks could be executed before cancellation. */ n_exec = 0; } TEST_ASSERT_EQUAL(n_exec, 0); s_destroy_arg(arg); }
void test_spiffs_overwrite_append(const char* filename) { /* Create new file with 'aaaa' */ test_spiffs_create_file_with_text(filename, "aaaa"); /* Append 'bbbb' to file */ FILE *f_a = fopen(filename, "a"); TEST_ASSERT_NOT_NULL(f_a); TEST_ASSERT_NOT_EQUAL(EOF, fputs("bbbb", f_a)); TEST_ASSERT_EQUAL(0, fclose(f_a)); /* Read back 8 bytes from file, verify it's 'aaaabbbb' */ char buf[10] = { 0 }; FILE *f_r = fopen(filename, "r"); TEST_ASSERT_NOT_NULL(f_r); TEST_ASSERT_EQUAL(8, fread(buf, 1, 8, f_r)); TEST_ASSERT_EQUAL_STRING_LEN("aaaabbbb", buf, 8); /* Be sure we're at end of file */ TEST_ASSERT_EQUAL(0, fread(buf, 1, 8, f_r)); TEST_ASSERT_EQUAL(0, fclose(f_r)); /* Overwrite file with 'cccc' */ test_spiffs_create_file_with_text(filename, "cccc"); /* Verify file now only contains 'cccc' */ f_r = fopen(filename, "r"); TEST_ASSERT_NOT_NULL(f_r); bzero(buf, sizeof(buf)); TEST_ASSERT_EQUAL(4, fread(buf, 1, 8, f_r)); // trying to read 8 bytes, only expecting 4 TEST_ASSERT_EQUAL_STRING_LEN("cccc", buf, 4); TEST_ASSERT_EQUAL(0, fclose(f_r)); }
TEST(ErrorCheck, CompareCalcCRC_Data_Process1BytesSize_GoodMatch) { uint8_t buffer[2]; buffer[0] = 1; buffer[1] = 2; TEST_ASSERT_NOT_EQUAL(0, CompareCalcCRC(buffer, 1, 4129)); }
void test_can_create_enumerator(void) { cc_enumerator *e = cc_enumerator_new(cc_enumerable_new(one_to_three)); e->data = GC_MALLOC(sizeof(int)); *((int *)e->data) = 0; TEST_ASSERT_NOT_EQUAL(e, NULL); }
/** \brief test function Task ** ** this function test transport Task ** **/ void test_ciaaModbus_transportTask_01(void) { int32_t hModbusTransp[10]; uint32_t loopi; for (loopi = 0 ; loopi < CIAA_MODBUS_TOTAL_TRANSPORT_ASCII; loopi++) { ciaaModbus_asciiTaskCount[loopi] = 0; } hModbusTransp[0] = ciaaModbus_transportOpen( CIAA_MODBUS_TRASNPORT_FIL_DES_MODBUS_ASCII, CIAAMODBUS_TRANSPORT_MODE_ASCII_MASTER); hModbusTransp[1] = ciaaModbus_transportOpen( CIAA_MODBUS_TRASNPORT_FIL_DES_MODBUS_RTU, CIAAMODBUS_TRANSPORT_MODE_RTU_MASTER); hModbusTransp[2] = ciaaModbus_transportOpen( CIAA_MODBUS_TRASNPORT_FIL_DES_MODBUS_TCP, CIAAMODBUS_TRANSPORT_MODE_TCP_MASTER); ciaaModbus_transportTask(hModbusTransp[0]); TEST_ASSERT_NOT_EQUAL(-1, hModbusTransp[0]); TEST_ASSERT_EQUAL(-1, hModbusTransp[1]); TEST_ASSERT_EQUAL(-1, hModbusTransp[2]); TEST_ASSERT_EQUAL(1, ciaaModbus_asciiTaskCount[0]); }
TEST(socktoa, HashNotEqual) { /* These two addresses should not generate the same hash. */ sockaddr_u input1 = CreateSockaddr4("192.0.2.1", 123); sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123); TEST_ASSERT_TRUE(IsDiffS(&input1, &input2)); TEST_ASSERT_NOT_EQUAL(sock_hash(&input1), sock_hash(&input2)); }
void test_AddFirst() { int i; for (i = 0; i < 10; i++) { list1->addFirst(list1, createTestObj(i * 1)); } ListNode node = list1->get(list1, 9); TEST_ASSERT_NOT_EQUAL(NULL, node); TEST_ASSERT_EQUAL(0, *((int*)(node->element))); }
void test_Last() { int i; for (i = 0; i < 10; i++) { list1->addLast(list1, createTestObj(i * 10)); } ListNode node = list1->last(list1); TEST_ASSERT_NOT_EQUAL(NULL, node); TEST_ASSERT_EQUAL(90, *((int*)(node->element))); }
//test case where r0 is not 0, should not jump //test CBZ r0 , bla (the bla label is at address 0x08000036) void test_CBZ_given_r0_0x10_should_not_get_PC_0x08000036() { coreReg[0] = 0x10; coreReg[PC] = 0x0800002a; uint32_t instruction = 0xb1200000; ARMSimulator(instruction); TEST_ASSERT_NOT_EQUAL(0x08000036, coreReg[PC]); }
TEST(Clock, Clock_SysClock_CheckTimeValid_GoodTime) { ClockTime_t time; time.seconds = 0; time.minutes = 0; time.hours = 0; TEST_ASSERT_NOT_EQUAL(0, SysClock_CheckTimeValid(time)); }
TEST(Clock, Clock_SysClock_CheckDateValid_GoodDate) { ClockDate_t date; date.day = 1; date.month = 1; date.year = 0; TEST_ASSERT_NOT_EQUAL(0, SysClock_CheckDateValid(date)); }
TEST(Clock, Clock_SysClock_SetDate_Good) { ClockDate_t date; date.day = 1; date.month = 12; date.year = 0; SysClock_SetDate(date); TEST_ASSERT_NOT_EQUAL(0, SysClock_IsDateSet()); }
TEST(Clock, Clock_SysClock_SetTime_Good) { ClockTime_t time; time.seconds = 0; time.minutes = 0; time.hours = 0; SysClock_SetTime(time); TEST_ASSERT_NOT_EQUAL(0, SysClock_IsTimeSet()); }
void testNotEqual(void) { TEST_ASSERT_NOT_EQUAL(0, 1); TEST_ASSERT_NOT_EQUAL(1, 0); TEST_ASSERT_NOT_EQUAL(100, 101); TEST_ASSERT_NOT_EQUAL(0, -1); TEST_ASSERT_NOT_EQUAL(65535, -65535); TEST_ASSERT_NOT_EQUAL(75, 900); TEST_ASSERT_NOT_EQUAL(-100, -101); }
//----------------------------------------------------------------------------- void test_LL_New_should_return_a_new_linked_list_with_the_supplied_contents(void) { // Setup int num = 42; // Expected Function Calls // Function to Test LinkedList_T* list = LL_New(&num); // Asserts TEST_ASSERT_NOT_EQUAL(NULL, list); TEST_ASSERT_EQUAL(&num, list->contents); TEST_ASSERT_EQUAL(NULL, list->next); }
void test_arithmeticEncoder_to_encode_acba_with_cftData_txt_should_generate_a_tag(){ Stream *cft = NULL, *in = NULL, *out = NULL; CFT *cftPtr; int dataLength = 0, tableSize; CEXCEPTION_T error; Try{ // Please check cftData.txt, inside has a lengthy string cft = openStream("cftData.txt","r"); cftPtr = cftNew(cft,&tableSize); TEST_ASSERT_EQUAL(3,tableSize); }Catch(error){ TEST_ASSERT_NOT_EQUAL(ERR_FILE_NOT_EXIST,error); } Try{ /* Please check encodeACBA.txt contain the encode data * tag.txt/.bin will store the tag generate from encode data * acba will encode into 1100 0101 0110 1101 0101 1100 1111 1001 1100 000 * * Unfortunately, editor cannot show the actual result as it show chinese character * To see the final result, using a hex editor to open the tag file and compare with * print statement at streamFlush. */ in = openStream("encodeACBA.txt","r"); out = openStream("tag.bin","w"); arithmeticEncode(in, &dataLength, cftPtr,tableSize,out); }Catch(error){ TEST_ASSERT_NOT_EQUAL(ERR_FILE_NOT_EXIST,error); } TEST_ASSERT_EQUAL(4,dataLength); if(in != NULL){ closeStream(in); }if(out != NULL){ closeStream(out); }if(cft != NULL){ closeStream(cft); } }
void testNotNotEqual(void) { int failed; EXPECT_ABORT_BEGIN TEST_ASSERT_NOT_EQUAL(10, 10); EXPECT_ABORT_END failed = Unity.CurrentTestFailed; Unity.CurrentTestFailed = 0; TEST_ASSERT_EQUAL_INT(1U, failed); TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures); }
void test_arithmeticDecoder_to_decode_tag_with_cftData_txt_should_generate_acba(){ Stream *cft = NULL, *in = NULL, *out = NULL; CFT *cftPtr; uint32 tag = 0; int tableSize, dataLength = 4; CEXCEPTION_T error; Try{ // Please check cftData.txt, inside has a lengthy string cft = openStream("cftData.txt","r"); cftPtr = cftNew(cft,&tableSize); TEST_ASSERT_EQUAL(3,tableSize); }Catch(error){ TEST_ASSERT_NOT_EQUAL(ERR_FILE_NOT_EXIST,error); } Try{ /* 1100 0101 0110 1101 0101 1100 1111 1001 1100 000 will decode back into acba * tag.txt/.bin will store the tag generate from encode data * acba store into decodeSymbol.txt */ in = openStream("tag.bin","r"); out = openStream("decodedSymbol.txt","w"); tagReader(in,&tag); arithmeticDecode(dataLength, &tag, cftPtr, tableSize, out, in); }Catch(error){ TEST_ASSERT_NOT_EQUAL(ERR_FILE_NOT_EXIST,error); } if(in != NULL){ closeStream(in); }if(out != NULL){ closeStream(out); }if(cft != NULL){ closeStream(cft); } }
static void test_suspend_resume(int target_core) { volatile unsigned counter = 0; TaskHandle_t counter_task; xTaskCreatePinnedToCore(task_count, "Count", 2048, (void *)&counter, UNITY_FREERTOS_PRIORITY + 1, &counter_task, target_core); vTaskDelay(10); /* check some counting has happened */ TEST_ASSERT_NOT_EQUAL(0, counter); // Do the next part a few times, just to be sure multiple suspends & resumes // work as expected... const int TEST_ITERATIONS = 5; for (int i = 0; i < TEST_ITERATIONS; i++) { vTaskSuspend(counter_task); unsigned suspend_count = counter; printf("Suspending @ %d\n", suspend_count); vTaskDelay(2); printf("Still suspended @ %d\n", counter); /* check the counter hasn't gone up while the task is suspended */ TEST_ASSERT_EQUAL(suspend_count, counter); vTaskResume(counter_task); vTaskDelay(2); printf("Resumed @ %d\n", counter); /* check the counter is going up again now the task is resumed */ TEST_ASSERT_NOT_EQUAL(suspend_count, counter); } vTaskDelete(counter_task); }
void test_idle_force(void) { lagopus_result_t r = LAGOPUS_RESULT_ANY_FAILURES; lagopus_callout_task_t t = NULL; size_t n_exec; size_t i; callout_arg_t arg = NULL; lagopus_callout_task_state_t st; arg = s_alloc_arg(10, 0LL); TEST_ASSERT_NOT_EQUAL(arg, NULL); r = lagopus_callout_create_task(&t, 0, __func__, callout_task, (void *)arg, s_freeup_arg); TEST_ASSERT_EQUAL(r, LAGOPUS_RESULT_OK); r = lagopus_callout_submit_task(&t, -1LL, 500LL * 1000LL * 1000LL); TEST_ASSERT_EQUAL(r, LAGOPUS_RESULT_OK); (void)lagopus_chrono_nanosleep(1000LL * 1000LL * 1000LL, NULL); for (i = 0; i < 5; i++) { lagopus_msg_debug(1, "iter. " PF64(u) "\n", i); r = lagopus_callout_task_state(&t, &st); TEST_ASSERT_EQUAL(r, LAGOPUS_RESULT_OK); if (st == TASK_STATE_ENQUEUED) { r = lagopus_callout_exec_task_forcibly(&t); if (r == LAGOPUS_RESULT_INVALID_STATE) { continue; } TEST_ASSERT_EQUAL(r, LAGOPUS_RESULT_OK); } else if (st == TASK_STATE_UNKNOWN || st == TASK_STATE_CANCELLED) { break; } (void)lagopus_chrono_nanosleep(100LL * 1000LL * 1000LL, NULL); } n_exec = s_wait_freeup_arg(arg); TEST_ASSERT_EQUAL(n_exec, 10); s_destroy_arg(arg); }
TEST(UniqueMap, MapPutUnique) { const int A = 0; const int B = 4; struct UniqueMap* map = create_unique_map(A, B); int values[] = {1,2,3}; int k[3]; k[0] = map_put_unique(map, &values[0]); TEST_ASSERT_TRUE(k[0] > A && k[0] < B); k[1] = map_put_unique(map, &values[1]); TEST_ASSERT_TRUE(k[1] > A && k[1] < B); TEST_ASSERT_NOT_EQUAL(k[0], k[1]); k[2] = map_put_unique(map, &values[2]); TEST_ASSERT_TRUE(k[2] > A && k[2] < B); TEST_ASSERT_NOT_EQUAL(k[0], k[2]); TEST_ASSERT_NOT_EQUAL(k[1], k[2]); TEST_ASSERT_EQUAL_INT(0, map_put_unique(map, &values[2])); destroy_unique_map(map); }
void test_initTask2Tcb_(void){ CpuContext* context; context = getTopAddressOfStack(&task1Tcb.virtualStack[TASK_STACK_SIZE] , sizeof(CpuContext) ); initTask2Tcb(taskTwo); TEST_ASSERT_EQUAL_STRING("task_2",task1Tcb.name); TEST_ASSERT_NULL(task2Tcb.next); TEST_ASSERT_EQUAL_PTR((uint32_t)&task2Tcb.virtualStack[TASK_STACK_SIZE-64],task1Tcb.sp); TEST_ASSERT_EQUAL_PTR(taskTwo,context->PC); TEST_ASSERT_EQUAL(0xaa,(uint32_t)task2Tcb.virtualStack[TASK_STACK_SIZE-4]); TEST_ASSERT_EQUAL(0xaa,(uint32_t)task2Tcb.virtualStack[TASK_STACK_SIZE-3]); TEST_ASSERT_EQUAL(0xaa,(uint32_t)task2Tcb.virtualStack[TASK_STACK_SIZE-2]); TEST_ASSERT_EQUAL(0xaa,(uint32_t)task2Tcb.virtualStack[TASK_STACK_SIZE-1]); TEST_ASSERT_NOT_EQUAL(0xff,(uint32_t)task2Tcb.virtualStack[TASK_STACK_SIZE]); }
/** \brief test function GetRespTimeout ** ** this function test transport get response timeout ** and set response timeout ** **/ void test_ciaaModbus_transportGetRespTimeout_01(void) { int32_t hModbusTransp; uint32_t timeout; hModbusTransp = ciaaModbus_transportOpen( CIAA_MODBUS_TRASNPORT_FIL_DES_MODBUS_ASCII, CIAAMODBUS_TRANSPORT_MODE_ASCII_MASTER); ciaaModbus_transportSetRespTimeout(hModbusTransp, CIAA_MODBUS_TRASNPORT_DEFAULT_TIMEOUT); timeout = ciaaModbus_transportGetRespTimeout(hModbusTransp); TEST_ASSERT_NOT_EQUAL(-1, hModbusTransp); TEST_ASSERT_EQUAL(CIAA_MODBUS_TRASNPORT_DEFAULT_TIMEOUT, timeout); }
void test_tagReader_should_read_in_32bit_of_tag_value(){ Stream *in = NULL; uint32 tag = 0; CEXCEPTION_T error; Try{ in = openStream("tag.bin","r"); tagReader(in,&tag); }Catch(error){ TEST_ASSERT_NOT_EQUAL(ERR_FILE_NOT_EXIST,error); } TEST_ASSERT_EQUAL(0xC56D5CF9,tag); if(in != NULL){ closeStream(in); } }
TEST(InternalMalloc, ReallocFailDoesNotFreeMem) { #ifdef UNITY_EXCLUDE_STDLIB_MALLOC void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2); void* n1 = malloc(10); void* out_of_mem = realloc(n1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); void* n2 = malloc(10); free(n2); if (out_of_mem == NULL) free(n1); free(m); TEST_ASSERT_NOT_NULL(m); /* Got a real memory location */ TEST_ASSERT_NULL(out_of_mem); /* The realloc should have failed */ TEST_ASSERT_NOT_EQUAL(n2, n1); /* If n1 != n2 then realloc did not free n1 */ TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n2); #endif }
/** \brief test function Open ** ** this function test modbus master open ** **/ void test_ciaaModbus_masterOpen_01(void) { uint32_t loopi; int32_t hModbusMaster[CIAA_MODBUS_TOTAL_MASTERS+1]; for (loopi = 0 ; loopi < (CIAA_MODBUS_TOTAL_MASTERS+1) ; loopi++) { /* open modbus master */ hModbusMaster[loopi] = ciaaModbus_masterOpen(); } for (loopi = 0 ; loopi < CIAA_MODBUS_TOTAL_MASTERS ; loopi++) { /* verify */ TEST_ASSERT_NOT_EQUAL(hModbusMaster[loopi],-1); } TEST_ASSERT_EQUAL(hModbusMaster[loopi],-1); }