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

Fix tests bench --opt=all and tests all --no-acvp #398

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

potsrevennil
Copy link
Contributor

No description provided.

Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have time to review another big refactor of the test scripts - can you please cut this down to just what is necessary to make it work? For example, just the first commit would be fine.

Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @potsrevennil. As discussed offline, please don't mix bugfixes and refactoring anymore in the future.

For the review of the bugfix, could you please describe in the commit message what the bug was in the first place (What did you do? What was the expected behaviour? What was the actual behaviour?) and brieflt how it is fixed?

Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but the 2nd commit message is not enough for me to understand what is going on, and I am not convinced that the refactoring is a net benefit. I will open a separate PR with just the bugfix.

@potsrevennil
Copy link
Contributor Author

@hanno-becker Done

@hanno-becker
Copy link
Contributor

#407 cherry-picks first commit.

@potsrevennil potsrevennil force-pushed the fix-tests branch 3 times, most recently from 95b89db to 4535d9f Compare November 14, 2024 10:15
@potsrevennil
Copy link
Contributor Author

I tried to make the git diff looked friendlier, hope that it'd be clear that this was just a simple rewrite, which is just merging the conditional compile and run_schemes local functions (ex: _func in func) into a general function Test_Implementation.test to avoid similar mistake fixed in the first commit

@hanno-becker
Copy link
Contributor

@potsrevennil I seem to remember there a different diff options locally at least... anyone in particular that will make it more obvious what is happening?

@@ -307,32 +319,27 @@ def expect(scheme: SCHEME, actual: str) -> tuple[bool, str]:
f"Failed, expecting {expect}, but getting {actual}" if fail else "",
)

return self._func.run_schemes(
return self._f(TEST_TYPES.MLKEM).test(
Copy link
Contributor

@hanno-becker hanno-becker Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the commit message I was expecting to see pairs of compile+run being replaced by test, but here we only call run_schemes before, while the new call to test() would additionally compile. Is that deliberate? Do we end up compiling more often than we did before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally, the paris of compile+run is in the local function _func in func
so the self._func is actually a replacement of the local function _func in self.func

so before the function calls was like

func -> local _func -> self._func.compile+ self._run_func -> self._func.run_schemes
all -> self._func.compile + self._run_func -> self._func.run_schemes

which is pretty hard to understand

it now became

func -> self._func -> self.__func.test -> self.__func.compile + self.__func.run_schemes
all -> self._func -> self.__func.test -> self.__func.compile + self.__func.run_schemes

self.compile_mode = copts.compile_mode()
self.compile = opts.compile
self.run = opts.run

def _run_func(self, opt: bool):
def _func(self, opt: bool, compile: bool, run: bool) -> TypedDict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this indirection needed? Can we not inline all of this into self.func?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but in the functions like self.func, there's logger configuration,
which means if I called self.func instead in all, then the logger would be configured multiple times.
and also in self.func if --opt=all it'd compile/run both the implementations, but in all we need to first compile/run one implementation then do the other due to the current build system restriction, therefore if without the indirection, there might required more changes in all
As we have discussed about build system change in the future (separate opt/non-opt build artifacts), once it's done, we could thus remove this annoying indirection by the way.

@@ -526,29 +525,32 @@ def init_results() -> TypedDict:

return fail

def _acvp(self, opt: bool, compmile: bool, run: bool, acvp_dir: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this handled differently from say _func? In _func, you just call self._f(...).test(), which bundles compile and run -- while here you still call both separately. Note also that L530 and L532 do not operate on the same test object -- they call _f twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the way we run acvp is very different from the other tests, the other tests only run once for each parameter set, but acvp test is run multiple times for each parameter set with different test vectors.
it's too hard and not necessary to reuse the same function test for now.

Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change makes the test script easier to understand than before. On the contrary, we now have one more indirection, namely a function self._f() returning a test object, and as indicated in the comments, we're at times compiling and running in separate test objects which morally ought to be the same (and were, previously).

@potsrevennil Could you think about how we can remove indirections rather than adding more?

Merge the call for compile and run_schemes into `Test_Implementations.test` function,
thus remove the repeated `if compile ... if run ...` part in test functions

Signed-off-by: Thing-han, Lim <[email protected]>
@potsrevennil
Copy link
Contributor Author

@hanno-becker thanks for the comment!
I removed one indirection, I think the indirections should be the same as before now.
And as I commented, once we have a build system that can separate opt/non-opt built artifacts, we could further reduce indriections, to make the tests script more readible.

@hanno-becker
Copy link
Contributor

hanno-becker commented Nov 15, 2024

@potsrevennil Thank you for the explanations, which I am still to read closely. On first though, we now have self.func, self._func and self.__func, which really can't be it, I feel.

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.

3 participants