dsh-remote 0.8.91 → 0.8.93

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 (181) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +369 -368
  3. package/README.md +354 -353
  4. package/cordis.patch.yml +9 -9
  5. package/lib/audit.js +45 -45
  6. package/lib/binding.js +172 -172
  7. package/lib/client.js +4647 -4550
  8. package/lib/credential.js +270 -263
  9. package/lib/errors.js +141 -141
  10. package/lib/exec-job.js +242 -242
  11. package/lib/file-reference.js +457 -457
  12. package/lib/forwards.js +258 -258
  13. package/lib/host-api.js +822 -822
  14. package/lib/hostkey.js +108 -108
  15. package/lib/http-transport.js +201 -201
  16. package/lib/ignore.js +202 -202
  17. package/lib/index.js +4488 -4394
  18. package/lib/instructions-dynamic.js +415 -415
  19. package/lib/instructions.js +288 -288
  20. package/lib/open-folder.js +56 -56
  21. package/lib/openssh.js +940 -881
  22. package/lib/paths.js +292 -292
  23. package/lib/pool.js +1029 -970
  24. package/lib/posix-shell.cjs +34 -0
  25. package/lib/registry.js +296 -296
  26. package/lib/remote-fs.js +173 -173
  27. package/lib/remote-sandbox.js +183 -183
  28. package/lib/remote-shell-child.cjs +397 -400
  29. package/lib/remote-shell.js +697 -697
  30. package/lib/remote-skills.js +312 -0
  31. package/lib/routes-audit.js +58 -58
  32. package/lib/routes-forwards.js +72 -72
  33. package/lib/routes-fs.js +251 -245
  34. package/lib/routes-machines.js +186 -186
  35. package/lib/routes-misc.js +187 -150
  36. package/lib/routes-term.js +169 -169
  37. package/lib/routes-update.js +143 -143
  38. package/lib/routes-web-attach.js +112 -112
  39. package/lib/routes-workspace.js +312 -312
  40. package/lib/search.js +235 -235
  41. package/lib/sftp-surface.js +119 -119
  42. package/lib/sshconfig.js +779 -779
  43. package/lib/sync.js +350 -350
  44. package/lib/tasks.js +95 -95
  45. package/lib/telemetry.js +247 -247
  46. package/lib/terminal.js +205 -205
  47. package/lib/tui/flow.js +130 -130
  48. package/lib/tui/format.js +380 -380
  49. package/lib/tui/i18n.js +350 -350
  50. package/lib/tui/index.js +531 -531
  51. package/lib/tui/provider.js +344 -344
  52. package/lib/tui/scene.js +986 -986
  53. package/lib/update.js +490 -472
  54. package/lib/web-attach.js +860 -850
  55. package/lib/workspace-cleanup.js +337 -337
  56. package/package.json +103 -100
  57. package/node_modules/buildcheck/.eslintrc.js +0 -5
  58. package/node_modules/buildcheck/.github/workflows/ci.yml +0 -88
  59. package/node_modules/buildcheck/.github/workflows/lint.yml +0 -27
  60. package/node_modules/buildcheck/.npmignore +0 -3
  61. package/node_modules/buildcheck/LICENSE +0 -19
  62. package/node_modules/buildcheck/README.md +0 -106
  63. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +0 -250
  64. package/node_modules/buildcheck/lib/findvs.js +0 -361
  65. package/node_modules/buildcheck/lib/index.js +0 -738
  66. package/node_modules/buildcheck/package.json +0 -36
  67. package/node_modules/buildcheck/test/test.js +0 -8
  68. package/node_modules/cpu-features/.eslintrc.js +0 -5
  69. package/node_modules/cpu-features/.github/workflows/ci.yml +0 -74
  70. package/node_modules/cpu-features/.github/workflows/lint.yml +0 -27
  71. package/node_modules/cpu-features/LICENSE +0 -19
  72. package/node_modules/cpu-features/README.md +0 -59
  73. package/node_modules/cpu-features/binding.gyp +0 -16
  74. package/node_modules/cpu-features/buildcheck.js +0 -32
  75. package/node_modules/cpu-features/deps/cpu_features/.clang-format +0 -4
  76. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +0 -31
  77. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +0 -5
  78. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +0 -30
  79. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +0 -22
  80. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +0 -26
  81. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +0 -31
  82. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +0 -43
  83. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +0 -25
  84. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +0 -31
  85. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +0 -24
  86. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +0 -30
  87. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +0 -29
  88. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +0 -28
  89. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +0 -27
  90. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +0 -21
  91. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +0 -329
  92. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +0 -261
  93. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +0 -23
  94. package/node_modules/cpu-features/deps/cpu_features/LICENSE +0 -230
  95. package/node_modules/cpu-features/deps/cpu_features/README.md +0 -272
  96. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +0 -19
  97. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +0 -5
  98. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +0 -11
  99. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +0 -3
  100. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +0 -3
  101. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +0 -30
  102. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +0 -252
  103. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +0 -40
  104. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +0 -64
  105. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +0 -312
  106. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +0 -7
  107. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +0 -48
  108. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +0 -34
  109. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +0 -22
  110. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +0 -11
  111. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +0 -107
  112. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +0 -15
  113. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +0 -105
  114. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +0 -54
  115. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +0 -384
  116. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +0 -259
  117. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +0 -121
  118. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +0 -74
  119. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +0 -149
  120. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +0 -72
  121. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +0 -108
  122. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +0 -288
  123. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +0 -40
  124. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +0 -37
  125. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +0 -39
  126. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +0 -240
  127. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +0 -49
  128. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +0 -110
  129. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +0 -70
  130. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +0 -60
  131. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +0 -4
  132. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +0 -205
  133. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +0 -320
  134. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +0 -12
  135. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +0 -456
  136. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +0 -165
  137. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +0 -75
  138. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +0 -490
  139. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +0 -79
  140. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +0 -19
  141. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +0 -86
  142. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +0 -26
  143. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +0 -22
  144. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +0 -62
  145. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +0 -169
  146. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +0 -88
  147. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +0 -79
  148. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +0 -82
  149. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +0 -138
  150. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +0 -212
  151. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +0 -93
  152. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +0 -163
  153. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +0 -111
  154. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +0 -120
  155. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +0 -2055
  156. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +0 -68
  157. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +0 -58
  158. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +0 -57
  159. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +0 -58
  160. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +0 -132
  161. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +0 -192
  162. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +0 -461
  163. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +0 -114
  164. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +0 -53
  165. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +0 -396
  166. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +0 -384
  167. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +0 -176
  168. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +0 -131
  169. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +0 -180
  170. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +0 -82
  171. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +0 -1729
  172. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +0 -103
  173. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +0 -61
  174. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +0 -52
  175. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +0 -31
  176. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +0 -132
  177. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +0 -202
  178. package/node_modules/cpu-features/lib/index.js +0 -5
  179. package/node_modules/cpu-features/package.json +0 -40
  180. package/node_modules/cpu-features/src/binding.cc +0 -151
  181. package/node_modules/cpu-features/test/test.js +0 -12
@@ -1,461 +0,0 @@
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
- // This program dumps current host data to the standard output.
16
- // Output can be text or json if the `--json` flag is passed.
17
-
18
- #include <assert.h>
19
- #include <stdarg.h>
20
- #include <stdbool.h>
21
- #include <stdint.h>
22
- #include <stdio.h>
23
- #include <stdlib.h>
24
- #include <string.h>
25
-
26
- #include "cpu_features_macros.h"
27
-
28
- #if defined(CPU_FEATURES_ARCH_X86)
29
- #include "cpuinfo_x86.h"
30
- #elif defined(CPU_FEATURES_ARCH_ARM)
31
- #include "cpuinfo_arm.h"
32
- #elif defined(CPU_FEATURES_ARCH_AARCH64)
33
- #include "cpuinfo_aarch64.h"
34
- #elif defined(CPU_FEATURES_ARCH_MIPS)
35
- #include "cpuinfo_mips.h"
36
- #elif defined(CPU_FEATURES_ARCH_PPC)
37
- #include "cpuinfo_ppc.h"
38
- #elif defined(CPU_FEATURES_ARCH_S390X)
39
- #include "cpuinfo_s390x.h"
40
- #elif defined(CPU_FEATURES_ARCH_RISCV)
41
- #include "cpuinfo_riscv.h"
42
- #endif
43
-
44
- // Design principles
45
- // -----------------
46
- // We build a tree structure containing all the data to be displayed.
47
- // Then depending on the output type (text or json) we walk the tree and display
48
- // the data accordingly.
49
-
50
- // We use a bump allocator to allocate strings and nodes of the tree,
51
- // Memory is not intended to be reclaimed.
52
- typedef struct {
53
- char* ptr;
54
- size_t size;
55
- } BumpAllocator;
56
-
57
- char gGlobalBuffer[64 * 1024];
58
- BumpAllocator gBumpAllocator = {.ptr = gGlobalBuffer,
59
- .size = sizeof(gGlobalBuffer)};
60
-
61
- static void internal_error(void) {
62
- fputs("internal error\n", stderr);
63
- exit(EXIT_FAILURE);
64
- }
65
-
66
- #define ALIGN 8
67
-
68
- static void assertAligned(void) {
69
- if ((uintptr_t)(gBumpAllocator.ptr) % ALIGN) internal_error();
70
- }
71
-
72
- static void BA_Align(void) {
73
- while (gBumpAllocator.size && (uintptr_t)(gBumpAllocator.ptr) % ALIGN) {
74
- --gBumpAllocator.size;
75
- ++gBumpAllocator.ptr;
76
- }
77
- assertAligned();
78
- }
79
-
80
- // Update the available memory left in the BumpAllocator.
81
- static void* BA_Bump(size_t size) {
82
- assertAligned();
83
- // Align size to next 8B boundary.
84
- size = (size + ALIGN - 1) / ALIGN * ALIGN;
85
- if (gBumpAllocator.size < size) internal_error();
86
- void* ptr = gBumpAllocator.ptr;
87
- gBumpAllocator.size -= size;
88
- gBumpAllocator.ptr += size;
89
- return ptr;
90
- }
91
-
92
- // The type of the nodes in the tree.
93
- typedef enum {
94
- NT_INVALID,
95
- NT_INT,
96
- NT_MAP,
97
- NT_MAP_ENTRY,
98
- NT_ARRAY,
99
- NT_ARRAY_ELEMENT,
100
- NT_STRING,
101
- } NodeType;
102
-
103
- // The node in the tree.
104
- typedef struct Node {
105
- NodeType type;
106
- unsigned integer;
107
- const char* string;
108
- struct Node* value;
109
- struct Node* next;
110
- } Node;
111
-
112
- // Creates an initialized Node.
113
- static Node* BA_CreateNode(NodeType type) {
114
- Node* tv = (Node*)BA_Bump(sizeof(Node));
115
- assert(tv);
116
- *tv = (Node){.type = type};
117
- return tv;
118
- }
119
-
120
- // Adds an integer node.
121
- static Node* CreateInt(int value) {
122
- Node* tv = BA_CreateNode(NT_INT);
123
- tv->integer = value;
124
- return tv;
125
- }
126
-
127
- // Adds a string node.
128
- // `value` must outlive the tree.
129
- static Node* CreateConstantString(const char* value) {
130
- Node* tv = BA_CreateNode(NT_STRING);
131
- tv->string = value;
132
- return tv;
133
- }
134
-
135
- // Adds a map node.
136
- static Node* CreateMap(void) { return BA_CreateNode(NT_MAP); }
137
-
138
- // Adds an array node.
139
- static Node* CreateArray(void) { return BA_CreateNode(NT_ARRAY); }
140
-
141
- // Adds a formatted string node.
142
- static Node* CreatePrintfString(const char* format, ...) {
143
- va_list arglist;
144
- va_start(arglist, format);
145
- char* const ptr = gBumpAllocator.ptr;
146
- const int written = vsnprintf(ptr, gBumpAllocator.size, format, arglist);
147
- va_end(arglist);
148
- if (written < 0 || written >= (int)gBumpAllocator.size) internal_error();
149
- return CreateConstantString((char*)BA_Bump(written));
150
- }
151
-
152
- // Adds a string node.
153
- static Node* CreateString(const char* value) {
154
- return CreatePrintfString("%s", value);
155
- }
156
-
157
- // Adds a map entry node.
158
- static void AddMapEntry(Node* map, const char* key, Node* value) {
159
- assert(map && map->type == NT_MAP);
160
- Node* current = map;
161
- while (current->next) current = current->next;
162
- current->next = (Node*)BA_Bump(sizeof(Node));
163
- *current->next = (Node){.type = NT_MAP_ENTRY, .string = key, .value = value};
164
- }
165
-
166
- // Adds an array element node.
167
- static void AddArrayElement(Node* array, Node* value) {
168
- assert(array && array->type == NT_ARRAY);
169
- Node* current = array;
170
- while (current->next) current = current->next;
171
- current->next = (Node*)BA_Bump(sizeof(Node));
172
- *current->next = (Node){.type = NT_ARRAY_ELEMENT, .value = value};
173
- }
174
-
175
- static int cmp(const void* p1, const void* p2) {
176
- return strcmp(*(const char* const*)p1, *(const char* const*)p2);
177
- }
178
-
179
- #define DEFINE_ADD_FLAGS(HasFeature, FeatureName, FeatureType, LastEnum) \
180
- static void AddFlags(Node* map, const FeatureType* features) { \
181
- size_t i; \
182
- const char* ptrs[LastEnum] = {0}; \
183
- size_t count = 0; \
184
- for (i = 0; i < LastEnum; ++i) { \
185
- if (HasFeature(features, i)) { \
186
- ptrs[count] = FeatureName(i); \
187
- ++count; \
188
- } \
189
- } \
190
- qsort((void*)ptrs, count, sizeof(char*), cmp); \
191
- Node* const array = CreateArray(); \
192
- for (i = 0; i < count; ++i) \
193
- AddArrayElement(array, CreateConstantString(ptrs[i])); \
194
- AddMapEntry(map, "flags", array); \
195
- }
196
-
197
- #if defined(CPU_FEATURES_ARCH_X86)
198
- DEFINE_ADD_FLAGS(GetX86FeaturesEnumValue, GetX86FeaturesEnumName, X86Features,
199
- X86_LAST_)
200
- #elif defined(CPU_FEATURES_ARCH_ARM)
201
- DEFINE_ADD_FLAGS(GetArmFeaturesEnumValue, GetArmFeaturesEnumName, ArmFeatures,
202
- ARM_LAST_)
203
- #elif defined(CPU_FEATURES_ARCH_AARCH64)
204
- DEFINE_ADD_FLAGS(GetAarch64FeaturesEnumValue, GetAarch64FeaturesEnumName,
205
- Aarch64Features, AARCH64_LAST_)
206
- #elif defined(CPU_FEATURES_ARCH_MIPS)
207
- DEFINE_ADD_FLAGS(GetMipsFeaturesEnumValue, GetMipsFeaturesEnumName,
208
- MipsFeatures, MIPS_LAST_)
209
- #elif defined(CPU_FEATURES_ARCH_PPC)
210
- DEFINE_ADD_FLAGS(GetPPCFeaturesEnumValue, GetPPCFeaturesEnumName, PPCFeatures,
211
- PPC_LAST_)
212
- #elif defined(CPU_FEATURES_ARCH_S390X)
213
- DEFINE_ADD_FLAGS(GetS390XFeaturesEnumValue, GetS390XFeaturesEnumName, S390XFeatures,
214
- S390X_LAST_)
215
- #elif defined(CPU_FEATURES_ARCH_RISCV)
216
- DEFINE_ADD_FLAGS(GetRiscvFeaturesEnumValue, GetRiscvFeaturesEnumName, RiscvFeatures,
217
- RISCV_LAST_)
218
- #endif
219
-
220
- // Prints a json string with characters escaping.
221
- static void printJsonString(const char* str) {
222
- putchar('"');
223
- for (; str && *str; ++str) {
224
- switch (*str) {
225
- case '\"':
226
- case '\\':
227
- case '/':
228
- case '\b':
229
- case '\f':
230
- case '\n':
231
- case '\r':
232
- case '\t':
233
- putchar('\\');
234
- }
235
- putchar(*str);
236
- }
237
- putchar('"');
238
- }
239
-
240
- // Walks a Node and print it as json.
241
- static void printJson(const Node* current) {
242
- assert(current);
243
- switch (current->type) {
244
- case NT_INVALID:
245
- break;
246
- case NT_INT:
247
- printf("%d", current->integer);
248
- break;
249
- case NT_STRING:
250
- printJsonString(current->string);
251
- break;
252
- case NT_ARRAY:
253
- putchar('[');
254
- if (current->next) printJson(current->next);
255
- putchar(']');
256
- break;
257
- case NT_MAP:
258
- putchar('{');
259
- if (current->next) printJson(current->next);
260
- putchar('}');
261
- break;
262
- case NT_MAP_ENTRY:
263
- printf("\"%s\":", current->string);
264
- printJson(current->value);
265
- if (current->next) {
266
- putchar(',');
267
- printJson(current->next);
268
- }
269
- break;
270
- case NT_ARRAY_ELEMENT:
271
- printJson(current->value);
272
- if (current->next) {
273
- putchar(',');
274
- printJson(current->next);
275
- }
276
- break;
277
- }
278
- }
279
-
280
- // Walks a Node and print it as text.
281
- static void printTextField(const Node* current) {
282
- switch (current->type) {
283
- case NT_INVALID:
284
- break;
285
- case NT_INT:
286
- printf("%3d (0x%02X)", current->integer, current->integer);
287
- break;
288
- case NT_STRING:
289
- fputs(current->string, stdout);
290
- break;
291
- case NT_ARRAY:
292
- if (current->next) printTextField(current->next);
293
- break;
294
- case NT_MAP:
295
- if (current->next) {
296
- printf("{");
297
- printJson(current->next);
298
- printf("}");
299
- }
300
- break;
301
- case NT_MAP_ENTRY:
302
- printf("%-15s : ", current->string);
303
- printTextField(current->value);
304
- if (current->next) {
305
- putchar('\n');
306
- printTextField(current->next);
307
- }
308
- break;
309
- case NT_ARRAY_ELEMENT:
310
- printTextField(current->value);
311
- if (current->next) {
312
- putchar(',');
313
- printTextField(current->next);
314
- }
315
- break;
316
- }
317
- }
318
-
319
- static void printTextRoot(const Node* current) {
320
- if (current->type == NT_MAP && current->next) printTextField(current->next);
321
- }
322
-
323
- static void showUsage(const char* name) {
324
- printf(
325
- "\n"
326
- "Usage: %s [options]\n"
327
- " Options:\n"
328
- " -h | --help Show help message.\n"
329
- " -j | --json Format output as json instead of plain text.\n"
330
- "\n",
331
- name);
332
- }
333
-
334
- static Node* GetCacheTypeString(CacheType cache_type) {
335
- switch (cache_type) {
336
- case CPU_FEATURE_CACHE_NULL:
337
- return CreateConstantString("null");
338
- case CPU_FEATURE_CACHE_DATA:
339
- return CreateConstantString("data");
340
- case CPU_FEATURE_CACHE_INSTRUCTION:
341
- return CreateConstantString("instruction");
342
- case CPU_FEATURE_CACHE_UNIFIED:
343
- return CreateConstantString("unified");
344
- case CPU_FEATURE_CACHE_TLB:
345
- return CreateConstantString("tlb");
346
- case CPU_FEATURE_CACHE_DTLB:
347
- return CreateConstantString("dtlb");
348
- case CPU_FEATURE_CACHE_STLB:
349
- return CreateConstantString("stlb");
350
- case CPU_FEATURE_CACHE_PREFETCH:
351
- return CreateConstantString("prefetch");
352
- }
353
- CPU_FEATURES_UNREACHABLE();
354
- }
355
-
356
- static void AddCacheInfo(Node* root, const CacheInfo* cache_info) {
357
- Node* array = CreateArray();
358
- for (int i = 0; i < cache_info->size; ++i) {
359
- CacheLevelInfo info = cache_info->levels[i];
360
- Node* map = CreateMap();
361
- AddMapEntry(map, "level", CreateInt(info.level));
362
- AddMapEntry(map, "cache_type", GetCacheTypeString(info.cache_type));
363
- AddMapEntry(map, "cache_size", CreateInt(info.cache_size));
364
- AddMapEntry(map, "ways", CreateInt(info.ways));
365
- AddMapEntry(map, "line_size", CreateInt(info.line_size));
366
- AddMapEntry(map, "tlb_entries", CreateInt(info.tlb_entries));
367
- AddMapEntry(map, "partitioning", CreateInt(info.partitioning));
368
- AddArrayElement(array, map);
369
- }
370
- AddMapEntry(root, "cache_info", array);
371
- }
372
-
373
- static Node* CreateTree(void) {
374
- Node* root = CreateMap();
375
- #if defined(CPU_FEATURES_ARCH_X86)
376
- const X86Info info = GetX86Info();
377
- const CacheInfo cache_info = GetX86CacheInfo();
378
- AddMapEntry(root, "arch", CreateString("x86"));
379
- AddMapEntry(root, "brand", CreateString(info.brand_string));
380
- AddMapEntry(root, "family", CreateInt(info.family));
381
- AddMapEntry(root, "model", CreateInt(info.model));
382
- AddMapEntry(root, "stepping", CreateInt(info.stepping));
383
- AddMapEntry(root, "uarch",
384
- CreateString(
385
- GetX86MicroarchitectureName(GetX86Microarchitecture(&info))));
386
- AddFlags(root, &info.features);
387
- AddCacheInfo(root, &cache_info);
388
- #elif defined(CPU_FEATURES_ARCH_ARM)
389
- const ArmInfo info = GetArmInfo();
390
- AddMapEntry(root, "arch", CreateString("ARM"));
391
- AddMapEntry(root, "implementer", CreateInt(info.implementer));
392
- AddMapEntry(root, "architecture", CreateInt(info.architecture));
393
- AddMapEntry(root, "variant", CreateInt(info.variant));
394
- AddMapEntry(root, "part", CreateInt(info.part));
395
- AddMapEntry(root, "revision", CreateInt(info.revision));
396
- AddFlags(root, &info.features);
397
- #elif defined(CPU_FEATURES_ARCH_AARCH64)
398
- const Aarch64Info info = GetAarch64Info();
399
- AddMapEntry(root, "arch", CreateString("aarch64"));
400
- AddMapEntry(root, "implementer", CreateInt(info.implementer));
401
- AddMapEntry(root, "variant", CreateInt(info.variant));
402
- AddMapEntry(root, "part", CreateInt(info.part));
403
- AddMapEntry(root, "revision", CreateInt(info.revision));
404
- AddFlags(root, &info.features);
405
- #elif defined(CPU_FEATURES_ARCH_MIPS)
406
- const MipsInfo info = GetMipsInfo();
407
- AddMapEntry(root, "arch", CreateString("mips"));
408
- AddFlags(root, &info.features);
409
- #elif defined(CPU_FEATURES_ARCH_PPC)
410
- const PPCInfo info = GetPPCInfo();
411
- const PPCPlatformStrings strings = GetPPCPlatformStrings();
412
- AddMapEntry(root, "arch", CreateString("ppc"));
413
- AddMapEntry(root, "platform", CreateString(strings.platform));
414
- AddMapEntry(root, "model", CreateString(strings.model));
415
- AddMapEntry(root, "machine", CreateString(strings.machine));
416
- AddMapEntry(root, "cpu", CreateString(strings.cpu));
417
- AddMapEntry(root, "instruction", CreateString(strings.type.platform));
418
- AddMapEntry(root, "microarchitecture",
419
- CreateString(strings.type.base_platform));
420
- AddFlags(root, &info.features);
421
- #elif defined(CPU_FEATURES_ARCH_S390X)
422
- const S390XInfo info = GetS390XInfo();
423
- const S390XPlatformStrings strings = GetS390XPlatformStrings();
424
- AddMapEntry(root, "arch", CreateString("s390x"));
425
- AddMapEntry(root, "platform", CreateString("zSeries"));
426
- AddMapEntry(root, "model", CreateString(strings.type.platform));
427
- AddMapEntry(root, "# processors", CreateInt(strings.num_processors));
428
- AddFlags(root, &info.features);
429
- #elif defined(CPU_FEATURES_ARCH_RISCV)
430
- const RiscvInfo info = GetRiscvInfo();
431
- AddMapEntry(root, "arch", CreateString("risc-v"));
432
- AddMapEntry(root, "vendor", CreateString(info.vendor));
433
- AddMapEntry(root, "microarchitecture", CreateString(info.uarch));
434
- AddFlags(root, &info.features);
435
- #endif
436
- return root;
437
- }
438
-
439
- int main(int argc, char** argv) {
440
- BA_Align();
441
- const Node* const root = CreateTree();
442
- bool outputJson = false;
443
- int i = 1;
444
- for (; i < argc; ++i) {
445
- const char* arg = argv[i];
446
- if (strcmp(arg, "-j") == 0 || strcmp(arg, "--json") == 0) {
447
- outputJson = true;
448
- } else {
449
- showUsage(argv[0]);
450
- if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)
451
- return EXIT_SUCCESS;
452
- return EXIT_FAILURE;
453
- }
454
- }
455
- if (outputJson)
456
- printJson(root);
457
- else
458
- printTextRoot(root);
459
- putchar('\n');
460
- return EXIT_SUCCESS;
461
- }
@@ -1,114 +0,0 @@
1
- #
2
- # libraries for tests
3
- #
4
-
5
- include_directories(../include)
6
- add_definitions(-DCPU_FEATURES_TEST)
7
-
8
- ##------------------------------------------------------------------------------
9
- add_library(string_view ../src/string_view.c)
10
- ##------------------------------------------------------------------------------
11
- add_library(filesystem_for_testing filesystem_for_testing.cc)
12
- target_compile_definitions(filesystem_for_testing PUBLIC CPU_FEATURES_MOCK_FILESYSTEM)
13
- ##------------------------------------------------------------------------------
14
- add_library(hwcaps_for_testing hwcaps_for_testing.cc)
15
- target_link_libraries(hwcaps_for_testing filesystem_for_testing)
16
- ##------------------------------------------------------------------------------
17
- add_library(stack_line_reader ../src/stack_line_reader.c)
18
- target_compile_definitions(stack_line_reader PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024)
19
- target_link_libraries(stack_line_reader string_view)
20
- ##------------------------------------------------------------------------------
21
- add_library(stack_line_reader_for_test ../src/stack_line_reader.c)
22
- target_compile_definitions(stack_line_reader_for_test PUBLIC STACK_LINE_READER_BUFFER_SIZE=16)
23
- target_link_libraries(stack_line_reader_for_test string_view filesystem_for_testing)
24
- ##------------------------------------------------------------------------------
25
- add_library(all_libraries ../src/hwcaps.c ../src/stack_line_reader.c)
26
- target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view)
27
-
28
- #
29
- # tests
30
- #
31
- link_libraries(gtest gmock_main)
32
-
33
- ## bit_utils_test
34
- add_executable(bit_utils_test bit_utils_test.cc)
35
- target_link_libraries(bit_utils_test)
36
- add_test(NAME bit_utils_test COMMAND bit_utils_test)
37
- ##------------------------------------------------------------------------------
38
- ## string_view_test
39
- add_executable(string_view_test string_view_test.cc ../src/string_view.c)
40
- target_link_libraries(string_view_test string_view)
41
- add_test(NAME string_view_test COMMAND string_view_test)
42
- ##------------------------------------------------------------------------------
43
- ## stack_line_reader_test
44
- add_executable(stack_line_reader_test stack_line_reader_test.cc)
45
- target_link_libraries(stack_line_reader_test stack_line_reader_for_test)
46
- add_test(NAME stack_line_reader_test COMMAND stack_line_reader_test)
47
- ##------------------------------------------------------------------------------
48
- ## cpuinfo_x86_test
49
- if(PROCESSOR_IS_X86)
50
- add_executable(cpuinfo_x86_test
51
- cpuinfo_x86_test.cc
52
- ../src/impl_x86_freebsd.c
53
- ../src/impl_x86_linux_or_android.c
54
- ../src/impl_x86_macos.c
55
- ../src/impl_x86_windows.c
56
- )
57
- target_compile_definitions(cpuinfo_x86_test PUBLIC CPU_FEATURES_MOCK_CPUID_X86)
58
- if(APPLE)
59
- target_compile_definitions(cpuinfo_x86_test PRIVATE HAVE_SYSCTLBYNAME)
60
- endif()
61
- target_link_libraries(cpuinfo_x86_test all_libraries)
62
- add_test(NAME cpuinfo_x86_test COMMAND cpuinfo_x86_test)
63
- endif()
64
- ##------------------------------------------------------------------------------
65
- ## cpuinfo_arm_test
66
- if(PROCESSOR_IS_ARM)
67
- add_executable(cpuinfo_arm_test cpuinfo_arm_test.cc ../src/impl_arm_linux_or_android.c)
68
- target_link_libraries(cpuinfo_arm_test all_libraries)
69
- add_test(NAME cpuinfo_arm_test COMMAND cpuinfo_arm_test)
70
- endif()
71
- ##------------------------------------------------------------------------------
72
- ## cpuinfo_aarch64_test
73
- if(PROCESSOR_IS_AARCH64)
74
- add_executable(cpuinfo_aarch64_test
75
- cpuinfo_aarch64_test.cc
76
- ../src/impl_aarch64_linux_or_android.c
77
- ../src/impl_aarch64_macos_or_iphone.c
78
- ../src/impl_aarch64_windows.c)
79
- if(APPLE)
80
- target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_SYSCTL_AARCH64)
81
- target_compile_definitions(cpuinfo_aarch64_test PRIVATE HAVE_SYSCTLBYNAME)
82
- endif()
83
- target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_CPUID_AARCH64)
84
- target_link_libraries(cpuinfo_aarch64_test all_libraries)
85
- add_test(NAME cpuinfo_aarch64_test COMMAND cpuinfo_aarch64_test)
86
- endif()
87
- ##------------------------------------------------------------------------------
88
- ## cpuinfo_mips_test
89
- if(PROCESSOR_IS_MIPS)
90
- add_executable(cpuinfo_mips_test cpuinfo_mips_test.cc ../src/impl_mips_linux_or_android.c)
91
- target_link_libraries(cpuinfo_mips_test all_libraries)
92
- add_test(NAME cpuinfo_mips_test COMMAND cpuinfo_mips_test)
93
- endif()
94
- ##------------------------------------------------------------------------------
95
- ## cpuinfo_ppc_test
96
- if(PROCESSOR_IS_POWER)
97
- add_executable(cpuinfo_ppc_test cpuinfo_ppc_test.cc ../src/impl_ppc_linux.c)
98
- target_link_libraries(cpuinfo_ppc_test all_libraries)
99
- add_test(NAME cpuinfo_ppc_test COMMAND cpuinfo_ppc_test)
100
- endif()
101
- ##------------------------------------------------------------------------------
102
- ## cpuinfo_s390x_test
103
- if(PROCESSOR_IS_S390X)
104
- add_executable(cpuinfo_s390x_test cpuinfo_s390x_test.cc ../src/impl_s390x_linux.c)
105
- target_link_libraries(cpuinfo_s390x_test all_libraries)
106
- add_test(NAME cpuinfo_s390x_test COMMAND cpuinfo_s390x_test)
107
- endif()
108
- ##------------------------------------------------------------------------------
109
- ## cpuinfo_riscv_test
110
- if(PROCESSOR_IS_RISCV)
111
- add_executable(cpuinfo_riscv_test cpuinfo_riscv_test.cc ../src/impl_riscv_linux.c)
112
- target_link_libraries(cpuinfo_riscv_test all_libraries)
113
- add_test(NAME cpuinfo_riscv_test COMMAND cpuinfo_riscv_test)
114
- endif()
@@ -1,53 +0,0 @@
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/bit_utils.h"
16
-
17
- #include "gtest/gtest.h"
18
-
19
- namespace cpu_features {
20
- namespace {
21
-
22
- TEST(UtilsTest, IsBitSet) {
23
- for (size_t bit_set = 0; bit_set < 32; ++bit_set) {
24
- const uint32_t value = 1UL << bit_set;
25
- for (uint32_t i = 0; i < 32; ++i) {
26
- EXPECT_EQ(IsBitSet(value, i), i == bit_set);
27
- }
28
- }
29
-
30
- // testing 0, all bits should be 0.
31
- for (uint32_t i = 0; i < 32; ++i) {
32
- EXPECT_FALSE(IsBitSet(0, i));
33
- }
34
-
35
- // testing ~0, all bits should be 1.
36
- for (uint32_t i = 0; i < 32; ++i) {
37
- EXPECT_TRUE(IsBitSet(-1, i));
38
- }
39
- }
40
-
41
- TEST(UtilsTest, ExtractBitRange) {
42
- // Extracting all bits gives the same number.
43
- EXPECT_EQ(ExtractBitRange(123, 31, 0), 123);
44
- // Extracting 1 bit gives parity.
45
- EXPECT_EQ(ExtractBitRange(123, 0, 0), 1);
46
- EXPECT_EQ(ExtractBitRange(122, 0, 0), 0);
47
-
48
- EXPECT_EQ(ExtractBitRange(0xF0, 7, 4), 0xF);
49
- EXPECT_EQ(ExtractBitRange(0x42 << 2, 10, 2), 0x42);
50
- }
51
-
52
- } // namespace
53
- } // namespace cpu_features