tests/ztest/mock: remove usage of legacy k_fifo_get()
Legacy FIFO operations were failing and thus the TC was failing to run. Stop using k_fifo_get() for allocation and use a bitmap allocator. A couple of the bitmap operations should be moved to a common header once ZEP-1347 is completed. Passes on all arches and boards, whitelist removed; ARM excluded though due to missing bitfield implementation as per ZEP-82. Note there is a false checkpatch positive in the decl of sys_bitfield_find_first_clear(). Change-Id: I1d3ce8e988bf799573041026e419e3946d153590 Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
This commit is contained in:
parent
b53e6d7774
commit
462c6efca4
2 changed files with 58 additions and 20 deletions
|
@ -55,37 +55,75 @@ void _init_mock(void)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static struct parameter params[CONFIG_ZTEST_PARAMETER_COUNT];
|
/*
|
||||||
static struct k_fifo *fifo;
|
* FIXME: move to sys_io.h once the argument signature for bitmap has
|
||||||
|
* been fixed to void* or similar ZEP-1347
|
||||||
|
*/
|
||||||
|
#define BITS_PER_UL (8 * sizeof(unsigned long int))
|
||||||
|
#define DEFINE_BITFIELD(name, bits) \
|
||||||
|
unsigned long int (name)[((bits) + BITS_PER_UL - 1) / BITS_PER_UL]
|
||||||
|
|
||||||
static void free_parameter(struct parameter *param)
|
static inline
|
||||||
|
int sys_bitfield_find_first_clear(const unsigned long *bitmap,
|
||||||
|
unsigned int bits)
|
||||||
{
|
{
|
||||||
if (param) {
|
unsigned int words = (bits + BITS_PER_UL - 1) / BITS_PER_UL;
|
||||||
k_fifo_put(fifo, param);
|
unsigned int cnt;
|
||||||
|
unsigned int long neg_bitmap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* By bitwise negating the bitmap, we are actually implemeting
|
||||||
|
* ffc (find first clear) using ffs (find first set).
|
||||||
|
*/
|
||||||
|
for (cnt = 0; cnt < words; cnt++) {
|
||||||
|
neg_bitmap = ~bitmap[cnt];
|
||||||
|
if (neg_bitmap == 0) /* all full */
|
||||||
|
continue;
|
||||||
|
else if (neg_bitmap == ~0UL) /* first bit */
|
||||||
|
return cnt * BITS_PER_UL;
|
||||||
|
else
|
||||||
|
return cnt * BITS_PER_UL + __builtin_ffsl(neg_bitmap);
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
static struct parameter *alloc_parameter(void)
|
|
||||||
|
static DEFINE_BITFIELD(params_allocation, CONFIG_ZTEST_PARAMETER_COUNT);
|
||||||
|
static struct parameter params[CONFIG_ZTEST_PARAMETER_COUNT];
|
||||||
|
|
||||||
|
static
|
||||||
|
void free_parameter(struct parameter *param)
|
||||||
{
|
{
|
||||||
|
unsigned int allocation_index = param - params;
|
||||||
|
|
||||||
|
if (param == NULL)
|
||||||
|
return;
|
||||||
|
__ASSERT(allocation_index < CONFIG_ZTEST_PARAMETER_COUNT,
|
||||||
|
"param %p given to free is not in the static buffer %p:%u",
|
||||||
|
param, params, CONFIG_ZTEST_PARAMETER_COUNT);
|
||||||
|
sys_bitfield_clear_bit((mem_addr_t) params_allocation,
|
||||||
|
allocation_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
struct parameter *alloc_parameter(void)
|
||||||
|
{
|
||||||
|
int allocation_index;
|
||||||
struct parameter *param;
|
struct parameter *param;
|
||||||
|
|
||||||
param = k_fifo_get(fifo, K_NO_WAIT);
|
allocation_index = sys_bitfield_find_first_clear(
|
||||||
if (!param) {
|
params_allocation, CONFIG_ZTEST_PARAMETER_COUNT);
|
||||||
PRINT("Failed to allocate mock parameter\n");
|
if (allocation_index == -1) {
|
||||||
|
printk("No more mock parameters available for allocation\n");
|
||||||
ztest_test_fail();
|
ztest_test_fail();
|
||||||
}
|
}
|
||||||
|
sys_bitfield_set_bit((mem_addr_t) params_allocation, allocation_index);
|
||||||
|
param = params + allocation_index;
|
||||||
|
memset(param, 0, sizeof(*param));
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _init_mock(void)
|
void _init_mock(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
k_fifo_init(fifo);
|
|
||||||
for (i = 0; i < CONFIG_ZTEST_PARAMETER_COUNT; i++) {
|
|
||||||
|
|
||||||
k_fifo_put(fifo, ¶ms[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -157,8 +195,7 @@ void _ztest_check_expected_value(const char *fn, const char *name,
|
||||||
* provide inttypes.h
|
* provide inttypes.h
|
||||||
*/
|
*/
|
||||||
PRINT("%s received wrong value: Got %lu, expected %lu\n",
|
PRINT("%s received wrong value: Got %lu, expected %lu\n",
|
||||||
fn, (unsigned long)val,
|
fn, (unsigned long)val, (unsigned long)expected);
|
||||||
(unsigned long)expected);
|
|
||||||
ztest_test_fail();
|
ztest_test_fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[test]
|
[test]
|
||||||
tags = test_framework
|
tags = test_framework
|
||||||
arch_whitelist = x86 arc
|
# sys_bitfield_*() still not implemented for ARM, ZEP-82
|
||||||
|
arch_exclude = arm
|
||||||
|
|
||||||
[test_unit]
|
[test_unit]
|
||||||
type = unit
|
type = unit
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue