def test_waning_file():
    log = MockLog()
    logger = FormatAdapter(log)
    log2 = MockLog()
    logger2 = FormatAdapter(log2)
    report_file = tempfile.mktemp()
    logger2.set_report_File(report_file)
    logger.warning("This is a warning")
    logger2.error("And an Error")
    with open(report_file, "r") as myfile:
        data = myfile.readlines()
    assert ("This is a warning\n" in data)
    assert ("And an Error\n" in data)
def test_logger_exception():
    log = MockLog()
    logger = FormatAdapter(log)
    logger._repeat_log()  # clear the log

    class Exn(Exception):
        pass

    try:
        raise Exn("hi")
    except Exn as ex:
        e = ex
        logger.exception("ho")

    assert str(e) == "hi"
    assert str(log.last_msg) == "ho"
    assert "exc_info" in log.last_kwargs
    assert log.last_level == logging.ERROR
    assert len(logger._repeat_log()) == 1
示例#3
0
# 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, see <http://www.gnu.org/licenses/>.

import logging
import os
import struct
from spinn_utilities.log import FormatAdapter
from spinn_utilities.progress_bar import ProgressBar
from data_specification.constants import MAX_MEM_REGIONS
from spinn_front_end_common.utilities.constants import BYTES_PER_WORD

logger = FormatAdapter(logging.getLogger(__name__))
_ONE_WORD = struct.Struct("<I")
MEM_MAP_SUBDIR_NAME = "memory_map_reports"
MEM_MAP_FILENAME = "memory_map_from_processor_{0:d}_{1:d}_{2:d}.txt"
REGION_HEADER_SIZE = 2 * BYTES_PER_WORD


class MemoryMapOnHostChipReport(object):
    """ Report on memory usage. Creates a report that states where in SDRAM \
        each region is (read from machine)

    :param str report_default_directory: the folder where reports are written
    :param iterable(tuple(int,int,int)) dsg_targets:
        the map between placement and file writer
    :param ~spinnman.transceiver.Transceiver transceiver: the spinnMan instance
    :rtype: None
示例#4
0
# the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.

import os
import logging
from spinn_utilities.log import FormatAdapter

logger = FormatAdapter(logging.getLogger())
_REPORT_FILENAME = "placement_isomorph.rpt"


class IsomorphicChecker(object):
    """ A short algorithm to check if there is an isomorphism of the placement\
        of vertices by two separate placement algorithms. One of the\
        algorithms must output to memory placements_copy in its method and\
        ``<param_type>MemoryPlacements2</param_type>`` in\
        ``algorithms_metadata.xml``.
    """

    def __call__(self, report_folder, placements, placements_copy):
        """ Outputs the result of the isomorphic check to a file.

        :param str report_folder:
Hello World program on SpiNNaker

Each core stores into its region in SDRAM the string:
"Hello World from $chip.x, $chip.y, $core"

We then fetch the written data and print it on the python console.
"""

import logging
import os
from spinn_utilities.log import FormatAdapter
import spinnaker_graph_front_end as front_end
from gfe_examples.hello_world_untimed.hello_world_vertex import (
    HelloWorldVertex)

logger = FormatAdapter(logging.getLogger(__name__))

front_end.setup(n_chips_required=1,
                model_binary_folder=os.path.dirname(__file__))

# Put HelloWorldVertex onto 16 cores
total_number_of_cores = 16
prints_per_run = 10
runs = 2
for x in range(total_number_of_cores):
    front_end.add_machine_vertex_instance(
        HelloWorldVertex(label=f"Hello World {x}"))

for _ in range(runs):
    front_end.run_until_complete(prints_per_run)
示例#6
0
# 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, see <http://www.gnu.org/licenses/>.
import logging
import sys
from spinn_utilities.overrides import overrides
from spinn_utilities.log import FormatAdapter
from pacman.model.graphs.machine import MachineVertex
from spinn_front_end_common.abstract_models import AbstractHasAssociatedBinary
from spinn_front_end_common.utilities.utility_objs import ExecutableType
from spinnaker_graph_front_end.utilities.data_utils import (
    generate_system_data_region)
from spinn_front_end_common.interface.buffer_management import (
    recording_utilities)
log = FormatAdapter(logging.getLogger(__file__))


class SimulatorVertex(MachineVertex, AbstractHasAssociatedBinary):
    """ A machine vertex that is implemented by a binary APLX that supports\
        the spin1_api simulation control protocol.
    """

    __slots__ = ["_binary_name", "__front_end"]

    def __init__(self, label, binary_name, constraints=()):
        """
        :param str label:
            The label for the vertex.
        :param str binary_name:
            The name of the APLX implementing the vertex.
def test_logger_adapter():
    log = MockLog()
    logger = FormatAdapter(log)
    logger._repeat_log()  # clear the log
    logger.debug("Debug {}", "debug")
    assert log.last_level is None
    logger.info("Info {}", "info")
    assert log.last_level == logging.INFO
    assert str(log.last_msg) == "Info info"
    logger.info("Test %s", "test")
    assert str(log.last_msg) == "Test %s"
    logger.warning("boo")
    assert str(log.last_msg) == "boo"
    assert log.last_level == logging.WARN
    logger.error("foo")
    assert str(log.last_msg) == "foo"
    assert log.last_level == logging.ERROR
    logger.critical("bar")
    assert str(log.last_msg) == "bar"
    assert log.last_level == logging.CRITICAL
    logger.set_kill_level(logging.CRITICAL)
    try:
        logger.critical("This is too high")
        assert False
    except LogLevelTooHighException:
        pass
    logger.set_kill_level()
    logger.critical("Should be ok now")
    assert len(logger._repeat_log()) == 4