deno.land / x / deno@v1.28.2 / test_ffi / tests / integration_tests.rs

integration_tests.rs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use std::process::Command;use test_util::deno_cmd;
#[cfg(debug_assertions)]const BUILD_VARIANT: &str = "debug";
#[cfg(not(debug_assertions))]const BUILD_VARIANT: &str = "release";
fn build() { let mut build_plugin_base = Command::new("cargo"); let mut build_plugin = build_plugin_base.arg("build").arg("-p").arg("test_ffi"); if BUILD_VARIANT == "release" { build_plugin = build_plugin.arg("--release"); } let build_plugin_output = build_plugin.output().unwrap(); assert!(build_plugin_output.status.success());}
#[test]fn basic() { build();
let output = deno_cmd() .arg("run") .arg("--allow-ffi") .arg("--allow-read") .arg("--unstable") .arg("--quiet") .arg(r#"--v8-flags=--allow-natives-syntax"#) .arg("tests/test.js") .env("NO_COLOR", "1") .output() .unwrap(); let stdout = std::str::from_utf8(&output.stdout).unwrap(); let stderr = std::str::from_utf8(&output.stderr).unwrap(); if !output.status.success() { println!("stdout {}", stdout); println!("stderr {}", stderr); } println!("{:?}", output.status); assert!(output.status.success()); let expected = "\ something\n\ [1, 2, 3, 4, 5, 6, 7, 8]\n\ [4, 5, 6]\n\ [1, 2, 3, 4, 5, 6, 7, 8] [9, 10]\n\ [1, 2, 3, 4, 5, 6, 7, 8]\n\ [ 1, 2, 3, 4, 5, 6 ]\n\ [ 4, 5, 6 ]\n\ [ 4, 5, 6 ]\n\ Hello from pointer!\n\ pointer!\n\ false\n\ true\n\ false\n\ true\n\ false\n\ 579\n\ true\n\ 579\n\ 579\n\ 5\n\ 5\n\ 579\n\ 8589934590\n\ -8589934590\n\ 8589934590\n\ -8589934590\n\ 9007199254740992n\n\ 9007199254740992n\n\ -9007199254740992n\n\ 9007199254740992n\n\ 9007199254740992n\n\ -9007199254740992n\n\ 579.9119873046875\n\ 579.912\n\ true\n\ false\n\ 579.9119873046875\n\ 579.9119873046875\n\ 579.912\n\ 579.912\n\ 579\n\ 8589934590\n\ -8589934590\n\ 8589934590\n\ -8589934590\n\ 9007199254740992n\n\ 9007199254740992n\n\ -9007199254740992n\n\ 9007199254740992n\n\ 9007199254740992n\n\ -9007199254740992n\n\ 579.9119873046875\n\ 579.912\n\ After sleep_blocking\n\ true\n\ Before\n\ true\n\ After\n\ true\n\ logCallback\n\ 1 -1 2 -2 3 -3 4 -4 0.5 -0.5 1 2 3 4 5 6 7 8\n\ u8: 8\n\ buf: [1, 2, 3, 4, 5, 6, 7, 8]\n\ logCallback\n\ 30\n\ 255 65535 4294967295 4294967296 123.456 789.876 -1 -2 -3 -4 -1000 1000 12345.67891 12345.679 12345.67891 12345.679 12345.67891 12345.679 12345.67891\n\ 255 65535 4294967295 4294967296 123.456 789.876 -1 -2 -3 -4 -1000 1000 12345.67891 12345.679 12345.67891 12345.679 12345.67891 12345.679 12345.67891\n\ 0\n\ 0\n\ 0\n\ 0\n\ 78\n\ 78\n\ STORED_FUNCTION cleared\n\ STORED_FUNCTION_2 cleared\n\ Thread safe call counter: 0\n\ logCallback\n\ Thread safe call counter: 1\n\ u8: 8\n\ Static u32: 42\n\ Static i64: -1242464576485\n\ Static ptr: true\n\ Static ptr value: 42\n\ arrayBuffer.byteLength: 4\n\ uint32Array.length: 1\n\ uint32Array[0]: 42\n\ uint32Array[0] after mutation: 55\n\ Static ptr value after mutation: 55\n\ 2264956937\n\ 2264956937\n\ Correct number of resources\n"; assert_eq!(stdout, expected); assert_eq!(stderr, "");}
#[test]fn symbol_types() { build();
let output = deno_cmd() .arg("check") .arg("--unstable") .arg("--quiet") .arg("tests/ffi_types.ts") .env("NO_COLOR", "1") .output() .unwrap(); let stdout = std::str::from_utf8(&output.stdout).unwrap(); let stderr = std::str::from_utf8(&output.stderr).unwrap(); if !output.status.success() { println!("stdout {}", stdout); println!("stderr {}", stderr); } println!("{:?}", output.status); assert!(output.status.success()); assert_eq!(stderr, "");}
#[test]fn thread_safe_callback() { build();
let output = deno_cmd() .arg("run") .arg("--allow-ffi") .arg("--allow-read") .arg("--unstable") .arg("--quiet") .arg("tests/thread_safe_test.js") .env("NO_COLOR", "1") .output() .unwrap(); let stdout = std::str::from_utf8(&output.stdout).unwrap(); let stderr = std::str::from_utf8(&output.stderr).unwrap(); if !output.status.success() { println!("stdout {}", stdout); println!("stderr {}", stderr); } println!("{:?}", output.status); assert!(output.status.success()); let expected = "\ Callback on main thread\n\ Callback on worker thread\n\ Calling callback, isolate should stay asleep until callback is called\n\ Callback being called\n\ Isolate should now exit\n"; assert_eq!(stdout, expected); assert_eq!(stderr, "");}
#[test]fn event_loop_integration() { build();
let output = deno_cmd() .arg("run") .arg("--allow-ffi") .arg("--allow-read") .arg("--unstable") .arg("--quiet") .arg("tests/event_loop_integration.ts") .env("NO_COLOR", "1") .output() .unwrap(); let stdout = std::str::from_utf8(&output.stdout).unwrap(); let stderr = std::str::from_utf8(&output.stderr).unwrap(); if !output.status.success() { println!("stdout {}", stdout); println!("stderr {}", stderr); } println!("{:?}", output.status); assert!(output.status.success()); // TODO(aapoalas): The order of logging in thread safe callbacks is // unexpected: The callback logs synchronously and creates an asynchronous // logging task, which then gets called synchronously before the callback // actually yields to the calling thread. This is in contrast to what the // logging would look like if the call was coming from within Deno itself, // and may lead users to unknowingly run heavy asynchronous tasks from thread // safe callbacks synchronously. // The fix would be to make sure microtasks are only run after the event loop // middleware that polls them has completed its work. This just does not seem // to work properly with Linux release builds. let expected = "\ SYNCHRONOUS\n\ Sync\n\ STORED_FUNCTION called\n\ Async\n\ Timeout\n\ THREAD SAFE\n\ Sync\n\ Async\n\ STORED_FUNCTION called\n\ Timeout\n"; assert_eq!(stdout, expected); assert_eq!(stderr, "");}
deno

Version Info

Tagged at
a year ago