1 use std::ptr;
2 
main()3 fn main() {
4     big_poll();
5     big_string();
6     big_iovecs();
7 }
8 
big_string()9 fn big_string() {
10     let mut s = String::new();
11     for _ in 0..10_000 {
12         s.push_str("hello world");
13     }
14     let dir_fd = test_programs::preview1::open_scratch_directory(".").unwrap();
15     assert_eq!(
16         unsafe { wasip1::path_create_directory(dir_fd, &s) },
17         Err(wasip1::ERRNO_NOMEM)
18     );
19 }
20 
big_iovecs()21 fn big_iovecs() {
22     let mut iovs = Vec::new();
23     let mut ciovs = Vec::new();
24     for _ in 0..10_000 {
25         iovs.push(wasip1::Iovec {
26             buf: ptr::null_mut(),
27             buf_len: 0,
28         });
29         ciovs.push(wasip1::Ciovec {
30             buf: ptr::null(),
31             buf_len: 0,
32         });
33     }
34     let dir_fd = test_programs::preview1::open_scratch_directory(".").unwrap();
35     let fd = unsafe {
36         wasip1::path_open(
37             dir_fd,
38             0,
39             "hi",
40             wasip1::OFLAGS_CREAT,
41             wasip1::RIGHTS_FD_WRITE | wasip1::RIGHTS_FD_READ,
42             0,
43             0,
44         )
45         .unwrap()
46     };
47 
48     unsafe {
49         assert_eq!(wasip1::fd_write(fd, &ciovs), Err(wasip1::ERRNO_NOMEM));
50         assert_eq!(wasip1::fd_read(fd, &iovs), Err(wasip1::ERRNO_NOMEM));
51         assert_eq!(wasip1::fd_pwrite(fd, &ciovs, 0), Err(wasip1::ERRNO_NOMEM));
52         assert_eq!(wasip1::fd_pread(fd, &iovs, 0), Err(wasip1::ERRNO_NOMEM));
53     }
54 
55     ciovs.truncate(1);
56     iovs.truncate(1);
57     iovs.push(wasip1::Iovec {
58         buf: ptr::null_mut(),
59         buf_len: 10_000,
60     });
61     ciovs.push(wasip1::Ciovec {
62         buf: ptr::null(),
63         buf_len: 10_000,
64     });
65     unsafe {
66         assert_eq!(wasip1::fd_write(fd, &ciovs), Err(wasip1::ERRNO_NOMEM));
67         assert_eq!(wasip1::fd_read(fd, &iovs), Err(wasip1::ERRNO_NOMEM));
68         assert_eq!(wasip1::fd_pwrite(fd, &ciovs, 0), Err(wasip1::ERRNO_NOMEM));
69         assert_eq!(wasip1::fd_pread(fd, &iovs, 0), Err(wasip1::ERRNO_NOMEM));
70     }
71 }
72 
big_poll()73 fn big_poll() {
74     let mut huge_poll = Vec::new();
75     let mut huge_events = Vec::new();
76     for _ in 0..10_000 {
77         huge_poll.push(subscribe_timeout(0));
78         huge_events.push(empty_event());
79     }
80     let err = unsafe {
81         wasip1::poll_oneoff(
82             huge_poll.as_ptr(),
83             huge_events.as_mut_ptr(),
84             huge_poll.len(),
85         )
86         .unwrap_err()
87     };
88     assert_eq!(err, wasip1::ERRNO_NOMEM);
89 
90     fn subscribe_timeout(timeout: u64) -> wasip1::Subscription {
91         wasip1::Subscription {
92             userdata: 0,
93             u: wasip1::SubscriptionU {
94                 tag: wasip1::EVENTTYPE_CLOCK.raw(),
95                 u: wasip1::SubscriptionUU {
96                     clock: wasip1::SubscriptionClock {
97                         id: wasip1::CLOCKID_MONOTONIC,
98                         timeout,
99                         precision: 0,
100                         flags: 0,
101                     },
102                 },
103             },
104         }
105     }
106 
107     fn empty_event() -> wasip1::Event {
108         wasip1::Event {
109             error: wasip1::ERRNO_SUCCESS,
110             fd_readwrite: wasip1::EventFdReadwrite {
111                 nbytes: 0,
112                 flags: 0,
113             },
114             type_: wasip1::EVENTTYPE_CLOCK,
115             userdata: 0,
116         }
117     }
118 }
119