mirror of
https://github.com/revyos/th1520-vendor-uboot.git
synced 2026-09-16 12:22:14 +02:00
Linux_SDK_V0.9.5
This commit is contained in:
9
test/env/Kconfig
vendored
Normal file
9
test/env/Kconfig
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
config UT_ENV
|
||||
bool "Enable env unit tests"
|
||||
depends on UNIT_TEST
|
||||
default y
|
||||
help
|
||||
This enables the 'ut env' command which runs a series of unit
|
||||
tests on the env code.
|
||||
If all is well then all tests pass although there will be a few
|
||||
messages printed along the way.
|
||||
7
test/env/Makefile
vendored
Normal file
7
test/env/Makefile
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
# Copyright (c) 2015 National Instruments, Inc
|
||||
|
||||
obj-y += cmd_ut_env.o
|
||||
obj-y += attr.o
|
||||
obj-y += hashtable.o
|
||||
88
test/env/attr.c
vendored
Normal file
88
test/env/attr.c
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* (C) Copyright 2015
|
||||
* Joe Hershberger, National Instruments, joe.hershberger@ni.com
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <env_attr.h>
|
||||
#include <test/env.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
static int env_test_attrs_lookup(struct unit_test_state *uts)
|
||||
{
|
||||
char attrs[32];
|
||||
|
||||
ut_assertok(env_attr_lookup("foo:bar", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(",foo:bar", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(",foo:bar,", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(" foo:bar", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup("foo : bar", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(" foo: bar ", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup("foo:bar ", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs));
|
||||
|
||||
ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs));
|
||||
|
||||
ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs));
|
||||
ut_asserteq_str("baz", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(
|
||||
" foo : bar , foo : bat , foot : baz ", "foo", attrs));
|
||||
ut_asserteq_str("bat", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(
|
||||
" foo : bar , foo : bat , ufoo : baz ", "foo", attrs));
|
||||
ut_asserteq_str("bat", attrs);
|
||||
|
||||
ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs));
|
||||
ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL));
|
||||
|
||||
return 0;
|
||||
}
|
||||
ENV_TEST(env_test_attrs_lookup, 0);
|
||||
|
||||
#ifdef CONFIG_REGEX
|
||||
static int env_test_attrs_lookup_regex(struct unit_test_state *uts)
|
||||
{
|
||||
char attrs[32];
|
||||
|
||||
ut_assertok(env_attr_lookup("foo1?:bar", "foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup("foo1?:bar", "foo1", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(".foo:bar", ".foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup(".foo:bar", "ufoo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_assertok(env_attr_lookup("\\.foo:bar", ".foo", attrs));
|
||||
ut_asserteq_str("bar", attrs);
|
||||
|
||||
ut_asserteq(-ENOENT, env_attr_lookup("\\.foo:bar", "ufoo", attrs));
|
||||
|
||||
return 0;
|
||||
}
|
||||
ENV_TEST(env_test_attrs_lookup_regex, 0);
|
||||
#endif
|
||||
19
test/env/cmd_ut_env.c
vendored
Normal file
19
test/env/cmd_ut_env.c
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* (C) Copyright 2015
|
||||
* Joe Hershberger, National Instruments, joe.hershberger@ni.com
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <test/env.h>
|
||||
#include <test/suites.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
{
|
||||
struct unit_test *tests = ll_entry_start(struct unit_test, env_test);
|
||||
const int n_ents = ll_entry_count(struct unit_test, env_test);
|
||||
|
||||
return cmd_ut_category("environment", tests, n_ents, argc, argv);
|
||||
}
|
||||
125
test/env/hashtable.c
vendored
Normal file
125
test/env/hashtable.c
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* (C) Copyright 2019
|
||||
* Roman Kapl, SYSGO, rka@sysgo.com
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <search.h>
|
||||
#include <stdio.h>
|
||||
#include <test/env.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
#define SIZE 32
|
||||
#define ITERATIONS 10000
|
||||
|
||||
static int htab_fill(struct unit_test_state *uts,
|
||||
struct hsearch_data *htab, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
struct env_entry item;
|
||||
struct env_entry *ritem;
|
||||
char key[20];
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
sprintf(key, "%d", (int)i);
|
||||
item.callback = NULL;
|
||||
item.data = key;
|
||||
item.flags = 0;
|
||||
item.key = key;
|
||||
ut_asserteq(1, hsearch_r(item, ENV_ENTER, &ritem, htab, 0));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int htab_check_fill(struct unit_test_state *uts,
|
||||
struct hsearch_data *htab, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
struct env_entry item;
|
||||
struct env_entry *ritem;
|
||||
char key[20];
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
sprintf(key, "%d", (int)i);
|
||||
item.callback = NULL;
|
||||
item.flags = 0;
|
||||
item.data = key;
|
||||
item.key = key;
|
||||
hsearch_r(item, ENV_FIND, &ritem, htab, 0);
|
||||
ut_assert(ritem);
|
||||
ut_asserteq_str(key, ritem->key);
|
||||
ut_asserteq_str(key, ritem->data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int htab_create_delete(struct unit_test_state *uts,
|
||||
struct hsearch_data *htab, size_t iterations)
|
||||
{
|
||||
size_t i;
|
||||
struct env_entry item;
|
||||
struct env_entry *ritem;
|
||||
char key[20];
|
||||
|
||||
for (i = 0; i < iterations; i++) {
|
||||
sprintf(key, "cd-%d", (int)i);
|
||||
item.callback = NULL;
|
||||
item.flags = 0;
|
||||
item.data = key;
|
||||
item.key = key;
|
||||
hsearch_r(item, ENV_ENTER, &ritem, htab, 0);
|
||||
ritem = NULL;
|
||||
|
||||
hsearch_r(item, ENV_FIND, &ritem, htab, 0);
|
||||
ut_assert(ritem);
|
||||
ut_asserteq_str(key, ritem->key);
|
||||
ut_asserteq_str(key, ritem->data);
|
||||
|
||||
ut_asserteq(1, hdelete_r(key, htab, 0));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Completely fill up the hash table */
|
||||
static int env_test_htab_fill(struct unit_test_state *uts)
|
||||
{
|
||||
struct hsearch_data htab;
|
||||
|
||||
memset(&htab, 0, sizeof(htab));
|
||||
ut_asserteq(1, hcreate_r(SIZE, &htab));
|
||||
|
||||
ut_assertok(htab_fill(uts, &htab, SIZE));
|
||||
ut_assertok(htab_check_fill(uts, &htab, SIZE));
|
||||
ut_asserteq(SIZE, htab.filled);
|
||||
|
||||
hdestroy_r(&htab);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ENV_TEST(env_test_htab_fill, 0);
|
||||
|
||||
/* Fill the hashtable up halfway an repeateadly delete/create elements
|
||||
* and check for corruption
|
||||
*/
|
||||
static int env_test_htab_deletes(struct unit_test_state *uts)
|
||||
{
|
||||
struct hsearch_data htab;
|
||||
|
||||
memset(&htab, 0, sizeof(htab));
|
||||
ut_asserteq(1, hcreate_r(SIZE, &htab));
|
||||
|
||||
ut_assertok(htab_fill(uts, &htab, SIZE / 2));
|
||||
ut_assertok(htab_create_delete(uts, &htab, ITERATIONS));
|
||||
ut_assertok(htab_check_fill(uts, &htab, SIZE / 2));
|
||||
ut_asserteq(SIZE / 2, htab.filled);
|
||||
|
||||
hdestroy_r(&htab);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ENV_TEST(env_test_htab_deletes, 0);
|
||||
Reference in New Issue
Block a user