diff --git a/libraries/libstratosphere/Makefile b/libraries/libstratosphere/Makefile index a01800fc5..93211fdfb 100644 --- a/libraries/libstratosphere/Makefile +++ b/libraries/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/libraries/libstratosphere/source/hos/hos_stratosphere_api.cpp b/libraries/libstratosphere/source/hos/hos_stratosphere_api.cpp index cf7145707..aa4446b76 100644 --- a/libraries/libstratosphere/source/hos/hos_stratosphere_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/hos/hos_version_api.cpp b/libraries/libstratosphere/source/hos/hos_version_api.cpp index 49075d736..76233755c 100644 --- a/libraries/libstratosphere/source/hos/hos_version_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/hos/hos_version_api_weak_for_unit_test.cpp b/libraries/libstratosphere/source/hos/hos_version_api_weak_for_unit_test.cpp new file mode 100644 index 000000000..8f79a62be --- /dev/null +++ b/libraries/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; + } + +} diff --git a/tests/TestSvc/source/test_main.cpp b/tests/TestSvc/source/test_main.cpp index 8f34f06d2..b01013832 100644 --- a/tests/TestSvc/source/test_main.cpp +++ b/tests/TestSvc/source/test_main.cpp @@ -27,6 +27,12 @@ namespace ams { } + namespace hos { + + bool IsUnitTestProgramForSetVersion() { return true; } + + } + namespace init { void InitializeSystemModuleBeforeConstructors() {