TestVM_ProfileOperations tests the profiling opcodes
(t *testing.T)
| 535 | |
| 536 | // TestVM_ProfileOperations tests the profiling opcodes |
| 537 | func TestVM_ProfileOperations(t *testing.T) { |
| 538 | program := &vm.Program{ |
| 539 | Bytecode: []vm.Opcode{ |
| 540 | vm.OpProfileStart, |
| 541 | vm.OpPush, |
| 542 | vm.OpCall, |
| 543 | vm.OpProfileEnd, |
| 544 | }, |
| 545 | Arguments: []int{0, 1, 0, 0}, |
| 546 | Constants: []any{ |
| 547 | &vm.Span{}, |
| 548 | func() (any, error) { |
| 549 | time.Sleep(time.Millisecond * 10) |
| 550 | return nil, nil |
| 551 | }, |
| 552 | }, |
| 553 | } |
| 554 | |
| 555 | testVM := &vm.VM{} |
| 556 | _, err := testVM.Run(program, nil) |
| 557 | require.NoError(t, err) |
| 558 | |
| 559 | span := program.Constants[0].(*vm.Span) |
| 560 | require.Greater(t, span.Duration, time.Millisecond) |
| 561 | } |
| 562 | |
| 563 | // TestVM_IndexOperations tests the index manipulation opcodes |
| 564 | func TestVM_IndexOperations(t *testing.T) { |