test: Add windows_equally_evictable

Tests for the condition where the minimum age is less than any window's
current age, in which case we can get a NULL dereference if the
windows_reset_all() implementation is broken.

    windows.c:409:23: runtime error: member access within null pointer of type 'struct window_context'
    ASAN:DEADLYSIGNAL
    =================================================================
    ==31400==ERROR: AddressSanitizer: SEGV on unknown address 0x00000004 (pc 0x0002b658 bp 0x74c00270 sp 0x7eb7c678 T0)
    ==31400==The signal is caused by a WRITE memory access.
    ==31400==Hint: address points to the zero page.
        #0 0x2b657 in window_reset windows.c:410
        #1 0x2cc9b in windows_create_map windows.c:572
        #2 0x1f3f3 in protocol_v1_create_window protocol.c:167
        #3 0x2121b in protocol_v2_create_window protocol.c:417
        #4 0x24cd7f in generic_vpnor_create_window vpnor/protocol.cpp:51
        #5 0x24d053 in protocol_v2_vpnor_create_window vpnor/protocol.cpp:63
        #6 0x2663b in mbox_handle_create_window transport_mbox.c:282
        #7 0x276db in handle_mbox_req transport_mbox.c:568
        #8 0x276db in transport_mbox_dispatch transport_mbox.c:649
        #9 0x17fcb in poll_loop mboxd.c:185
        #10 0x17fcb in main mboxd.c:423
        #11 0x46b68517 in __libc_start_main (/lib/libc.so.6+0x46b68517)

    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV windows.c:410 in window_reset
    ==31400==ABORTING

Change-Id: I8161e2ea17953e196d4bb3ca90d19e44ec10c86d
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
2 files changed
tree: 301ac4d200d3423d613fb2f7a8854b25e95acd45
  1. Documentation/
  2. m4/
  3. test/
  4. vpnor/
  5. .clang-format-c
  6. .clang-format-c++
  7. .gitignore
  8. bootstrap.sh
  9. common.c
  10. common.h
  11. configure.ac
  12. control.c
  13. control_dbus.c
  14. control_dbus.h
  15. control_legacy.c
  16. dbus.h
  17. flash.c
  18. flash.h
  19. format-code.sh
  20. LICENSE
  21. lpc.c
  22. lpc.h
  23. lpc_reset.c
  24. MAINTAINERS
  25. Makefile.am
  26. mboxctl.c
  27. mboxd.c
  28. mboxd.h
  29. mtd.c
  30. protocol.c
  31. protocol.h
  32. protocol_negotiate_version.c
  33. README.md
  34. transport.h
  35. transport_dbus.c
  36. transport_dbus.h
  37. transport_mbox.c
  38. transport_mbox.h
  39. windows.c
  40. windows.h
README.md

Copyright 2017 IBM

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.

MBOX

This repo contains the protocol definition for the host to BMC mailbox communication specification which can be found in Documentation/mbox_procotol.md.

There is also a reference implementation of a BMC mailbox daemon, the details of which can be found in Documentation/mboxd.md.

Finally there is also an implementation of a mailbox daemon control program, the details of which can be found in Documentation/mboxctl.md.

Building

The build system is a standard autotools setup. bootstrap.sh runs all the jobs necessary to initialise autotools.

By default mboxd is configured and built without the 'virtual PNOR' feature discussed below. The virtual PNOR functionality is written in C++, and due to some autotools clunkiness even if it is disabled mboxd will still be linked with CXX. Point CXX to cc at configure time if you do not have a C++ compiler for your target (./configure CXX=cc).

If you are hacking on the reference implementation it's recommended to run bootstrap.sh with the dev argument:

$ ./bootstrap.sh dev
$ ./configure
$ make
$ make check

This will turn on several of the compiler's sanitizers to help find bad memory management and undefined behaviour in the code via the test suites.

Otherwise, build with:

$ ./bootstrap.sh
$ ./configure
$ make
$ make check

In addition to its role as a flash abstraction mboxd can also serve as a partition/filesystem abstraction. This feature is known as 'virtual PNOR' and it can be enabled at configure time (note that this requires a C++ compiler for your target):

$ ./bootstrap.sh
$ ./configure --enable-virtual-pnor
$ make
$ make check

Style Guide

Preamble

This codebase is a mix of C (due to its heritage) and C++. This is an ugly split: message logging and error handling can be vastly different inside the same codebase. The aim is to remove the split one way or the other over time and have consistent approaches to solving problems.

phosphor-mboxd is developed as part of the OpenBMC project, which also leads to integration of frameworks such as phosphor-logging. Specifically on phosphor-logging, it's noted that without care we can achieve absurd duplication or irritating splits in where errors are reported, as the C code is not capable of making use of the interfaces provided.

Rules

  1. Message logging MUST be done to stdout or stderr, and MUST NOT be done directly via journal APIs or wrappers of the journal APIs.

    Rationale:

    We have two scenarios where we care about output, with the important restriction that the method must be consistent between C and C++:

    1. Running in-context on an OpenBMC-based system
    2. Running the test suite

    In the first case it is desirable that the messages appear in the system journal. To this end, systemd will by default capture stdout and stderr of the launched binary and redirect it to the journal.

    In the second case it is desirable that messages be captured by the test runner (make check) for test failure analysis, and it is undesirable for messages to appear in the system journal (as these are tests, not issues affecting the health of the system they are being executed on).

    Therefore direct calls to the journal MUST be avoided for the purpose of message logging.

    Note: This section specifically targets the use of phosphor-logging's log<T>(). It does not prevent the use of elog<T>().