Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "core/platform/telemetry_context.h"
#include "core/platform/telemetry_sha256.h"
 
#include <map>
#include <string>
 
#include "gtest/gtest.h"
 
namespace onnxruntime::test {
namespace {
 
class RecordingSemanticContext {
 public:
  void SetCommonField(const std::string& name, const std::string& value) {
    fields_[name] = value;
  }
 
  const std::map<std::string, std::string>& Fields() const {
    return fields_;
  }
 
 private:
  std::map<std::string, std::string> fields_;
};
 
TEST(TelemetryContextTest, SuppressesUnneededCommonContext) {
  RecordingSemanticContext context;
  telemetry_internal::SuppressUnneededCommonContext(context);
 
  ASSERT_EQ(context.Fields().size(), telemetry_internal::kSuppressedCommonContextFields.size());
  for (const char* field : telemetry_internal::kSuppressedCommonContextFields) {
    EXPECT_EQ(context.Fields().at(field), "");
  }
  EXPECT_EQ(context.Fields().count("AppInfo.Name"), 0);
}
 
TEST(TelemetryContextTest, SetsBoundedApplicationNameOrPreservesSdkFallback) {
  const std::string names[] = {"", "onnxruntime_test_all", std::string(kMaxTelemetryStringLength + 1, 'a')};
  for (const auto& name : names) {
    SCOPED_TRACE(name.size());
    RecordingSemanticContext context;
    context.SetCommonField("AppInfo.Name", "sdk fallback");
    telemetry_internal::SetApplicationNameFromProcessName(context, name);
    ASSERT_EQ(context.Fields().size(), 1);
    EXPECT_EQ(context.Fields().at("AppInfo.Name"),
              name.empty() ? "sdk fallback" : name.substr(0, kMaxTelemetryStringLength));
  }
}
 
TEST(TelemetryContextTest, SuppressesNetworkContextAfterProcessInfo) {
  RecordingSemanticContext context;
  telemetry_internal::SuppressNetworkContext(context);
 
  ASSERT_EQ(context.Fields().size(), telemetry_internal::kProcessInfoOnlyNetworkContextFields.size());
  for (const char* field : telemetry_internal::kProcessInfoOnlyNetworkContextFields) {
    EXPECT_EQ(context.Fields().at(field), "");
  }
}
 
TEST(TelemetryContextTest, SharedDeviceIdUsesUnsaltedSha256) {
  EXPECT_EQ(telemetry_internal::Sha256::HashStringHex(""),
            "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855");
  EXPECT_EQ(telemetry_internal::Sha256::HashStringHex("abc"),
            "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD");
  EXPECT_EQ(telemetry_internal::Sha256::HashStringHex(
                "01234567-89ab-4def-8123-456789abcdef"),
            "6225BD190D6CCF87766A49C9986D174DEF3391FE175A61525E49A1D2334D6A43");
}
 
}  // namespace
}  // namespace onnxruntime::test