mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-29 16:10:24 +09:00
test: Add a macro to check that a value is not an error pointer
Some functions can return ERR_PTR(errval). Add a unit test macro to check that no error is returned in a pointer. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
0503e8207c
commit
85aeda4a62
@ -9,6 +9,8 @@
|
|||||||
#ifndef __TEST_UT_H
|
#ifndef __TEST_UT_H
|
||||||
#define __TEST_UT_H
|
#define __TEST_UT_H
|
||||||
|
|
||||||
|
#include <linux/err.h>
|
||||||
|
|
||||||
struct unit_test_state;
|
struct unit_test_state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,6 +103,19 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assert that a pointer is not an error pointer */
|
||||||
|
#define ut_assertok_ptr(expr) { \
|
||||||
|
const void *val = (expr); \
|
||||||
|
\
|
||||||
|
if (IS_ERR(val)) { \
|
||||||
|
ut_failf(uts, __FILE__, __LINE__, __func__, \
|
||||||
|
#expr " = NULL", \
|
||||||
|
"Expected pointer, got error %ld", \
|
||||||
|
PTR_ERR(val)); \
|
||||||
|
return CMD_RET_FAILURE; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
/* Assert that an operation succeeds (returns 0) */
|
/* Assert that an operation succeeds (returns 0) */
|
||||||
#define ut_assertok(cond) ut_asserteq(0, cond)
|
#define ut_assertok(cond) ut_asserteq(0, cond)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user