From 358cd4d95fa1ef4ea684d0cbf629d286875cf69f Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 22 Oct 2021 09:40:18 -0700 Subject: [PATCH] hos: allow turning off ams extension hard-reqs for unit testing --- libstratosphere/Makefile | 1 + .../source/hos/hos_stratosphere_api.cpp | 3 ++- .../source/hos/hos_version_api.cpp | 9 +++++++ .../hos_version_api_weak_for_unit_test.cpp | 24 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 libstratosphere/source/hos/hos_version_api_weak_for_unit_test.cpp diff --git a/libstratosphere/Makefile b/libstratosphere/Makefile index a01800fc..93211fdf 100644 --- a/libstratosphere/Makefile +++ b/libstratosphere/Makefile @@ -123,6 +123,7 @@ $(OFILES) : $(GCH_FILES) $(OFILES_SRC) : $(HFILES_BIN) ams_environment_weak.o: CXXFLAGS += -fno-lto +hos_version_api_weak_for_unit_test.o: CXXFLAGS += -fno-lto pm_info_api_weak.o: CXXFLAGS += -fno-lto hos_stratosphere_api.o: CXXFLAGS += -fno-lto diff --git a/libstratosphere/source/hos/hos_stratosphere_api.cpp b/libstratosphere/source/hos/hos_stratosphere_api.cpp index cf714570..aa4446b7 100644 --- a/libstratosphere/source/hos/hos_stratosphere_api.cpp +++ b/libstratosphere/source/hos/hos_stratosphere_api.cpp @@ -48,6 +48,7 @@ namespace ams::hos { } + bool IsUnitTestProgramForSetVersion(); void InitializeVersionInternal(bool allow_approximate); void InitializeForStratosphere() { @@ -58,7 +59,7 @@ namespace ams::hos { hos::InitializeVersionInternal(CanAllowTemporaryApproximateVersion()); /* Check that we're running under mesosphere. */ - AMS_ABORT_UNLESS(svc::IsKernelMesosphere()); + AMS_ABORT_UNLESS(IsUnitTestProgramForSetVersion() || svc::IsKernelMesosphere()); } } diff --git a/libstratosphere/source/hos/hos_version_api.cpp b/libstratosphere/source/hos/hos_version_api.cpp index 49075d73..76233755 100644 --- a/libstratosphere/source/hos/hos_version_api.cpp +++ b/libstratosphere/source/hos/hos_version_api.cpp @@ -61,7 +61,16 @@ namespace ams::hos { } + bool IsUnitTestProgramForSetVersion(); + void InitializeVersionInternal(bool allow_approximate) { + /* If we're unit testing, just set the version and move on. */ + if (IsUnitTestProgramForSetVersion()) { + g_hos_version = hos::Version_Current; + g_set_hos_version = true; + return; + } + /* Get the current (and previous approximation of) target firmware. */ hos::Version prev, current; bool has_prev = false; diff --git a/libstratosphere/source/hos/hos_version_api_weak_for_unit_test.cpp b/libstratosphere/source/hos/hos_version_api_weak_for_unit_test.cpp new file mode 100644 index 00000000..8f79a62b --- /dev/null +++ b/libstratosphere/source/hos/hos_version_api_weak_for_unit_test.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 . + */ +#include + +namespace ams::hos { + + WEAK_SYMBOL bool IsUnitTestProgramForSetVersion() { + return false; + } + +}