diff options
| author | Amitay Isaacs <amitay@ozlabs.org> | 2018-08-21 17:54:41 +1000 |
|---|---|---|
| committer | Alistair Popple <alistair@popple.id.au> | 2018-09-07 13:42:52 +1000 |
| commit | 44337292dd54cf5d234d37a1e74a4ef52a1bf6df (patch) | |
| tree | 12ffd3b204175bd02bdf2163e0cf2786899db3c0 | |
| parent | d4d9a621af9d54d71f8b212bec50109cd161992b (diff) | |
| download | pdbg-44337292dd54cf5d234d37a1e74a4ef52a1bf6df.tar.gz pdbg-44337292dd54cf5d234d37a1e74a4ef52a1bf6df.zip | |
tests: Add tests for libpdbg probe functions
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
| -rw-r--r-- | Makefile.am | 22 | ||||
| -rw-r--r-- | src/tests/libpdbg_probe_test.c | 253 |
2 files changed, 274 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 1e9b08a..3dc7c3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,10 @@ AM_MAKEFLAGS = --no-print-directory GIT_SHA1 ?= `git --work-tree=$(top_srcdir) --git-dir=$(top_srcdir)/.git describe --always --long --dirty 2>/dev/null || echo unknown` -libpdbg_tests = libpdbg_target_test +libpdbg_tests = libpdbg_target_test \ + libpdbg_probe_test1 \ + libpdbg_probe_test2 \ + libpdbg_probe_test3 bin_PROGRAMS = pdbg check_PROGRAMS = $(libpdbg_tests) optcmd_test @@ -159,6 +162,23 @@ libpdbg_target_test_LDADD = fake.dtb.o $(libpdbg_test_ldadd) src/tests/libpdbg_target_test.c: fake.dt.h +libpdbg_probe_test1_SOURCES = src/tests/libpdbg_probe_test.c +libpdbg_probe_test1_CFLAGS = $(libpdbg_test_cflags) -DTEST_ID=1 +libpdbg_probe_test1_LDFLAGS = $(libpdbg_test_ldflags) +libpdbg_probe_test1_LDADD = fake.dtb.o $(libpdbg_test_ldadd) + +libpdbg_probe_test2_SOURCES = src/tests/libpdbg_probe_test.c +libpdbg_probe_test2_CFLAGS = $(libpdbg_test_cflags) -DTEST_ID=2 +libpdbg_probe_test2_LDFLAGS = $(libpdbg_test_ldflags) +libpdbg_probe_test2_LDADD = fake.dtb.o $(libpdbg_test_ldadd) + +libpdbg_probe_test3_SOURCES = src/tests/libpdbg_probe_test.c +libpdbg_probe_test3_CFLAGS = $(libpdbg_test_cflags) -DTEST_ID=3 +libpdbg_probe_test3_LDFLAGS = $(libpdbg_test_ldflags) +libpdbg_probe_test3_LDADD = fake.dtb.o $(libpdbg_test_ldadd) + +src/tests/libpdbg_probe_test.c: fake.dt.h + M4_V = $(M4_V_$(V)) M4_V_ = $(M4_V_$(AM_DEFAULT_VERBOSITY)) M4_V_0 = @echo " M4 " $@; diff --git a/src/tests/libpdbg_probe_test.c b/src/tests/libpdbg_probe_test.c new file mode 100644 index 0000000..8d7070b --- /dev/null +++ b/src/tests/libpdbg_probe_test.c @@ -0,0 +1,253 @@ +/* Copyright 2018 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 <stdio.h> +#include <inttypes.h> +#include <assert.h> + +#include <libpdbg.h> + +#include "fake.dt.h" + +static void for_each_target(struct pdbg_target *parent, + void (*callback)(struct pdbg_target *target, + enum pdbg_target_status status), + enum pdbg_target_status status) +{ + struct pdbg_target *child; + + assert(parent); + + callback(parent, status); + + pdbg_for_each_child_target(parent, child) { + for_each_target(child, callback, status); + } +} + +static void for_target_to_root(struct pdbg_target *target, + void (*callback)(struct pdbg_target *target, + enum pdbg_target_status status), + enum pdbg_target_status status) +{ + assert(target); + + do { + callback(target, status); + target = pdbg_target_parent(NULL, target); + } while (target != NULL); +} + +static void check_status(struct pdbg_target *target, + enum pdbg_target_status status) +{ + struct pdbg_target *root; + + root = pdbg_target_root(); + if (target == root) { + if (pdbg_target_status(target) != status) { + printf("root node: status=%u, expected=%u\n", + pdbg_target_status(target), status); + assert(pdbg_target_status(target) == status); + } + return; + } + + assert(pdbg_target_status(target) == status); +} + +static void test1(void) +{ + struct pdbg_target *root, *target; + + pdbg_targets_init(&_binary_fake_dtb_o_start); + + root = pdbg_target_root(); + assert(root); + + for_each_target(root, check_status, PDBG_TARGET_UNKNOWN); + + pdbg_target_probe_all(root); + for_each_target(root, check_status, PDBG_TARGET_ENABLED); + + pdbg_for_each_class_target("core", target) { + pdbg_target_release(target); + } + pdbg_for_each_class_target("fsi", target) { + check_status(target, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("pib", target) { + check_status(target, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("core", target) { + for_each_target(target, check_status, PDBG_TARGET_RELEASED); + } + + pdbg_for_each_class_target("pib", target) { + pdbg_target_release(target); + } + pdbg_for_each_class_target("fsi", target) { + check_status(target, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("pib", target) { + for_each_target(target, check_status, PDBG_TARGET_RELEASED); + } + + pdbg_for_each_class_target("fsi", target) { + pdbg_target_release(target); + } + pdbg_for_each_class_target("fsi", target) { + for_each_target(target, check_status, PDBG_TARGET_RELEASED); + } + check_status(root, PDBG_TARGET_ENABLED); +} + +static void test2(void) +{ + struct pdbg_target *root, *target; + enum pdbg_target_status status; + + pdbg_targets_init(&_binary_fake_dtb_o_start); + + root = pdbg_target_root(); + assert(root); + + for_each_target(root, check_status, PDBG_TARGET_UNKNOWN); + + pdbg_for_each_class_target("pib", target) { + status = pdbg_target_probe(target); + assert(status == PDBG_TARGET_ENABLED); + + for_target_to_root(target, check_status, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("core", target) { + for_each_target(target, check_status, PDBG_TARGET_UNKNOWN); + } + + pdbg_for_each_class_target("core", target) { + status = pdbg_target_probe(target); + assert(status == PDBG_TARGET_ENABLED); + + for_target_to_root(target, check_status, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("thread", target) { + for_each_target(target, check_status, PDBG_TARGET_UNKNOWN); + } + + pdbg_for_each_class_target("core", target) { + pdbg_target_probe_all(target); + } + pdbg_for_each_class_target("thread", target) { + for_each_target(target, check_status, PDBG_TARGET_ENABLED); + } + + pdbg_for_each_class_target("core", target) { + pdbg_target_release(target); + } + pdbg_for_each_class_target("fsi", target) { + check_status(target, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("pib", target) { + check_status(target, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("core", target) { + check_status(target, PDBG_TARGET_RELEASED); + } + pdbg_for_each_class_target("thread", target) { + check_status(target, PDBG_TARGET_RELEASED); + } + + pdbg_for_each_class_target("fsi", target) { + pdbg_target_release(target); + } + pdbg_for_each_class_target("fsi", target) { + for_each_target(target, check_status, PDBG_TARGET_RELEASED); + } +} + +static void test3(void) +{ + struct pdbg_target *root, *target; + enum pdbg_target_status status; + + pdbg_targets_init(&_binary_fake_dtb_o_start); + + root = pdbg_target_root(); + assert(root); + + for_each_target(root, check_status, PDBG_TARGET_UNKNOWN); + + pdbg_for_each_class_target("core", target) { + pdbg_target_status_set(target, PDBG_TARGET_DISABLED); + } + pdbg_for_each_class_target("thread", target) { + check_status(target, PDBG_TARGET_UNKNOWN); + } + + pdbg_for_each_class_target("thread", target) { + status = pdbg_target_probe(target); + assert(status == PDBG_TARGET_UNKNOWN); + check_status(target, PDBG_TARGET_UNKNOWN); + } + + pdbg_target_probe_all(root); + + pdbg_for_each_class_target("core", target) { + check_status(target, PDBG_TARGET_DISABLED); + } + pdbg_for_each_class_target("thread", target) { + check_status(target, PDBG_TARGET_UNKNOWN); + } + + pdbg_for_each_class_target("pib", target) { + pdbg_target_release(target); + } + pdbg_for_each_class_target("fsi", target) { + for_target_to_root(target, check_status, PDBG_TARGET_ENABLED); + } + pdbg_for_each_class_target("pib", target) { + check_status(target, PDBG_TARGET_RELEASED); + } + + pdbg_target_release(root); + pdbg_for_each_class_target("pib", target) { + for_target_to_root(target, check_status, PDBG_TARGET_RELEASED); + } + pdbg_for_each_class_target("core", target) { + check_status(target, PDBG_TARGET_DISABLED); + } + pdbg_for_each_class_target("thread", target) { + check_status(target, PDBG_TARGET_UNKNOWN); + } +} + +int main(void) +{ + int test_id = TEST_ID; + + if (test_id == 1) { + test1(); + } else if (test_id == 2) { + test2(); + } else if (test_id == 3) { + test3(); + } else { + printf("No test for TEST_ID=%d\n", test_id); + return 1; + } + + return 0; +} |

