forked from Minki/linux
of/selftest: Use selftest() macro throughout
Some of the selftests are open-coded. Others use the selftest() macro defined in drivers/of/selftest.c. The macro makes for cleaner selftest code, so refactor the of_parse_phandle_with_args() tests to use it. Cc: Rob Herring <rob.herring@calxeda.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
This commit is contained in:
parent
f7f951c298
commit
cabb7d5b78
@ -2,7 +2,7 @@
|
|||||||
* Self tests for device tree subsystem
|
* Self tests for device tree subsystem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define pr_fmt(fmt) "### %s(): " fmt, __func__
|
#define pr_fmt(fmt) "### dt-test ### " fmt
|
||||||
|
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
@ -16,19 +16,20 @@
|
|||||||
|
|
||||||
static bool selftest_passed = true;
|
static bool selftest_passed = true;
|
||||||
#define selftest(result, fmt, ...) { \
|
#define selftest(result, fmt, ...) { \
|
||||||
selftest_passed &= (result); \
|
if (!(result)) { \
|
||||||
if (!(result)) \
|
|
||||||
pr_err("FAIL %s:%i " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
pr_err("FAIL %s:%i " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
|
||||||
|
selftest_passed = false; \
|
||||||
|
} else { \
|
||||||
|
pr_info("pass %s:%i\n", __FILE__, __LINE__); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __init of_selftest_parse_phandle_with_args(void)
|
static void __init of_selftest_parse_phandle_with_args(void)
|
||||||
{
|
{
|
||||||
struct device_node *np;
|
struct device_node *np;
|
||||||
struct of_phandle_args args;
|
struct of_phandle_args args;
|
||||||
int rc, i;
|
int i, rc;
|
||||||
bool passed_all = true;
|
|
||||||
|
|
||||||
pr_info("start\n");
|
|
||||||
np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
|
np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
|
||||||
if (!np) {
|
if (!np) {
|
||||||
pr_err("missing testcase data\n");
|
pr_err("missing testcase data\n");
|
||||||
@ -79,45 +80,35 @@ static void __init of_selftest_parse_phandle_with_args(void)
|
|||||||
passed &= (args.args[0] == (i + 1));
|
passed &= (args.args[0] == (i + 1));
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
passed &= (rc == -EINVAL);
|
passed &= (rc == -ENOENT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
passed = false;
|
passed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passed) {
|
selftest(passed, "index %i - data error on node %s rc=%i\n",
|
||||||
int j;
|
i, args.np->full_name, rc);
|
||||||
pr_err("index %i - data error on node %s rc=%i regs=[",
|
|
||||||
i, args.np->full_name, rc);
|
|
||||||
for (j = 0; j < args.args_count; j++)
|
|
||||||
printk(" %i", args.args[j]);
|
|
||||||
printk(" ]\n");
|
|
||||||
|
|
||||||
passed_all = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for missing list property */
|
/* Check for missing list property */
|
||||||
rc = of_parse_phandle_with_args(np, "phandle-list-missing",
|
rc = of_parse_phandle_with_args(np, "phandle-list-missing",
|
||||||
"#phandle-cells", 0, &args);
|
"#phandle-cells", 0, &args);
|
||||||
passed_all &= (rc == -EINVAL);
|
selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
|
||||||
|
|
||||||
/* Check for missing cells property */
|
/* Check for missing cells property */
|
||||||
rc = of_parse_phandle_with_args(np, "phandle-list",
|
rc = of_parse_phandle_with_args(np, "phandle-list",
|
||||||
"#phandle-cells-missing", 0, &args);
|
"#phandle-cells-missing", 0, &args);
|
||||||
passed_all &= (rc == -EINVAL);
|
selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
|
||||||
|
|
||||||
/* Check for bad phandle in list */
|
/* Check for bad phandle in list */
|
||||||
rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
|
rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
|
||||||
"#phandle-cells", 0, &args);
|
"#phandle-cells", 0, &args);
|
||||||
passed_all &= (rc == -EINVAL);
|
selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
|
||||||
|
|
||||||
/* Check for incorrectly formed argument list */
|
/* Check for incorrectly formed argument list */
|
||||||
rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
|
rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
|
||||||
"#phandle-cells", 1, &args);
|
"#phandle-cells", 1, &args);
|
||||||
passed_all &= (rc == -EINVAL);
|
selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
|
||||||
|
|
||||||
pr_info("end - %s\n", passed_all ? "PASS" : "FAIL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __init of_selftest_property_match_string(void)
|
static void __init of_selftest_property_match_string(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user