示例#1
0
文件: map.c 项目: 32bitmicro/zephyr
void HelperTask(void)
{
	void *ptr[NUMBLOCKS];      /* Pointer to memory block */

	/* Wait for part 1 to complete */
	task_sem_take(SEM_REGRESSDONE, TICKS_UNLIMITED);

	/* Part 2 of test */

	TC_PRINT("Starts %s\n", __func__);

	/* Test task_mem_map_alloc */
	tcRC = testMapGetAllBlocks(ptr);
	if (tcRC == TC_FAIL) {
		TC_ERROR("Failed testMapGetAllBlocks function\n");
		goto exitTest1;          /* terminate test */
	}

	task_sem_give(SEM_HELPERDONE);  /* Indicate part 2 is complete */
	/* Wait for part 3 to complete */
	task_sem_take(SEM_REGRESSDONE, TICKS_UNLIMITED);

	/*
	 * Part 4 of test.
	 * Free the first memory block.  RegressionTask is currently blocked
	 * waiting (with a timeout) for a memory block.  Freeing the memory
	 * block will unblock RegressionTask.
	 */

	TC_PRINT("%s: About to free a memory block\n", __func__);
	task_mem_map_free(MAP_LgBlks, &ptr[0]);
	task_sem_give(SEM_HELPERDONE);

	/* Part 5 of test */
	task_sem_take(SEM_REGRESSDONE, TICKS_UNLIMITED);
	TC_PRINT("%s: About to free another memory block\n", __func__);
	task_mem_map_free(MAP_LgBlks, &ptr[1]);

	/*
	 * Free all the other blocks.  The first 2 blocks are freed by this task
	 */
	for (int i = 2; i < NUMBLOCKS; i++) {
		task_mem_map_free(MAP_LgBlks, &ptr[i]);
	}
	TC_PRINT("%s: freed all blocks allocated by this task\n", __func__);

exitTest1:

	TC_END_RESULT(tcRC);
	task_sem_give(SEM_HELPERDONE);
}  /* HelperTask */
示例#2
0
void upm_free(int mem_map, void* ptr){
#if defined(linux)
    free(ptr);
#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB)
    kmemory_map_t map_name = (kmemory_map_t) mem_map;
    task_mem_map_free(map_name, &ptr);
#endif
}
示例#3
0
文件: map.c 项目: 32bitmicro/zephyr
int testMapFreeAllBlocks(void **p)
{
	int retValue;     /* task_mem_map_xxx interface return value */

	TC_PRINT("Function %s\n", __func__);

	/* Number of blocks in the map is defined in MDEF file */
	for (int i = 0; i < NUMBLOCKS; i++) {
		/* Verify number of used blocks in the map */
		retValue = task_mem_map_used_get(MAP_LgBlks);
		if (verifyRetValue(NUMBLOCKS - i, retValue)) {
			TC_PRINT("MAP_LgBlks used %d blocks\n", retValue);
		} else {
			TC_ERROR("Failed task_mem_map_used_get for MAP_LgBlks, expect %d, got %d\n",
				NUMBLOCKS - i, retValue);
			return TC_FAIL;
		}

		TC_PRINT("  block ptr to free p[%d] = %p\n", i, p[i]);
		/* Free memory block */
		task_mem_map_free(MAP_LgBlks, &p[i]);

		TC_PRINT("MAP_LgBlks freed %d block\n", i + 1);

	} /* for */

	/*
	 * Verify number of used blocks in the map
	 *  - should be 0 as no blocks are used
	 */

	retValue = task_mem_map_used_get(MAP_LgBlks);
	if (verifyRetValue(0, retValue)) {
		TC_PRINT("MAP_LgBlks used %d blocks\n", retValue);
	} else {
		TC_ERROR("Failed task_mem_map_used_get for MAP_LgBlks, retValue %d\n",
			retValue);
		return TC_FAIL;
	}

	PRINT_LINE;
	return TC_PASS;
}   /* testMapFreeAllBlocks */
示例#4
0
文件: map.c 项目: 32bitmicro/zephyr
void RegressionTask(void)
{
	int   retValue;            /* task_mem_map_xxx interface return value */
	void *b;                   /* Pointer to memory block */
	void *ptr[NUMBLOCKS];      /* Pointer to memory block */

	/* Part 1 of test */

	TC_START("Test Microkernel Memory Maps");
	TC_PRINT("Starts %s\n", __func__);

	/* Test task_mem_map_alloc */
	tcRC = testMapGetAllBlocks(ptr);
	if (tcRC == TC_FAIL) {
		TC_ERROR("Failed testMapGetAllBlocks function\n");
		goto exitTest;           /* terminate test */
	}

	printPointers(ptr);
	/* Test task_mem_map_free */
	tcRC = testMapFreeAllBlocks(ptr);
	if (tcRC == TC_FAIL) {
		TC_ERROR("Failed testMapFreeAllBlocks function\n");
		goto exitTest;           /* terminate test */
	}

	printPointers(ptr);

	task_sem_give(SEM_REGRESSDONE);   /* Allow HelperTask to run */
	/* Wait for HelperTask to finish */
	task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED);

	/*
	 * Part 3 of test.
	 *
	 * HelperTask got all memory blocks.  There is no free block left.
	 * The call will timeout.  Note that control does not switch back to
	 * HelperTask as it is waiting for SEM_REGRESSDONE.
	 */

	retValue = task_mem_map_alloc(MAP_LgBlks, &b, 2);
	if (verifyRetValue(RC_TIME, retValue)) {
		TC_PRINT("%s: task_mem_map_alloc timeout expected\n", __func__);
	} else {
		TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue);
		tcRC = TC_FAIL;
		goto exitTest;           /* terminate test */
	}

	TC_PRINT("%s: start to wait for block\n", __func__);
	task_sem_give(SEM_REGRESSDONE);    /* Allow HelperTask to run part 4 */
	retValue = task_mem_map_alloc(MAP_LgBlks, &b, 5);
	if (verifyRetValue(RC_OK, retValue)) {
		TC_PRINT("%s: task_mem_map_alloc OK, block allocated at %p\n",
			__func__, b);
	} else {
		TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue);
		tcRC = TC_FAIL;
		goto exitTest;           /* terminate test */
	}

	/* Wait for HelperTask to complete */
	task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED);

	TC_PRINT("%s: start to wait for block\n", __func__);
	task_sem_give(SEM_REGRESSDONE);    /* Allow HelperTask to run part 5 */
	retValue = task_mem_map_alloc(MAP_LgBlks, &b, TICKS_UNLIMITED);
	if (verifyRetValue(RC_OK, retValue)) {
		TC_PRINT("%s: task_mem_map_alloc OK, block allocated at %p\n",
			__func__, b);
	} else {
		TC_ERROR("Failed task_mem_map_alloc, retValue %d\n", retValue);
		tcRC = TC_FAIL;
		goto exitTest;           /* terminate test */
	}

	/* Wait for HelperTask to complete */
	task_sem_take(SEM_HELPERDONE, TICKS_UNLIMITED);


	/* Free memory block */
	TC_PRINT("%s: Used %d block\n", __func__,  task_mem_map_used_get(MAP_LgBlks));
	task_mem_map_free(MAP_LgBlks, &b);
	TC_PRINT("%s: 1 block freed, used %d block\n",
		__func__,  task_mem_map_used_get(MAP_LgBlks));

exitTest:

	TC_END_RESULT(tcRC);
	TC_END_REPORT(tcRC);
}  /* RegressionTask */