mirror of
https://github.com/smaeul/u-boot.git
synced 2025-10-14 12:56:00 +01:00
test: Move stats into a struct
Use a struct to hold the stats, since we also want to have the same stats for all runs as we have for each suite. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
bbff0b165c
commit
0925659a52
@ -9,11 +9,21 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <linux/bitops.h>
|
#include <linux/bitops.h>
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* struct unit_test_state - Entire state of test system
|
* struct ut_stats - Statistics about tests run
|
||||||
*
|
*
|
||||||
* @fail_count: Number of tests that failed
|
* @fail_count: Number of tests that failed
|
||||||
* @skip_count: Number of tests that were skipped
|
* @skip_count: Number of tests that were skipped
|
||||||
|
*/
|
||||||
|
struct ut_stats {
|
||||||
|
int fail_count;
|
||||||
|
int skip_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct unit_test_state - Entire state of test system
|
||||||
|
*
|
||||||
|
* @cur: Statistics for the current run
|
||||||
* @start: Store the starting mallinfo when doing leak test
|
* @start: Store the starting mallinfo when doing leak test
|
||||||
* @of_live: true to use livetree if available, false to use flattree
|
* @of_live: true to use livetree if available, false to use flattree
|
||||||
* @of_root: Record of the livetree root node (used for setting up tests)
|
* @of_root: Record of the livetree root node (used for setting up tests)
|
||||||
@ -34,8 +44,7 @@
|
|||||||
* @actual_str: Temporary string used to hold actual string value
|
* @actual_str: Temporary string used to hold actual string value
|
||||||
*/
|
*/
|
||||||
struct unit_test_state {
|
struct unit_test_state {
|
||||||
int fail_count;
|
struct ut_stats cur;
|
||||||
int skip_count;
|
|
||||||
struct mallinfo start;
|
struct mallinfo start;
|
||||||
struct device_node *of_root;
|
struct device_node *of_root;
|
||||||
bool of_live;
|
bool of_live;
|
||||||
|
@ -448,7 +448,7 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
|
|||||||
*/
|
*/
|
||||||
static int skip_test(struct unit_test_state *uts)
|
static int skip_test(struct unit_test_state *uts)
|
||||||
{
|
{
|
||||||
uts->skip_count++;
|
uts->cur.skip_count++;
|
||||||
|
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
@ -460,7 +460,7 @@ static int skip_test(struct unit_test_state *uts)
|
|||||||
* the name of each test before running it.
|
* the name of each test before running it.
|
||||||
*
|
*
|
||||||
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
||||||
* the first call to this function. On exit, @uts->fail_count is
|
* the first call to this function. On exit, @uts->cur.fail_count is
|
||||||
* incremented by the number of failures (0, one hopes)
|
* incremented by the number of failures (0, one hopes)
|
||||||
* @test_name: Test to run
|
* @test_name: Test to run
|
||||||
* @name: Name of test, possibly skipping a prefix that should not be displayed
|
* @name: Name of test, possibly skipping a prefix that should not be displayed
|
||||||
@ -510,7 +510,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
|
|||||||
* SPL.
|
* SPL.
|
||||||
*
|
*
|
||||||
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
||||||
* the first call to this function. On exit, @uts->fail_count is
|
* the first call to this function. On exit, @uts->cur.fail_count is
|
||||||
* incremented by the number of failures (0, one hopes)
|
* incremented by the number of failures (0, one hopes)
|
||||||
* @test: Test to run
|
* @test: Test to run
|
||||||
* Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
|
* Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
|
||||||
@ -574,7 +574,7 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
|
|||||||
* the name of each test before running it.
|
* the name of each test before running it.
|
||||||
*
|
*
|
||||||
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
* @uts: Test state to update. The caller should ensure that this is zeroed for
|
||||||
* the first call to this function. On exit, @uts->fail_count is
|
* the first call to this function. On exit, @uts->cur.fail_count is
|
||||||
* incremented by the number of failures (0, one hopes)
|
* incremented by the number of failures (0, one hopes)
|
||||||
* @prefix: String prefix for the tests. Any tests that have this prefix will be
|
* @prefix: String prefix for the tests. Any tests that have this prefix will be
|
||||||
* printed without the prefix, so that it is easier to see the unique part
|
* printed without the prefix, so that it is easier to see the unique part
|
||||||
@ -632,7 +632,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
|||||||
if (len < 6 || strcmp(test_name + len - 6, "_norun")) {
|
if (len < 6 || strcmp(test_name + len - 6, "_norun")) {
|
||||||
printf("Test '%s' is manual so must have a name ending in _norun\n",
|
printf("Test '%s' is manual so must have a name ending in _norun\n",
|
||||||
test_name);
|
test_name);
|
||||||
uts->fail_count++;
|
uts->cur.fail_count++;
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
if (!uts->force_run) {
|
if (!uts->force_run) {
|
||||||
@ -641,23 +641,24 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
old_fail_count = uts->fail_count;
|
old_fail_count = uts->cur.fail_count;
|
||||||
|
|
||||||
if (one && upto == pos) {
|
if (one && upto == pos) {
|
||||||
ret = ut_run_test_live_flat(uts, one);
|
ret = ut_run_test_live_flat(uts, one);
|
||||||
if (uts->fail_count != old_fail_count) {
|
if (uts->cur.fail_count != old_fail_count) {
|
||||||
printf("Test '%s' failed %d times (position %d)\n",
|
printf("Test '%s' failed %d times (position %d)\n",
|
||||||
one->name,
|
one->name,
|
||||||
uts->fail_count - old_fail_count, pos);
|
uts->cur.fail_count - old_fail_count,
|
||||||
|
pos);
|
||||||
}
|
}
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < uts->runs_per_test; i++)
|
for (i = 0; i < uts->runs_per_test; i++)
|
||||||
ret = ut_run_test_live_flat(uts, test);
|
ret = ut_run_test_live_flat(uts, test);
|
||||||
if (uts->fail_count != old_fail_count) {
|
if (uts->cur.fail_count != old_fail_count) {
|
||||||
printf("Test '%s' failed %d times\n", test_name,
|
printf("Test '%s' failed %d times\n", test_name,
|
||||||
uts->fail_count - old_fail_count);
|
uts->cur.fail_count - old_fail_count);
|
||||||
}
|
}
|
||||||
found++;
|
found++;
|
||||||
if (ret == -EAGAIN)
|
if (ret == -EAGAIN)
|
||||||
@ -668,7 +669,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
|
|||||||
if (select_name && !found)
|
if (select_name && !found)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
return uts->fail_count ? -EBADF : 0;
|
return uts->cur.fail_count ? -EBADF : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ut_run_list(struct unit_test_state *uts, const char *category,
|
int ut_run_list(struct unit_test_state *uts, const char *category,
|
||||||
@ -716,12 +717,12 @@ int ut_run_list(struct unit_test_state *uts, const char *category,
|
|||||||
if (has_dm_tests)
|
if (has_dm_tests)
|
||||||
dm_test_restore(uts->of_root);
|
dm_test_restore(uts->of_root);
|
||||||
|
|
||||||
if (uts->skip_count)
|
if (uts->cur.skip_count)
|
||||||
printf("Skipped: %d, ", uts->skip_count);
|
printf("Skipped: %d, ", uts->cur.skip_count);
|
||||||
if (ret == -ENOENT)
|
if (ret == -ENOENT)
|
||||||
printf("Test '%s' not found\n", select_name);
|
printf("Test '%s' not found\n", select_name);
|
||||||
else
|
else
|
||||||
printf("Failures: %d\n", uts->fail_count);
|
printf("Failures: %d\n", uts->cur.fail_count);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ void ut_fail(struct unit_test_state *uts, const char *fname, int line,
|
|||||||
{
|
{
|
||||||
gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
|
gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
|
||||||
printf("%s:%d, %s(): %s\n", fname, line, func, cond);
|
printf("%s:%d, %s(): %s\n", fname, line, func, cond);
|
||||||
uts->fail_count++;
|
uts->cur.fail_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ut_failf(struct unit_test_state *uts, const char *fname, int line,
|
void ut_failf(struct unit_test_state *uts, const char *fname, int line,
|
||||||
@ -35,7 +35,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
|
|||||||
vprintf(fmt, args);
|
vprintf(fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
putc('\n');
|
putc('\n');
|
||||||
uts->fail_count++;
|
uts->cur.fail_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong ut_check_free(void)
|
ulong ut_check_free(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user