Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ecebea3d23a0
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2594c74b67c7
Choose a head ref
  • 12 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 16, 2021

  1. Copy the full SHA
    fd0d405 View commit details

Commits on Jul 18, 2021

  1. merge

    eggrobin committed Jul 18, 2021
    Copy the full SHA
    3cbaead View commit details
  2. Log the compatibility paths

    eggrobin committed Jul 18, 2021
    Copy the full SHA
    18219d5 View commit details
  3. merge

    eggrobin committed Jul 18, 2021
    Copy the full SHA
    bc45c73 View commit details

Commits on Jul 21, 2021

  1. Copy the full SHA
    e41991f View commit details

Commits on Jul 22, 2021

  1. rename

    eggrobin committed Jul 22, 2021
    Copy the full SHA
    07410d7 View commit details

Commits on Jul 25, 2021

  1. a problem for another day

    eggrobin committed Jul 25, 2021
    Copy the full SHA
    a3d2788 View commit details
  2. number

    eggrobin committed Jul 25, 2021
    Copy the full SHA
    d253fb1 View commit details

Commits on Jul 26, 2021

  1. after pleroy’s review

    eggrobin committed Jul 26, 2021
    Copy the full SHA
    fe46775 View commit details

Commits on Jul 30, 2021

  1. review

    eggrobin committed Jul 30, 2021
    Copy the full SHA
    aa77053 View commit details

Commits on Jul 31, 2021

  1. minimal_severity_

    eggrobin committed Jul 31, 2021
    Copy the full SHA
    49fa494 View commit details
  2. Merge pull request #3076 from eggrobin/saves

    Test passage in the compatibility paths, add a save by Reach
    eggrobin authored Jul 31, 2021
    Copy the full SHA
    2594c74 View commit details
164 changes: 151 additions & 13 deletions ksp_plugin_test/plugin_compatibility_test.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
#include <string>
#include <vector>

#include "astronomy/time_scales.hpp"
#include "base/file.hpp"
#include "base/not_null.hpp"
#include "base/pull_serializer.hpp"
@@ -18,18 +19,68 @@
namespace principia {
namespace interface {

using astronomy::operator""_TT;
using astronomy::TTSecond;
using astronomy::date_time::DateTime;
using astronomy::date_time::operator""_DateTime;
using base::not_null;
using base::OFStream;
using base::PullSerializer;
using base::PushDeserializer;
using ksp_plugin::Plugin;
using quantities::Speed;
using testing_utilities::ReadLinesFromBase64File;
using testing_utilities::ReadLinesFromHexadecimalFile;
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::HasSubstr;
using ::testing::Not;
using ::testing::NotNull;
using ::testing::Pair;
using ::testing::internal::CaptureStderr;
using ::testing::internal::GetCapturedStderr;

const char preferred_compressor[] = "gipfeli";
const char preferred_encoder[] = "base64";

class StringLogSink : google::LogSink {
public:
StringLogSink(google::LogSeverity const minimal_severity)
: minimal_severity_(minimal_severity) {
google::AddLogSink(this);
}

~StringLogSink() {
google::RemoveLogSink(this);
}

void send(google::LogSeverity const severity,
char const* const full_filename,
char const* const base_filename,
int const line,
tm const* const tm_time,
const char* const message,
size_t const message_len) override {
if (severity < minimal_severity_) {
return;
}
absl::MutexLock lock(&mutex_);
absl::StrAppend(
&string_,
ToString(severity, base_filename, line, tm_time, message, message_len));
}

std::string& string() {
return string_;
}

private:
google::LogSeverity const minimal_severity_;
absl::Mutex mutex_;
std::string string_ GUARDED_BY(mutex_);
};

class PluginCompatibilityTest : public testing::Test {
protected:
PluginCompatibilityTest() {
@@ -38,7 +89,7 @@ class PluginCompatibilityTest : public testing::Test {

// Reads a plugin from a file containing only the "serialized_plugin = "
// lines, with "serialized_plugin = " dropped.
not_null<std::unique_ptr<Plugin const>> ReadPluginFromFile(
static not_null<std::unique_ptr<Plugin const>> ReadPluginFromFile(
std::filesystem::path const& filename,
std::string_view const compressor,
std::string_view const encoder) {
@@ -70,10 +121,11 @@ class PluginCompatibilityTest : public testing::Test {
}

// Writes a plugin to a file.
void WritePluginToFile(std::filesystem::path const& filename,
std::string_view const compressor,
std::string_view const encoder,
not_null<std::unique_ptr<Plugin const>> plugin) {
static void WritePluginToFile(
std::filesystem::path const& filename,
std::string_view const compressor,
std::string_view const encoder,
not_null<std::unique_ptr<Plugin const>> plugin) {
OFStream file(filename);
PullSerializer* serializer = nullptr;
char const* b64 = nullptr;
@@ -96,13 +148,8 @@ class PluginCompatibilityTest : public testing::Test {
principia__DeletePlugin(&released_plugin);
}

void CheckSaveCompatibility(std::filesystem::path const& filename,
std::string_view const compressor,
std::string_view const encoder) {
// Read a plugin from the given file.
auto plugin1 = ReadPluginFromFile(filename, compressor, encoder);

// Write that plugin back to another file with the preferred format.
static void WriteAndReadBack(not_null<std::unique_ptr<Plugin const>> plugin1) {
// Write the plugin to a new file with the preferred format.
WritePluginToFile(TEMP_DIR / "serialized_plugin.proto.b64",
preferred_compressor,
preferred_encoder,
@@ -113,17 +160,108 @@ class PluginCompatibilityTest : public testing::Test {
preferred_compressor,
preferred_encoder);
}

static void CheckSaveCompatibility(std::filesystem::path const& filename,
std::string_view const compressor,
std::string_view const encoder) {
// Read a plugin from the given file.
auto plugin = ReadPluginFromFile(filename, compressor, encoder);

WriteAndReadBack(std::move(plugin));
}
};

TEST_F(PluginCompatibilityTest, PreCartan) {
// This space for rent.
}

TEST_F(PluginCompatibilityTest, PreCohen) {
StringLogSink log_warning(google::WARNING);
CheckSaveCompatibility(
SOLUTION_DIR / "ksp_plugin_test" / "pre_cohen.proto.hex",
SOLUTION_DIR / "ksp_plugin_test" / "saves" / "3039.proto.hex",
/*compressor=*/"",
/*decoder=*/"hexadecimal");
EXPECT_THAT(
log_warning.string(),
AllOf(
HasSubstr(
"pre-Cohen ContinuousTrajectory"), // Regression test for #3039.
HasSubstr("pre-Cauchy"), // The save is even older.
Not(HasSubstr("pre-Cartan")) // But not *that* old.
));
}

TEST_F(PluginCompatibilityTest, Reach) {
StringLogSink log_warning(google::WARNING);
not_null<std::unique_ptr<Plugin const>> plugin = ReadPluginFromFile(
SOLUTION_DIR / "ksp_plugin_test" / "saves" / "3072.proto.b64",
/*compressor=*/"gipfeli",
/*decoder=*/"base64");
EXPECT_THAT(log_warning.string(),
AllOf(HasSubstr("pre-Galileo"), Not(HasSubstr("pre-Frobenius"))));
auto const test = plugin->GetVessel("f2d77873-4776-4809-9dfb-de9e7a0620a6");
EXPECT_THAT(test->name(), Eq("TEST"));
EXPECT_THAT(TTSecond(test->psychohistory().front().time),
Eq("1970-08-14T08:03:18"_DateTime));
EXPECT_THAT(TTSecond(test->psychohistory().back().time),
Eq("1970-08-14T08:47:05"_DateTime));
EXPECT_FALSE(test->has_flight_plan());

auto const ifnity = plugin->GetVessel("29142a79-7acd-47a9-a34d-f9f2a8e1b4ed");
EXPECT_THAT(ifnity->name(), Eq("IFNITY-5.2"));
EXPECT_THAT(TTSecond(ifnity->psychohistory().front().time),
Eq("1970-08-14T08:03:46"_DateTime));
EXPECT_THAT(TTSecond(ifnity->psychohistory().back().time),
Eq("1970-08-14T08:47:05"_DateTime));
ASSERT_TRUE(ifnity->has_flight_plan());
EXPECT_THAT(ifnity->flight_plan().number_of_manœuvres(), Eq(16));
std::vector<std::pair<DateTime, Speed>> manœuvre_ignition_tt_seconds_and_Δvs;
for (int i = 0; i < ifnity->flight_plan().number_of_manœuvres(); ++i) {
manœuvre_ignition_tt_seconds_and_Δvs.emplace_back(
TTSecond(ifnity->flight_plan().GetManœuvre(i).initial_time()),
ifnity->flight_plan().GetManœuvre(i).Δv().Norm());
}
// The flight plan only covers the inner solar system (this is probably
// because of #3035).
// It also differs from https://youtu.be/7BDxZV7UD9I?t=439.
// TODO(egg): Compute the flybys and figure out what exactly is going on in
// this flight plan.
EXPECT_THAT(manœuvre_ignition_tt_seconds_and_Δvs,
ElementsAre(Pair("1970-08-14T09:34:49"_DateTime,
3.80488671073918022e+03 * (Metre / Second)),
Pair("1970-08-15T13:59:24"_DateTime,
3.04867185471741759e-04 * (Metre / Second)),
Pair("1970-12-22T07:48:21"_DateTime,
1.58521291818444873e-03 * (Metre / Second)),
Pair("1971-01-08T17:36:55"_DateTime,
1.40000000034068623e-03 * (Metre / Second)),
Pair("1971-07-02T17:16:00"_DateTime,
1.00000000431022681e-04 * (Metre / Second)),
Pair("1971-09-06T03:27:33"_DateTime,
1.78421858738381537e-03 * (Metre / Second)),
Pair("1972-02-13T22:47:26"_DateTime,
7.72606625794511597e-04 * (Metre / Second)),
Pair("1972-03-25T16:30:19"_DateTime,
5.32846131747503372e-03 * (Metre / Second)),
Pair("1972-12-24T04:09:32"_DateTime,
3.45000000046532824e-03 * (Metre / Second)),
Pair("1973-06-04T01:59:07"_DateTime,
9.10695453328359134e-03 * (Metre / Second)),
Pair("1973-07-09T06:07:17"_DateTime,
4.49510921430966881e-01 * (Metre / Second)),
Pair("1973-09-10T03:59:44"_DateTime,
1.00000000431022681e-04 * (Metre / Second)),
Pair("1974-11-20T17:34:27"_DateTime,
5.10549409572428781e-01 * (Metre / Second)),
Pair("1975-10-07T01:29:45"_DateTime,
2.86686518692948443e-02 * (Metre / Second)),
Pair("1975-12-29T21:27:13"_DateTime,
1.00404183285598275e-03 * (Metre / Second)),
Pair("1977-07-28T22:47:53"_DateTime,
1.39666705839172456e-01 * (Metre / Second))));

// Make sure that we can upgrade, save, and reload.
WriteAndReadBack(std::move(plugin));
}

// Use for debugging saves given by users.
File renamed without changes.
Loading