dsh-remote 0.8.94 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +128 -370
  3. package/README.md +129 -355
  4. package/cordis.patch.yml +9 -9
  5. package/lib/audit.js +45 -45
  6. package/lib/auto-update.js +70 -0
  7. package/lib/binding.js +174 -172
  8. package/lib/boot.js +42 -42
  9. package/lib/client.js +6381 -4662
  10. package/lib/credential.js +277 -270
  11. package/lib/errors.js +141 -141
  12. package/lib/exec-job.js +245 -242
  13. package/lib/file-changes.js +57 -0
  14. package/lib/file-reference.js +457 -457
  15. package/lib/forwards.js +258 -258
  16. package/lib/host-api.js +822 -822
  17. package/lib/hostkey.js +108 -108
  18. package/lib/http-transport.js +201 -201
  19. package/lib/ignore.js +202 -202
  20. package/lib/index.js +4555 -4488
  21. package/lib/instructions-dynamic.js +415 -415
  22. package/lib/instructions.js +288 -288
  23. package/lib/open-folder.js +56 -56
  24. package/lib/openssh.js +950 -940
  25. package/lib/paths.js +292 -292
  26. package/lib/pool.js +1029 -1029
  27. package/lib/posix-shell.cjs +34 -34
  28. package/lib/registry.js +296 -296
  29. package/lib/remote-fs.js +179 -173
  30. package/lib/remote-git.js +127 -0
  31. package/lib/remote-sandbox.js +183 -183
  32. package/lib/remote-shell-child.cjs +460 -397
  33. package/lib/remote-shell.js +697 -697
  34. package/lib/remote-skills.js +312 -312
  35. package/lib/remote-write.js +51 -0
  36. package/lib/routes-audit.js +58 -58
  37. package/lib/routes-forwards.js +72 -72
  38. package/lib/routes-fs.js +299 -251
  39. package/lib/routes-machines.js +217 -186
  40. package/lib/routes-misc.js +187 -187
  41. package/lib/routes-term.js +169 -169
  42. package/lib/routes-update.js +147 -143
  43. package/lib/routes-web-attach.js +121 -112
  44. package/lib/routes-workspace.js +325 -312
  45. package/lib/search.js +235 -235
  46. package/lib/self-heal.js +130 -130
  47. package/lib/sftp-surface.js +119 -119
  48. package/lib/sshconfig.js +779 -779
  49. package/lib/sync-status.js +31 -0
  50. package/lib/sync.js +350 -350
  51. package/lib/tasks.js +95 -95
  52. package/lib/telemetry.js +247 -247
  53. package/lib/terminal.js +205 -205
  54. package/lib/tui/flow.js +130 -130
  55. package/lib/tui/format.js +380 -380
  56. package/lib/tui/i18n.js +350 -350
  57. package/lib/tui/index.js +531 -531
  58. package/lib/tui/provider.js +344 -344
  59. package/lib/tui/scene.js +986 -986
  60. package/lib/update.js +497 -490
  61. package/lib/vendor/jsdiff/LICENSE +29 -0
  62. package/lib/vendor/jsdiff/SOURCE.md +4 -0
  63. package/lib/vendor/jsdiff/diff/base.js +254 -0
  64. package/lib/vendor/jsdiff/diff/line.js +66 -0
  65. package/lib/vendor/jsdiff/patch/create.js +229 -0
  66. package/lib/vendor/jsdiff/util/params.js +15 -0
  67. package/lib/web-attach.js +1081 -860
  68. package/lib/workspace-cleanup.js +337 -337
  69. package/lib/workspace-search.js +219 -0
  70. package/node_modules/buildcheck/.eslintrc.js +5 -0
  71. package/node_modules/buildcheck/.github/workflows/ci.yml +88 -0
  72. package/node_modules/buildcheck/.github/workflows/lint.yml +27 -0
  73. package/node_modules/buildcheck/.npmignore +3 -0
  74. package/node_modules/buildcheck/LICENSE +19 -0
  75. package/node_modules/buildcheck/README.md +106 -0
  76. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +250 -0
  77. package/node_modules/buildcheck/lib/findvs.js +361 -0
  78. package/node_modules/buildcheck/lib/index.js +738 -0
  79. package/node_modules/buildcheck/package.json +36 -0
  80. package/node_modules/buildcheck/test/test.js +8 -0
  81. package/node_modules/cpu-features/.eslintrc.js +5 -0
  82. package/node_modules/cpu-features/.github/workflows/ci.yml +74 -0
  83. package/node_modules/cpu-features/.github/workflows/lint.yml +27 -0
  84. package/node_modules/cpu-features/LICENSE +19 -0
  85. package/node_modules/cpu-features/README.md +59 -0
  86. package/node_modules/cpu-features/binding.gyp +16 -0
  87. package/node_modules/cpu-features/buildcheck.js +32 -0
  88. package/node_modules/cpu-features/deps/cpu_features/.clang-format +4 -0
  89. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +31 -0
  90. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +5 -0
  91. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +30 -0
  92. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +22 -0
  93. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +26 -0
  94. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +31 -0
  95. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +43 -0
  96. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +25 -0
  97. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +31 -0
  98. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +24 -0
  99. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +30 -0
  100. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +29 -0
  101. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +28 -0
  102. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +27 -0
  103. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +21 -0
  104. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +329 -0
  105. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +261 -0
  106. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +23 -0
  107. package/node_modules/cpu-features/deps/cpu_features/LICENSE +230 -0
  108. package/node_modules/cpu-features/deps/cpu_features/README.md +272 -0
  109. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +19 -0
  110. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +5 -0
  111. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +11 -0
  112. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +3 -0
  113. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +3 -0
  114. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +30 -0
  115. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +252 -0
  116. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +40 -0
  117. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +64 -0
  118. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +312 -0
  119. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +7 -0
  120. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +48 -0
  121. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +34 -0
  122. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +22 -0
  123. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +11 -0
  124. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +107 -0
  125. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +15 -0
  126. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +105 -0
  127. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +54 -0
  128. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +384 -0
  129. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +259 -0
  130. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +121 -0
  131. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +74 -0
  132. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +149 -0
  133. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +72 -0
  134. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +108 -0
  135. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +288 -0
  136. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +40 -0
  137. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +37 -0
  138. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +39 -0
  139. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +240 -0
  140. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +49 -0
  141. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +110 -0
  142. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +70 -0
  143. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +60 -0
  144. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +4 -0
  145. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +205 -0
  146. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +320 -0
  147. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +12 -0
  148. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +456 -0
  149. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +165 -0
  150. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +75 -0
  151. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +490 -0
  152. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +79 -0
  153. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +19 -0
  154. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +86 -0
  155. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +26 -0
  156. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +22 -0
  157. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +62 -0
  158. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +169 -0
  159. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +88 -0
  160. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +79 -0
  161. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +82 -0
  162. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +138 -0
  163. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +212 -0
  164. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +93 -0
  165. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +163 -0
  166. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +111 -0
  167. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +120 -0
  168. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +2055 -0
  169. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +68 -0
  170. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +58 -0
  171. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +57 -0
  172. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +58 -0
  173. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +132 -0
  174. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +192 -0
  175. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +461 -0
  176. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +114 -0
  177. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +53 -0
  178. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +396 -0
  179. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +384 -0
  180. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +176 -0
  181. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +131 -0
  182. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +180 -0
  183. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +82 -0
  184. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +1729 -0
  185. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +103 -0
  186. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +61 -0
  187. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +52 -0
  188. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +31 -0
  189. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +132 -0
  190. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +202 -0
  191. package/node_modules/cpu-features/lib/index.js +5 -0
  192. package/node_modules/cpu-features/package.json +40 -0
  193. package/node_modules/cpu-features/src/binding.cc +151 -0
  194. package/node_modules/cpu-features/test/test.js +12 -0
  195. package/node_modules/nan/tools/1to2.js +0 -0
  196. package/package.json +107 -103
@@ -0,0 +1,103 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "filesystem_for_testing.h"
16
+
17
+ #include <cassert>
18
+ #include <climits>
19
+ #include <cstdio>
20
+ #include <cstring>
21
+ #include <utility>
22
+
23
+ namespace cpu_features {
24
+
25
+ FakeFile::FakeFile(int file_descriptor, const char* content)
26
+ : file_descriptor_(file_descriptor), content_(content) {}
27
+
28
+ FakeFile::~FakeFile() { assert(!opened_); }
29
+
30
+ void FakeFile::Open() {
31
+ assert(!opened_);
32
+ opened_ = true;
33
+ }
34
+
35
+ void FakeFile::Close() {
36
+ assert(opened_);
37
+ opened_ = false;
38
+ }
39
+
40
+ int FakeFile::Read(int fd, void* buf, size_t count) {
41
+ assert(count < INT_MAX);
42
+ assert(fd == file_descriptor_);
43
+ const size_t remainder = content_.size() - head_index_;
44
+ const size_t read = count > remainder ? remainder : count;
45
+ memcpy(buf, content_.data() + head_index_, read);
46
+ head_index_ += read;
47
+ assert(read < INT_MAX);
48
+ return (int)read;
49
+ }
50
+
51
+ void FakeFilesystem::Reset() { files_.clear(); }
52
+
53
+ FakeFile* FakeFilesystem::CreateFile(const std::string& filename,
54
+ const char* content) {
55
+ auto& file = files_[filename];
56
+ file =
57
+ std::unique_ptr<FakeFile>(new FakeFile(next_file_descriptor_++, content));
58
+ return file.get();
59
+ }
60
+
61
+ FakeFile* FakeFilesystem::FindFileOrNull(const std::string& filename) const {
62
+ const auto itr = files_.find(filename);
63
+ return itr == files_.end() ? nullptr : itr->second.get();
64
+ }
65
+
66
+ FakeFile* FakeFilesystem::FindFileOrDie(const int file_descriptor) const {
67
+ for (const auto& filename_file_pair : files_) {
68
+ FakeFile* const file_ptr = filename_file_pair.second.get();
69
+ if (file_ptr->GetFileDescriptor() == file_descriptor) {
70
+ return file_ptr;
71
+ }
72
+ }
73
+ assert(false);
74
+ return nullptr;
75
+ }
76
+
77
+ static FakeFilesystem* kFilesystem = new FakeFilesystem();
78
+
79
+ FakeFilesystem& GetEmptyFilesystem() {
80
+ kFilesystem->Reset();
81
+ return *kFilesystem;
82
+ }
83
+
84
+ extern "C" int CpuFeatures_OpenFile(const char* filename) {
85
+ auto* const file = kFilesystem->FindFileOrNull(filename);
86
+ if (file) {
87
+ file->Open();
88
+ return file->GetFileDescriptor();
89
+ }
90
+ return -1;
91
+ }
92
+
93
+ extern "C" void CpuFeatures_CloseFile(int file_descriptor) {
94
+ kFilesystem->FindFileOrDie(file_descriptor)->Close();
95
+ }
96
+
97
+ extern "C" int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
98
+ size_t buffer_size) {
99
+ return kFilesystem->FindFileOrDie(file_descriptor)
100
+ ->Read(file_descriptor, buffer, buffer_size);
101
+ }
102
+
103
+ } // namespace cpu_features
@@ -0,0 +1,61 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ // Implements a fake filesystem, useful for tests.
16
+ #ifndef CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_
17
+ #define CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_
18
+
19
+ #include <memory>
20
+ #include <string>
21
+ #include <unordered_map>
22
+
23
+ #include "internal/filesystem.h"
24
+
25
+ namespace cpu_features {
26
+
27
+ class FakeFile {
28
+ public:
29
+ explicit FakeFile(int file_descriptor, const char* content);
30
+ ~FakeFile();
31
+
32
+ void Open();
33
+ void Close();
34
+ int Read(int fd, void* buf, size_t count);
35
+
36
+ int GetFileDescriptor() const { return file_descriptor_; }
37
+
38
+ private:
39
+ const int file_descriptor_;
40
+ const std::string content_;
41
+ bool opened_ = false;
42
+ size_t head_index_ = 0;
43
+ };
44
+
45
+ class FakeFilesystem {
46
+ public:
47
+ void Reset();
48
+ FakeFile* CreateFile(const std::string& filename, const char* content);
49
+ FakeFile* FindFileOrDie(const int file_descriptor) const;
50
+ FakeFile* FindFileOrNull(const std::string& filename) const;
51
+
52
+ private:
53
+ int next_file_descriptor_ = 0;
54
+ std::unordered_map<std::string, std::unique_ptr<FakeFile>> files_;
55
+ };
56
+
57
+ FakeFilesystem& GetEmptyFilesystem();
58
+
59
+ } // namespace cpu_features
60
+
61
+ #endif // CPU_FEATURES_TEST_FILESYSTEM_FOR_TESTING_H_
@@ -0,0 +1,52 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "hwcaps_for_testing.h"
16
+
17
+ #include <string.h>
18
+
19
+ #include "internal/string_view.h"
20
+
21
+ namespace cpu_features {
22
+
23
+ namespace {
24
+ static auto* const g_hardware_capabilities = new HardwareCapabilities();
25
+ static const char* g_platform_pointer = nullptr;
26
+ static const char* g_base_platform_pointer = nullptr;
27
+ } // namespace
28
+
29
+ void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
30
+ g_hardware_capabilities->hwcaps = hwcaps;
31
+ g_hardware_capabilities->hwcaps2 = hwcaps2;
32
+ }
33
+ void SetPlatformPointer(const char* string) { g_platform_pointer = string; }
34
+ void SetBasePlatformPointer(const char* string) {
35
+ g_base_platform_pointer = string;
36
+ }
37
+
38
+ void ResetHwcaps() {
39
+ SetHardwareCapabilities(0, 0);
40
+ SetPlatformPointer(nullptr);
41
+ SetBasePlatformPointer(nullptr);
42
+ }
43
+
44
+ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
45
+ return *g_hardware_capabilities;
46
+ }
47
+ const char* CpuFeatures_GetPlatformPointer(void) { return g_platform_pointer; }
48
+ const char* CpuFeatures_GetBasePlatformPointer(void) {
49
+ return g_base_platform_pointer;
50
+ }
51
+
52
+ } // namespace cpu_features
@@ -0,0 +1,31 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef CPU_FEATURES_TEST_HWCAPS_FOR_TESTING_H_
16
+ #define CPU_FEATURES_TEST_HWCAPS_FOR_TESTING_H_
17
+
18
+ #include "internal/hwcaps.h"
19
+
20
+ namespace cpu_features {
21
+
22
+ void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2);
23
+ void SetPlatformPointer(const char* string);
24
+ void SetBasePlatformPointer(const char* string);
25
+
26
+ // To be called before each test.
27
+ void ResetHwcaps();
28
+
29
+ } // namespace cpu_features
30
+
31
+ #endif // CPU_FEATURES_TEST_HWCAPS_FOR_TESTING_H_
@@ -0,0 +1,132 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "internal/stack_line_reader.h"
16
+
17
+ #include "filesystem_for_testing.h"
18
+ #include "gtest/gtest.h"
19
+
20
+ namespace cpu_features {
21
+
22
+ bool operator==(const StringView& a, const StringView& b) {
23
+ return CpuFeatures_StringView_IsEquals(a, b);
24
+ }
25
+
26
+ namespace {
27
+
28
+ std::string ToString(StringView view) { return {view.ptr, view.size}; }
29
+
30
+ TEST(StackLineReaderTest, Empty) {
31
+ auto& fs = GetEmptyFilesystem();
32
+ auto* file = fs.CreateFile("/proc/cpuinfo", "");
33
+ StackLineReader reader;
34
+ StackLineReader_Initialize(&reader, file->GetFileDescriptor());
35
+ {
36
+ const auto result = StackLineReader_NextLine(&reader);
37
+ EXPECT_TRUE(result.eof);
38
+ EXPECT_TRUE(result.full_line);
39
+ EXPECT_EQ(result.line, str(""));
40
+ }
41
+ }
42
+
43
+ TEST(StackLineReaderTest, ManySmallLines) {
44
+ auto& fs = GetEmptyFilesystem();
45
+ auto* file = fs.CreateFile("/proc/cpuinfo", "a\nb\nc");
46
+
47
+ StackLineReader reader;
48
+ StackLineReader_Initialize(&reader, file->GetFileDescriptor());
49
+ {
50
+ const auto result = StackLineReader_NextLine(&reader);
51
+ EXPECT_FALSE(result.eof);
52
+ EXPECT_TRUE(result.full_line);
53
+ EXPECT_EQ(result.line, str("a"));
54
+ }
55
+ {
56
+ const auto result = StackLineReader_NextLine(&reader);
57
+ EXPECT_FALSE(result.eof);
58
+ EXPECT_TRUE(result.full_line);
59
+ EXPECT_EQ(result.line, str("b"));
60
+ }
61
+ {
62
+ const auto result = StackLineReader_NextLine(&reader);
63
+ EXPECT_TRUE(result.eof);
64
+ EXPECT_TRUE(result.full_line);
65
+ EXPECT_EQ(result.line, str("c"));
66
+ }
67
+ }
68
+
69
+ TEST(StackLineReaderTest, TruncatedLine) {
70
+ auto& fs = GetEmptyFilesystem();
71
+ auto* file = fs.CreateFile("/proc/cpuinfo", R"(First
72
+ Second
73
+ More than 16 characters, this will be truncated.
74
+ last)");
75
+
76
+ StackLineReader reader;
77
+ StackLineReader_Initialize(&reader, file->GetFileDescriptor());
78
+ {
79
+ const auto result = StackLineReader_NextLine(&reader);
80
+ EXPECT_FALSE(result.eof);
81
+ EXPECT_TRUE(result.full_line);
82
+ EXPECT_EQ(result.line, str("First"));
83
+ }
84
+ {
85
+ const auto result = StackLineReader_NextLine(&reader);
86
+ EXPECT_FALSE(result.eof);
87
+ EXPECT_TRUE(result.full_line);
88
+ EXPECT_EQ(result.line, str("Second"));
89
+ }
90
+ {
91
+ const auto result = StackLineReader_NextLine(&reader);
92
+ EXPECT_FALSE(result.eof);
93
+ EXPECT_FALSE(result.full_line);
94
+ EXPECT_EQ(result.line, str("More than 16 cha"));
95
+ }
96
+ {
97
+ const auto result = StackLineReader_NextLine(&reader);
98
+ EXPECT_TRUE(result.eof);
99
+ EXPECT_TRUE(result.full_line);
100
+ EXPECT_EQ(result.line, str("last"));
101
+ }
102
+ }
103
+
104
+ TEST(StackLineReaderTest, TruncatedLines) {
105
+ auto& fs = GetEmptyFilesystem();
106
+ auto* file = fs.CreateFile("/proc/cpuinfo", R"(More than 16 characters
107
+ Another line that is too long)");
108
+
109
+ StackLineReader reader;
110
+ StackLineReader_Initialize(&reader, file->GetFileDescriptor());
111
+ {
112
+ const auto result = StackLineReader_NextLine(&reader);
113
+ EXPECT_FALSE(result.eof);
114
+ EXPECT_FALSE(result.full_line);
115
+ EXPECT_EQ(result.line, str("More than 16 cha"));
116
+ }
117
+ {
118
+ const auto result = StackLineReader_NextLine(&reader);
119
+ EXPECT_FALSE(result.eof);
120
+ EXPECT_FALSE(result.full_line);
121
+ EXPECT_EQ(result.line, str("Another line tha"));
122
+ }
123
+ {
124
+ const auto result = StackLineReader_NextLine(&reader);
125
+ EXPECT_TRUE(result.eof);
126
+ EXPECT_TRUE(result.full_line);
127
+ EXPECT_EQ(result.line, str(""));
128
+ }
129
+ }
130
+
131
+ } // namespace
132
+ } // namespace cpu_features
@@ -0,0 +1,202 @@
1
+ // Copyright 2017 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "internal/string_view.h"
16
+
17
+ #include "gtest/gtest.h"
18
+
19
+ namespace cpu_features {
20
+
21
+ bool operator==(const StringView& a, const StringView& b) {
22
+ return CpuFeatures_StringView_IsEquals(a, b);
23
+ }
24
+
25
+ namespace {
26
+
27
+ TEST(StringViewTest, Empty) {
28
+ EXPECT_EQ(kEmptyStringView.ptr, nullptr);
29
+ EXPECT_EQ(kEmptyStringView.size, 0);
30
+ }
31
+
32
+ TEST(StringViewTest, Build) {
33
+ const auto view = str("test");
34
+ EXPECT_EQ(view.ptr[0], 't');
35
+ EXPECT_EQ(view.size, 4);
36
+ }
37
+
38
+ TEST(StringViewTest, CpuFeatures_StringView_IndexOfChar) {
39
+ // Found.
40
+ EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(str("test"), 'e'), 1);
41
+ EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(str("test"), 't'), 0);
42
+ EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(str("beef"), 'e'), 1);
43
+ // Not found.
44
+ EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(str("test"), 'z'), -1);
45
+ // Empty.
46
+ EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(kEmptyStringView, 'z'), -1);
47
+ }
48
+
49
+ TEST(StringViewTest, CpuFeatures_StringView_IndexOf) {
50
+ // Found.
51
+ EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("test"), str("es")), 1);
52
+ EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("test"), str("test")), 0);
53
+ EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("tesstest"), str("test")), 4);
54
+ // Not found.
55
+ EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("test"), str("aa")), -1);
56
+ // Empty.
57
+ EXPECT_EQ(CpuFeatures_StringView_IndexOf(kEmptyStringView, str("aa")), -1);
58
+ EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("aa"), kEmptyStringView), -1);
59
+ }
60
+
61
+ TEST(StringViewTest, CpuFeatures_StringView_StartsWith) {
62
+ EXPECT_TRUE(CpuFeatures_StringView_StartsWith(str("test"), str("te")));
63
+ EXPECT_TRUE(CpuFeatures_StringView_StartsWith(str("test"), str("test")));
64
+ EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), str("st")));
65
+ EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), str("est")));
66
+ EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), str("")));
67
+ EXPECT_FALSE(
68
+ CpuFeatures_StringView_StartsWith(str("test"), kEmptyStringView));
69
+ EXPECT_FALSE(
70
+ CpuFeatures_StringView_StartsWith(kEmptyStringView, str("test")));
71
+ }
72
+
73
+ TEST(StringViewTest, CpuFeatures_StringView_IsEquals) {
74
+ EXPECT_TRUE(
75
+ CpuFeatures_StringView_IsEquals(kEmptyStringView, kEmptyStringView));
76
+ EXPECT_TRUE(CpuFeatures_StringView_IsEquals(kEmptyStringView, str("")));
77
+ EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str(""), kEmptyStringView));
78
+ EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str("test"), str("test")));
79
+ EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str("a"), str("a")));
80
+ EXPECT_FALSE(CpuFeatures_StringView_IsEquals(str("a"), str("b")));
81
+ EXPECT_FALSE(CpuFeatures_StringView_IsEquals(str("aa"), str("a")));
82
+ EXPECT_FALSE(CpuFeatures_StringView_IsEquals(str("a"), str("aa")));
83
+ EXPECT_FALSE(CpuFeatures_StringView_IsEquals(str("a"), kEmptyStringView));
84
+ EXPECT_FALSE(CpuFeatures_StringView_IsEquals(kEmptyStringView, str("a")));
85
+ }
86
+
87
+ TEST(StringViewTest, CpuFeatures_StringView_PopFront) {
88
+ EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 2), str("st"));
89
+ EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 0), str("test"));
90
+ EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 4), str(""));
91
+ EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 100), str(""));
92
+ }
93
+
94
+ TEST(StringViewTest, CpuFeatures_StringView_PopBack) {
95
+ EXPECT_EQ(CpuFeatures_StringView_PopBack(str("test"), 2), str("te"));
96
+ EXPECT_EQ(CpuFeatures_StringView_PopBack(str("test"), 0), str("test"));
97
+ EXPECT_EQ(CpuFeatures_StringView_PopBack(str("test"), 4), str(""));
98
+ EXPECT_EQ(CpuFeatures_StringView_PopBack(str("test"), 100), str(""));
99
+ }
100
+
101
+ TEST(StringViewTest, CpuFeatures_StringView_KeepFront) {
102
+ EXPECT_EQ(CpuFeatures_StringView_KeepFront(str("test"), 2), str("te"));
103
+ EXPECT_EQ(CpuFeatures_StringView_KeepFront(str("test"), 0), str(""));
104
+ EXPECT_EQ(CpuFeatures_StringView_KeepFront(str("test"), 4), str("test"));
105
+ EXPECT_EQ(CpuFeatures_StringView_KeepFront(str("test"), 6), str("test"));
106
+ }
107
+
108
+ TEST(StringViewTest, CpuFeatures_StringView_Front) {
109
+ EXPECT_EQ(CpuFeatures_StringView_Front(str("apple")), 'a');
110
+ EXPECT_EQ(CpuFeatures_StringView_Front(str("a")), 'a');
111
+ }
112
+
113
+ TEST(StringViewTest, CpuFeatures_StringView_Back) {
114
+ EXPECT_EQ(CpuFeatures_StringView_Back(str("apple")), 'e');
115
+ EXPECT_EQ(CpuFeatures_StringView_Back(str("a")), 'a');
116
+ }
117
+
118
+ TEST(StringViewTest, CpuFeatures_StringView_TrimWhitespace) {
119
+ EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str(" first middle last ")),
120
+ str("first middle last"));
121
+ EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str("first middle last ")),
122
+ str("first middle last"));
123
+ EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str(" first middle last")),
124
+ str("first middle last"));
125
+ EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str("first middle last")),
126
+ str("first middle last"));
127
+ }
128
+
129
+ TEST(StringViewTest, CpuFeatures_StringView_ParsePositiveNumber) {
130
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("42")), 42);
131
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("0x2a")), 42);
132
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("0x2A")), 42);
133
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("0x2A2a")), 10794);
134
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("0x2a2A")), 10794);
135
+
136
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("-10")), -1);
137
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("-0x2A")), -1);
138
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("abc")), -1);
139
+ EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("")), -1);
140
+ }
141
+
142
+ TEST(StringViewTest, CpuFeatures_StringView_CopyString) {
143
+ char buf[4];
144
+ buf[0] = 'X';
145
+
146
+ // Empty
147
+ CpuFeatures_StringView_CopyString(str(""), buf, sizeof(buf));
148
+ EXPECT_STREQ(buf, "");
149
+
150
+ // Less
151
+ CpuFeatures_StringView_CopyString(str("a"), buf, sizeof(buf));
152
+ EXPECT_STREQ(buf, "a");
153
+
154
+ // exact
155
+ CpuFeatures_StringView_CopyString(str("abc"), buf, sizeof(buf));
156
+ EXPECT_STREQ(buf, "abc");
157
+
158
+ // More
159
+ CpuFeatures_StringView_CopyString(str("abcd"), buf, sizeof(buf));
160
+ EXPECT_STREQ(buf, "abc");
161
+ }
162
+
163
+ TEST(StringViewTest, CpuFeatures_StringView_HasWord) {
164
+ // Find flags at beginning, middle and end.
165
+ EXPECT_TRUE(
166
+ CpuFeatures_StringView_HasWord(str("first middle last"), "first", ' '));
167
+ EXPECT_TRUE(
168
+ CpuFeatures_StringView_HasWord(str("first middle last"), "middle", ' '));
169
+ EXPECT_TRUE(
170
+ CpuFeatures_StringView_HasWord(str("first middle last"), "last", ' '));
171
+ // Find flags at beginning, middle and end with a different separator
172
+ EXPECT_TRUE(
173
+ CpuFeatures_StringView_HasWord(str("first-middle-last"), "first", '-'));
174
+ EXPECT_TRUE(
175
+ CpuFeatures_StringView_HasWord(str("first-middle-last"), "middle", '-'));
176
+ EXPECT_TRUE(
177
+ CpuFeatures_StringView_HasWord(str("first-middle-last"), "last", '-'));
178
+ // Do not match partial flags
179
+ EXPECT_FALSE(
180
+ CpuFeatures_StringView_HasWord(str("first middle last"), "irst", ' '));
181
+ EXPECT_FALSE(
182
+ CpuFeatures_StringView_HasWord(str("first middle last"), "mid", ' '));
183
+ EXPECT_FALSE(
184
+ CpuFeatures_StringView_HasWord(str("first middle last"), "las", ' '));
185
+ }
186
+
187
+ TEST(StringViewTest, CpuFeatures_StringView_GetAttributeKeyValue) {
188
+ const StringView line = str(" key : first middle last ");
189
+ StringView key, value;
190
+ EXPECT_TRUE(CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value));
191
+ EXPECT_EQ(key, str("key"));
192
+ EXPECT_EQ(value, str("first middle last"));
193
+ }
194
+
195
+ TEST(StringViewTest, FailingGetAttributeKeyValue) {
196
+ const StringView line = str("key first middle last");
197
+ StringView key, value;
198
+ EXPECT_FALSE(CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value));
199
+ }
200
+
201
+ } // namespace
202
+ } // namespace cpu_features
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const binding = require('../build/Release/cpufeatures.node');
4
+
5
+ module.exports = binding.getCPUInfo;
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "cpu-features",
3
+ "version": "0.0.10",
4
+ "author": "Brian White <mscdex@mscdex.net>",
5
+ "description": "A simple binding to Google's cpu_features library for obtaining information about installed CPU(s)",
6
+ "main": "./lib/index",
7
+ "dependencies": {
8
+ "buildcheck": "~0.0.6",
9
+ "nan": "^2.19.0"
10
+ },
11
+ "devDependencies": {
12
+ "@mscdex/eslint-config": "^1.1.0",
13
+ "eslint": "^7.0.0"
14
+ },
15
+ "scripts": {
16
+ "install": "node buildcheck.js > buildcheck.gypi && node-gyp rebuild",
17
+ "test": "node test/test.js",
18
+ "lint": "eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js lib test",
19
+ "lint:fix": "npm run lint -- --fix"
20
+ },
21
+ "engines": {
22
+ "node": ">=10.0.0"
23
+ },
24
+ "keywords": [
25
+ "cpu",
26
+ "detect",
27
+ "detection",
28
+ "features"
29
+ ],
30
+ "licenses": [
31
+ {
32
+ "type": "MIT",
33
+ "url": "https://github.com/mscdex/cpu-features/raw/master/LICENSE"
34
+ }
35
+ ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/mscdex/cpu-features.git"
39
+ }
40
+ }