Creating a logger

This commit is contained in:
Zoe Roux
2021-07-06 16:04:13 +02:00
parent 7a51648ac9
commit 0287effdb5
9 changed files with 72 additions and 62 deletions
-12
View File
@@ -21,18 +21,6 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install the SFML.
run: sudo apt-get update &&
sudo apt-get install --yes libsfml-dev qt5-default
- name: Install Criterion
run: git clone --recursive https://github.com/Snaipe/Criterion &&
cd Criterion &&
sudo apt install --yes ninja-build &&
pip3 install meson &&
meson build &&
ninja -C build &&
sudo ninja -C build install &&
sudo cp -r /usr/local/lib/x86_64-linux-gnu/libcriterion* /usr/lib
- name: Install Gcovr
run: python -m pip install --upgrade pip gcovr
- name: Update G++
+5 -2
View File
@@ -95,7 +95,7 @@ set(SOURCES
sources/PPU/TileRenderer.hpp
sources/PPU/Tile.hpp
sources/CPU/Registers.hpp
sources/Memory/IMemoryBus.hpp sources/Models/Callback.hpp)
sources/Memory/IMemoryBus.hpp sources/Models/Callback.hpp sources/Models/Logger.hpp)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
@@ -184,6 +184,9 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
tests/CPU/testAddressingMode.cpp
tests/testMemoryBus.cpp
)
target_include_directories(unit_tests PUBLIC tests)
target_compile_definitions(unit_tests PUBLIC TESTS)
if (CMAKE_COMPILER_IS_GNUCXX)
# target_link_libraries(unit_tests PRIVATE -lgcov)
@@ -192,7 +195,7 @@ endif ()
find_package(Catch2 QUIET)
if (NOT Catch2_FOUND)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-dependencies)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libs)
find_package(Catch2 REQUIRED)
endif ()
target_link_libraries(unit_tests PRIVATE Catch2::Catch2)
+3 -2
View File
@@ -7,6 +7,7 @@
#include "Memory/MemoryBus.hpp"
#include "Memory/MemoryShadow.hpp"
#include "Exceptions/InvalidAddress.hpp"
#include "Models/Logger.hpp"
namespace ComSquare::Memory
{
@@ -26,7 +27,7 @@ namespace ComSquare::Memory
IMemory *handler = this->getAccessor(addr);
if (!handler) {
std::cout << "Unknown memory accessor for address $" << std::hex << addr << ". Using open bus." << std::endl;
log(LogLevel::WARNING, "Unknown memory accessor for address $" << std::hex << addr << ". Using open bus.");
return this->_openBus;
}
@@ -61,7 +62,7 @@ namespace ComSquare::Memory
IMemory *handler = this->getAccessor(addr);
if (!handler) {
std::cout << "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write." << std::endl;
log(LogLevel::ERROR, "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write.");
return;
}
handler->write(handler->getRelativeAddress(addr), data);
+32
View File
@@ -0,0 +1,32 @@
//
// Created by Zoe Roux on 2021-07-06.
//
#pragma once
#include <iostream>
#ifdef TESTS
#include <catch2/catch.hpp>
#endif
namespace ComSquare
{
enum LogLevel
{
INFO,
WARNING,
ERROR
};
constexpr LogLevel GlobalLevel = INFO;
#ifndef TESTS
#define log(level, message) \
if constexpr((level) >= GlobalLevel) \
std::cout << message << std::endl // NOLINT(bugprone-macro-parentheses)
#else
#define log(_, msg) INFO(msg)
#endif
}
+4 -3
View File
@@ -7,12 +7,13 @@
#include <QIcon>
#include <QMenuBar>
#include <iostream>
#include "Models/Logger.hpp"
#include "SNES.hpp"
#include "QtSFML.hpp"
#ifdef Q_WS_X11
#include <Qt/qx11info_x11.h>
#include <X11/Xlib.h>
#include <Qt/qx11info_x11.h>
#include <X11/Xlib.h>
#endif
namespace ComSquare::Renderer
@@ -57,7 +58,7 @@ namespace ComSquare::Renderer
}
#ifdef DEBUGGER_ENABLED
catch (const DebuggableError &e) {
std::cout << "Invalid rom's instruction: " << e.what() << std::endl;
log(LogLevel::ERROR, "Invalid rom's instruction: " << e.what());
this->_snes.enableCPUDebuggingWithError(e);
}
#endif
+24 -25
View File
@@ -3,11 +3,10 @@
//
#include <catch2/catch.hpp>
#include "../tests.hpp"
#include "tests.hpp"
#include "SNES.hpp"
#include "APU/APU.hpp"
#include "Exceptions/InvalidAddress.hpp"
#include "Exceptions/InvalidOpcode.hpp"
using namespace ComSquare;
@@ -29,9 +28,9 @@ TEST_CASE("register internalRead", "[internalRead]")
TEST_CASE("Page0 read Read", "[Read]")
{
Init()
uint8_t result = 0;
uint8_t result;
snes.apu._map->Page0._data[0x0010] = 123;
snes.apu._map.Page0._data[0x0010] = 123;
result = snes.apu._internalRead(0x0010);
REQUIRE(result == 123);
}
@@ -41,7 +40,7 @@ TEST_CASE("Page1 read Read", "[Read]")
Init()
uint8_t result = 0;
snes.apu._map->Page1._data[0x0042] = 123;
snes.apu._map.Page1._data[0x0042] = 123;
result = snes.apu._internalRead(0x0142);
REQUIRE(result == 123);
}
@@ -51,7 +50,7 @@ TEST_CASE("Memory internalRead", "[internalRead]")
Init()
uint8_t result = 0;
snes.apu._map->Memory._data[0xFCDC] = 123;
snes.apu._map.Memory._data[0xFCDC] = 123;
result = snes.apu._internalRead(0xFEDC);
REQUIRE(result == 123);
}
@@ -61,7 +60,7 @@ TEST_CASE("IPL internalRead", "[internalRead]")
Init()
uint8_t result = 0;
snes.apu._map->IPL._data[0x001F] = 123;
snes.apu._map.IPL._data[0x001F] = 123;
result = snes.apu._internalRead(0xFFDF);
REQUIRE(result == 123);
}
@@ -69,7 +68,7 @@ TEST_CASE("IPL internalRead", "[internalRead]")
TEST_CASE("Invalid internalRead", "[internalRead]")
{
Init()
auto apu = snes.apu;
REQUIRE_THROWS_AS(snes.apu._internalRead(0x10000), InvalidAddress);
}
@@ -83,16 +82,16 @@ TEST_CASE("Invalid internalRead", "[internalRead]")
TEST_CASE("Page0 write Write", "[Write]")
{
Init()
auto apu = snes.apu;
snes.apu._internalWrite(0x0001, 123);
REQUIRE(snes.apu._map->Page0._data[0x0001] == 123);
REQUIRE(snes.apu._map.Page0._data[0x0001] == 123);
}
TEST_CASE("register write Write", "[Write]")
{
Init()
auto apu = snes.apu;
snes.apu._internalWrite(0x00F4, 123);
REQUIRE(snes.apu._registers.port0 == 123);
@@ -101,34 +100,34 @@ TEST_CASE("register write Write", "[Write]")
TEST_CASE("Page1 internalWrite", "[internalWrite]")
{
Init()
auto apu = snes.apu;
snes.apu._internalWrite(0x01FF, 123);
REQUIRE(snes.apu._map->Page1._data[0x00FF] == 123);
REQUIRE(snes.apu._map.Page1._data[0x00FF] == 123);
}
TEST_CASE("Memory write internalWrite", "[internalWrite]")
{
Init()
auto apu = snes.apu;
snes.apu._internalWrite(0x0789, 123);
REQUIRE(snes.apu._map->Memory._data[0x0589] == 123);
REQUIRE(snes.apu._map.Memory._data[0x0589] == 123);
}
TEST_CASE("IPL internalWrite", "[internalWrite]")
{
Init()
auto apu = snes.apu;
snes.apu._internalWrite(0xFFF0, 123);
REQUIRE(snes.apu._map->IPL._data[0x0030] == 123);
REQUIRE(snes.apu._map.IPL._data[0x0030] == 123);
}
TEST_CASE("Invalid internalWrite", "[internalWrite]")
{
Init()
auto apu = snes.apu;
REQUIRE_THROWS_AS(snes.apu._internalWrite(0x10000, 123), InvalidAddress);
}
@@ -152,7 +151,7 @@ TEST_CASE("Valid read", "[read]")
TEST_CASE("Invalid read", "[read]")
{
Init()
auto apu = snes.apu;
REQUIRE_THROWS_AS(snes.apu.read(0x10000), InvalidAddress);
}
@@ -166,7 +165,7 @@ TEST_CASE("Invalid read", "[read]")
TEST_CASE("Valid write", "[write]")
{
Init()
auto apu = snes.apu;
snes.apu.write(0x03, 123);
REQUIRE(snes.apu._registers.port3 == 123);
@@ -175,7 +174,7 @@ TEST_CASE("Valid write", "[write]")
TEST_CASE("Invalid write", "[write]")
{
Init()
auto apu = snes.apu;
REQUIRE_THROWS_AS(snes.apu.write(0x04, 123), InvalidAddress);
}
@@ -205,7 +204,7 @@ TEST_CASE("Valid executeInstruction", "[executeInstruction]")
TEST_CASE("running update", "[update]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x00;
snes.apu.update(1);
@@ -215,7 +214,7 @@ TEST_CASE("running update", "[update]")
TEST_CASE("stopped update", "[update]")
{
Init()
auto apu = snes.apu;
snes.apu._state = APU::Stopped;
snes.apu.update(1);
@@ -231,7 +230,7 @@ TEST_CASE("stopped update", "[update]")
TEST_CASE("direct get", "[get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalWrite(0x32, 123);
@@ -241,7 +240,7 @@ TEST_CASE("direct get", "[get]")
TEST_CASE("absolute get", "[get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalWrite(0x32, 0b00001111);
+4 -17
View File
@@ -3,18 +3,16 @@
//
#include <catch2/catch.hpp>
#include "../tests.hpp"
#include "../../sources/SNES.hpp"
#include "../../sources/APU/APU.hpp"
#include "../../sources/Exceptions/InvalidAddress.hpp"
#include "../../sources/Exceptions/InvalidOpcode.hpp"
#include "tests.hpp"
#include "SNES.hpp"
#include "APU/APU.hpp"
#include "Exceptions/InvalidAddress.hpp"
using namespace ComSquare;
TEST_CASE("immediate apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalWrite(0x32, 0x40);
@@ -24,7 +22,6 @@ TEST_CASE("immediate apu_get", "[apu_get]")
TEST_CASE("direct apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.p = true;
@@ -35,7 +32,6 @@ TEST_CASE("direct apu_get", "[apu_get]")
TEST_CASE("X apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.x = 0x32;
snes.apu._internalRegisters.p = true;
@@ -45,7 +41,6 @@ TEST_CASE("X apu_get", "[apu_get]")
TEST_CASE("Y apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.y = 0x32;
snes.apu._internalRegisters.p = true;
@@ -55,7 +50,6 @@ TEST_CASE("Y apu_get", "[apu_get]")
TEST_CASE("directbyX apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.x = 0x03;
@@ -66,7 +60,6 @@ TEST_CASE("directbyX apu_get", "[apu_get]")
TEST_CASE("directbyY apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.y = 0x05;
@@ -77,7 +70,6 @@ TEST_CASE("directbyY apu_get", "[apu_get]")
TEST_CASE("absolute apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalWrite(0x32, 0b00001111);
@@ -88,7 +80,6 @@ TEST_CASE("absolute apu_get", "[apu_get]")
TEST_CASE("absolutebyx apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.x = 10;
@@ -101,7 +92,6 @@ TEST_CASE("absolutebyx apu_get", "[apu_get]")
TEST_CASE("absoluteaddrbyx apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.x = 10;
@@ -113,7 +103,6 @@ TEST_CASE("absoluteaddrbyx apu_get", "[apu_get]")
TEST_CASE("absoluteaddrbyy apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.y = 10;
@@ -138,7 +127,6 @@ TEST_CASE("absolutebit apu_get", "[apu_get]")
TEST_CASE("absolutebyxdirect apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.p = true;
@@ -152,7 +140,6 @@ TEST_CASE("absolutebyxdirect apu_get", "[apu_get]")
TEST_CASE("absolutedirectbyy apu_get", "[apu_get]")
{
Init()
auto apu = snes.apu;
snes.apu._internalRegisters.pc = 0x32;
snes.apu._internalRegisters.p = true;
-1
View File
@@ -13,7 +13,6 @@
#define protected public
#define class struct
#include "Memory/MemoryBus.hpp"
#include "Renderer/NoRenderer.hpp"
#include "SNES.hpp"