pioneers / runtime

Firmware for the PiE kit robots and devices
7 stars 2 forks source link

[EXECUTOR] Fix regex for subscription parsing in student code #167

Closed levincent06 closed 3 years ago

levincent06 commented 3 years ago

The regex matching is made to be more precise to capture subscribed params via Robot.get_value(). The regex now properly handles whitespace, multiple subscriptions per line, and variable name-sharing.

Important note: if the student code has a variable that shares the name with a variable used in studentcode.pyx, then eval(<that variable>) would cause undefined behavior. For example, if the student named a variable code_file in their code, it may evaluate to studentcode, as it does in studentcode.pyx. To reduce the occurrence of this, we prefixed all variables in get_all_params with an underscore, assuming that students won't do the same.

Test tc_159_1 covers several cases that should (or shouldn't) prompt a subscription. This test may fail for the current executor. To properly check the device subscriptions, a new assertion check_sub_requests was added to test.c.

A utility function check_start_pos() was also added to test.c/test.h and tc_71_1 was changed accordingly to avoid using the shared memory print function.

Finally, this PR also adds additional sleeps to tc_150_1 because it sometimes fails due to latency between when a user input is sent and when it changes in shared memory.

Resolves #159