| 1 | module scheme |
| 2 | |
| 3 | import arena |
| 4 | import os |
| 5 | |
| 6 | fn nested_first_goops_use(mut instance BoundedVM, alternate bool) !Value { |
| 7 | if alternate { return instance.eval_alt('class-name(class-of(1))') } |
| 8 | return instance.eval('(class-name (class-of 1))') |
| 9 | } |
| 10 | |
| 11 | fn test_nested_first_goops_denial_quarantines_both_frontends_and_closes_owned_files() { |
| 12 | for alternate in [false, true] { |
| 13 | path := os.join_path(os.temp_dir(), 'vile-goops-nested428-${os.getpid()}-${alternate}.txt') |
| 14 | defer { os.rm(path) or {} } |
| 15 | mut instance := new_bounded(Options{max_open_files: 1}, arena.ChunkLimits{max_live_bytes: 512 * 1024}) or { panic(err) } |
| 16 | defer { instance.close() or { panic(err) } } |
| 17 | instance.eval('(define sink (open-output-file "${path}"))') or { panic(err) } |
| 18 | assert instance.vm.goops.deferred |
| 19 | stream := instance.files.head.stream |
| 20 | assert stream.file.is_opened |
| 21 | if _ := nested_first_goops_use(mut instance, alternate) { |
| 22 | panic('GOOPS initialization exceeded its hard budget') |
| 23 | } else { |
| 24 | assert err is ResourceLimitRequest |
| 25 | if err is ResourceLimitRequest { assert err.kind == .vm_chunk_bytes } |
| 26 | } |
| 27 | assert instance.vm.goops.bootstrap_failed && !instance.vm.goops.starting |
| 28 | assert instance.state == .failed && !stream.file.is_opened && isnil(instance.files.head) |
| 29 | if _ := instance.eval('42') { panic('reused partial nested bootstrap metadata') } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn test_host_publication_first_goops_denial_disables_further_bounded_callbacks() { |
| 34 | mut instance := new_bounded(Options{}, arena.ChunkLimits{max_live_bytes: 256 * 1024}) or { panic(err) } |
| 35 | defer { instance.close() or { panic(err) } } |
| 36 | assert instance.vm.goops.deferred |
| 37 | if _ := instance.run(fn (mut vm VM) !Value { |
| 38 | vm.define('class-of', integer(7))! |
| 39 | return unspecified() |
| 40 | }) { |
| 41 | panic('host publication exceeded its hard GOOPS initialization budget') |
| 42 | } else { |
| 43 | assert err is ResourceLimitRequest |
| 44 | if err is ResourceLimitRequest { assert err.kind == .vm_chunk_bytes } |
| 45 | } |
| 46 | assert instance.vm.goops.bootstrap_failed && !instance.vm.goops.starting |
| 47 | if _ := instance.run(fn (mut _vm VM) !Value { return integer(7) }) { |
| 48 | panic('host callback ran on a partially initialized bounded VM') |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | fn test_handled_publication_error_still_reports_bootstrap_exhaustion_to_the_handle() { |
| 53 | mut instance := new_bounded(Options{}, arena.ChunkLimits{max_live_bytes: 256 * 1024}) or { panic(err) } |
| 54 | defer { instance.close() or { panic(err) } } |
| 55 | if _ := instance.run(fn (mut vm VM) !Value { |
| 56 | vm.define('class-of', integer(7)) or {} |
| 57 | return integer(99) |
| 58 | }) { |
| 59 | panic('handled error concealed an interrupted GOOPS bootstrap') |
| 60 | } else { |
| 61 | assert err is ResourceLimitRequest |
| 62 | if err is ResourceLimitRequest { assert err.kind == .vm_chunk_bytes } |
| 63 | } |
| 64 | assert instance.state == .failed |
| 65 | if _ := instance.run(fn (mut _vm VM) !Value { return integer(7) }) { |
| 66 | panic('host callback ran after handled bootstrap exhaustion') |
| 67 | } |
| 68 | } |
| 69 | |