1*910382afSGarrett D'Amore# 2*910382afSGarrett D'Amore# This file and its contents are supplied under the terms of the 3*910382afSGarrett D'Amore# Common Development and Distribution License ("CDDL"), version 1.0. 4*910382afSGarrett D'Amore# You may only use this file in accordance with the terms of version 5*910382afSGarrett D'Amore# 1.0 of the CDDL. 6*910382afSGarrett D'Amore# 7*910382afSGarrett D'Amore# A full copy of the text of the CDDL should have accompanied this 8*910382afSGarrett D'Amore# source. A copy of the CDDL is also available via the Internet at 9*910382afSGarrett D'Amore# http://www.illumos.org/license/CDDL. 10*910382afSGarrett D'Amore# 11*910382afSGarrett D'Amore 12*910382afSGarrett D'Amore# 13*910382afSGarrett D'Amore# Copyright 2014 Garrett D'Amore <garrett@damore.org> 14*910382afSGarrett D'Amore# 15*910382afSGarrett D'Amore 16*910382afSGarrett D'AmoreThe configuration files in this directory are structured as lines, 17*910382afSGarrett D'Amorewhere each line is made up of fields, separated by "|" characters, 18*910382afSGarrett D'Amorepossibly surrounded by whitespace. 19*910382afSGarrett D'Amore 20*910382afSGarrett D'AmoreNew lines preceeded by backslashes are ignored, allowing for a continuation 21*910382afSGarrett D'Amoreof lines, in the usual UNIX way. 22*910382afSGarrett D'Amore 23*910382afSGarrett D'AmoreA line beginning with a hashmark is a comment, and is ignored, as are lines 24*910382afSGarrett D'Amoreconsisting solely of whitespace. 25*910382afSGarrett D'Amore 26*910382afSGarrett D'AmoreThe first field is always the "keyword", which determines the meaning and 27*910382afSGarrett D'Amorepresence of any other fields. 28*910382afSGarrett D'Amore 29*910382afSGarrett D'AmoreThese files are parsed using the test_load_config() function. This 30*910382afSGarrett D'Amorefunction has the following prototype: 31*910382afSGarrett D'Amore 32*910382afSGarrett D'Amore int test_load_config(test_t, const char *, ...); 33*910382afSGarrett D'Amore 34*910382afSGarrett D'AmoreThe variable arguments are the keywords and handling functions. These 35*910382afSGarrett D'Amoremust be supplied in pairs and the list is terminated with a NULL, like this: 36*910382afSGarrett D'Amore 37*910382afSGarrett D'Amore test_config_load(t, "myfile.cfg", "mykeyword", keywordcb, NULL); 38*910382afSGarrett D'Amore 39*910382afSGarrett D'AmoreThe test_config_load function will search for the named file (provided it 40*910382afSGarrett D'Amoreis not an absolute path) in a few locations: 41*910382afSGarrett D'Amore 42*910382afSGarrett D'Amore * relative to the current directory, exactly as specified 43*910382afSGarrett D'Amore * relative to $STF_SUITE/cfg/ (if $STF_SUITE is defined) 44*910382afSGarrett D'Amore * relative to ../../cfg/ (if $STF_SUITE is undefined) 45*910382afSGarrett D'Amore * relative to cfg/ 46*910382afSGarrett D'Amore 47*910382afSGarrett D'AmoreThe handling functions (keywordcb in the example above) have the following 48*910382afSGarrett D'Amoretypedef: 49*910382afSGarrett D'Amore 50*910382afSGarrett D'Amore typedef int (*test_cfg_func_t)(char **fields, int nfields, char **err); 51*910382afSGarrett D'Amore 52*910382afSGarrett D'Amoreso for example, keywordcb should be declared thusly: 53*910382afSGarrett D'Amore 54*910382afSGarrett D'Amore int keywordcb(char **fields, int nfields, char **err); 55*910382afSGarrett D'Amore 56*910382afSGarrett D'AmoreThese functions are called each time a paired keyword is seen in the file. 57*910382afSGarrett D'Amore"fields" is an array of fields, pre-split with surrounding whitespace removed, 58*910382afSGarrett D'Amoreand contains "nfields" items. Internal whitespace is unaffected. 59*910382afSGarrett D'Amore 60*910382afSGarrett D'AmoreThe function should return 0 on successful handling, or -1 on failure. In 61*910382afSGarrett D'Amorethe event of failure, it should record an error string in "err" using 62*910382afSGarrett D'Amoreasprintf() or strdup(). ("err" should be unmodified otherwise.) 63*910382afSGarrett D'Amore 64*910382afSGarrett D'AmoreThis parser is rather simplistic, and it lacks support for embedding "|" 65*910382afSGarrett D'Amorefields in lines, and also doesn't support escaping, so you can't add "\" 66*910382afSGarrett D'Amoreat the end of a line (if you need that, leave some trailing whitespace). 67*910382afSGarrett D'Amore 68*910382afSGarrett D'AmoreThere are also some internal limits on the length of lines (1K), and on the 69*910382afSGarrett D'Amorenumber of fields (20). As this is only used for these test suites, this 70*910382afSGarrett D'Amoreshould not be a significant limitation. 71*910382afSGarrett D'Amore 72*910382afSGarrett D'AmorePlease see ../tests/symbols/symbols_test.c for an example of correct usage. 73*910382afSGarrett D'Amore 74*910382afSGarrett D'AmoreAside: 75*910382afSGarrett D'Amore 76*910382afSGarrett D'Amore Astute readers may ask why invent a new configuration file, and why use 77*910382afSGarrett D'Amore position based parsing instead of name value pairs. These files are 78*910382afSGarrett D'Amore optimized for specific needs, and intended to support relatively dense 79*910382afSGarrett D'Amore information in a format that is easy for humans to work with. JSON or XML 80*910382afSGarrett D'Amore or even YAML could have served, but the overhead of a syntax was more than 81*910382afSGarrett D'Amore we wanted to introduce. Test suites are free to use other formats if they 82*910382afSGarrett D'Amore choose, but this simple format has the advantage of being built-in and 83*910382afSGarrett D'Amore easy to use. 84