lib/igt_debugfs: s/igt_pipe_crc_check/igt_require_pipe_crc/
PATCH 1/3 lib/igt_debugfs: s/igt_pipe_crc_check/igt_require_pipe_crc/
Functions which provide feature checks through igt_skip should be of the form <prefix>_require_<feature>.
Otoh feature checks which return in a boolean whether the feature is available should be of the form <prefix>_has_<feature>, e.g. gem_has_blt.
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt_debugfs.c | 4 ++-- lib/igt_debugfs.h | 2 +- tests/kms_cursor_crc.c | 2 +- tests/kms_fbc_crc.c | 2 +- tests/kms_pipe_crc_basic.c | 2 +- tests/kms_plane.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
lib/igt_debugfs.c +2 -2
@@ -320,13 +320,13 @@ static void pipe_crc_exit_handler(int sig) }/** -* igt_pipe_crc_check: +* igt_require_pipe_crc: * * Convenience helper to check whether pipe CRC capturing is supported by the * kernel. Uses igt_skip to automatically skip the test/subtest if this isn't * the case. */ -void igt_pipe_crc_check (void ) +void igt_require_pipe_crc (void ) {const char *cmd ="pipe A none" ;FILE *ctl;
lib/igt_debugfs.h +1 -1
@@ -89,7 +89,7 @@ bool igt_crc_is_null(igt_crc_t *crc);bool igt_crc_equal (igt_crc_t *a,igt_crc_t *b);char *igt_crc_to_string (igt_crc_t *crc); -void igt_pipe_crc_check (void ); +void igt_require_pipe_crc (void );igt_pipe_crc_t *igt_pipe_crc_new (enum pipe pipe,enum intel_pipe_crc_source source);void igt_pipe_crc_free (igt_pipe_crc_t *pipe_crc);
tests/kms_cursor_crc.c +1 -1
@@ -316,7 +316,7 @@ igt_mainigt_set_vt_graphics_mode (); -igt_pipe_crc_check (); +igt_require_pipe_crc ();igt_display_init (&data.display, data.drm_fd); data.pipe_crc = calloc(igt_display_get_n_pipes(&data.display),
tests/kms_fbc_crc.c +1 -1
@@ -491,7 +491,7 @@ igt_main data.devid =intel_get_drm_devid (data.drm_fd); -igt_pipe_crc_check (); +igt_require_pipe_crc (); status =igt_debugfs_fopen ("i915_fbc_status" ,"r" );igt_require_f (status,"No i915_fbc_status found\n" );
tests/kms_pipe_crc_basic.c +1 -1
@@ -137,7 +137,7 @@ igt_mainigt_set_vt_graphics_mode (); -igt_pipe_crc_check (); +igt_require_pipe_crc ();igt_display_init (&data.display, data.drm_fd); }
tests/kms_plane.c +1 -1
@@ -229,7 +229,7 @@ igt_mainigt_set_vt_graphics_mode (); -igt_pipe_crc_check (); +igt_require_pipe_crc ();igt_display_init (&data.display, data.drm_fd); }
Signature · 1 line
1.8.1.4
PATCH 2/3 lib/igt_core: Small api doc fix
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_core.c +1 -1
@@ -955,7 +955,7 @@ static void fatal_sig_handler(int sig)* The handler will be passed the signal number if called due to a signal, or * 0 otherwise. Exit handlers can also be used from test children spawned with * igt_fork(), but not from within helper processes spawned with -* igt_helper_process(). The list of exit handlers is reset when forking to +* igt_fork_helper(). The list of exit handlers is reset when forking to * avoid issues with children cleanup up the parent's state too early. */ void igt_install_exit_handler (igt_exit_handler_t fn)
Signature · 1 line
1.8.1.4
PATCH 3/3 lib/igt_core: Document library design best practices
In reply to Daniel VetterThis is what I've been doing in the past few months when refactoring i-g-t code. More ideas and also patterns to add highly welcome.
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt_core.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
lib/igt_core.c +49 -0
@@ -115,6 +115,55 @@* - "they are local to the function that made the corresponding setjmp() call; * - "their values are changed between the calls to setjmp() and longjmp(); and * - "they are not declared as volatile." +* +* # Best Practices for Test Helper Libraries Design +* +* Kernel tests itself tend to have fairly complex logic already. It is +* therefore paramount that helper code, both in libraries and test-private +* function, add as little boilerplate code to the main test logic as possible. +* But then dense code is hard to understand without constantly consulting +* documentation and implementation of all the helper functions if it doesn't +* follow some clear patterns. Hence follow these established best practices: +* +* - Make extensive use of the implicit control flow afforded by igt_skip(), +* igt_fail and igt_success(). When dealing with optional kernel features +* combine igt_skip() with igt_fail() to skip when the kernel support isn't +* available but fail when anything else goes awry. void should be the most +* common return type in all your functions. +* +* - Main test logic should have no explicit control flow for failure +* conditions, but instead such assumptions should be written in a declarative +* style. Use one of the many macros which encapsulate i-g-t's implicit +* control flow. Pick the most suitable one to have as much debug output as +* possible, without polluting the code unecessarily. For example +* igt_assert_cmpint() for comparing integers or do_ioctl() for running ioctls +* and checking their results. Feel free to add new ones to the libary or +* wrap up a set of checks into a private function to further condense your +* test logic. +* +* - When adding a new feature test function which uses igt_skip() internally, +* use the <prefix>_require_<feature_name> naming scheme. When you +* instead add a feature test function which returns a boolean, because your +* main test logic must take different actions depending upon the feature's +* availability, then instead use the <prefix>_has_<feature_name>. +* +* - As already mentioned eschew explicit error handling logic as much as +* possible. If your test absolutely has to handle the error of some function +* the customary naming pattern is to prefix those variants with __. Try to +* restrict explicit error handling to leaf functions. For the main test flow +* simply pass the expected error condition down into your helper code, which +* results in tidy and declarative test logic. +* +* - Make your library functions as simple to use as possible. Automatically +* register cleanup handlers through igt_install_exit_handler(). Reduce the +* amount of setup boilerplate needed by using implicit singletons and lazy +* structure initialization and similar design patterns as much as possible. +* +* - Don't shy away from refactoring common code, even when there are just 2-3 +* users and even if it's not a net reduction in code. As long as it helps to +* remove boilerplate and makes the code more declarative the resulting +* clearer test flow is worth it. All i-g-t library code has been organically +* extracted from testcases in this fashion. */ static unsigned int exit_handler_count;
Signature · 1 line
1.8.1.4