fix(test): Fixed the error in the testcase operation judgment condition.
This commit is contained in:
@@ -174,7 +174,10 @@ char *mr_strchr(const char *s, int c);
|
||||
* @return The first set bit index.
|
||||
*/
|
||||
MR_INLINE int mr_ffs32(mr_uint32_t x) {
|
||||
extern const int __mr_ffs_debruijn32[32];
|
||||
const int debruijn32[32] = {
|
||||
1, 2, 29, 3, 30, 15, 25, 4, 31, 23, 21, 16, 26, 18, 5, 9,
|
||||
32, 28, 14, 24, 22, 20, 17, 8, 27, 13, 19, 7, 12, 6, 11, 10,
|
||||
};
|
||||
|
||||
/* Check zero */
|
||||
if (x == 0) {
|
||||
@@ -182,7 +185,7 @@ MR_INLINE int mr_ffs32(mr_uint32_t x) {
|
||||
}
|
||||
|
||||
/* DeBruijn ffs32 */
|
||||
return __mr_ffs_debruijn32[((x & (-x)) * 0x077cb531U) >> 27];
|
||||
return debruijn32[((x & (-x)) * 0x077cb531U) >> 27];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +195,12 @@ MR_INLINE int mr_ffs32(mr_uint32_t x) {
|
||||
* @return The first set bit index.
|
||||
*/
|
||||
MR_INLINE int mr_ffs64(mr_uint64_t x) {
|
||||
extern const int __mr_ffs_debruijn64[64];
|
||||
const int debruijn64[64] = {
|
||||
1, 2, 57, 3, 58, 50, 29, 4, 62, 59, 43, 51, 39, 30, 18, 5,
|
||||
63, 48, 60, 37, 46, 44, 52, 23, 54, 40, 34, 31, 25, 19, 13, 6,
|
||||
64, 56, 49, 28, 61, 42, 38, 17, 47, 36, 45, 22, 53, 33, 24, 12,
|
||||
55, 27, 41, 16, 35, 21, 32, 11, 26, 15, 20, 10, 14, 9, 8, 7,
|
||||
};
|
||||
|
||||
/* Check zero */
|
||||
if (x == 0) {
|
||||
@@ -200,7 +208,7 @@ MR_INLINE int mr_ffs64(mr_uint64_t x) {
|
||||
}
|
||||
|
||||
/* DeBruijn ffs64 */
|
||||
return __mr_ffs_debruijn64[((x & (-x)) * 0x03f79d71b4cb0a89ULL) >> 58];
|
||||
return debruijn64[((x & (-x)) * 0x03f79d71b4cb0a89ULL) >> 58];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,10 +80,10 @@ MR_INLINE void mr_ref_init(mr_ref_t *ref) {
|
||||
MR_INLINE mr_bool_t mr_ref_get(mr_ref_t *ref) {
|
||||
mr_atomic_t last;
|
||||
|
||||
do {
|
||||
/* Get current ref */
|
||||
last = mr_atomic_load(ref);
|
||||
/* Get current ref */
|
||||
last = mr_atomic_load(ref);
|
||||
|
||||
do {
|
||||
/* Check if ref is inited or ref count is zero */
|
||||
if ((!MR_REF_IS_INITED(last)) || (MR_REF_COUNT(last) == 0)) {
|
||||
MR_ASSERT(last != MR_REF_OVERFLOW);
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#ifndef __MR_SERVICE_H__
|
||||
#define __MR_SERVICE_H__
|
||||
|
||||
#include <libc/mr_compiler.h>
|
||||
#include <libc/mr_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
@@ -81,6 +84,39 @@ extern "C" {
|
||||
*/
|
||||
#define MR_ALIGN_DOWN(_x, _ali) ((_x) & ~((_ali)-1))
|
||||
|
||||
/**
|
||||
* @brief This function verifies the parity(even).
|
||||
*
|
||||
* @param src The source.
|
||||
* @param size The verify size.
|
||||
* @return MR_TRUE on even, MR_FALSE on odd.
|
||||
*/
|
||||
MR_INLINE mr_bool_t mr_parity_even(const void *src, mr_size_t size) {
|
||||
const mr_uint8_t bits16[16]
|
||||
= {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
|
||||
mr_uint8_t *s, parity;
|
||||
mr_size_t i;
|
||||
|
||||
/* Bitwise parity */
|
||||
for (s = (mr_uint8_t *)src, parity = 0, i = 0; i < size; ++i) {
|
||||
parity += bits16[s[i] & (0x0fU)];
|
||||
parity += bits16[s[i] >> 4];
|
||||
}
|
||||
return (parity & 0x01U) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function verifies the parity(odd).
|
||||
*
|
||||
* @param src The source.
|
||||
* @param size The verify size.
|
||||
* @return MR_TRUE on odd, MR_FALSE on even.
|
||||
*/
|
||||
MR_INLINE mr_bool_t mr_parity_odd(const void *src, mr_size_t size) {
|
||||
/* Even parity negation */
|
||||
return !mr_parity_even(src, size);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -32,7 +32,7 @@ extern "C" {
|
||||
#define MR_TEST_EXPECT_EQ_PTR(_a, _b) \
|
||||
__MR_TEST_EXPECT(__MR_TEST_COND_PTR(_a, EQ, _b))
|
||||
#define MR_TEST_EXPECT_EQ_FLOAT(_a, _b) \
|
||||
__MR_TEST_EXPECT(__MR_TEST_COND_NEAR(_a, _b, 1e-6))
|
||||
__MR_TEST_EXPECT(__MR_TEST_COND_NEAR(_a, _b, 1e-4f))
|
||||
#define MR_TEST_EXPECT_EQ_DOUBLE(_a, _b) \
|
||||
__MR_TEST_EXPECT(__MR_TEST_COND_NEAR(_a, _b, 1e-8))
|
||||
#define MR_TEST_ASSERT_EQ_INT(_a, _b) \
|
||||
@@ -42,7 +42,7 @@ extern "C" {
|
||||
#define MR_TEST_ASSERT_EQ_PTR(_a, _b) \
|
||||
__MR_TEST_ASSERT(__MR_TEST_COND_PTR(_a, EQ, _b))
|
||||
#define MR_TEST_ASSERT_EQ_FLOAT(_a, _b) \
|
||||
__MR_TEST_ASSERT(__MR_TEST_COND_NEAR(_a, _b, 1e-6))
|
||||
__MR_TEST_ASSERT(__MR_TEST_COND_NEAR(_a, _b, 1e-4f))
|
||||
#define MR_TEST_ASSERT_EQ_DOUBLE(_a, _b) \
|
||||
__MR_TEST_ASSERT(__MR_TEST_COND_NEAR(_a, _b, 1e-8))
|
||||
|
||||
|
||||
@@ -11,20 +11,6 @@
|
||||
#include <libc/mr_errno.h>
|
||||
#endif /* defined(MR_USE_STRING) */
|
||||
|
||||
/* DeBruijn ffs32 */
|
||||
const int __mr_ffs_debruijn32[32] = {
|
||||
1, 2, 29, 3, 30, 15, 25, 4, 31, 23, 21, 16, 26, 18, 5, 9,
|
||||
32, 28, 14, 24, 22, 20, 17, 8, 27, 13, 19, 7, 12, 6, 11, 10,
|
||||
};
|
||||
|
||||
/* DeBruijn ffs64 */
|
||||
const int __mr_ffs_debruijn64[64] = {
|
||||
1, 2, 57, 3, 58, 50, 29, 4, 62, 59, 43, 51, 39, 30, 18, 5,
|
||||
63, 48, 60, 37, 46, 44, 52, 23, 54, 40, 34, 31, 25, 19, 13, 6,
|
||||
64, 56, 49, 28, 61, 42, 38, 17, 47, 36, 45, 22, 53, 33, 24, 12,
|
||||
55, 27, 41, 16, 35, 21, 32, 11, 26, 15, 20, 10, 14, 9, 8, 7,
|
||||
};
|
||||
|
||||
#if defined(MR_USE_STRING)
|
||||
void *mr_memccpy(void *dst, const void *src, int c, mr_size_t size) {
|
||||
const char *s;
|
||||
|
||||
@@ -73,4 +73,21 @@ static void test_service_align(void) {
|
||||
MR_TEST_ASSERT_EQ_INT(MR_ALIGN_DOWN(8, 8), 8);
|
||||
}
|
||||
MR_TEST_EXPORT(service, align, test_service_align);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Test: parity_even / parity_odd */
|
||||
static void test_service_parity(void) {
|
||||
mr_uint8_t odd, j;
|
||||
mr_uint16_t i;
|
||||
|
||||
for (i = 0; i < 65535; i++) {
|
||||
for (odd = 0, j = 0; j < 16; j++) {
|
||||
odd ^= ((i >> j) & 0x1U);
|
||||
}
|
||||
|
||||
MR_TEST_ASSERT_EQ_INT(mr_parity_even(&i, sizeof(i)), !odd);
|
||||
MR_TEST_ASSERT_EQ_INT(mr_parity_odd(&i, sizeof(i)), odd);
|
||||
}
|
||||
}
|
||||
MR_TEST_EXPORT(service, parity, test_service_parity);
|
||||
#endif /* defined(MR_USE_TEST) */
|
||||
|
||||
@@ -14,20 +14,20 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Utilities: fill / verify canary pattern */
|
||||
static void canary_fill(void *p, mr_size_t n) {
|
||||
mr_uint8_t *u8;
|
||||
mr_uint8_t *d;
|
||||
mr_size_t i;
|
||||
|
||||
for (u8 = (mr_uint8_t *)p, i = 0; i < n; ++i) {
|
||||
u8[i] = (mr_uint8_t)(i & 0xFFU);
|
||||
for (d = (mr_uint8_t *)p, i = 0; i < n; ++i) {
|
||||
d[i] = (mr_uint8_t)(i & 0xFFU);
|
||||
}
|
||||
}
|
||||
|
||||
static int canary_verify(void *p, mr_size_t n) {
|
||||
mr_uint8_t *u8;
|
||||
mr_uint8_t *d;
|
||||
mr_size_t i;
|
||||
|
||||
for (u8 = (mr_uint8_t *)p, i = 0; i < n; ++i) {
|
||||
if (u8[i] != (mr_uint8_t)(i & 0xFFU)) {
|
||||
for (d = (mr_uint8_t *)p, i = 0; i < n; ++i) {
|
||||
if (d[i] != (mr_uint8_t)(i & 0xFFU)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,8 @@ void mr_testcase_run(const char *suite, const char *name) {
|
||||
/* Each test cases */
|
||||
for (cs = start + 1; cs < end; cs++) {
|
||||
/* Match testcase */
|
||||
if ((!mr_strcmp(cs->suite, suite)) || (!mr_strcmp(cs->name, name))) {
|
||||
if ((mr_strcmp(cs->suite, suite) != 0)
|
||||
|| (mr_strcmp(cs->name, name) != 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user