/* * (C) Copyright David Gibson , IBM Corporation. 2007. * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "dtc.h" #ifdef TRACE_CHECKS #define TRACE(c, ...) \ do { \ fprintf(stderr, "=== %s: ", (c)->name); \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, "\n"); \ } while (0) #else #define TRACE(c, fmt, ...) do { } while (0) #endif enum checkstatus { UNCHECKED = 0, PREREQ, PASSED, FAILED, }; struct check; typedef void (*tree_check_fn)(struct check *c, struct node *dt); typedef void (*node_check_fn)(struct check *c, struct node *dt, struct node *node); typedef void (*prop_check_fn)(struct check *c, struct node *dt, struct node *node, struct property *prop); struct check { const char *name; tree_check_fn tree_fn; node_check_fn node_fn; prop_check_fn prop_fn; void *data; bool warn, error; enum checkstatus status; int inprogress; int num_prereqs; struct check **prereq; }; #define CHECK_ENTRY(nm, tfn, nfn, pfn, d, w, e, ...) \ static struct check *nm##_prereqs[] = { __VA_ARGS__ }; \ static struct check nm = { \ .name = #nm, \ .tree_fn = (tfn), \ .node_fn = (nfn), \ .prop_fn = (pfn), \ .data = (d), \ .warn = (w), \ .error = (e), \ .status = UNCHECKED, \ .num_prereqs = ARRAY_SIZE(nm##_prereqs), \ .prereq = nm##_prereqs, \ }; #define WARNING(nm, tfn, nfn, pfn, d, ...) \ CHECK_ENTRY(nm, tfn, nfn, pfn, d, true, false, __VA_ARGS__) #define ERROR(nm, tfn, nfn, pfn, d, ...) \ CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, true, __VA_ARGS__) #define CHECK(nm, tfn, nfn, pfn, d, ...) \ CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, false, __VA_ARGS__) #define TREE_WARNING(nm, d, ...) \ WARNING(nm, check_##nm, NULL, NULL, d, __VA_ARGS__) #define TREE_ERROR(nm, d, ...) \ ERROR(nm, check_##nm, NULL, NULL, d, __VA_ARGS__) #define TREE_CHECK(nm, d, ...) \ CHECK(nm, check_##nm, NULL, NULL, d, __VA_ARGS__) #define NODE_WARNING(nm, d, ...) \ WARNING(nm, NULL, check_##nm, NULL, d, __VA_ARGS__) #define NODE_ERROR(nm, d, ...) \ ERROR(nm, NULL, check_##nm, NULL, d, __VA_ARGS__) #define NODE_CHECK(nm, d, ...) \ CHECK(nm, NULL, check_##nm, NULL, d, __VA_ARGS__) #define PROP_WARNING(nm, d, ...) \ WARNING(nm, NULL, NULL, check_##nm, d, __VA_ARGS__) #define PROP_ERROR(nm, d, ...) \ ERROR(nm, NULL, NULL, check_##nm, d, __VA_ARGS__) #define PROP_CHECK(nm, d, ...) \ CHECK(nm, NULL, NULL, check_##nm, d, __VA_ARGS__) #ifdef __GNUC__ static inline void check_msg(struct check *c, const char *fmt, ...) __attribute__((format (printf, 2, 3))); #endif static inline void check_msg(struct check *c, const char *fmt, ...) { va_list ap; va_start(ap, fmt); if ((c->warn && (quiet < 1)) || (c->error && (quiet < 2))) { fprintf(stderr, "%s (%s): ", (c->error) ? "ERROR" : "Warning", c->name); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); } } #define FAIL(c, ...) \ do { \ TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \ (c)->status = FAILED; \ check_msg((c), __VA_ARGS__); \ } while (0) static void check_nodes_props(struct check *c, struct node *dt, struct node *node) { struct node *child; struct property *prop; TRACE(c, "%s", node->fullpath); if (c->node_fn) c->node_fn(c, dt, node); if (c->prop_fn) for_each_property(node, prop) { TRACE(c, "%s\t'%s'", node->fullpath, prop->name); c->prop_fn(c, dt, node, prop); } for_each_child(node, child) check_nodes_props(c, dt, child); } static int run_check(struct check *c, struct node *dt) { int error = 0; int i; assert(!c->inprogress); if (c->status != UNCHECKED) goto out; c->inprogress = 1; for (i = 0; i < c->num_prereqs; i++) { struct check *prq = c->prereq[i]; error |= run_check(prq, dt); if (prq->status != PASSED) { c->status = PREREQ; check_msg(c, "Failed prerequisite '%s'", c->prereq[i]->name); } } if (c->status != UNCHECKED) goto out; if (c->node_fn || c->prop_fn) check_nodes_props(c, dt, dt); if (c->tree_fn) c->tree_fn(c, dt); if (c->status == UNCHECKED) c->status = PASSED; TRACE(c, "\tCompleted, status %d", c->status); out: c->inprogress = 0; if ((c->status != PASSED) && (c->error)) error = 1; return error; } /* * Utility check functions */ /* A check which always fails, for testing purposes only */ static inline void check_always_fail(struct check *c, struct node *dt) { FAIL(c, "always_fail check"); } TREE_CHECK(always_fail, NULL); static void check_is_string(struct check *c, struct n
# Copyright 2015 Intel Corporation.
#
# 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.
"""IResult interface definition.
"""

class IResults(object):
    """Abstract class defining an interface for gathering results
    """
    def print_results(self):
        """Prints gathered results to screen.
        """
        raise NotImplementedError("This class does not implement the" \
                                  " \"print_results\" function.")

    def get_results(self):
        """Returns gathered results as a list of dictionaries.

        Each list element represents one record of data.

        :return: Results dictionary
            - key: Column name
            - value: Column value.
        """
        raise NotImplementedError("This class does not implement the" \
                                  " \"get_results\" function.")
, &name_is_string, &name_properties, &duplicate_label, &explicit_phandles, &phandle_references, &path_references, &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, &device_type_is_string, &model_is_string, &status_is_string, &addr_size_cells, ®_format, &ranges_format, &avoid_default_addr_size, &obsolete_chosen_interrupt_controller, &always_fail, }; static void enable_warning_error(struct check *c, bool warn, bool error) { int i; /* Raising level, also raise it for prereqs */ if ((warn && !c->warn) || (error && !c->error)) for (i = 0; i < c->num_prereqs; i++) enable_warning_error(c->prereq[i], warn, error); c->warn = c->warn || warn; c->error = c->error || error; } static void disable_warning_error(struct check *c, bool warn, bool error) { int i; /* Lowering level, also lower it for things this is the prereq * for */ if ((warn && c->warn) || (error && c->error)) { for (i = 0; i < ARRAY_SIZE(check_table); i++) { struct check *cc = check_table[i]; int j; for (j = 0; j < cc->num_prereqs; j++) if (cc->prereq[j] == c) disable_warning_error(cc, warn, error); } } c->warn = c->warn && !warn; c->error = c->error && !error; } void parse_checks_option(bool warn, bool error, const char *optarg) { int i; const char *name = optarg; bool enable = true; if ((strncmp(optarg, "no-", 3) == 0) || (strncmp(optarg, "no_", 3) == 0)) { name = optarg + 3; enable = false; } for (i = 0; i < ARRAY_SIZE(check_table); i++) { struct check *c = check_table[i]; if (streq(c->name, name)) { if (enable) enable_warning_error(c, warn, error); else disable_warning_error(c, warn, error); return; } } die("Unrecognized check name \"%s\"\n", name); } void process_checks(int force, struct boot_info *bi) { struct node *dt = bi->dt; int i; int error = 0; for (i = 0; i < ARRAY_SIZE(check_table); i++) { struct check *c = check_table[i]; if (c->warn || c->error) error = error || run_check(c, dt); } if (error) { if (!force) { fprintf(stderr, "ERROR: Input tree has errors, aborting " "(use -f to force output)\n"); exit(2); } else if (quiet < 3) { fprintf(stderr, "Warning: Input tree has errors, " "output forced\n"); } } }