aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorCyril Hrubis <chrubis@suse.cz>2015-03-09 17:35:43 +0100
committerCyril Hrubis <chrubis@suse.cz>2015-03-10 11:36:01 +0100
commitd6d11d08678aac1ed2c370ea8e42e5f45aea07be (patch)
tree06c02a2384125f70518c1dccfe00cdf16ed63133 /doc
parent0eeb59587ba239eed131677655a9c131681d20a6 (diff)
Introduce tst_parse_opts()
The pattern that was used in all testcases is: const char *msg; msg = parse_opts(...); if (msg) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); This change simplifies the steps to just calling: tst_parse_opts(...); Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'doc')
-rw-r--r--doc/test-writing-guidelines.txt24
1 files changed, 19 insertions, 5 deletions
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 203a1eb2c..73e14e6b8 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -279,11 +279,9 @@ static void test(void)
int main(int argc, char *argv[])
{
- const char *msg;
int lc;
- if ((msg = parse_opts(argc, argv, NULL, NULL)))
- tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ tst_parse_opts(argc, argv, NULL, NULL);
setup();
@@ -319,8 +317,24 @@ WARNING: Don't use 'tst_brkm()' in 'cleanup()' unless you really want to exit
the cleanup prematurely. See discussion below for further
information.
-The 'parse_opts()' parses the test command line arguments, it's important to
-use it even if the test has no (other than default) parameters.
+[source,c]
+-------------------------------------------------------------------------------
+typedef struct {
+ char *option; /* Valid option string (one option only) like "a:" */
+ int *flag; /* Pointer to location to set true if option given */
+ char **arg; /* Pointer to location to place argument, if needed */
+} option_t;
+
+void tst_parse_opts(int argc, char *argv[], const option_t *user_optarg,
+ void (*user_help)(void));
+-------------------------------------------------------------------------------
+
+The 'tst_parse_opts()' parses the test command line arguments, it's important
+to use it even if the test has no (other than default) parameters.
+
+Test specific parameters can be passed to the function by the 'NULL' terminated
+'user_optarg' array as far as they don't conflict with the parameters used by
+the test library (these can be listed by passing '-h' to a LTP testcase).
The last important thing is the 'TEST_LOOPING()' macro, each test has standard
options so that it can be executed N times or for M seconds.