Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockVM #99

Closed
qinsoon opened this issue Jun 5, 2020 · 3 comments · Fixed by #1049
Closed

MockVM #99

qinsoon opened this issue Jun 5, 2020 · 3 comments · Fixed by #1049
Labels
A-test Area: Testing C-enhancement Category: Enhancement F-project Call For Participation: Student projects. These issues are available student projects.

Comments

@qinsoon
Copy link
Member

qinsoon commented Jun 5, 2020

For testing, we include a DummyVM in the mmtk-core repo. We should rename it to MockVM to properly reflect its usage. And we should allow proper mocking for testing.

@qinsoon
Copy link
Member Author

qinsoon commented Sep 30, 2020

Here is a list of mock libraries in Rust: https://asomers.github.io/mock_shootout/

With some attempts, here are some of my opinions:

  • We need these features from a mocking library (based on the current implementation):
    • mocking associated types
    • mocking static methods in trait
    • mocking generic methods
  • We probably need to manually implement mock types. Auto generation of mock types seems fragile and does not cover some edge cases. For example, mockall cannot auto generate mocks for us, due to some unsupported Rust syntaxes.

@qinsoon qinsoon removed this from the v0.2 milestone Nov 9, 2020
@steveblackburn steveblackburn added the F-project Call For Participation: Student projects. These issues are available student projects. label Feb 22, 2021
wenyuzhao pushed a commit to wenyuzhao/mmtk-core that referenced this issue Sep 14, 2021
* Bump version to v0.6

* Update changelog
@qinsoon
Copy link
Member Author

qinsoon commented Apr 20, 2022

We have gradually added some tests to DummyVM to MMTk core: https://github.com/mmtk/mmtk-core/tree/master/vmbindings/dummyvm/src/tests

We would at some point refactor DummyVM into a proper MockVM. Specifically, we need to be able to define the MockVM's behavior per each test.

For example, currently, when a GC is triggered for a DummyVM, we simply panic.

panic!("block_for_gc is not implemented")

In the test in which we expect a GC to be triggered, we check if the test panics
#[should_panic(expected = "block_for_gc is not implemented")]

and in the test in which we expect no GC to be triggered, we simply see if the test passes without panic
pub fn allocate_with_disable_collection() {

The panic behavior of block_for_gc() makes it impossible for us to use the binding for any GC test, as it will panic whenever a GC is triggered. We would expect that MockVM would allow us to define block_for_gc() per each test case.

The simplest approach is to use function pointers. MockVM forwards each call to a separate function pointer, and the function pointer initially points to a default implementation. Each test can create their own function, and update the function pointer for certain API calls.

@wks @KipHamiltons

@wks
Copy link
Collaborator

wks commented Apr 20, 2022

I have another example.

I want my is_mmtk_object feature to work for different VMs. The offsets from the allocated address and the object reference is different among VMs, So I want my test cases to control the behaviour of ObjectModel::object_start_ref of a VM.

github-merge-queue bot pushed a commit that referenced this issue Dec 18, 2023
This PR introduces `MockVM`, a type that implements `VMBinding` and
allows users to control the behavior of each method for testing. This PR
also moves all the tests in the current `DummyVM` to `MockVM`, and
removes the current `DummyVM`.

This PR closes #99. Note that
the current `MockVM` implementation does not allow changing constants or
associated types in `VMBinding` -- I would suggest we create another
issue to track this problem.

Changes:
* Introduce `MockVM`, and write all the current `DummyVM` tests with
`MockVM`.
* Remove `DummyVM`, and remove `./examples` which uses `DummyVM`.
* Change CI scripts to run tests with `MockVM`.
* Remove `pub` visibility for some modules. Those modules were exposed
so we can test them from `DummyVM`. As now `MockVM` is a part of the
main crate, we can test private items. We no longer need `pub` for those
modules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-test Area: Testing C-enhancement Category: Enhancement F-project Call For Participation: Student projects. These issues are available student projects.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants