|
| 1 | +====================== |
| 2 | +Migrating to ReFrame 3 |
| 3 | +====================== |
| 4 | + |
| 5 | + |
| 6 | +Updating your tests |
| 7 | +------------------- |
| 8 | + |
| 9 | + |
| 10 | +ReFrame 2.20 introduced a new powerful mechanism for attaching arbitrary functions hooks at the different pipeline stages. |
| 11 | +This mechanism provides an easy way to configure and extend the functionality of a test, eliminating essentially the need to override pipeline stages for this purpose. |
| 12 | +ReFrame 3.0 deprecates the old practice for overriding pipeline stage methods in favor of using pipeline hooks. |
| 13 | +In the old syntax, it was quite common to override the ``setup()`` method, in order to configure your test based on the current programming environment or the current system partition. |
| 14 | +The following is a typical example of that: |
| 15 | + |
| 16 | + |
| 17 | +.. code:: python |
| 18 | +
|
| 19 | + def setup(self, partition, environ, **job_opts): |
| 20 | + if environ.name == 'gnu': |
| 21 | + self.build_system.cflags = ['-fopenmp'] |
| 22 | + elif environ.name == 'intel': |
| 23 | + self.build_system.cflags = ['-qopenmp'] |
| 24 | +
|
| 25 | + super().setup(partition, environ, **job_opts) |
| 26 | +
|
| 27 | +
|
| 28 | +Alternatively, this example could have been written as follows: |
| 29 | + |
| 30 | +.. code:: python |
| 31 | +
|
| 32 | + def setup(self, partition, environ, **job_opts): |
| 33 | + super().setup(partition, environ, **job_opts) |
| 34 | + if self.current_environ.name == 'gnu': |
| 35 | + self.build_system.cflags = ['-fopenmp'] |
| 36 | + elif self.current_environ.name == 'intel': |
| 37 | + self.build_system.cflags = ['-qopenmp'] |
| 38 | +
|
| 39 | +
|
| 40 | +This syntax now issues a deprecation warning. |
| 41 | +Rewriting this using pipeline hooks is quite straightforward and leads to nicer and more intuitive code: |
| 42 | + |
| 43 | +.. code:: python |
| 44 | +
|
| 45 | + @rfm.run_before('compile') |
| 46 | + def setflags(self): |
| 47 | + if self.current_environ.name == 'gnu': |
| 48 | + self.build_system.cflags = ['-fopenmp'] |
| 49 | + elif self.current_environ.name == 'intel': |
| 50 | + self.build_system.cflags = ['-qopenmp'] |
| 51 | +
|
| 52 | +
|
| 53 | +You could equally attach this function to run after the "setup" phase with ``@rfm.run_after('setup')``, as in the original example, but attaching it to the "compile" phase makes more sense. |
| 54 | +However, you can't attach this function *before* the "setup" phase, because the ``current_environ`` will not be available and it will be still ``None``. |
| 55 | + |
| 56 | + |
| 57 | +Force override a pipeline method |
| 58 | +================================ |
| 59 | + |
| 60 | +Although pipeline hooks should be able to cover almost all the cases for writing tests in ReFrame, there might be corner cases that you need to override one of the pipeline methods, e.g., because you want to implement a stage differently. |
| 61 | +In this case, all you have to do is mark your test class as "special", and ReFrame will not issue any deprecation warning if you override pipeline stage methods: |
| 62 | + |
| 63 | +.. code:: python |
| 64 | +
|
| 65 | + class MyExtendedTest(rfm.RegressionTest, special=True): |
| 66 | + def setup(self, partition, environ, **job_opts): |
| 67 | + # do your custom stuff |
| 68 | + super().setup(partition, environ, **job_opts) |
| 69 | +
|
| 70 | +
|
| 71 | +If you try to override the ``setup()`` method in any of the subclasses of ``MyExtendedTest``, you will still get a deprecation warning, which a desired behavior since the subclasses should be normal tests. |
| 72 | + |
| 73 | + |
| 74 | +Suppressing deprecation warnings |
| 75 | +================================ |
| 76 | + |
| 77 | +You can suppress any deprecation warning issued by ReFrame by passing the ``--no-deprecation-warnings`` flag. |
| 78 | + |
0 commit comments