AdaCore / e3-core

Core framework for developing portable automated build systems
26 stars 36 forks source link

Allow serializing BaseEnv instances #723

Open peniblec opened 3 months ago

peniblec commented 3 months ago

Hi!

Some e3-testsuite-based testsuites define a test.py script for each testcase, make the driver execute that script plus some pre-/post-processing steps. These test.py scripts typically import a harness module shared with the main testsuite process, and that module will load data that has been serialized by the driver.

This data generally includes

As things stand, testsuite drivers need to devise their own serialization strategy, e.g. a record where the driver will tuck Env() platforms, test_env items, etc; the driver will pickle that record, spawn test.py and let it un-pickle the record.

It would be convenient to use e3.env's existing de/serialization code for this, using a protocol along the lines of:

# Driver side:
testcase_env = BaseEnv.from_env()       # Copy Env singleton into a non-global instance.
testcase_env.test_env = self.test_env   # Add per-testcase data.
testcase_env.store(self.working_dir(harness.TESTCASE_ENV_FILE))
self.shell(["test.py"])                 # Spawn test.py in self.working_dir().

# test.py side:
Env.restore(harness.TESTCASE_ENV_FILE)

However, currently this cannot work:

Filing this enhancement request after chatting with @Nikokrock. The title might be too biased toward a preconceived solution; open to discussing the use-case more and seeing where else we can go.