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

pyapi: generate basic python bindings with PyO3 #165

Merged
merged 80 commits into from
Mar 22, 2021
Merged

Conversation

Wenzel
Copy link
Owner

@Wenzel Wenzel commented Feb 2, 2021

Generate (basic) python bindings to initialize libmicromi from Python, based on PyO3
fix #162

Capture d’écran de 2021-02-02 16-21-12

@Wenzel Wenzel force-pushed the python_bindings branch 2 times, most recently from 02bca72 to 84949bc Compare February 2, 2021 20:53
@codecov-io
Copy link

codecov-io commented Feb 2, 2021

Codecov Report

Merging #165 (d4414ab) into master (cb49f1a) will decrease coverage by 0.18%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #165      +/-   ##
==========================================
- Coverage   14.80%   14.61%   -0.19%     
==========================================
  Files           5        5              
  Lines         466      472       +6     
  Branches       86       87       +1     
==========================================
  Hits           69       69              
- Misses        377      383       +6     
  Partials       20       20              
Flag Coverage Δ
unittests 14.61% <0.00%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/api.rs 0.00% <ø> (ø)
src/capi.rs 0.00% <0.00%> (ø)
src/driver/kvm.rs 23.20% <0.00%> (-0.16%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb49f1a...d4414ab. Read the comment docs.

@Wenzel
Copy link
Owner Author

Wenzel commented Feb 2, 2021

So I managed to expose the DriverType and DriverInitParam types to Python.

It might not be the best way, but it works
Capture d’écran de 2021-02-02 22-14-44

There is an opened issue on PyO3 to discuss how they should implement and expose Rust enum to Python.
Maybe in the future we could remove this code and let it managed by PyO3.

@Wenzel
Copy link
Owner Author

Wenzel commented Feb 2, 2021

Note: I had to remove the conditional compilation in DriverType:
https://github.com/Wenzel/libmicrovmi/pull/165/files#diff-adea2445327e39eb215de697b440dbbc02135357380fb612a10a9e659129a46bL25

But this is what we wanted with #151 anyway, so i will rebase once this other PR merged.

@Wenzel Wenzel force-pushed the python_bindings branch 9 times, most recently from 7dff700 to 1d2e2c2 Compare February 4, 2021 12:40
python/Cargo.toml Outdated Show resolved Hide resolved
python/setup.py Outdated Show resolved Hide resolved
@Wenzel Wenzel force-pushed the python_bindings branch 4 times, most recently from 951357c to 532bd02 Compare February 4, 2021 18:59
@Wenzel
Copy link
Owner Author

Wenzel commented Feb 5, 2021

Capture d’écran de 2021-02-05 09-26-09
library init works (here on Xen), but read_physical implementation returns an empty List (?)

@Wenzel
Copy link
Owner Author

Wenzel commented Feb 5, 2021

Ok, so, this implementation is not working:

        let mut buffer = Vec::with_capacity(size);
        self.driver.read_physical(paddr, &mut buffer).map_err(PyMicrovmiError::from)?;
        debug!("buffer = {:?}", buffer);

but this one is:

        let mut buffer2: [u8; 1024] = [0; 1024];
        self.driver.read_physical(paddr, &mut buffer2).map_err(PyMicrovmiError::from)?;
        debug!("buffer2 = {:?}", buffer2);

Why I can't manage to fill my vector and return it ?
Capture d’écran de 2021-02-05 11-25-44

@Wenzel
Copy link
Owner Author

Wenzel commented Feb 5, 2021

Ok, so the catch was that Vec::with_capacity was creating an empty vec, so the array had a size of 0 🤡

This is fixed now.

@Wenzel Wenzel force-pushed the python_bindings branch 3 times, most recently from ed2e5ab to d4414ab Compare March 19, 2021 12:01
@Wenzel Wenzel merged commit df95347 into master Mar 22, 2021
@Wenzel Wenzel deleted the python_bindings branch March 22, 2021 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libmicrovmi python bindings
3 participants