diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-05-21 15:31:13 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-05-21 15:32:37 +1000 |
commit | e51f45d7c17013fd6c75e5df9c1611e135c211b9 (patch) | |
tree | 12feee74705c8ed0ddb0e4b887e75bbf3b8f8eb3 /core/test | |
parent | 806dbb9bd35d01e0a2e94d46e152723a1f6b1a7d (diff) | |
parent | 417333aa73103b3cc05b27df5e4b328fe71dab5f (diff) | |
download | blackbird-skiboot-e51f45d7c17013fd6c75e5df9c1611e135c211b9.tar.gz blackbird-skiboot-e51f45d7c17013fd6c75e5df9c1611e135c211b9.zip |
Merge PRD rework from stable
Diffstat (limited to 'core/test')
-rw-r--r-- | core/test/Makefile.check | 4 | ||||
-rw-r--r-- | core/test/run-mem_region_next.c | 117 | ||||
-rw-r--r-- | core/test/run-mem_region_reservations.c | 108 |
3 files changed, 197 insertions, 32 deletions
diff --git a/core/test/Makefile.check b/core/test/Makefile.check index c6cf8357..452dfc13 100644 --- a/core/test/Makefile.check +++ b/core/test/Makefile.check @@ -4,11 +4,11 @@ CORE_TEST := core/test/run-device \ core/test/run-malloc \ core/test/run-malloc-speed \ core/test/run-mem_region_init \ + core/test/run-mem_region_next \ core/test/run-mem_region_release_unused \ core/test/run-mem_region_release_unused_noalloc \ core/test/run-mem_region_reservations \ - core/test/run-trace \ - core/test/run-msg \ + core/test/run-trace core/test/run-msg \ core/test/run-pel \ core/test/run-pool \ core/test/run-timer diff --git a/core/test/run-mem_region_next.c b/core/test/run-mem_region_next.c new file mode 100644 index 00000000..209ce67d --- /dev/null +++ b/core/test/run-mem_region_next.c @@ -0,0 +1,117 @@ +/* Copyright 2013-2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> + +#define BITS_PER_LONG (sizeof(long) * 8) +/* Don't include this, it's PPC-specific */ +#define __CPU_H +static unsigned int cpu_max_pir = 1; +struct cpu_thread { + unsigned int chip_id; +}; + +#include <stdlib.h> +#include <string.h> + +/* Use these before we override definitions below. */ +static void *real_malloc(size_t size) +{ + return malloc(size); +} + +static void real_free(void *p) +{ + return free(p); +} + +#undef malloc +#undef free + +#include <skiboot.h> + +#define is_rodata(p) true + +#include "../mem_region.c" +#include "../malloc.c" +#include "../device.c" + +#include <assert.h> +#include <stdio.h> + +void lock(struct lock *l) +{ + assert(!l->lock_val); + l->lock_val++; +} + +void unlock(struct lock *l) +{ + assert(l->lock_val); + l->lock_val--; +} + +bool lock_held_by_me(struct lock *l) +{ + return l->lock_val; +} + + +#define TEST_HEAP_ORDER 12 +#define TEST_HEAP_SIZE (1ULL << TEST_HEAP_ORDER) + +int main(void) +{ + struct mem_region *r; + char *test_heap; + + /* Use malloc for the heap, so valgrind can find issues. */ + test_heap = real_malloc(TEST_HEAP_SIZE); + skiboot_heap.start = (unsigned long)test_heap; + skiboot_heap.len = TEST_HEAP_SIZE; + + lock(&mem_region_lock); + + /* empty regions */ + r = mem_region_next(NULL); + assert(!r); + + r = new_region("test.1", 0x1000, 0x1000, NULL, REGION_RESERVED); + assert(add_region(r)); + r = new_region("test.2", 0x2000, 0x1000, NULL, REGION_RESERVED); + assert(add_region(r)); + mem_regions_finalised = true; + + r = mem_region_next(NULL); + assert(r); + assert(r->start = 0x1000); + assert(r->len = 0x1000); + assert(r->type = REGION_RESERVED); + + r = mem_region_next(r); + assert(r); + assert(r->start = 0x2000); + assert(r->len = 0x1000); + assert(r->type = REGION_RESERVED); + + r = mem_region_next(r); + assert(!r); + + unlock(&mem_region_lock); + real_free(test_heap); + + return 0; +} diff --git a/core/test/run-mem_region_reservations.c b/core/test/run-mem_region_reservations.c index 3288432d..fcde1107 100644 --- a/core/test/run-mem_region_reservations.c +++ b/core/test/run-mem_region_reservations.c @@ -112,13 +112,83 @@ static struct { { "test.3", 0x4000, false }, }; -int main(void) +static void check_property_reservations(void) { const struct dt_property *names, *ranges; - struct mem_region *r; - unsigned int i, l, c; - uint64_t *rangep; + unsigned int i, l; const char *name; + uint64_t *rangep; + + /* check dt properties */ + names = dt_find_property(dt_root, "reserved-names"); + ranges = dt_find_property(dt_root, "reserved-ranges"); + + assert(names && ranges); + + /* walk through names & ranges properies, ensuring that the test + * regions are all present */ + for (name = names->prop, rangep = (uint64_t *)ranges->prop; + name < names->prop + names->len; + name += l, rangep += 2) { + uint64_t addr; + + addr = dt_get_number(rangep, 2); + l = strlen(name) + 1; + + for (i = 0; i < ARRAY_SIZE(test_regions); i++) { + if (strcmp(test_regions[i].name, name)) + continue; + assert(test_regions[i].addr == addr); + assert(!test_regions[i].found); + test_regions[i].found = true; + } + } + + for (i = 0; i < ARRAY_SIZE(test_regions); i++) { + assert(test_regions[i].found); + test_regions[i].found = false; + } +} + +static void check_node_reservations(void) +{ + struct dt_node *parent, *node; + unsigned int i; + + parent = dt_find_by_name(dt_root, "reserved-memory"); + assert(parent); + + assert(dt_prop_get_cell(parent, "#address-cells", 0) == 2); + assert(dt_prop_get_cell(parent, "#size-cells", 0) == 2); + dt_require_property(parent, "ranges", 0); + + dt_for_each_child(parent, node) { + uint64_t addr, size; + + addr = dt_get_address(node, 0, &size); + + for (i = 0; i < ARRAY_SIZE(test_regions); i++) { + if (strncmp(test_regions[i].name, node->name, + strlen(test_regions[i].name))) + continue; + + assert(!test_regions[i].found); + assert(test_regions[i].addr == addr); + assert(size = 0x1000); + test_regions[i].found = true; + } + } + + for (i = 0; i < ARRAY_SIZE(test_regions); i++) { + assert(test_regions[i].found); + test_regions[i].found = false; + } +} + +int main(void) +{ + struct mem_region *r; + unsigned int i; void *buf; /* Use malloc for the heap, so valgrind can find issues. */ @@ -150,33 +220,11 @@ int main(void) r = new_region("test.4", 0x5000, 0x1000, NULL, REGION_RESERVED); assert(!add_region(r)); - /* check dt properties */ - names = dt_find_property(dt_root, "reserved-names"); - ranges = dt_find_property(dt_root, "reserved-ranges"); - - assert(names && ranges); - - /* walk through names & ranges properies, ensuring that the test - * regions are all present */ - for (name = names->prop, rangep = (uint64_t *)ranges->prop, c = 0; - name < names->prop + names->len; - name += l, rangep += 2) { - uint64_t addr; - - addr = dt_get_number(rangep, 2); - l = strlen(name) + 1; - - for (i = 0; i < ARRAY_SIZE(test_regions); i++) { - if (strcmp(test_regions[i].name, name)) - continue; - assert(test_regions[i].addr == addr); - assert(!test_regions[i].found); - test_regions[i].found = true; - c++; - } - } + /* check old property-style reservations */ + check_property_reservations(); - assert(c == ARRAY_SIZE(test_regions)); + /* and new node-style reservations */ + check_node_reservations(); dt_free(dt_root); real_free(buf); |